FFFF BUG: Reject extra JSON content in strict comparisons by jdotc1 · Pull Request #567 · QIICR/dcmqi · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: '3.10.11'
python-version: '3.10'

- name: "Install jsondiff"
run: pip install jsondiff
Expand Down Expand Up @@ -105,7 +105,7 @@
if: ${{ (github.event_name != 'pull_request') && (github.repository_owner == 'QIICR')}}
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} && \
docker push qiicr/dcmqi:`git describe --tags --exact-match 2> /dev/null || echo "latest"` \

Check warning on line 108 in .github/workflows/cmake-linux.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace backticks with '$()' syntax for command substitution.

See more on https://sonarcloud.io/project/issues?id=QIICR_dcmqi&issues=AaHLbAnViTxU0BsvbH2h&open=AaHLbAnViTxU0BsvbH2h&pullRequest=567
|| echo "skipping docker push"

- name: "Upload package as artifact"
Expand Down
31 changes: 16 additions & 15 deletions .github/workflows/cmake-macos.ym 8000 l
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
build-macos:

runs-on: ${{ matrix.runner }}
# So far, a full superbuild (no caches) has always been complete in < 45 minutes.
timeout-minutes: 45
# Cold Intel superbuilds can exceed 45 minutes before tests and packaging.
timeout-minutes: ${{ matrix.arch == 'x86_64' && 90 || 45 }}

permissions:
contents: write
Expand Down Expand Up @@ -144,9 +144,23 @@ jobs:

# Build dcmqi
- name: "Build dcmqi"
id: build
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix adding id: build. One remaining gap: the save step (line 191) runs after Test and Package, behind !cancelled(). If 8000 a cold Intel build plus the full test run hits the 90-minute job timeout, the job is cancelled and the cache is never saved, so the next run starts cold again. Moving the cache save to right after the build step would avoid that.

Related, though outside this diff: .github/workflows/cmake-win.yml has the same bug this PR fixes on macOS. Its save step (line 128) checks steps.build.outcome, but the "Build dcmqi" step (line 83) has no id: build, so Windows never saves its dependency cache. Adding the id there, in this PR or a follow-up, would fix it.

🤖 Comment generated by Claude (Claude Code), posted on behalf of @fedorov.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed both caching points in bb84de0. On macOS, dependency cache saving runs immediately after a successful build, before dciodvfy checks, tests, and packaging. Windows now has id: build and likewise saves dependencies immediately after the build. The original cache keys, paths, and conditions are preserved. Both workflow YAML files parse and the new ordering was checked locally.

run: |
cd ${{ github.workspace }}/dcmqi-build && ninja

# Persist a successful cold build before tests/packaging can time out.
- name: Save DCMTK, ITK and ZLIB cache
if: ${{ !cancelled() && steps.build.outcome == 'success' && steps.cache-dcmtk-itk-zlib.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v6
with:
path: |
${{ github.workspace }}/dcmqi-build/DCMTK
${{ github.workspace }}/dcmqi-build/DCMTK-build
${{ github.workspace }}/dcmqi-build/ITK
${{ github.workspace }}/dcmqi-build/ITK-build
${{ github.workspace }}/dcmqi-build/zlib-install
key: ${{ steps.cache-dcmtk-itk-zlib.outputs.cache-primary-key }}

# Guard against the silent-skip failure mode: when find_program() fails to locate
# dciodvfy, CMake drops the conformance tests without failing anything, so the checks
# stop running unnoticed. Assert they were registered before running the suite.
Expand Down Expand Up @@ -186,19 +200,6 @@ jobs:
path: ${{ github.workspace }}/dcmqi-build/dcmqi-build/dcmqi-*-mac*.tar.gz
overwrite: true

# Save cache even if a later step (test, package) failed, so deps don't need rebuilding next run
- name: Save DCMTK, ITK and ZLIB cache
if: ${{ !cancelled() && steps.build.outcome == 'success' && steps.cache-dcmtk-itk-zlib.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v6
with:
path: |
${{ github.workspace }}/dcmqi-build/DCMTK
${{ github.workspace }}/dcmqi-build/DCMTK-build
${{ github.workspace }}/dcmqi-build/ITK
${{ github.workspace }}/dcmqi-build/ITK-build
${{ github.workspace }}/dcmqi-build/zlib-install
key: ${{ steps.cache-dcmtk-itk-zlib.outputs.cache-primary-key }}

- name: Publish package
# Publish tagged (stable) releases only. The rolling "latest" prerelease is
# (re)created by the finalize-latest workflow once all platforms finish building.
Expand Down
41 changes: 21 additions & 20 deletions .github/workflows/cmake-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,31 @@ jobs:
cmake -G "Visual Studio 17 2022" -Ax64 -DBUILD_SHARED_LIBS:BOOL=OFF ${{ github.workspace }}

- name: Build dcmqi
id: build
run: |
cd ${{ github.workspace }}\b/
cmake --build . --config Release -- /m

# Save dependencies before tests/packaging can time out.
- name: Save build dependencies cache
if: ${{ !cancelled() && steps.build.outcome == 'success' && steps.cache-build-deps.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v6
with:
path: |
${{ github.workspace }}\b\DCMTK
${{ github.workspace }}\b\DCMTK-build
${{ github.workspace }}\b\DCMTK-install
${{ github.workspace }}\b\DCMTK-prefix
${{ github.workspace }}\b\ITK
${{ github.workspace }}\b\ITK-build
${{ github.workspace }}\b\ITK-install
${{ github.workspace }}\b\ITK-prefix
${{ github.workspace }}\b\zlib
${{ github.workspace }}\b\zlib-build
${{ github.workspace }}\b\zlib-install
${{ github.workspace }}\b\zlib-prefix
key: ${{ steps.cache-build-deps.outputs.cache-primary-key }}

# Guard against the silent-skip failure mode: when find_program() fails to locate
# dciodvfy, CMake drops the conformance tests without failing anything, so the checks
# stop running unnoticed. Assert they were registered before running the suite.
Expand Down Expand Up @@ -123,26 +144,6 @@ jobs:
path: ${{ github.workspace }}\b\dcmqi-build\dcmqi-*-win64*.zip
overwrite: true

# Save cache even if a later step (test, package) failed, so deps don't need rebuilding next run
- name: Save build dependencies cache
if: ${{ !cancelled() && steps.build.outcome == 'success' && steps.cache-build-deps.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v6
with:
path: |
${{ github.workspace }}\b\DCMTK
${{ github.workspace }}\b\DCMTK-build
${{ github.workspace }}\b\DCMTK-install
${{ github.workspace }}\b\DCMTK-prefix
${{ github.workspace }}\b\ITK
${{ github.workspace }}\b\ITK-build
${{ github.workspace }}\b\ITK-install
${{ github.workspace }}\b\ITK-prefix
${{ github.workspace }}\b\zlib
${{ github.workspace }}\b\zlib-build
${{ github.workspace }}\b\zlib-install
${{ github.workspace }}\b\zlib-prefix
key: ${{ steps.cache-build-deps.outputs.cache-primary-key }}

- name: Publish package
# Publish tagged (stable) releases only, inline like the Linux/macOS builds, so
# there is no separate publish job that shows up "skipped" on every master push.
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ endif()

add_subdirectory("libsrc")

if(BUILD_TESTING)
add_test(NAME dcmqi_jsoncompare
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unittest discover -s <source>/util writes util/__pycache__/*.pyc into the source tree, so an out-of-source ctest run leaves the checkout dirty, which is a problem for read-only or shared source trees. Adding -B to the Python invocation (or setting PYTHONDONTWRITEBYTECODE=1 via set_tests_properties(... ENVIRONMENT ...)) avoids it.

🤖 Comment generated by Claude (Claude Code), posted on behalf of @fedorov.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added -B to the utility CTest, all nine metadata-comparison commands, and CLI test subprocesses. The out-of-source harness ran all ten Python CTests with PYTHONDONTWRITEBYTECODE unset and created no source-tree .pyc files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fedorov edorov, thank you again for the thorough review. I've addressed all seven points in commit 6f8ee01 and responded to each comment inline.

When you have a chance, would you mind taking another look? I'd be happy to address anything that remains.

Thanks again!

COMMAND "${Python3_EXECUTABLE}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/util/test_jsoncompare.py"
)
set_tests_properties(dcmqi_jsoncompare PROPERTIES
LABELS "segmentation;paramap;tid1500;jsoncompare")
endif()

if(DCMQI_BUILD_APPS)
add_subdirectory("apps")
endif()
Expand Down
4 changes: 2 additions & 2 deletions apps/paramaps/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME ${MODULE_NAME}_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/pm-example.json
${MODULE_TEMP_DIR}/makeNRRDParametricMap-meta.json
TEST_DEPENDS
Expand All @@ -185,7 +185,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME ${MODULE_NAME}_FP_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/pm-example-float.json
${MODULE_TEMP_DIR}/makeNRRDParametricMapFP-meta.json
TEST_DEPENDS
Expand Down
14 changes: 7 additions & 7 deletions apps/seg/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME ${dcm2itk}_makeNRRD_merged_segment_file_JSON
MODULE_NAME ${MODULE_NAME}
COMMAND python ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/seg-example_multiple_segments_merged.json
${MODULE_TEMP_DIR}/makeNRRD_merged_segment_file-meta.json
TEST_DEPENDS
Expand Down Expand Up @@ -492,7 +492,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME ${dcm2itk}_makeNRRD_merged_segment_files_from_partial_overlaps_JSON
MODULE_NAME ${MODULE_NAME}
COMMAND python ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/seg-example_partial_overlaps.json
${MODULE_TEMP_DIR}/makeNRRD_merged_segment_files_from_partial_overlaps-meta.json
TEST_DEPENDS
Expand All @@ -504,7 +504,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME seg_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/seg-example.json
${MODULE_TEMP_DIR}/makeNRRD-meta.json
TEST_DEPENDS
Expand All @@ -519,7 +519,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME labelmap_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/seg-example.json
${MODULE_TEMP_DIR}/makeNRRD_labelmap_direct-meta.json
TEST_DEPENDS
Expand All @@ -532,7 +532,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME labelmap_gapped_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/seg-example_liver_spine_gapped_merged.json
${MODULE_TEMP_DIR}/makeNRRD_labelmap_gapped-meta.json
TEST_DEPENDS
Expand All @@ -542,7 +542,7 @@ dcmqi_add_test(
dcmqi_add_test(
NAME multi_seg_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${CMAKE_SOURCE_DIR}/doc/examples/seg-example_multiple_segments.json
${MODULE_TEMP_DIR}/makeNRRD_multiple_segments-meta.json
"['labelID']"
Expand Down Expand Up @@ -970,4 +970,4 @@ foreach(overlapping_segs ${SEG_SAMPLES})
)
set_tests_properties(${overlapping_segs}_to_labelmap PROPERTIES WILL_FAIL TRUE)

endforeach()
endforeach()
4 changes: 2 additions & 2 deletions apps/sr/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ set(MODULE_NAME tid1500)
dcmqi_add_test(
NAME ${MODULE_NAME}_meta_roundtrip
MODULE_NAME ${READER_MODULE_NAME}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/util/comparejson.py
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/util/comparejson.py
${EXAMPLES}/sr-tid1500-ct-liver-example.json
${MODULE_TEMP_DIR}/sr-tid1500-ct-liver-example.json
"['activitySession', 'timePoint', 'imageLibrary', 'compositeContext','procedureReported']"
"['activitySession', 'timePoint', 'imageLibrary', 'compositeContext','procedureReported', 'TrackingUniqueIdentifier']"
TEST_DEPENDS
${READER_MODULE_NAME}_ct-liver
)
4 changes: 3 additions & 1 deletion doc/examples/pm-example-float.json
8
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
"CodeMeaning": "Prostate"
},
"FrameLaterality" : "U",
"RealWorldValueSlope" : "1"
"RealWorldValueSlope" : "1",
"DerivationDescription" : "",
"DerivedPixelContrast" : "NONE"
}
4 changes: 3 additions & 1 deletion doc/examples/pm-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
"CodeMeaning": "Prostate"
},
"FrameLaterality" : "U",
"RealWorldValueSlope" : "1"
"RealWorldValueSlope" : "1",
"DerivationDescription" : "",
"DerivedPixelContrast" : "NONE"
}
1 change: 0 additions & 1 deletion doc/examples/seg-example_liver_spine_gapped_merged.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"BodyPartExamined" : "",
"ClinicalTrialCoordinatingCenterName" : "BWH",
"ClinicalTrialSeriesID" : "Session1",
"ClinicalTrialTimePointID" : "1",
Expand Down
1 change: 0 additions & 1 deletion doc/examples/seg-example_multiple_segments_merged.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"BodyPartExamined" : "",
"ClinicalTrialCoordinatingCenterName" : "BWH",
"ClinicalTrialSeriesID" : "Session1",
"ClinicalTrialTimePointID" : "1",
Expand Down
3 changes: 1 addition & 2 deletions doc/examples/seg-example_partial_overlaps.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"BodyPartExamined" : "",
"ClinicalTrialCoordinatingCenterName" : "QIICR",
"ClinicalTrialSeriesID" : "1",
"ClinicalTrialTimePointID" : "1",
Expand Down Expand Up @@ -111,4 +110,4 @@
}
]
]
}
}
4 changes: 4 additions & 0 deletions doc/schemas/pm-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
"type": "string",
"default": ""
},
"DerivedPixelContrast": {
"$ref": "https://raw.githubusercontent.com/qiicr/dcmqi/master/doc/schemas/common-schema.json#/definitions/CS",
"default": "NONE"
},
"SourceImageDiffusionBValues": {
"type": "array",
"minItems": 1,
Expand Down
3 changes: 2 additions & 1 deletion libsrc/JSONSegmentationMetaInformationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ namespace dcmqi {
data["SeriesDescription"] = this->seriesDescription;
data["SeriesNumber"] = this->seriesNumber;
data["InstanceNumber"] = this->instanceNumber;
data["BodyPartExamined"] = this->bodyPartExamined;
if (!this->bodyPartExamined.empty())
data["BodyPartExamined"] = this->bodyPartExamined;

data["segmentAttributes"] = createAndGetSegmentAttributesJSON();

Expand Down
Loading
Loading
0