Skip to content

Warn when 'format' is used on a non-File parameter (#1616, #607) - #2291

Merged
mr-c merged 3 commits into
common-workflow-language:mainfrom
arimu1:fix/537-no-container-cachedir
Jul 20, 2026
Merged

mr-c merged 3 commits into
common-workflow-language:mainfrom
arimu1:fix/537-no-container-cachedir

Conversation

@arimu1

@arimu1 arimu1 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1616 and #607.

format is only meaningful for File parameters. cwltool silently accepted it on Directory (and other) inputs/outputs, so --validate passed with no indication that the field would be ignored — exactly the "validation passes with no warnings/errors" behavior reported in #1616, and the "complains far too late" symptom in #607.

$ cwltool --validate format-on-directory.cwl
format-on-directory.cwl is valid CWL.    # before — no hint that `format` is bogus

Change

In Process.__init__ (cwltool/process.py), while iterating the tool's inputs/outputs, emit a warning when a parameter declares format but its type does not contain a File. A small recursive helper _type_contains_file handles plain (File), namespaced, array (File[]), nullable (File?) and record forms.

$ cwltool --validate format-on-directory.cwl
format-on-directory.cwl:10:5: 'format' is only valid for 'File' type parameters, but 'indir' is not a File; the 'format' field will be ignored.
format-on-directory.cwl is valid CWL.    # after

A warning (not a hard error as #607 literally suggested) was chosen so existing documents carrying a harmless stray format keep validating; this also matches the direction in the newer #1616. The warning respects --no-warnings/--quiet like other validation warnings.

Tests

Added tests/wf/format-on-directory.cwl and tests/wf/format-on-file.cwl fixtures, plus two tests in tests/test_validate.py:

  • test_validate_warns_on_format_for_non_file — asserts the warning is emitted (captured via a custom log handler, as test_validate_custom_logger does).
  • test_validate_no_format_warning_for_file — asserts format on a File does not warn.

I verified the warn-test fails against the pre-fix code and passes after, and that the File case never warns. Full test_validate.py passes (8); black/flake8/isort clean.


This change was produced with the assistance of Claude Code (model: Claude Opus). The diff, analysis, and tests were reviewed by a human before submission.

@mr-c
mr-c marked this pull request as draft June 25, 2026 13:34
@arimu1
arimu1 force-pushed the fix/537-no-container-cachedir branch from 0781d11 to d28dc0c Compare June 28, 2026 06:40
@codecov

codecov Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.18%. Comparing base (a49e83f) to head (6bf60b1).

Files with missing lines Patch % Lines
cwltool/process.py 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2291      +/-   ##
==========================================
+ Coverage   85.16%   85.18%   +0.02%     
==========================================
  Files          46       46              
  Lines        8595     8608      +13     
  Branches     2012     2017       +5     
==========================================
+ Hits         7320     7333      +13     
+ Misses        810      808       -2     
- Partials      465      467       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arimu1
arimu1 force-pushed the fix/537-no-container-cachedir branch from d28dc0c to bdac046 Compare June 28, 2026 10:02
@arimu1
arimu1 force-pushed the fix/537-no-container-cachedir branch 2 times, most recently from 5cd87c9 to dbb5d78 Compare July 15, 2026 13:21
@arimu1
arimu1 force-pushed the fix/537-no-container-cachedir branch from dbb5d78 to 12c576a Compare July 18, 2026 15:01
…anguage#1616, common-workflow-language#607)

`format` is only meaningful for File parameters, but cwltool silently
accepted it on Directory (and other) inputs/outputs, so validation
passed with no indication that the field would be ignored.

Emit a validation warning (pointing at the offending `format` line)
when a parameter declares `format` but its type does not contain a
File. File and File[] parameters are unaffected. A warning, rather
than a hard error, avoids breaking documents that currently carry a
harmless stray `format`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@arimu1
arimu1 force-pushed the fix/537-no-container-cachedir branch from 12c576a to adc0244 Compare July 20, 2026 00:23

@mr-c mr-c left a comment

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.

Thank you @arimu1 ; please add tests to complete the test coverage

Comment thread cwltool/process.py Resolved
@mr-c
mr-c marked this pull request as ready for review July 20, 2026 06:23
Add fixtures and tests for File[], Directory[], and record types so
_type_contains_file's array and record branches are exercised. Also
accept string array items (e.g. items: File), which is the common
loaded form — matching only list items incorrectly warned on File[].

Co-authored-by: Cursor <[email protected]>
@arimu1

arimu1 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @mr-c — added coverage for the array and record arms:

  • File[] / Directory[] (array recursion; string items after load)
  • record with a File field / record with only string fields

Also adjusted the array match to accept string items (not only lists). After schema salad load, type: File[] is {"type": "array", "items": "File"}, so the list()-only pattern was incorrectly warning on valid File[] + format.

tests/test_validate.py — 12 passed locally.

@mr-c
mr-c merged commit f79659f into common-workflow-language:main Jul 20, 2026
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cwltool validate must have a warning when format is used with an invalid type (e.g. Directory)

2 participants