Skip to content

feat(cli): accept multiple data files in 'validate data' - #49

Merged
cmungall merged 2 commits into
mainfrom
feat/multi-file-validate-data
Jun 17, 2026
Merged

cmungall merged 2 commits into
mainfrom
feat/multi-file-validate-data

Conversation

@cmungall

Copy link
Copy Markdown
Member

Motivation

validate data takes a single DATA_FILE, so validating many files means one
process per file — and each process re-parses the LinkML schema and rebuilds the
Validator, which is the expensive step. For bulk validation (e.g. thousands of
curation YAMLs in CI) this is dominated by per-file process + schema startup, not
the actual validation work. (linkml-term-validator already accepts
DATA_PATHS... for exactly this reason.)

Change

Make validate data accept one or more DATA_FILE arguments. The config,
ReferenceValidationPlugin, and Validator are constructed once and reused
across all files. Each file is validated independently with per-file reporting,
and the command exits non-zero if any file has issues.

  • Backward compatible: a single file is just a one-element list; existing
    single-file output strings (All validations passed!, Issues found,
    [severity] message) are preserved.
  • Adds CLI tests for multi-file (mixed valid/invalid → exit 1 with both files
    reported; all-valid → exit 0).

Impact

Smoke test on real data (cached references): 10 files in one process ≈ 2.1 s
vs ≈ 12 s as ten separate processes (~6×), and the gap widens with file count
since the schema is parsed once.

All existing tests pass (516 passed), mypy and ruff clean.

'validate data' previously took a single DATA_FILE, so validating many files
required one process per file — each re-parsing the schema and rebuilding the
Validator (the expensive step). This made bulk validation (e.g. thousands of
curation files in CI) dominated by per-file process/schema startup.

Make 'validate data' accept one or more DATA_FILE arguments (mirroring
linkml-term-validator's 'validate-data DATA_PATHS...'). The config, plugin, and
Validator are built once and reused across all files; each file is validated
independently with per-file reporting and a combined exit code (non-zero if any
file has issues). Single-file usage is unchanged (a one-element list).

Smoke test on real data: 10 files in one process ~2.1s vs ~12s as 10 processes
(~6x), with the gap widening as file count grows.

Adds multi-file CLI tests (mixed valid/invalid and all-valid).
@claude

claude Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the CLI bulk-validation workflow by allowing validate data to accept multiple data files in a single invocation, reusing the parsed LinkML schema and Validator across files to avoid repeated startup cost.

Changes:

  • Update validate data to accept DATA_FILE... (one or more files) and validate each file independently while reusing a single Validator instance.
  • Add CLI tests covering multi-file behavior for mixed valid/invalid inputs and all-valid inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/linkml_reference_validator/cli/validate.py Accept multiple input files and reuse a single LinkML Validator; aggregate per-file results into one exit status.
tests/test_cli.py Add tests verifying multi-file invocation behavior and exit codes.

Comment on lines +313 to +316
else:
typer.echo(f"Error: Unexpected data format in {data_file}", err=True)
files_with_issues += 1
continue
Per Copilot review on #49: a data file that loads to an unexpected YAML
type (e.g. an empty file -> None, or a bare scalar) logged an error and
`continue`d, incrementing files_with_issues but not total_results. Since
the exit decision keyed only off total_results, such a file -- with no
other failing files -- printed "All validations passed!" and exited 0,
silently greenlighting malformed input in CI.

Base the exit status on files_with_issues (which already counts both
validation failures and unreadable files) and report the count honestly.

Adds a parametrized test covering empty-file and bare-scalar input ->
exit 1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cmungall's task in 57s —— View job


PR Review: accept multiple data files in validate data

  • Read changed files (cli/validate.py, tests/test_cli.py)
  • Check the Copilot review concern (line 316 / malformed-file exit code)
  • Assess test coverage
  • Review for bugs, quality, performance

This is a clean, well-motivated change. The "build the schema/Validator once, loop over files" approach is the right shape for the bulk-CI use case, and backward compatibility (single file = one-element list) is preserved.

✅ The Copilot concern is already resolved

Copilot flagged that a file loading to an unexpected YAML type would continue without affecting the exit code, letting a malformed file be silently reported as "All validations passed!". That was fixed in commit 10f99ee:

  • validate.py:313-316 now does files_with_issues += 1 before continue.
  • The exit logic at validate.py:341 keys off files_with_issues (not total_results), so a malformed file forces exit 1 even when it contributes zero validation results.
  • Covered by test_validate_data_command_malformed_file_fails (tests/test_cli.py:444), parametrized over an empty file and a bare scalar, asserting exit_code == 1 and that "All validations passed" is absent.

So this PR as it stands handles the raised issue correctly. 👍

Observations / minor suggestions

  1. files_with_issues count vs. validation-issue count in the summary. The summary line reads:

    Issues found in {files_with_issues} file(s) ({total_results} validation issue(s))
    

    For a malformed file, files_with_issues is incremented but total_results stays 0, so a single bad file prints Issues found in 1 file(s) (0 validation issue(s)). That's technically accurate but slightly confusing — the "0 validation issues" reads like nothing was wrong. Not blocking; consider distinguishing format errors from validation issues in the summary if you want the output to be self-explanatory. (validate.py:342)

  2. No guard for a missing/unreadable data file. open(data_file) (validate.py:301) will raise an uncaught FileNotFoundError (traceback + exit code 1) if a path doesn't exist. The text-file command checks file_path.exists() first and emits a clean error. With multiple files this matters more — one bad path aborts the whole batch mid-loop, skipping the remaining files. Consider an existence check (or wrapping the load) so one missing file is reported as that file's failure and the rest still run. This is the one functional gap I'd flag as worth addressing, though it's outside the original scope of the PR.

  3. Test coverage is solid. test_validate_data_command_multiple_files (mixed valid/invalid → exit 1, both files named in output) and test_validate_data_command_multiple_valid_files (all valid → exit 0) cover the new behavior well, alongside the malformed-file test.

Verdict

The change is correct, backward compatible, and the previously-raised review issue is already fixed and tested. The only thing I'd genuinely suggest before merge is item #2 (clean handling of a nonexistent file path), since the multi-file batch use case makes an uncaught mid-loop crash more impactful. Items #1 is cosmetic.

Note: I was unable to run the test suite in this environment (the pytest invocation needs approval), so I'm relying on code reading and the PR's reported 516 passed.
• branch feat/multi-file-validate-data

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.

2 participants