Skip to content

Harden the repository validator against legitimate change - #18

Merged
AM-L merged 2 commits into
mainfrom
tooling/harden-validator
Sep 7, 2026
Merged

AM-L merged 2 commits into
mainfrom
tooling/harden-validator

Conversation

@ambroise-leclerc

Copy link
Copy Markdown
Contributor

Closes #5.

tools/validate.py hardcoded VERSION == "0.1.0", an exact registered-diagnostic count, and an exact decision count — each trips on a change this repository exists to make.

  • VERSION checked for semantic-version shape, not a literal value.
  • Diagnostic registry checked for no duplicate row and for retaining every 0.1 baseline code (the invariant MEDUI-DEC-005 states) instead of an exact count.
  • Decision identifiers checked for contiguity from 001, not an exact count.
  • Each case's phase cross-checked against the phase its asserted code is registered under in spec/diagnostics.md.
  • Case-envelope and inputs member names are read from case.schema.json rather than restated, so a schema edit can't silently diverge from the validator.
  • MDX-E alias set need only map into the registry, not cover it — 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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 VERSION validation from an exact string match to a SemVer-shape check and bumps VERSION to 0.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.json as the source of truth for case envelope and key names, and cross-checks each case’s phase against the phase of asserted diagnostic codes in spec/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'] < 0 will 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-check line/column before 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

  • expected is assumed to be a dict (expected.keys()), which will crash the validator with an AttributeError if a case accidentally sets expected to 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.

Comment thread tools/validate.py Outdated
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")
Comment thread tools/validate.py Outdated
Comment on lines 105 to 107
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")
Base automatically changed from chore/gitignore-assistant-settings to main September 7, 2026 07:21
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.
@AM-L
AM-L force-pushed the tooling/harden-validator branch from ba7e561 to 7c67162 Compare September 7, 2026 07:21
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.
@ambroise-leclerc

Copy link
Copy Markdown
Contributor Author

Addressed in 12aa769:

  • SemVer strictness — intentional, now made explicit. VERSION is MAJOR.MINOR.PATCH with no pre-release or build metadata; rc / -candidate labels live in git tags and the consumer manifest's version field (see governance/versioning.md), so a suffix in VERSION is deliberately rejected. The regex is renamed VERSION_SHAPE and the message is now "VERSION must be MAJOR.MINOR.PATCH".
  • expected assumed to be a dict — added isinstance(expected, dict) (and isinstance(case, dict), and a per-diagnostic dict check) before any member access, each with a clear failure message.
  • line / column numeric compare on non-int — added an is_int() guard (non-bool int, mirroring the schema's "integer" type) before the < 0 comparison.
  • Also: load_json() now turns a JSONDecodeError into a validation failure rather than a traceback; id / source are string-checked and source may not contain /.

Verified with malformed-fixture cases (non-object expected, string/bool line, invalid JSON, top-level array, source with a slash, rc-suffixed VERSION) — each now prints a diagnosable MedUI validation: failure instead of crashing.

@AM-L
AM-L merged commit 82751c5 into main Sep 7, 2026
2 checks passed
@AM-L
AM-L deleted the tooling/harden-validator branch September 7, 2026 08:17
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.

validate.py reimplements the schemas and hardcodes VERSION and the diagnostic count

3 participants