Repository navigation
Harden the repository validator against legitimate change - #18
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The updated validator has a few robustness gaps that can still crash on invalid JSON shapes (and the SemVer check is stricter than SemVer), so it should be corrected before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the repository’s dependency-free validator to be resilient to legitimate contract evolution (version bumps, additional diagnostics/decisions, schema edits), while tightening invariants around diagnostic registry integrity and conformance case consistency.
Changes:
- Relaxes
VERSIONvalidation from an exact string match to a SemVer-shape check and bumpsVERSIONto0.2.0. - Replaces hardcoded diagnostic/decision counts with invariant-based checks (baseline-code retention, no duplicate registry rows, contiguous decision IDs).
- Uses
schemas/case.schema.jsonas the source of truth for case envelope and key names, and cross-checks each case’s phase against the phase of asserted diagnostic codes inspec/diagnostics.md.
File summaries
| File | Description |
|---|---|
VERSION |
Bumps repository version to 0.2.0. |
tools/validate.py |
Hardens validation logic by deriving constraints from schemas and enforcing registry/case invariants instead of fixed counts. |
Review details
Suppressed comments (2)
tools/validate.py:151
diagnostic['line'] < 0/diagnostic['column'] < 0will raise a TypeError if either value is not an int (e.g. a string), which makes the validator crash instead of emitting a helpful failure. Since this validator is meant to be dependency-free and robust, it should explicitly type-checkline/columnbefore doing numeric comparisons.
if diagnostic["code"] not in known_codes or diagnostic["line"] < 0 or diagnostic["column"] < 0:
fail(f"{case['id']} references an invalid diagnostic")
tools/validate.py:146
expectedis assumed to be a dict (expected.keys()), which will crash the validator with an AttributeError if a case accidentally setsexpectedto a non-object type. Since this script is the primary structural validation, it should fail with a clear message instead of throwing.
expected = case["expected"]
if not expected_required <= expected.keys() or set(expected) - expected_keys:
fail(f"{case['id']} has invalid expected members")
if not isinstance(expected.get("valid"), bool) or not isinstance(expected.get("diagnostics"), list):
fail(f"{case['id']} has invalid expected shape")
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| PRECISIONS = ["full", "line-only", "none"] | ||
| CASE_ID = re.compile(r"MEDUI-CASE-[A-Z0-9-]+\Z") | ||
| CODE = re.compile(r"MEDUI-E[0-9]{3}\Z") | ||
| SEMVER = re.compile(r"[0-9]+\.[0-9]+\.[0-9]+\Z") |
| case = json.loads(path.read_text(encoding="utf-8")) | ||
| required = {"id", "phase", "source", "expected"} | ||
| if not required <= case.keys() or set(case) - (required | {"inputs"}): | ||
| if not case_required <= case.keys() or set(case) - case_top_level: | ||
| fail(f"{path.relative_to(ROOT)} has invalid top-level members") |
The validator hardcoded VERSION == "0.1.0", an exact registered-diagnostic count, and an exact decision count. Each of those trips on a change this repository exists to make, so a version bump or a new code had to edit the validator in the same commit. - VERSION is checked for semantic-version shape, not an exact value. - The diagnostic registry is checked for no duplicate row and for retaining every 0.1 baseline code (the invariant MEDUI-DEC-005 actually states), instead of an exact count. - Decision identifiers are checked for contiguity from 001, not an exact count. - Each case's phase is cross-checked against the phase its asserted code is registered under in spec/diagnostics.md. - Member names for the case envelope and its inputs are read from case.schema.json rather than restated, so a schema edit cannot silently diverge from the validator. - The MDX-E alias set need only map into the registry, not cover it exactly, so a MedUI-native code with no historical MDX name is allowed. - A registered code with no conformance case is reported as a note. VERSION moves to 0.2.0 to open the next pre-1.0 line.
ba7e561 to
7c67162
Compare
Follow-up to review on PR #18. The validator could raise AttributeError or TypeError on a case file whose shape is wrong (expected as a non-object, a non-integer position, a top-level array, unparseable JSON) instead of printing a diagnosable failure. - load_json() reports a JSONDecodeError as a validation failure. - case, expected and each diagnostic are type-checked before member access. - line/column are checked as non-bool integers (mirroring the schema's "integer" type) before the numeric comparison. - id and source are checked as strings; source may not contain "/". Also renames the VERSION check: it is a MAJOR.MINOR.PATCH shape check, not a full SemVer check - a pre-release suffix in VERSION is deliberately an error because rc/candidate labels live in tags and the consumer manifest.
|
Addressed in
Verified with malformed-fixture cases (non-object |
Closes #5.
tools/validate.pyhardcodedVERSION == "0.1.0", an exact registered-diagnostic count, and an exact decision count — each trips on a change this repository exists to make.VERSIONchecked for semantic-version shape, not a literal value.MEDUI-DEC-005states) instead of an exact count.spec/diagnostics.md.inputsmember names are read fromcase.schema.jsonrather than restated, so a schema edit can't silently diverge from the validator.VERSIONmoves to0.2.0to open the next pre-1.0 line.Validation:
python3 tools/validate.py→ OK (18 cases, 24 diagnostics); plus negative checks for the semver, phase-mismatch, and dropped-baseline-code paths.Stacked on #17.