From 94a56f69e3aec739d6414c6f4ff316f47ab03d2f Mon Sep 17 00:00:00 2001 From: Aviral Saxena Date: Sat, 28 Feb 2026 00:47:29 +0530 Subject: [PATCH] Added regression tests --- .github/workflows/backend-ci.yml | 43 +++++++++++++++++ apps/backend/tests/test_api_schema.py | 24 ++++++++++ apps/backend/tests/test_regression.py | 46 +++++++++++++++++++ apps/frontend/src/app/_home/UploadButtons.tsx | 2 +- .../frontend/src/app/_home/WhatIsThisTool.tsx | 4 +- .../src/app/_layout/navigation-data.ts | 4 +- .../src/app/convert/dcm-to-bdis/page.tsx | 2 +- docs/assets/Package-Arch.svg | 2 +- docs/development/architecture.mdx | 2 +- docs/user-guide/quick-start.mdx | 2 +- 10 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/backend-ci.yml create mode 100644 apps/backend/tests/test_api_schema.py create mode 100644 apps/backend/tests/test_regression.py diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml new file mode 100644 index 00000000..65801f3e --- /dev/null +++ b/.github/workflows/backend-ci.yml @@ -0,0 +1,43 @@ +name: Backend CI + +on: + push: + paths: + - "apps/backend/**" + - "package/**" + pull_request: + paths: + - "apps/backend/**" + - "package/**" + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + cd apps/backend + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest pytest-regressions httpx + + - name: Install package (editable) + run: | + cd package + pip install -e . + + - name: Run tests + run: | + cd apps/backend + pytest -v \ No newline at end of file diff --git a/apps/backend/tests/test_api_schema.py b/apps/backend/tests/test_api_schema.py new file mode 100644 index 00000000..bac9a562 --- /dev/null +++ b/apps/backend/tests/test_api_schema.py @@ -0,0 +1,24 @@ +from fastapi.testclient import TestClient +from app.main import app + +client = TestClient(app) + + +def test_bids_endpoint_returns_expected_schema(): + response = client.post( + "/api/report/process/bids", + data={"modality": "ASL"} + ) + + assert response.status_code == 200 + data = response.json() + + expected_keys = { + "basic_report", + "extended_report", + "asl_parameters", + "errors", + "warnings", + } + + assert expected_keys.issubset(data.keys()) \ No newline at end of file diff --git a/apps/backend/tests/test_regression.py b/apps/backend/tests/test_regression.py new file mode 100644 index 00000000..e2a42f6b --- /dev/null +++ b/apps/backend/tests/test_regression.py @@ -0,0 +1,46 @@ +from fastapi.testclient import TestClient +from app.main import app + +client = TestClient(app) + + +def normalize_response(data: dict) -> dict: + """ + Remove volatile fields to ensure deterministic regression. + """ + data.pop("nifti_slice_number", None) + return data + + +def test_root_endpoint_regression(data_regression): + response = client.get("/") + assert response.status_code == 200 + + data = response.json() + data_regression.check(data) + + +def test_bids_endpoint_regression(data_regression): + response = client.post( + "/api/report/process/bids", + data={"modality": "ASL"} + ) + + assert response.status_code == 200 + + data = normalize_response(response.json()) + data_regression.check(data) + + +def test_dicom_invalid_file_returns_500(tmp_path): + file_path = tmp_path / "invalid.txt" + file_path.write_text("not a dicom") + + with open(file_path, "rb") as f: + response = client.post( + "/api/report/process/dicom", # fixed /api prefix + files={"dcm_files": ("invalid.txt", f, "text/plain")}, + data={"modality": "ASL"}, + ) + + assert response.status_code == 500 \ No newline at end of file diff --git a/apps/frontend/src/app/_home/UploadButtons.tsx b/apps/frontend/src/app/_home/UploadButtons.tsx index 5c141393..40de33ca 100644 --- a/apps/frontend/src/app/_home/UploadButtons.tsx +++ b/apps/frontend/src/app/_home/UploadButtons.tsx @@ -126,7 +126,7 @@ const UploadButtons = () => { )} onClick={() => setActiveFileTypeOption(UploadDataType.BIDS)} > - BDIS + BIDS diff --git a/apps/frontend/src/app/_layout/navigation-data.ts b/apps/frontend/src/app/_layout/navigation-data.ts index 2a52bb75..583e8059 100644 --- a/apps/frontend/src/app/_layout/navigation-data.ts +++ b/apps/frontend/src/app/_layout/navigation-data.ts @@ -42,8 +42,8 @@ const NavData: { countType: "warnings", }, { - title: "Convert DICOM to BDIS", - url: "/convert/dcm-to-bdis", + title: "Convert DICOM to BIDS", + url: "/convert/dcm-to-bids", icon: IconTransform, showCount: false, } diff --git a/apps/frontend/src/app/convert/dcm-to-bdis/page.tsx b/apps/frontend/src/app/convert/dcm-to-bdis/page.tsx index f5f34d2e..7185100a 100644 --- a/apps/frontend/src/app/convert/dcm-to-bdis/page.tsx +++ b/apps/frontend/src/app/convert/dcm-to-bdis/page.tsx @@ -2,7 +2,7 @@ const Page = () => { return (
-

DCM to BDIS Conversion

+

DCM to BIDS Conversion

This feature is under development.

); diff --git a/docs/assets/Package-Arch.svg b/docs/assets/Package-Arch.svg index 62e00c51..819d25f2 100644 --- a/docs/assets/Package-Arch.svg +++ b/docs/assets/Package-Arch.svg @@ -1,4 +1,4 @@ -
Core
IO
Modalities
Sequences
Converters
Utils
CLI
ASL
DSC
Processors
Validators
Utils
Readers
Writers
PCASL_siemens
CASL_ucl
DICOM to BDIS
Desktop App
Web App
CLI App
Tests
\ No newline at end of file +
Core
IO
Modalities
Sequences
Converters
Utils
CLI
ASL
DSC
Processors
Validators
Utils
Readers
Writers
PCASL_siemens
CASL_ucl
DICOM to BIDS
Desktop App
Web App
CLI App
Tests
\ No newline at end of file diff --git a/docs/development/architecture.mdx b/docs/development/architecture.mdx index a4306b26..fc508fe7 100644 --- a/docs/development/architecture.mdx +++ b/docs/development/architecture.mdx @@ -95,7 +95,7 @@ modalities/ #### Sequence Management -This Handles the extraction of BDIS metadata (e.g. asl.json) from DICOM for vendors and organization implementation of modalities +This Handles the extraction of BIDS metadata (e.g. asl.json) from DICOM for vendors and organization implementation of modalities ``` sequences/ diff --git a/docs/user-guide/quick-start.mdx b/docs/user-guide/quick-start.mdx index b337ac0b..af3cb8bb 100644 --- a/docs/user-guide/quick-start.mdx +++ b/docs/user-guide/quick-start.mdx @@ -58,7 +58,7 @@ If you have DICOM files: - Or drag and drop files directly 2. **Select Data Type**: - - Choose "BDIS" for BIDS format + - Choose "BIDS" for BIDS format - Choose "DICOM" for DICOM files 3. **Select Modality**: