Skip to content

feat: HC2104 — contract value validation (PR-5)#23

Merged
SoundBlaster merged 6 commits into
mainfrom
feat/hc-111-value-validation
Jun 12, 2026
Merged

feat: HC2104 — contract value validation (PR-5)#23
SoundBlaster merged 6 commits into
mainfrom
feat/hc-111-value-validation

Conversation

@SoundBlaster

Copy link
Copy Markdown
Member

Summary

Closes the R9 review follow-up (decision 2026-06-11): contracts now check values, not just each other.

  • ContractValueValidator validates every node's resolved values against all applicable contracts — intersection semantics per Resolution §7.3: type conformance (an int satisfies a float contract; everything else exact), declared >= / <= bounds, and required presence
  • hypercode validate gains --ctx key=value: resolution is context-dependent, so the same sheet can be clean in development and violating under env=production
  • Violations point at the winning rule (where the value was written); a missing required property points at the contract that demands it
  • Resolution spec §7.3 updated from planned to implemented

Stacked on #22 (base: feat/hc-111-contracts).

Example

$ hypercode validate app.hc --hcs app.hcs --ctx env=production
app.hcs:1:1: error[HC2104]: contract violation for 'timeout': 999 exceeds upper bound 300.0 from contract 'Service'

Test plan

  • 89 tests pass, zero warnings
  • 10 new tests: upper/lower bound, type mismatch, missing required, optional-missing clean, in-bounds clean, intersection of accumulated contracts, int-under-float, context-dependent violation, diagnostic location
  • Original review repro (timeout: 999 under int <= 300 passing silently) now fails with error[HC2104], exit 1

🤖 Generated with Claude Code

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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".

Comment thread Sources/Hypercode/Validation/ContractValueValidator.swift Outdated

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

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 ContractValueValidator to validate resolved values for type conformance, numeric bounds, and required presence (HC2104).
  • Extend hypercode validate to accept --ctx key=value and 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.

Comment thread Sources/Hypercode/Validation/ContractValueValidator.swift
Comment thread Tests/HypercodeTests/ContractValueTests.swift
Comment thread DOCS/Workplan.md Outdated
SoundBlaster and others added 4 commits June 12, 2026 00:49
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>
@SoundBlaster SoundBlaster changed the base branch from feat/hc-111-contracts to main June 12, 2026 13:53
@SoundBlaster SoundBlaster merged commit c426246 into main Jun 12, 2026
5 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.

2 participants