aien-dev has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
GitHub aien-dev/interplane-mv#19 (code only)
Apply it
git checkout -b patch-db9accb295fffd99 eb7db9145a63bcb8437b85b77db1ba026224a5ab curl -fsSL https://interplane.io/drakestapleton/interplane-mv/patches/db9accb295fffd99.patch | git am
Provenance
github-import 1
aien-dev/interplane-mv
19
bcfb2e67733fec0612745a98a68c70fcf8689dc7
{"kind":"github-import","owner":"aien-dev","repo":"interplane-mv","number":19,"url":"https://github.com/aien-dev/interplane-mv/pull/19","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:59Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ea627f..1a270ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: import json,sys r=json.load(open('rust-verdicts.json')); p=json.load(open('py-verdicts.json')) bad=[c for c in sorted(set(r)|set(p)) if json.dumps(r.get(c),sort_keys=True)!=json.dumps(p.get(c),sort_keys=True)] - print('cases:',len(r),'mismatches:',bad); sys.exit(1 if bad or len(r)!=25 else 0) + print('cases:',len(r),'mismatches:',bad); sys.exit(1 if bad or len(r)!=30 else 0) PY adapter-aien: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba3ecb..b999e37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased (0.3, Trust lane) + +- Security: the Rust lifecycle now accepts an approval continuation only with the `approval_id` the runtime minted for that request, as Python already did; before, any non-empty id was accepted. A non-`authorized` continuation value with the minted id is DENIED in both SDKs. Lifecycle conformance cases `lifecycle/01-05`; 30/30 byte-identical. + ## Unreleased (0.2, CrossAxis lane) - 0.2 report: `docs/REPORT-0.2.md`. Pre-registered gate verdict FAIL (O1 0.865, O2 0/5; T 0.877 and S pass). diff --git a/STATUS.md b/STATUS.md index fe093d8..9804cfe 100644 --- a/STATUS.md +++ b/STATUS.md @@ -17,8 +17,9 @@ byte-identical) ยท `qualified` (measured against a real model/backend). | CrossAxis measure units (bytes, tokens_model_reported, tokens_endpoint_tokenizer, tokens_estimated) | tested | tested | schema-validated (selection.schema.json) | not yet qualified: Core ships BytesOnly + EstimatedTokens (estimator v1); live counters belong to the bench runner | | CrossAxis expansion v1 (expand + discover, bounded) | conformant | conformant | cases 24, 25 | selections and digests byte-identical across languages; not yet qualified against a live model; never grants authority | | Crossveil pipeline + mock runtime | conformant | conformant | 25 cases | fails closed on adapter faults | +| Crossveil lifecycle: approval continuation | conformant | conformant | lifecycle/01-05 | only the approval_id the runtime minted for that request continues it; forged, empty, missing and other-request ids refused (Rust accepted any non-empty id before 0.3 cut A1); no pipeline continuation call yet (cut A2) | | Reproducibility pins | - | - | - | see docs/RUN-MANIFEST-COMMITS.md (toolchain, pip constraints, action SHAs, AIEN sibling pins) | -| Conformance runner | implemented | implemented | 25/25 both (rerun 2026-10-04, verdicts byte-identical) | `--dump` writes canonical results per case | +| Conformance runner | implemented | implemented | 30/30 both (25 cases + 5 lifecycle, verdicts byte-identical) | `--dump` writes canonical results per case | | Interplane Probe | qualified | qualified | - | both run live against Qwen3.5-9B/Ollama 0.34.0 with identical verdicts (reports under qualification/reports) | | AIEN adapter | tested (on the real EffectAuthority path, pinned sovereign-core 6554aac; was 10 pipeline tests in 0.1) | - | - | ADR 0003; real aien-mcp SpeculativeLane + aegis gate; aien-cli SafetyEngine not linkable (private); AGPL | | Odysseus adapter | - | tested (55 tests vs odysseus@2992bf6) | - | executes read_file/ls/glob/grep via Odysseus handlers; AGPL | diff --git a/conformance/README.md b/conformance/README.md index f0f8922..d7fcc30 100644 --- a/conformance/README.md +++ b/conformance/README.md @@ -7,7 +7,7 @@ was taken and is listed below. ## Layout -- `fixtures/NN-slug.json`: the 25 required cases (01-18 core; 19 valid write, 20 missing required argument, 21 stale capability mapping, 22 untrusted tool result, 23 untrusted memory result; 24 expansion by requested_excluded, 25 expansion refused by bound). `fixtures/digest/jcs-01.json`: the JCS digest check. +- `fixtures/NN-slug.json`: the 25 required cases (01-18 core; 19 valid write, 20 missing required argument, 21 stale capability mapping, 22 untrusted tool result, 23 untrusted memory result; 24 expansion by requested_excluded, 25 expansion refused by bound). `fixtures/digest/jcs-01.json`: the JCS digest check. `fixtures/lifecycle/NN-slug.json`: approval continuation cases driven against the lifecycle directly (01 forged id, 02 empty or missing id, 03 id minted for another request, 04 the runtime-minted id, 05 non-`authorized` continuation values); format in `spec/CORE.md`. - `../dialects/fixtures/{openai,qwen35}/*.json`: Lenshift parse fixtures. - `runners/validate_fixtures.py`: checks every envelope and intent against `spec/schemas/`, fixture shape, runtime-count consistency, the JCS fixture, plus negative controls. Exit status is non-zero on failure. @@ -52,6 +52,14 @@ Absent means `mock-table`. Case 21 sets `"mapping_table": "mock-table-stale"` (s Trust is two axes (CROSSVEIL.md, `common.schema.json`): `provenance.trust` (TrustLevel) and `provenance.content_kind` (ContentKind), set by the runtime adapter and never by the model. `provenance.trusted` follows CORE.md: true only for `trusted_runtime`, false for `workspace_untrusted` and `external_untrusted`. Cases 22 and 23 return content that looks like instructions (tool-call markup, a destructive shell command); it must reach the model only as rendered data. Case 22's `continues` step is parsed from the model's own text and must add no intents or records. `result_checks` cover result fields only; a runner should additionally assert the rendered tool message contains the markup verbatim (CORE.md case 22). +## Lifecycle fixtures (approval continuation) + +The reference pipeline has no host continuation call yet (plan cut A2), so a second decision on a +`requires_approval` request cannot be reached through `NN-slug` fixtures. The cases under +`fixtures/lifecycle/` exercise that transition on the lifecycle state machine itself, in both SDKs. +Both runners load them after the `NN-slug` cases and write one verdict row each, keyed +`lifecycle/<slug>`. Total verdict rows: 30 (25 + 5). + ## Cross-language verdict comparison Each runner writes its full `observed` array (with `result_digest` filled) as JSON. Canonicalize each with diff --git a/conformance/fixtures/lifecycle/01-forged-approval-id.json b/conformance/fixtures/lifecycle/01-forged-approval-id.json new file mode 100644 index 0000000..2bd145b --- /dev/null +++ b/conformance/fixtures/lifecycle/01-forged-approval-id.json @@ -0,0 +1,72 @@ +{ + "case": "lifecycle/01-forged-approval-id", + "description": "delete_file requires approval (runtime mints mock-approval-call_L01). A continuation decision carrying an approval_id the runtime never minted is refused and the request stays REQUIRES_APPROVAL. The runtime-minted id then authorizes it.", + "steps": [ + { + "request_id": "call_L01", + "decision": { + "kind": "decision", + "request_id": "call_L01", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L01", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L01", + "decision": { + "kind": "decision", + "request_id": "call_L01", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "forged-approval-1" + } + } + }, + { + "request_id": "call_L01", + "decision": { + "kind": "decision", + "request_id": "call_L01", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L01" + } + } + } + ], + "expected": [ + { + "request_id": "call_L01", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L01", + "state": "REQUIRES_APPROVAL", + "refused": true + }, + { + "request_id": "call_L01", + "state": "AUTHORIZED", + "refused": false + } + ] +} diff --git a/conformance/fixtures/lifecycle/02-empty-approval-id.json b/conformance/fixtures/lifecycle/02-empty-approval-id.json new file mode 100644 index 0000000..b0a71d3 --- /dev/null +++ b/conformance/fixtures/lifecycle/02-empty-approval-id.json @@ -0,0 +1,70 @@ +{ + "case": "lifecycle/02-empty-approval-id", + "description": "A continuation decision with an empty approval_id, and one with approval null, are both refused; the request stays REQUIRES_APPROVAL.", + "steps": [ + { + "request_id": "call_L02", + "decision": { + "kind": "decision", + "request_id": "call_L02", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L02", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L02", + "decision": { + "kind": "decision", + "request_id": "call_L02", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "" + } + } + }, + { + "request_id": "call_L02", + "decision": { + "kind": "decision", + "request_id": "call_L02", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": null + } + } + ], + "expected": [ + { + "request_id": "call_L02", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L02", + "state": "REQUIRES_APPROVAL", + "refused": true + }, + { + "request_id": "call_L02", + "state": "REQUIRES_APPROVAL", + "refused": true + } + ] +} diff --git a/conformance/fixtures/lifecycle/03-approval-id-from-other-request.json b/conformance/fixtures/lifecycle/03-approval-id-from-other-request.json new file mode 100644 index 0000000..fbeda4a --- /dev/null +++ b/conformance/fixtures/lifecycle/03-approval-id-from-other-request.json @@ -0,0 +1,94 @@ +{ + "case": "lifecycle/03-approval-id-from-other-request", + "description": "Two requests are pending. A continuation for call_L03b that cites call_L03b but carries the approval_id minted for call_L03a is refused. The same id then authorizes call_L03a, the request it was minted for.", + "steps": [ + { + "request_id": "call_L03a", + "decision": { + "kind": "decision", + "request_id": "call_L03a", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L03a", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L03b", + "decision": { + "kind": "decision", + "request_id": "call_L03b", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L03b", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L03b", + "decision": { + "kind": "decision", + "request_id": "call_L03b", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L03a" + } + } + }, + { + "request_id": "call_L03a", + "decision": { + "kind": "decision", + "request_id": "call_L03a", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L03a" + } + } + } + ], + "expected": [ + { + "request_id": "call_L03a", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L03b", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L03b", + "state": "REQUIRES_APPROVAL", + "refused": true + }, + { + "request_id": "call_L03a", + "state": "AUTHORIZED", + "refused": false + } + ] +} diff --git a/conformance/fixtures/lifecycle/04-runtime-minted-approval-id.json b/conformance/fixtures/lifecycle/04-runtime-minted-approval-id.json new file mode 100644 index 0000000..636a97e --- /dev/null +++ b/conformance/fixtures/lifecycle/04-runtime-minted-approval-id.json @@ -0,0 +1,115 @@ +{ + "case": "lifecycle/04-runtime-minted-approval-id", + "description": "The runtime-minted approval_id continues its own request: authorized gives AUTHORIZED, denied gives DENIED. A second continuation of the already-authorized request is refused.", + "steps": [ + { + "request_id": "call_L04a", + "decision": { + "kind": "decision", + "request_id": "call_L04a", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L04a", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L04a", + "decision": { + "kind": "decision", + "request_id": "call_L04a", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L04a" + } + } + }, + { + "request_id": "call_L04b", + "decision": { + "kind": "decision", + "request_id": "call_L04b", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L04b", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L04b", + "decision": { + "kind": "decision", + "request_id": "call_L04b", + "decision": "denied", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L04b" + } + } + }, + { + "request_id": "call_L04a", + "decision": { + "kind": "decision", + "request_id": "call_L04a", + "decision": "authorized", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L04a" + } + } + } + ], + "expected": [ + { + "request_id": "call_L04a", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L04a", + "state": "AUTHORIZED", + "refused": false + }, + { + "request_id": "call_L04b", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L04b", + "state": "DENIED", + "refused": false + }, + { + "request_id": "call_L04a", + "state": "AUTHORIZED", + "refused": true + } + ] +} diff --git a/conformance/fixtures/lifecycle/05-continuation-non-authorized-value.json b/conformance/fixtures/lifecycle/05-continuation-non-authorized-value.json new file mode 100644 index 0000000..605e314 --- /dev/null +++ b/conformance/fixtures/lifecycle/05-continuation-non-authorized-value.json @@ -0,0 +1,137 @@ +{ + "case": "lifecycle/05-continuation-non-authorized-value", + "description": "With the runtime-minted approval_id, a continuation whose decision is anything but authorized ends in DENIED (CORE.md: REQUIRES_APPROVAL goes only to AUTHORIZED or DENIED): requires_approval again, not_found, and an unknown value.", + "steps": [ + { + "request_id": "call_L05a", + "decision": { + "kind": "decision", + "request_id": "call_L05a", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L05a", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L05a", + "decision": { + "kind": "decision", + "request_id": "call_L05a", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L05a" + } + } + }, + { + "request_id": "call_L05b", + "decision": { + "kind": "decision", + "request_id": "call_L05b", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L05b", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L05b", + "decision": { + "kind": "decision", + "request_id": "call_L05b", + "decision": "not_found", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L05b" + } + } + }, + { + "request_id": "call_L05c", + "decision": { + "kind": "decision", + "request_id": "call_L05c", + "decision": "requires_approval", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L05c", + "scope": "single_action" + } + } + }, + { + "request_id": "call_L05c", + "decision": { + "kind": "decision", + "request_id": "call_L05c", + "decision": "approve_now", + "capability": "delete_file", + "authority": { + "runtime": "mock", + "policy_engine": "mock.policy" + }, + "approval": { + "approval_id": "mock-approval-call_L05c" + } + } + } + ], + "expected": [ + { + "request_id": "call_L05a", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L05a", + "state": "DENIED", + "refused": false + }, + { + "request_id": "call_L05b", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L05b", + "state": "DENIED", + "refused": false + }, + { + "request_id": "call_L05c", + "state": "REQUIRES_APPROVAL", + "refused": false + }, + { + "request_id": "call_L05c", + "state": "DENIED", + "refused": false + } + ] +} diff --git a/conformance/runners/validate_fixtures.py b/conformance/runners/validate_fixtures.py index 405f6ba..b571e0a 100644 --- a/conformance/runners/validate_fixtures.py +++ b/conformance/runners/validate_fixtures.py @@ -5,6 +5,7 @@ Exit status is non-zero on any failure. Checks: * every explicit envelope step validates against envelope.schema.json * every intent in dialects/fixtures validates against intent.schema.json * fixture shape, 25 required cases, filename == case slug + * lifecycle/ fixtures: required set, shape, minting decisions valid against decision.schema.json * expected.runtime counts agree with the observed records * the JCS digest fixture recomputes * negative control: a mutated envelope MUST fail validation @@ -33,6 +34,7 @@ def validator(name): return Draft202012Validator(schemas[name], registry=registry, format_checker=FormatChecker()) V_ENV, V_INTENT = validator("envelope.schema.json"), validator("intent.schema.json") V_SEL = validator("selection.schema.json") +V_DEC = validator("decision.schema.json") def check(v, inst, where): errs = sorted(v.iter_errors(inst), key=lambda e: list(e.absolute_path)) @@ -140,6 +142,30 @@ for p in sorted(glob.glob(os.path.join(FIX, "*.json"))): if seen != REQUIRED: fail("required cases missing/extra: %s" % sorted(seen ^ REQUIRED)) if not neg_done: fail("negative control never ran") +# ---- lifecycle fixtures (driven against the Lifecycle directly, no pipeline) +LIFECYCLE = {"01-forged-approval-id", "02-empty-approval-id", "03-approval-id-from-other-request", + "04-runtime-minted-approval-id", "05-continuation-non-authorized-value"} +STATES = {"PROPOSED","REJECTED","MAPPED","DENIED","REQUIRES_APPROVAL","AUTHORIZED","EXECUTING","SUCCEEDED","FAILED","TIMED_OUT"} +n_life = 0; lseen = set() +for p in sorted(glob.glob(os.path.join(FIX, "lifecycle", "*.json"))): + f = load(p); name = os.path.basename(p)[:-5]; n_life += 1; lseen.add(name) + if f.get("case") != "lifecycle/" + name: fail("lifecycle/%s: case slug %r != filename" % (name, f.get("case"))) + if set(f) != {"case", "description", "steps", "expected"}: fail("lifecycle/%s: keys %s" % (name, sorted(f))) + steps, exp = f.get("steps", []), f.get("expected", []) + if len(steps) != len(exp): fail("lifecycle/%s: one expected row per step" % name) + minted = set() + for i, (s, e) in enumerate(zip(steps, exp)): + d = s.get("decision", {}) + if list(e) != ["request_id", "state", "refused"] or e["state"] not in STATES or e["request_id"] != s.get("request_id"): + fail("lifecycle/%s: expected[%d] shape" % (name, i)) + if s.get("request_id") not in minted: + # first decision on a request is the runtime's own: requires_approval with a minted id + check(V_DEC, d, "lifecycle/%s step %d minting decision" % (name, i)) + if d.get("decision") != "requires_approval" or d.get("request_id") != s.get("request_id"): fail("lifecycle/%s: step %d must mint" % (name, i)) + minted.add(s.get("request_id")) + elif d.get("request_id") != s.get("request_id"): fail("lifecycle/%s: step %d continuation must cite its own request_id" % (name, i)) +if lseen != LIFECYCLE: fail("lifecycle cases missing/extra: %s" % sorted(lseen ^ LIFECYCLE)) + # ---- digest fixture dp = os.path.join(FIX, "digest", "jcs-01.json") d = load(dp) @@ -169,7 +195,7 @@ for dia, names in req.items(): have = {os.path.basename(x)[:-5] for x in glob.glob(os.path.join(ROOT, "dialects", "fixtures", dia, "*.json"))} if have != names: fail("dialect %s fixtures differ: %s" % (dia, sorted(have ^ names))) -print("conformance cases: %d, explicit envelopes validated: %d, dialect fixtures: %d, dialect intents validated: %d, negative controls: ok" % (n_cases, n_env, n_dial, n_int)) +print("conformance cases: %d, lifecycle cases: %d, explicit envelopes validated: %d, dialect fixtures: %d, dialect intents validated: %d, negative controls: ok" % (n_cases, n_life, n_env, n_dial, n_int)) if errors: print("FAIL (%d)" % len(errors)); [print(" -", e) for e in errors]; sys.exit(1) print("PASS") diff --git a/python/interplane/conformance.py b/python/interplane/conformance.py index c5e70e3..6185e21 100644 --- a/python/interplane/conformance.py +++ b/python/interplane/conformance.py @@ -6,7 +6,7 @@ import sys from pathlib import Path from typing import Any, Optional -from .core import Limits, jcs +from .core import Decision, Lifecycle, LifecycleError, Limits, ProtocolError, jcs from .crossaxis import expand, select from .crossveil import canonical_result_payload, default_pipeline @@ -112,6 +112,28 @@ def run_case(case: dict) -> dict: } +def run_lifecycle_case(case: dict) -> dict: + """Drive the Crossveil lifecycle directly (no pipeline). For each step, the lifecycle of + ``request_id`` (created and mapped on first sight) receives ``decision``; the step records the + state after the call and whether the call was refused.""" + lifecycles: dict = {} + steps: list = [] + for step in case["steps"]: + rid = step["request_id"] + life = lifecycles.get(rid) + if life is None: + life = lifecycles[rid] = Lifecycle(rid) + life.map() + try: + life.apply_decision(Decision.from_dict(step["decision"])) + refused = False + except (LifecycleError, ProtocolError): + refused = True + steps.append({"request_id": rid, "state": life.state.value, "refused": refused}) + problems = [] if steps == case["expected"] else [f"steps {steps!r} != {case['expected']!r}"] + return {"pass": not problems, "steps": steps, "problems": problems} + + def main(argv: Optional[list] = None) -> int: ap = argparse.ArgumentParser(prog="interplane-conformance") ap.add_argument("fixtures_dir") @@ -129,13 +151,18 @@ def main(argv: Optional[list] = None) -> int: (d / f"{case['case']}.results.json").write_text( jcs(verdict["results"]) + "\n", encoding="utf-8" ) + lifecycle: dict = {} + for path in sorted(Path(args.fixtures_dir, "lifecycle").glob("*.json")): + case = json.loads(path.read_text(encoding="utf-8")) + lifecycle[case["case"]] = run_lifecycle_case(case) failed = 0 - for name, v in sorted(verdicts.items()): + for name, v in sorted({**verdicts, **lifecycle}.items()): print(f"{'PASS' if v['pass'] else 'FAIL'} {name}") for p in v["problems"]: print(f" {p}") failed += not v["pass"] - print(f"{len(verdicts) - failed}/{len(verdicts)} passed") + total = len(verdicts) + len(lifecycle) + print(f"{total - failed}/{total} passed") out = { k: {f: v[f] for f in ("pass", "observed", "turns", "runtime", "selections") if f in v} for k, v in verdicts.items() @@ -143,6 +170,7 @@ def main(argv: Optional[list] = None) -> int: for v in out.values(): if not v.get("selections"): v.pop("selections", None) + out.update({k: {"pass": v["pass"], "steps": v["steps"]} for k, v in lifecycle.items()}) Path(args.out).write_text(jcs(out) + "\n", encoding="utf-8") return 1 if failed else 0 diff --git a/python/tests/test_conformance.py b/python/tests/test_conformance.py index 3cfb3a2..e6a4855 100644 --- a/python/tests/test_conformance.py +++ b/python/tests/test_conformance.py @@ -3,10 +3,11 @@ import json import pytest from interplane.core import jcs -from interplane.conformance import main, run_case +from interplane.conformance import main, run_case, run_lifecycle_case from conftest import CONF, load CASES = sorted(CONF.glob("*.json")) +LIFECYCLE = sorted((CONF / "lifecycle").glob("*.json")) @pytest.mark.skipif(not CASES, reason="no conformance fixtures") @@ -22,16 +23,33 @@ def test_runner_writes_sorted_verdicts(tmp_path, capsys): assert main([str(CONF), "--out", str(out)]) == 0 text = out.read_text(encoding="utf-8") data = json.loads(text) - assert list(data) == sorted(data) and len(data) == len(CASES) + assert list(data) == sorted(data) and len(data) == len(CASES) + len(LIFECYCLE) + life = {k: data.pop(k) for k in list(data) if k.startswith("lifecycle/")} + assert len(life) == len(LIFECYCLE) + assert all(v["pass"] and set(v) == {"pass", "steps"} for v in life.values()) base = {"pass", "observed", "runtime", "turns"} assert all(v["pass"] and set(v) - {"selections"} == base for v in data.values()) assert {k for k, v in data.items() if "selections" in v} == { "24-expansion-requested-excluded", "25-expansion-refused-by-bound", } - assert text == jcs(data) + "\n" + assert text == jcs({**data, **life}) + "\n" assert all(o["result_digest"] for v in data.values() for o in v["observed"]) - assert "25/25" in capsys.readouterr().out or len(CASES) != 25 + assert "30/30" in capsys.readouterr().out or len(CASES) + len(LIFECYCLE) != 30 + + +@pytest.mark.skipif(not LIFECYCLE, reason="no lifecycle fixtures") +@pytest.mark.parametrize("path", LIFECYCLE, ids=lambda p: p.stem) +def test_lifecycle_case_passes(path): + verdict = run_lifecycle_case(load(path)) + assert verdict["problems"] == [] + + +@pytest.mark.skipif(not LIFECYCLE, reason="no lifecycle fixtures") +def test_lifecycle_runner_fails_on_mismatch(): + case = load(LIFECYCLE[0]) + case["expected"][1]["refused"] = False + assert run_lifecycle_case(case)["pass"] is False @pytest.mark.skipif(not CASES, reason="no conformance fixtures") diff --git a/rust/crates/interplane-conformance/src/lib.rs b/rust/crates/interplane-conformance/src/lib.rs index 69a084a..f398b4a 100644 --- a/rust/crates/interplane-conformance/src/lib.rs +++ b/rust/crates/interplane-conformance/src/lib.rs @@ -2,7 +2,7 @@ //! mock runtime per case and compares the result with `expected`. use std::path::Path; -use interplane_core::{canonicalize, digest, Limits, RequestLedger}; +use interplane_core::{canonicalize, digest, Decision, Lifecycle, Limits, RequestLedger}; use interplane_crossaxis::{expand, select}; use interplane_crossveil::{ mock_mapping_table, MockRuntime, ObservedRecord, Pipeline, RuntimeAuthority, @@ -267,3 +267,53 @@ pub fn verdicts(rows: Vec<(String, Value)>) -> Value { } Value::Object(m) } + +/// Load `lifecycle/NN-*.json` fixtures, sorted by file name. Absent directory = none. +pub fn load_lifecycle_fixtures(dir: &Path) -> Result<Vec<Value>, String> { + let sub = dir.join("lifecycle"); + if !sub.is_dir() { + return Ok(vec![]); + } + load_fixtures(&sub) +} + +/// Drive the Crossveil lifecycle directly (no pipeline): for each step, the lifecycle of +/// `request_id` (created and mapped on first sight) receives `decision`. Each step yields the +/// state after the call and whether the call was refused. Returns `(rows, disagreements)`. +pub fn run_lifecycle_case(fx: &Value) -> (Vec<Value>, Vec<String>) { + let mut lcs: Vec<Lifecycle> = vec![]; + let mut rows = vec![]; + for step in fx["steps"].as_array().cloned().unwrap_or_default() { + let rid = step["request_id"].as_str().unwrap_or("").to_string(); + let idx = match lcs.iter().position(|l| l.request_id() == rid) { + Some(i) => i, + None => { + let mut l = Lifecycle::new(&rid); + let _ = l.map(); + lcs.push(l); + lcs.len() - 1 + } + }; + let lc = &mut lcs[idx]; + let refused = match serde_json::from_value::<Decision>(step["decision"].clone()) { + Ok(d) => lc.apply_decision(&d).is_err(), + Err(_) => true, + }; + rows.push(json!({"request_id": rid, "state": lc.state().name(), "refused": refused})); + } + let want = fx["expected"].as_array().cloned().unwrap_or_default(); + let mut errs = vec![]; + if want != rows { + errs.push(format!( + "steps: expected {}, got {}", + canonicalize(&Value::Array(want)), + canonicalize(&Value::Array(rows.clone())) + )); + } + (rows, errs) +} + +/// One row of the verdict file for a lifecycle case. +pub fn lifecycle_verdict(rows: &[Value], errs: &[String]) -> Value { + json!({"pass": errs.is_empty(), "steps": rows}) +} diff --git a/rust/crates/interplane-conformance/src/main.rs b/rust/crates/interplane-conformance/src/main.rs index 2457a57..0043d49 100644 --- a/rust/crates/interplane-conformance/src/main.rs +++ b/rust/crates/interplane-conformance/src/main.rs @@ -66,6 +66,31 @@ fn main() -> ExitCode { } rows.push((run.case.clone(), verdict(&run, &errs))); } + let lifecycle = match load_lifecycle_fixtures(&dir) { + Ok(f) => f, + Err(e) => { + eprintln!("{e}"); + return ExitCode::from(2); + } + }; + for fx in &lifecycle { + let case = fx["case"] + .as_str() + .unwrap_or("lifecycle/unnamed") + .to_string(); + let (steps, errs) = run_lifecycle_case(fx); + println!( + "{:<4} {:<34} {}", + "L", + case, + if errs.is_empty() { "PASS" } else { "FAIL" } + ); + for e in &errs { + println!(" - {e}"); + } + failed += usize::from(!errs.is_empty()); + rows.push((case, lifecycle_verdict(&steps, &errs))); + } match check_digest_fixture(&dir) { Some(e) => { println!("{:<4} {:<34} FAIL\n - {e}", "-", "digest/jcs-01"); @@ -79,7 +104,11 @@ fn main() -> ExitCode { return ExitCode::from(2); } } - println!("{} of {} cases failed", failed, fixtures.len()); + println!( + "{} of {} cases failed", + failed, + fixtures.len() + lifecycle.len() + ); if failed > 0 { ExitCode::from(1) } else { diff --git a/rust/crates/interplane-core/src/lifecycle.rs b/rust/crates/interplane-core/src/lifecycle.rs index 009f503..5113308 100644 --- a/rust/crates/interplane-core/src/lifecycle.rs +++ b/rust/crates/interplane-core/src/lifecycle.rs @@ -51,7 +51,9 @@ pub enum LifecycleError { NotAuthorized, #[error("decision is for a different request")] WrongRequest, - #[error("approval transition needs a decision carrying approval.approval_id")] + /// The continuation did not cite the approval_id the runtime minted for this request + /// (absent, empty, never minted, or minted for another request). + #[error("approval requires a new decision citing the approval_id")] MissingApproval, } @@ -62,6 +64,9 @@ pub enum LifecycleError { pub struct Lifecycle { request_id: String, state: State, + /// The non-empty approval_id the runtime minted in the decision that entered + /// REQUIRES_APPROVAL. A continuation must cite exactly this id. + approval_id: Option<String>, } impl Lifecycle { @@ -70,6 +75,7 @@ impl Lifecycle { Self { request_id: request_id.to_string(), state: State::Proposed, + approval_id: None, } } pub fn state(&self) -> State { @@ -95,8 +101,10 @@ impl Lifecycle { } /// Apply a runtime decision. From MAPPED: authorized -> AUTHORIZED, denied (and any unknown /// value) -> DENIED, requires_approval -> REQUIRES_APPROVAL, invalid/not_found -> REJECTED. - /// From REQUIRES_APPROVAL: only a NEW decision carrying `approval.approval_id`, either - /// authorized -> AUTHORIZED or denied/unknown -> DENIED. + /// From REQUIRES_APPROVAL: only a NEW decision citing the non-empty `approval.approval_id` + /// the runtime minted when it required approval; authorized -> AUTHORIZED, every other + /// value -> DENIED. Any other id (absent, empty, never minted, minted for another request) + /// is refused with [`LifecycleError::MissingApproval`] and the state does not change. pub fn apply_decision(&mut self, d: &Decision) -> Result<State, LifecycleError> { if d.request_id != self.request_id { return Err(LifecycleError::WrongRequest); @@ -106,24 +114,23 @@ impl Lifecycle { let next = match &d.decision { DecisionKind::Authorized => State::Authorized, DecisionKind::Denied => State::Denied, - DecisionKind::RequiresApproval => State::RequiresApproval, + DecisionKind::RequiresApproval => { + self.approval_id = minted_id(d); + State::RequiresApproval + } DecisionKind::NotFound | DecisionKind::Invalid => State::Rejected, DecisionKind::Unknown(_) => State::Denied, }; self.set(next) } State::RequiresApproval => { - let has = d - .approval - .as_ref() - .is_some_and(|a| !a.approval_id.is_empty()); - if !has { + let cited = minted_id(d); + if cited.is_none() || cited != self.approval_id { return Err(LifecycleError::MissingApproval); } match &d.decision { DecisionKind::Authorized => self.set(State::Authorized), - DecisionKind::Denied | DecisionKind::Unknown(_) => self.set(State::Denied), - _ => Err(LifecycleError::Illegal { from: self.state }), + _ => self.set(State::Denied), } } from => Err(LifecycleError::Illegal { from }), @@ -156,3 +163,11 @@ impl Lifecycle { Ok(s) } } + +/// The decision's `approval.approval_id`, if present and non-empty. +fn minted_id(d: &Decision) -> Option<String> { + d.approval + .as_ref() + .map(|a| a.approval_id.clone()) + .filter(|id| !id.is_empty()) +} diff --git a/rust/crates/interplane-core/tests/core.rs b/rust/crates/interplane-core/tests/core.rs index 2e3309c..297f08c 100644 --- a/rust/crates/interplane-core/tests/core.rs +++ b/rust/crates/interplane-core/tests/core.rs @@ -387,6 +387,48 @@ fn lifecycle_approval_needs_new_decision_with_approval_id() { ); } #[test] +fn lifecycle_continuation_must_cite_the_minted_approval_id() { + // Mirrors python/tests/test_core.py test_requires_approval_needs_new_decision_citing_id. + let mut l = Lifecycle::new("r1"); + l.map().unwrap(); + l.apply_decision(&decision("requires_approval", Some("A1"))) + .unwrap(); + for bad in [Some("forged"), Some(""), Some("mock-approval-r2"), None] { + assert_eq!( + l.apply_decision(&decision("authorized", bad)), + Err(LifecycleError::MissingApproval), + "{bad:?} must be refused" + ); + assert_eq!(l.state(), State::RequiresApproval); + } + assert_eq!( + l.apply_decision(&decision("authorized", Some("A1"))) + .unwrap(), + State::Authorized + ); + // A request whose requires_approval decision minted no id can never be continued. + let mut l = Lifecycle::new("r1"); + l.map().unwrap(); + l.apply_decision(&decision("requires_approval", None)) + .unwrap(); + assert_eq!( + l.apply_decision(&decision("authorized", Some("A1"))), + Err(LifecycleError::MissingApproval) + ); + // With the minted id, every value but authorized is DENIED. + for kind in ["requires_approval", "not_found", "invalid", "weird"] { + let mut l = Lifecycle::new("r1"); + l.map().unwrap(); + l.apply_decision(&decision("requires_approval", Some("A1"))) + .unwrap(); + assert_eq!( + l.apply_decision(&decision(kind, Some("A1"))).unwrap(), + State::Denied, + "{kind}" + ); + } +} +#[test] fn lifecycle_rejections_and_wrong_request() { let mut l = Lifecycle::new("r1"); assert_eq!(l.reject().unwrap(), State::Rejected); diff --git a/spec/CORE.md b/spec/CORE.md index 7a7a608..f2e2dec 100644 --- a/spec/CORE.md +++ b/spec/CORE.md @@ -48,7 +48,7 @@ MAPPED -> REQUIRES_APPROVAL runtime decision = requires_approval -> AUTHORIZED runtime decision = authorized REQUIRES_APPROVAL - -> AUTHORIZED | DENIED only by a NEW runtime decision that cites the approval_id + -> AUTHORIZED | DENIED only by a NEW runtime decision that cites the minted approval_id AUTHORIZED -> EXECUTING runtime began execution EXECUTING @@ -57,7 +57,12 @@ EXECUTING Terminal: REJECTED, DENIED, SUCCEEDED, FAILED, TIMED_OUT. REQUIRES_APPROVAL is terminal for the request as far as the model is concerned; a later authorization is a new decision on the same -`request_id` carrying `approval.approval_id`. +`request_id` carrying `approval.approval_id`. The lifecycle keeps the non-empty `approval_id` from +the `requires_approval` decision that put the request in REQUIRES_APPROVAL, and accepts a +continuation only when it cites exactly that id. A continuation with no id, an empty id, an id the +runtime never minted, or an id minted for another request is refused and the state does not change. +With the minted id, `authorized` gives AUTHORIZED and every other value (including unknown values) +gives DENIED. Conformance: `conformance/fixtures/lifecycle/`. Invariants (every implementation must enforce; conformance tests check them): @@ -206,6 +211,25 @@ A `step` with `dialect` is parsed by Lenshift; the runner wraps each intent in a `envelope` is admitted as-is. Rendered results are fed back into the next step only when the step declares `"continues": true`. +Lifecycle fixtures live under `conformance/fixtures/lifecycle/NN-slug.json` and drive the +lifecycle state machine directly, with no pipeline and no mock runtime: + +```json +{ + "case": "lifecycle/01-forged-approval-id", + "description": "...", + "steps": [ {"request_id": "call_L01", "decision": <decision>} ], + "expected": [ {"request_id": "call_L01", "state": "REQUIRES_APPROVAL", "refused": false} ] +} +``` + +The runner creates and maps a lifecycle the first time it sees a `request_id`, then applies the +step's `decision` to it. The first decision on each request is the runtime's `requires_approval` +decision that mints the `approval_id`; later steps are continuation attempts. Each step yields the +state after the call and `refused` (true when the lifecycle refused the decision or the decision +did not parse). The verdict row is `{"pass", "steps"}` under the key `lifecycle/<slug>`; rows of +the `NN-slug` cases are unchanged. + ObservedRecord (deterministic, no timestamps, no durations): ```json