Skip to content

feat(evidence): add the calc evidence model, validation and builder (#206) - #229

Draft
shunsuke-shimomura wants to merge 2 commits into
feat/205-calc-propertyfrom
feat/206-calc-evidence-model
Draft

shunsuke-shimomura wants to merge 2 commits into
feat/205-calc-propertyfrom
feat/206-calc-evidence-model

Conversation

@shunsuke-shimomura

@shunsuke-shimomura shunsuke-shimomura commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

Closes #206 (parent: #40). Stacked on #227 (calc: rename), which is stacked on #226 (the calc evidence design and schemas/calc-evidence-v1.schema.json).

Adds the calc evidence model to the shared inka-evidence crate, following the test evidence pattern so a producer cannot emit what the consumer rejects:

  • inka_evidence::calc — the serde mirror of the schema (Target, Definition, DefinitionKind, Leaf), a strict parse (unknown fields rejected outside provenance, version checked) and a CalcEvidenceBuilder whose add_target runs the same check as parse. The checks: target, definition and leaf paths are non-empty with no whitespace; a target declares at least one definition and is among its own definitions; definition paths and leaf IDs are unique per target; sources are non-empty; assumption IDs follow the inka ID grammar (ident(::ident)*) and are unique; target paths are unique per file; provenance entries are non-blank. Whether an assumption ID names a real node, and the interface hash, remain the consumer's job (calc evidence: load-time consumption, interface hash and assumption edges in check #208).
  • Emission defaults match the schema: a missing leaf result is an absent result key (never null), xfail: false is omitted, empty provenance is omitted.
  • Shared provenance helpers (provenance.rs): the blank-entry rule and the CAPSULA_RUN_ID fill are now one implementation used by both builders; EvidenceBuilder's behaviour is unchanged.
  • Python binding (inka-evidence-py): CalcEvidenceBuilder, Definition, Leaf, re-exported from inka_evidence; invalid input raises the existing InvalidEvidenceError. Definition kinds and outcomes are read through the crate's serde vocabulary, so the accepted strings cannot drift from the wire format. README documents the API.

Not included: a merge operation for calc evidence (no use case yet — a veriq project is evaluated in one run) and the wasm binding (no TypeScript producer of calc evidence).

Test results

  • cargo test -p inka-evidence: 49 tests pass. tests/calc_emission.rs covers the round trip, the schema conformance of emitted files (via jsonschema), every InvalidCalcEvidence variant at add time, the duplicate-target rejection on both sides, and a proptest asserting that builder, parser and the repository JSON Schema agree on arbitrary (often invalid) input: the first defect the builder and parser report is identical, and the schema admits a file exactly when the crate does — except for the one rule the schema cannot express (a target being among its own definitions), which is exercised and exempted explicitly.
  • uv run pytest in crate/inka-evidence-py: 73 pass (17 new in tests/test_calc_emission.py, including schema conformance of the emitted file and every rejection reachable from Python).
  • cargo test --workspace: all pass except the inka-evidence-rust adapter tests, which need cargo-nextest (not installed locally; unrelated).
  • cargo fmt --check, cargo clippy --workspace --all-targets, prek on changed files: clean.

Impact

  • Additive: new public module inka_evidence::calc and three new Python classes. The existing test evidence API and wire format are untouched; the provenance refactor is behaviour-preserving (existing tests cover it).
  • inka-evidence-py gains a direct serde dependency (already in the workspace) for the generic vocabulary helpers; Cargo.lock updated accordingly. uv.lock is unchanged.

Supplementary information

🤖 Generated with Claude Code

@github-actions github-actions Bot added sys::SE システムズエンジニアリング documentation 📓 Improvements or additions to documentation and removed sys::SE システムズエンジニアリング labels Nov 9, 2026
@shunsuke-shimomura
shunsuke-shimomura force-pushed the feat/206-calc-evidence-model branch from c75d9d2 to 90e4082 Compare November 10, 2026 00:56
shunsuke-shimomura and others added 2 commits November 10, 2026 12:29
…206)

`inka_evidence::calc` mirrors schemas/calc-evidence-v1.schema.json: a
strict parser and a builder sharing one validation pass, so the veriq
adapter cannot emit a file the consumer rejects. The provenance rules
both builders apply move into one shared module. The Python binding
exposes `CalcEvidenceBuilder`, `Definition` and `Leaf`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The parser and the schema disagreed in three places a producer other than
inka's own builder can reach:

- A file of a later version was refused for the keys v1 lacks instead of
  for its version. The version stamp is now read before the v1 shape.
- `result: null` and `provenance: null` were read as absent keys. The
  schema has no null there, so both are now input errors.
- A path or leaf ID with whitespace was reported without saying which, and
  whitespace other than a plain space is invisible in the message. The
  offending value is now quoted with its escapes.

A test pins "whitespace" to the Unicode White_Space set on both sides.
@shunsuke-shimomura
shunsuke-shimomura force-pushed the feat/206-calc-evidence-model branch from 90e4082 to cde6f83 Compare November 10, 2026 03:55
@shunsuke-shimomura

Copy link
Copy Markdown
Member Author

Review follow-up (2026-11-10)

Rebased onto the updated #227 and force-pushed. One commit was added.

cde6f83 — fix(evidence): read calc evidence as strictly as its schema does

  • A file of a later version is refused for its version, not for the keys v1 lacks: the version stamp is read before the v1 shape.
  • result: null and provenance: null are input errors (the schema has no null there); they were read as absent keys.
  • A path or leaf ID containing whitespace is reported with the offending value quoted and escaped. A test pins "whitespace" to the Unicode White_Space set on both the parser and the schema.

Left as is

  • The test evidence parser on main keeps its looser behaviour (shape before version, its own whitespace rule). This PR only makes the calc side match its schema; aligning the test side would be a separate change.
  • The \S patterns on the provenance fields of the calc schema are unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 📓 Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

calc evidence: shared model, validation and builder in inka-evidence

1 participant