()
| 12 | |
| 13 | |
| 14 | def main(): |
| 15 | parser = argparse.ArgumentParser(description=__doc__) |
| 16 | parser.add_argument("intent_id") |
| 17 | parser.add_argument("output_directory", type=Path) |
| 18 | parser.add_argument("--atomic", default="atomic") |
| 19 | args = parser.parse_args() |
| 20 | report = subprocess.run( |
| 21 | [args.atomic, "intent", "validate", args.intent_id, "--json", "--evidence-context"], |
| 22 | check=False, capture_output=True, text=True, |
| 23 | ) |
| 24 | # Exit 2 is normal for an unattested draft. Other gate violations stay in |
| 25 | # the report and will still fail validation when the example is replayed. |
| 26 | if report.returncode not in {0, 2}: |
| 27 | raise SystemExit(report.stderr) |
| 28 | context = json.loads(report.stdout)["evidence_context"] |
| 29 | shown = subprocess.run([args.atomic, "intent", "show", args.intent_id, "--json"], |
| 30 | check=True, capture_output=True, text=True) |
| 31 | criteria = json.loads(shown.stdout)["hasAcceptanceCriterion"] |
| 32 | if len(criteria) != 1: |
| 33 | raise SystemExit("example requires exactly one criterion; author a policy for each real criterion") |
| 34 | source = b"The selected literal passage is retained.\n" |
| 35 | record = source + b"Synthetic review copy.\n" |
| 36 | root = args.output_directory |
| 37 | root.mkdir(parents=True, exist_ok=False) |
| 38 | (root / "source.txt").write_bytes(source) |
| 39 | (root / "record.txt").write_bytes(record) |
| 40 | digest = lambda data: hashlib.sha256(data).hexdigest() |
| 41 | case = {"schema_version": "probity-case/v1", "case_id": "synthetic-source-coverage", "artifacts": { |
| 42 | "source": {"path": "source.txt", "sha256": digest(source), "length": len(source)}, |
| 43 | "record": {"path": "record.txt", "sha256": digest(record), "length": len(record)}, |
| 44 | }} |
| 45 | policy = {"schema_version": "probity-policy/v1", "witnesses": {"source": { |
| 46 | "artifact": "source", "sha256": digest(source), "captured_at": "2026-10-02T00:00:00Z", |
| 47 | "source_url": "https://example.invalid/synthetic-source", "authority": "synthetic local fixture", |
| 48 | "source_format": "text_utf8/v1", |
| 49 | }}, "assessments": {case["case_id"]: { |
| 50 | "claim_type": "source_text_coverage/v1", "source_witness": "source", "record_artifact": "record", |
| 51 | "record_sha256": digest(record), "record_version": "synthetic-fixture-1", |
| 52 | "source_window": {"start": "2026-10-01T00:00:00Z", "end": "2026-10-03T00:00:00Z"}, |
| 53 | "required_spans": [{"id": "passage-1", "text": "selected literal passage is retained"}], |
| 54 | }}} |
| 55 | manifest = {"schema_version": "atomic-evidence-replay-manifest/v1", "context": context, "claims": [{ |
| 56 | "criterion_id": criteria[0]["@id"], "claim_type": "source_text_coverage/v1", |
| 57 | "artifact_root": ".", "case": case, "policy": policy, |
| 58 | }]} |
| 59 | (root / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8") |
| 60 | print(root / "manifest.json") |
| 61 | |
| 62 | |
| 63 | if __name__ == "__main__": |
no test coverage detected