feat: HC2104 — contract value validation (PR-5)#23
Conversation
ContractValueValidator checks every node's resolved values against all applicable contracts (intersection semantics, Resolution §7.3): type conformance (int satisfies float, everything else exact), declared bounds, and required presence. Violations point at the winning rule; a missing required property points at the contract demanding it. Resolution is context-dependent, so the check runs on the resolved graph and `hypercode validate` gains --ctx — the same sheet can be clean in development and violating in production. - 10 new tests incl. context-dependent violation and accumulated-contract intersection (89 total) - Resolution §7.3 planned → implemented; DOCS/Workplan R9 marked done Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fab0dd8ea4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Implements HC2104 contract value-level validation by checking resolved property values against all applicable @contract: constraints, and wires context-dependent resolution into hypercode validate via --ctx.
Changes:
- Add
ContractValueValidatorto validate resolved values for type conformance, numeric bounds, and required presence (HC2104). - Extend
hypercode validateto accept--ctx key=valueand run value validation on the resolved graph. - Add focused XCTest coverage for bounds/type/required/context-dependent violations and update Resolution spec/workplan docs accordingly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/HypercodeTests/ContractValueTests.swift | Adds XCTest cases covering HC2104 value validation behaviors and diagnostic location expectations. |
| Sources/HypercodeCLI/main.swift | Adds --ctx handling to validate and runs ContractValueValidator on resolved output. |
| Sources/Hypercode/Validation/ContractValueValidator.swift | Introduces the new HC2104 validator that checks resolved values against applicable contracts. |
| EBNF/Hypercode_Resolution.md | Updates §7.3 to document HC2104 as implemented (not planned) and describes --ctx implications. |
| DOCS/Workplan.md | Marks R9 as done and records the delivered implementation details for PR-5. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Double(i) rounds beyond 2^53, so 9007199254740993 under int <= 9007199254740992 passed silently. Integer values now compare in the Int domain whenever the bound is an exactly representable integer, falling back to Double comparison only for fractional or out-of-Int-range bounds. Regression test with the 2^53 + 1 example. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… R9 tense - ContractValueValidator.walk asserts command/resolved arrays stay parallel instead of silently skipping trailing nodes via zip - testViolationPointsAtWinningRule asserts the diagnostic count before inspecting it (clear failure instead of a crash) - DOCS/Workplan.md R9 reworded to past tense to match its ✅ status Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…xture - DOCS/Usage.md — every command end to end with genuine outputs: contexts / white-label, contracts as a CI gate (HC2104 walkthrough), explain trace, IR v2 anatomy (typed values, stable hashes, winner/losers, contracts[]), the AI-codegen pipeline, and a scalar-typing cheat-sheet - Examples/service.hcs gains a @contract: block (port/host/pool_size), so the reference fixture exercises HC-111 and is contract-validated in CI for both contexts - README: pipeline line and CLI block reflect v2/explain/validate --ctx; contracts and hashed IR added to "Why"; usage guide linked - workplan.md: new tasks HC-116 (@import for .hcs), HC-124 (end-to-end AI codegen demo); HC-092 usage guide marked done 92 tests green; ajv validates the contract-bearing fixture IR in both contexts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Closes the R9 review follow-up (decision 2026-06-11): contracts now check values, not just each other.
ContractValueValidatorvalidates every node's resolved values against all applicable contracts — intersection semantics per Resolution §7.3: type conformance (an int satisfies afloatcontract; everything else exact), declared>= / <=bounds, and required presencehypercode validategains--ctx key=value: resolution is context-dependent, so the same sheet can be clean in development and violating underenv=productionStacked on #22 (base:
feat/hc-111-contracts).Example
Test plan
timeout: 999underint <= 300passing silently) now fails witherror[HC2104], exit 1🤖 Generated with Claude Code