Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.ci.schema

Requirements index · View definition

evidence Valid

Requirement

A requirement or example evidence file at evidence/<full-name>.json MUST be a JSON object with exactly requirement or example, determination, rationale, references, and inputs. references MUST be the reference-set digest defined by cite requirements.ci.reference_set. The definition text and rationale MUST be nonempty strings, determination MUST use one of the outcomes defined by cite requirements.ci.outcomes, and inputs MUST be an array. Every evidence input MUST have exactly one of three forms: an outline input with file, item, and hash; a requirements input with requirements, matches, and text; or a definition input with definition and text. File paths MUST resolve to permitted inputs under cite requirements.ci.input_containment. Project-local paths SHOULD be recorded relative to the project for portability; absolute and parent-relative paths MAY be used when their resolved targets are permitted. matches MUST be an array of distinct full definition names, hash MUST be a lowercase hexadecimal SHA-256 digest, and text MUST be a nonempty array of strings. Evidence MUST NOT store source text for outline inputs.

Rationale

The reviewed tests cover each obligation in requirements.ci.schema, and their assertions enforce the outcomes.

Top-level object and exact fields

  • src/evidence.rs#mod[tests]/fn[schema_rejects_each_malformed_field_and_input_form] asserts that a top-level array is rejected with “expected a JSON object”.
  • The same test asserts that a whitespace-only requirement gives “requirement must not be empty” and that a whitespace-only rationale gives “rationale must not be empty”.
  • fn[collects_missing_orphan_format_false_and_changed_line_errors] asserts the errors “requirement must be a string”, missing field "determination" and “inputs must be an array”.
  • fn[cited_example_with_a_test_and_matching_evidence_validates] swaps example for requirement and asserts both missing field "example" and unexpected field "requirement".
  • tests/authoring_cli.rs#fn[stdout_emits_only_evidence_json_without_changing_project_files] asserts that authored output has exactly determination, inputs, rationale, references and requirement.
  • src/evidence.rs reaches the nonempty-text check through the shared string_field helper.

references digest

  • fn[validation_requires_a_current_reference_set_digest] covers a missing field, a non-string value, an uppercase digest and a truncated digest. It also checks that a current digest validates.
  • It checks that a newly added reference inside an already-covered node makes the evidence stale.

determination outcomes

  • tests/outcomes.rs#fn[judgments_round_trip_and_reject_invalid_fixme_shapes] and fn[malformed_fixme_is_invalid_and_reports_the_required_shape] cover valid and invalid shapes.
  • The invalid shapes include null, a string, an empty array and FIXME objects with an empty array, an empty string, a non-string entry or an extra key.
  • tests/commands.rs#fn[fixme_fixture] covers valid FIXME evidence being accepted.

Three input forms, exactly one

  • fn[schema_rejects_each_malformed_field_and_input_form] covers the following cases:
    • a non-object input
    • a definition input with a non-string definition, an empty text array, or an extra requirements field
    • a requirements input with duplicate matches, a non-string matches entry, a matches value that is not an array, or a missing matches or requirements
    • an outline input with an extra text field
  • fn[collects_missing_orphan_format_false_and_changed_line_errors] covers an old-style input with line_start, which gives an unexpected-field error and a missing item. It also covers a non-string text element.
  • tests/evidence_boundaries.rs#fn[outline_inputs_survive_moves_and_unhashed_comments_but_not_edits] covers rust_file and text as unexpected fields, and an input with a file and item but no hash.
  • The nonempty-text check is the shared text_field helper, which every input form uses.

hash format

  • Tests cover a 63-character hash, a non-hex g hash and the uppercase ABC.

Containment and path recording

  • fn[symlinks_may_resolve_inside_but_not_to_a_sibling_with_the_same_prefix] covers a symlink that resolves outside the project.
  • fn[definition_and_requirements_inputs_obey_containment_for_declaring_files] covers a disallowed declaring file for definition and requirements inputs.
  • src/authoring/tools.rs#mod[tests]/fn[project_local_absolute_paths_are_recorded_relative_to_the_project] checks that absolute and ./ paths are recorded project-relative. This covers the SHOULD on relative recording.
  • Absolute and parent-relative paths are a MAY, so nothing needs checking there.

No source text for outline inputs

  • Validation rejects text on an outline input (see above).
  • The authoring test asserts that each outline input has exactly the keys file, hash and item.

I found no obligation that lacks a test with an assertion on its outcome.

Inputs

Tests

Input 5: outline src/authoring/tools.rs mod[tests]/fn[project_local_absolute_paths_are_recorded_relative_to_the_project]
    // {test}`requirements.ci.schema`
    #[test]
    fn project_local_absolute_paths_are_recorded_relative_to_the_project() {
        let root = project();
        fs::write(root.path().join("src/lib.rs"), "fn work() {}\n").unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        for path in [
            root.path().join("src/lib.rs"),
            fs::canonicalize(root.path()).unwrap().join("src/./lib.rs"),
        ] {
            let file = path.to_str().unwrap();
            for arguments in [
                json!({"file": file, "item": "fn[work]"}),
                json!({"file": file, "line_start": 1}),
            ] {
                let delivery = dispatch(&sources, "habeas", &arguments).unwrap();
                let recorded = delivery
                    .inputs
                    .iter()
                    .map(crate::inputs::recorded_input)
                    .filter(|input| input.get("item").is_some())
                    .collect::<Vec<_>>();
                assert_eq!(recorded.len(), 1, "{arguments}: {recorded:?}");
                assert_eq!(recorded[0]["file"], "src/lib.rs", "{arguments}");
                assert_eq!(recorded[0]["item"], "fn[work]", "{arguments}");
            }
        }
    }
Input 6: outline src/evidence.rs mod[tests]/fn[collects_missing_orphan_format_false_and_changed_line_errors]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[collects_missing_orphan_format_false_and_changed_line_errors]
  • Kind: fn
  • src/evidence.rs:2566–2667
    // {test}`requirements.integration.report_api`
    // {test}`requirements.ci.errors`
    // {test}`requirements.ci.diagnostics`
    // {test}`requirements.ci.input_containment`
    // {test}`requirements.ci.definition_errors`
    // {test}`requirements.ci.orphans`
    // {test}`requirements.ci.coverage`
    // {test}`requirements.ci.determination`
    // {test}`requirements.ci.outline_inputs`
    // {test}`requirements.ci.requirement_text`
    // {test}`requirements.ci.schema`
    #[test]
    fn collects_missing_orphan_format_false_and_changed_line_errors() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/requirements.md"),
            "# Requirements\n\n:::{req} one\nFirst.\n:::\n\n:::{req} two\nSecond.\n:::\n\n:::{req} three\nThird.\n:::\n\n:::{req} one\nDuplicate.\n:::\n\n:::{req} empty\n  \n:::\n",
        )
        .unwrap();
        fs::write(
            temp.path().join("evidence/requirements.one.json"),
            json!({
                "requirement": "Old text.",
                "determination": false,
                "rationale": "Work remains.",
                "inputs": [
                    {
                        "file": "src/main.rs",
                        "item": "",
                        "hash": "0".repeat(64)
                    },
                    {
                        "file": "",
                        "item": 0,
                        "hash": "ABC"
                    },
                    {
                        "file": "src/main.rs",
                        "item": "fn[missing]",
                        "hash": "0".repeat(64)
                    },
                    {
                        "file": "src/main.rs",
                        "line_start": 1,
                        "line_end": 1,
                        "text": ["// first line"]
                    },
                    {
                        "requirements": "requirements.two",
                        "matches": ["requirements.two"],
                        "text": [1]
                    }
                ]
            })
            .to_string(),
        )
        .unwrap();
        fs::write(
            temp.path().join("evidence/requirements.three.json"),
            json!({"requirement": 3, "inputs": {}}).to_string(),
        )
        .unwrap();
        fs::write(
            temp.path().join("evidence/ghost.json"),
            json!({
                "requirement": "Ghost.",
                "determination": true,
                "rationale": "A valid but orphaned file.",
                "inputs": []
            })
            .to_string(),
        )
        .unwrap();
        fs::write(temp.path().join("evidence/broken.json"), "{").unwrap();

        let report = validate_repository(temp.path()).unwrap();
        let errors = report.errors.join("\n");
        for detail in [
            "no matching requirement",
            "invalid JSON",
            "missing for requirement",
            "requirement text changed",
            "- Old text.",
            "+ First.",
            "determination is false",
            "inputs[0]: outline input changed: src/main.rs <root> (now lines 1-2) no longer has the recorded hash",
            "inputs[1]: file must be a nonempty path",
            "inputs[1]: item must be a string",
            "inputs[1]: hash must be a lowercase hexadecimal SHA-256 digest",
            "inputs[2]: src/main.rs: no outline node matches \"fn[missing]\"",
            "inputs[3]: unexpected field \"line_start\"",
            "inputs[3]: missing field \"item\"",
            "inputs[4]: text[0] must be a string",
            "requirement must be a string",
            "missing field \"determination\"",
            "inputs must be an array",
            "duplicate requirement requirements.one; first declared at md/requirements.md:3",
            "requirement requirements.empty has no text",
        ] {
            assert!(errors.contains(detail), "missing {detail:?} in:\n{errors}");
        }
    }
Input 7: outline src/evidence.rs mod[tests]/fn[schema_rejects_each_malformed_field_and_input_form]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[schema_rejects_each_malformed_field_and_input_form]
  • Kind: fn
  • src/evidence.rs:3102–3182
    // {test}`requirements.ci.schema`
    #[test]
    fn schema_rejects_each_malformed_field_and_input_form() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/rules.md"),
            "# Rules\n\n:::{req} ready\nReady.\n:::\n\n:::{req} blank\nBlank.\n:::\n\n:::{req} listed\nListed.\n:::\n\n:::{definition} term\n:phrase: term\n\nA term.\n:::\n",
        )
        .unwrap();
        // A whitespace-only definition text and a top-level value that is not
        // an object are each rejected.
        fs::write(
            temp.path().join("evidence/rules.blank.json"),
            json!({
                "requirement": " \n",
                "determination": true,
                "rationale": "Examined.",
                "references": "0".repeat(64),
                "inputs": []
            })
            .to_string(),
        )
        .unwrap();
        fs::write(temp.path().join("evidence/rules.listed.json"), "[]").unwrap();
        let term = [
            ":::{definition} term",
            ":phrase: term",
            "",
            "A term.",
            ":::",
        ];
        fs::write(
            temp.path().join("evidence/rules.ready.json"),
            json!({
                "requirement": "Ready.",
                "determination": true,
                "rationale": " \n",
                "inputs": [
                    {"definition": "rules.term", "text": term},
                    {"definition": 7, "text": term},
                    {"definition": "rules.term", "text": []},
                    {"definition": "rules.term", "requirements": "rules.*", "text": term},
                    {"requirements": "rules.ready", "matches": ["rules.ready", "rules.ready"], "text": ["x"]},
                    {"requirements": "rules.ready", "matches": [1], "text": ["x"]},
                    "src/main.rs",
                    {"file": "src/main.rs", "item": "", "hash": "a".repeat(63)},
                    {"file": "src/main.rs", "item": "", "hash": "g".repeat(64)},
                    {"file": "src/main.rs", "item": "", "hash": "0".repeat(64), "text": ["// first line"]},
                    {"matches": ["rules.ready"], "text": ["x"]},
                    {"requirements": "rules.ready", "text": ["x"]},
                    {"requirements": "rules.ready", "matches": "rules.ready", "text": ["x"]}
                ]
            })
            .to_string(),
        )
        .unwrap();
        let report = validate_repository(temp.path()).unwrap();
        let errors = report.errors.join("\n");
        let label = "evidence/rules.ready.json";
        for detail in [
            format!("{label}: rationale must not be empty"),
            format!("{label}: inputs[1]: definition must be a string"),
            format!("{label}: inputs[2]: text must be a nonempty array"),
            format!("{label}: inputs[3]: unexpected field \"requirements\""),
            format!("{label}: inputs[4]: matches must have distinct definition names"),
            format!("{label}: inputs[5]: matches[0] must be a string"),
            format!("{label}: inputs[6]: expected a JSON object"),
            format!("{label}: inputs[7]: hash must be a lowercase hexadecimal SHA-256 digest"),
            format!("{label}: inputs[8]: hash must be a lowercase hexadecimal SHA-256 digest"),
            format!("{label}: inputs[9]: unexpected field \"text\""),
            format!("{label}: inputs[10]: missing field \"requirements\""),
            format!("{label}: inputs[11]: missing field \"matches\""),
            format!("{label}: inputs[12]: matches must be an array"),
            "evidence/rules.blank.json: requirement must not be empty".to_owned(),
            "evidence/rules.listed.json: expected a JSON object".to_owned(),
        ] {
            assert!(errors.contains(&detail), "missing {detail:?} in:\n{errors}");
        }
        // The well-formed definition input is accepted.
        assert!(!errors.contains("inputs[0]"), "{errors}");
    }
Input 8: outline src/evidence.rs mod[tests]/fn[cited_example_with_a_test_and_matching_evidence_validates]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[cited_example_with_a_test_and_matching_evidence_validates]
  • Kind: fn
  • src/evidence.rs:3498–3632
    // {test}`requirements.examples.definition`
    // {test}`requirements.examples.evidence`
    // {test}`requirements.integration.report_api`
    // {test}`requirements.ci.schema`
    // {test}`requirements.references.evidence_coverage`
    // {test}`requirements.ci.requirements_inputs`
    // {test}`requirements.ci.orphans`
    #[test]
    fn cited_example_with_a_test_and_matching_evidence_validates() {
        let temp = fixture();
        let chapter = "# Rules\n\n:::{req} ready\nReady.\n:::\n\n:::{example} case\nGiven ready, it succeeds. {cite}`rules.ready` {test}`rules.ready`\n:::\n";
        fs::write(temp.path().join("md/rules.md"), chapter).unwrap();
        let test_source = "// {test}`rules.case`\n#[test]\nfn checks_case() { assert!(true); }\n";
        fs::write(temp.path().join("src/main.rs"), test_source).unwrap();
        fs::write(
            temp.path().join("evidence/rules.ready.json"),
            json!({
                "requirement": "Ready.",
                "determination": true,
                "rationale": "The example cites this rule.",
                "inputs": crate::inputs::outline_inputs_for_lines(temp.path(), "md/rules.md", 8, 8)
                    .unwrap()
            })
            .to_string(),
        )
        .unwrap();
        let example_path = temp.path().join("evidence/rules.case.json");
        fs::write(
            &example_path,
            json!({
                "example": "Given ready, it succeeds. {cite}`rules.ready` {test}`rules.ready`",
                "determination": true,
                "rationale": "checks_case sets up ready and asserts the result.",
                "inputs": [
                    outline(temp.path(), "src/main.rs", "fn[checks_case]"),
                    {
                        "requirements": "rules.*",
                        "matches": ["rules.case", "rules.ready"],
                        "text": [
                            chapter.lines().nth(6).unwrap(),
                            chapter.lines().nth(7).unwrap(),
                            chapter.lines().nth(8).unwrap(),
                            "",
                            chapter.lines().nth(2).unwrap(),
                            chapter.lines().nth(3).unwrap(),
                            chapter.lines().nth(4).unwrap()
                        ]
                    }
                ]
            })
            .to_string(),
        )
        .unwrap();

        let report = validate_repository(temp.path()).unwrap();
        assert_eq!(report.requirements, 1);
        assert_eq!(report.examples, 1);
        assert_eq!(report.evidence_files, 2);
        assert!(report.errors.is_empty(), "{:?}", report.errors);

        let ready_path = temp.path().join("evidence/rules.ready.json");
        let ready = fs::read_to_string(&ready_path).unwrap();
        let mut missing: Value = serde_json::from_str(&ready).unwrap();
        missing["inputs"] = json!([]);
        fs::write(&ready_path, missing.to_string()).unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors;
        assert!(
            errors.iter().any(|error| error.contains("no input covers")
                && error.contains("{test}")
                && error.contains("rules.ready")
                && error.contains("md/rules.md:8")),
            "{errors:?}"
        );
        fs::write(ready_path, ready).unwrap();

        let old = fs::read_to_string(&example_path).unwrap();
        let mut uncovered: serde_json::Value = serde_json::from_str(&old).unwrap();
        uncovered["inputs"] = json!([]);
        fs::write(&example_path, uncovered.to_string()).unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(errors.contains("no input covers"), "{errors}");
        assert!(errors.contains("src/main.rs:1"), "{errors}");
        fs::write(&example_path, &old).unwrap();
        fs::write(
            temp.path().join("src/main.rs"),
            test_source.replace("assert!(true)", "assert!(false)"),
        )
        .unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(
            errors.contains(
                "outline input changed: src/main.rs fn[checks_case] (now lines 1-3) no longer has the recorded hash"
            ),
            "{errors}"
        );
        fs::write(temp.path().join("src/main.rs"), test_source).unwrap();
        fs::write(
            temp.path().join("md/rules.md"),
            format!("{chapter}\n:::{req} added\nAdded.\n:::\n", req = "{req}"),
        )
        .unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(
            errors.contains(
                "requirements glob \"rules.*\" matches changed; added [\"rules.added\"], removed []"
            ),
            "{errors}"
        );

        let mut evidence: serde_json::Value = serde_json::from_str(&old).unwrap();
        evidence["example"] = "Outdated.".into();
        fs::write(&example_path, evidence.to_string()).unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(errors.contains("example text changed"), "{errors}");
        assert!(errors.contains("- Outdated."), "{errors}");

        let mut wrong_field: serde_json::Value = serde_json::from_str(&old).unwrap();
        let example_text = wrong_field
            .as_object_mut()
            .unwrap()
            .remove("example")
            .unwrap();
        wrong_field["requirement"] = example_text;
        fs::write(&example_path, wrong_field.to_string()).unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(errors.contains("missing field \"example\""), "{errors}");
        assert!(
            errors.contains("unexpected field \"requirement\""),
            "{errors}"
        );

        fs::remove_file(&example_path).unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(errors.contains("missing for example"), "{errors}");
    }
Input 9: outline src/evidence.rs mod[tests]/fn[validation_requires_a_current_reference_set_digest]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[validation_requires_a_current_reference_set_digest]
  • Kind: fn
  • src/evidence.rs:4109–4186
    // {test}`requirements.ci.reference_set`
    // {test}`requirements.ci.schema`
    #[test]
    fn validation_requires_a_current_reference_set_digest() {
        let temp = fixture();
        let root = temp.path();
        fs::write(
            root.join("md/requirements.md"),
            ":::{req} ready\nReady MUST hold.\n:::\n",
        )
        .unwrap();
        let impl_role = "{impl}`requirements.ready`";
        let cite_role = "{cite}`requirements.ready`";
        fs::write(
            root.join("src/lib.rs"),
            format!(
                "// {impl_role}\nfn run() {{}}\n\n// {cite_role}\nfn other() {{\n    work();\n}}\n"
            ),
        )
        .unwrap();
        let path = root.join("evidence/requirements.ready.json");
        let write = |references: Option<Value>| {
            let mut record = json!({
                "requirement": "Ready MUST hold.",
                "determination": true,
                "rationale": "Checked.",
                "inputs": [outline(root, "src/lib.rs", "")],
            });
            if let Some(references) = references {
                record["references"] = references;
            }
            fs::write(&path, record.to_string()).unwrap();
        };
        let errors = || without_citation_reviews(super::validate_repository(root).unwrap().errors);

        let current = super::reference_set_digest_for(root, "requirements.ready").unwrap();
        write(Some(json!(current)));
        assert!(errors().is_empty(), "{:?}", errors());

        for (references, expected) in [
            (
                None,
                "evidence/requirements.ready.json: missing field \"references\"",
            ),
            (
                Some(json!(7)),
                "evidence/requirements.ready.json: references must be a string",
            ),
            (
                Some(json!(current.to_uppercase())),
                "evidence/requirements.ready.json: references must be a lowercase hexadecimal SHA-256 digest",
            ),
            (
                Some(json!(&current[1..])),
                "evidence/requirements.ready.json: references must be a lowercase hexadecimal SHA-256 digest",
            ),
        ] {
            write(references);
            assert_eq!(errors(), [expected]);
        }

        // A new reference inside a node the inputs already cover changes no
        // recorded hash, but makes the evidence stale.
        write(Some(json!(current)));
        fs::write(
            root.join("src/lib.rs"),
            format!(
                "// {impl_role}\nfn run() {{}}\n\n// {cite_role}\nfn other() {{\n    // {impl_role}\n    work();\n}}\n"
            ),
        )
        .unwrap();
        let reported = errors();
        assert_eq!(reported.len(), 1, "{reported:?}");
        assert!(
            reported[0].starts_with("evidence/requirements.ready.json: reference set changed"),
            "{reported:?}"
        );
    }
Input 10: outline tests/authoring_cli.rs fn[stdout_emits_only_evidence_json_without_changing_project_files]
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.reporting`
// {test}`requirements.ci.schema`
#[test]
fn stdout_emits_only_evidence_json_without_changing_project_files() {
    for (determination, kind, existing_evidence, verbose) in [
        (json!(true), "true", true, false),
        (json!(false), "false", true, false),
        (json!({"FIXME":["#125"]}), "FIXME", true, false),
        (json!(true), "true", false, false),
        (json!(false), "false", true, true),
        (json!(true), "true", true, true),
    ] {
        let rationale = "The supplied sources explain this judgment.";
        let server = Server::start(vec![reply(vec![call(
            "submit",
            "submit_judgment",
            json!({"determination":determination,"rationale":rationale}),
        )])]);
        let fixture = Fixture::new(&server.endpoint);
        if !existing_evidence {
            fs::remove_dir_all(fixture.project.join("evidence")).unwrap();
        }
        let mut args = vec!["author-evidence", SUBJECT, "--stdout"];
        if verbose {
            args.push("--verbose");
        }
        let output = fixture.run(&args);
        assert!(
            output.status.success(),
            "{}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert_eq!(server.finish().len(), 1);
        let evidence: Value = serde_json::from_slice(&output.stdout).unwrap();
        assert!(output.stdout.ends_with(b"\n"));
        assert_eq!(evidence["requirement"], REQUIREMENT);
        assert_eq!(evidence["determination"], determination);
        assert_eq!(evidence["rationale"], rationale);
        let inputs = evidence["inputs"].as_array().unwrap();
        assert!(inputs.iter().any(|input| input["requirements"] == SUBJECT));
        assert!(
            inputs
                .iter()
                .any(|input| input["definition"] == "terms.readiness")
        );
        assert!(
            inputs
                .iter()
                .any(|input| input["file"] == "src/lib.rs" && input["item"].is_string())
        );
        // The record has exactly the schema's fields, and outline inputs carry
        // only their file, selector, and hash, never source text.
        let keys = |value: &Value| {
            let mut keys: Vec<_> = value.as_object().unwrap().keys().cloned().collect();
            keys.sort();
            keys
        };
        assert_eq!(
            keys(&evidence),
            [
                "determination",
                "inputs",
                "rationale",
                "references",
                "requirement"
            ]
        );
        for input in inputs.iter().filter(|input| input.get("item").is_some()) {
            assert_eq!(keys(input), ["file", "hash", "item"], "{input}");
        }
        if existing_evidence {
            assert_eq!(
                fs::read_to_string(&fixture.evidence).unwrap(),
                fixture.original
            );
        } else {
            assert!(!fixture.project.join("evidence").exists());
        }
        let stderr = String::from_utf8_lossy(&output.stderr);
        assert!(
            stderr.contains(&format!("{SUBJECT}: ollama / {MODEL}")),
            "{stderr}"
        );
        assert!(!stderr.contains("— true"), "{stderr}");
        assert!(!stderr.contains(&format!("{SUBJECT}: true")), "{stderr}");
        assert_eq!(
            stderr.contains(&format!("{SUBJECT}: false")),
            kind == "false",
            "{stderr}"
        );
        if kind == "FIXME" {
            assert!(stderr.contains("— FIXME"), "{stderr}");
        }
        assert_eq!(
            stderr.contains(rationale),
            verbose && kind == "false",
            "{stderr}"
        );
        assert!(!stderr.contains("SECRET_REQUIREMENT_TEXT"), "{stderr}");
        assert!(!stderr.contains("SECRET_DEFINITION_TEXT"), "{stderr}");
        assert!(stderr.contains("Evidence: stdout\n"));
        let usage_path = stderr
            .lines()
            .find_map(|line| line.strip_prefix("Usage: "))
            .expect("stderr reports usage location");
        assert!(std::path::Path::new(usage_path).is_file());
        let usage = fixture.usage();
        assert_eq!(usage["outcome"], "completed");
        assert_eq!(usage["determination"], kind);
        assert_eq!(usage["evidence_output"], "stdout");
        assert_eq!(usage["evidence_written"], true);
    }
}
Input 11: outline tests/commands.rs fn[fixme_fixture]
// {test}`requirements.ci.outcomes`
// {test}`requirements.ci.determination`
// {test}`requirements.ci.schema`
// {test}`requirements.integration.report_api`
fn fixme_fixture() -> TempDir {
    let temp = TempDir::new().unwrap();
    fs::create_dir(temp.path().join("md")).unwrap();
    fs::create_dir(temp.path().join("evidence")).unwrap();
    fs::write(
        temp.path().join("Cargo.toml"),
        "[package]\nname = 'fixture'\n",
    )
    .unwrap();
    fs::write(temp.path().join("book.toml"), "[book]\nsrc = 'md'\n").unwrap();
    let example = "A concrete case. {cite}`rules.alpha`.";
    let declarations = [
        (
            "req",
            "alpha",
            "Alpha MUST work.",
            vec![
                "example/app#123",
                "rust-lang/rust#456",
                "Unlinked extra detail",
            ],
        ),
        (
            "req",
            "beta",
            "Beta MUST work.",
            vec![
                "example/app#123",
                "example/app#45",
                "Rust-Lang/rust#456",
                "An unrelated note",
            ],
        ),
        ("example", "case", example, vec!["example/app#45"]),
        (
            "req",
            "unlinked",
            "Unlinked MUST work.",
            vec![
                "No ticket for <script>alert(1)</script>",
                "#123 is not a qualified issue",
                "https://github.com/rust-lang/rust/issues/456",
            ],
        ),
    ];
    let source: String = declarations
        .iter()
        .map(|(kind, name, text, _)| format!(":::{{{kind}}} {name}\n{text}\n:::\n\n"))
        .collect();
    fs::write(temp.path().join("md/rules.md"), &source).unwrap();
    // Each judgment's strings come from the `{fixme}` references to it: one
    // naming its issues, and one per gap without an issue.
    let mut gaps = String::new();
    for (_, name, _, entries) in &declarations {
        let (issues, others): (Vec<&str>, Vec<&str>) = entries
            .iter()
            .partition(|entry| entry.contains('/') && !entry.contains(' ') && !entry.contains(':'));
        if !issues.is_empty() {
            gaps.push_str(&format!(":::{{fixme}} rules.{name}\n"));
            for issue in issues {
                gaps.push_str(&format!(":github: {issue}\n"));
            }
            gaps.push_str("Tracked gaps.\n:::\n\n");
        }
        for other in others {
            gaps.push_str(&format!(":::{{fixme}} rules.{name}\n{other}\n:::\n\n"));
        }
    }
    fs::write(temp.path().join("gaps.txt"), gaps).unwrap();
    let input = habeas::outline_input(temp.path(), "md/rules.md", "").unwrap();
    let gaps_input = habeas::outline_input(temp.path(), "gaps.txt", "").unwrap();
    for (kind, name, text, references) in declarations {
        let subject_key = if kind == "example" {
            "example"
        } else {
            "requirement"
        };
        fs::write(
            temp.path().join(format!("evidence/rules.{name}.json")),
            json!({
                subject_key: text,
                "determination": {"FIXME": references},
                "rationale": "The fixture records acknowledged implementation gaps.",
                "references": habeas::reference_set_digest_for(
                    temp.path(),
                    &format!("rules.{name}")
                )
                .unwrap(),
                "inputs": [input, gaps_input]
            })
            .to_string(),
        )
        .unwrap();
    }
    common::coverage_setup(temp.path());
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
    temp
}
Input 12: outline tests/evidence_boundaries.rs fn[outline_inputs_survive_moves_and_unhashed_comments_but_not_edits]
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.ci.input_containment`
// {test}`requirements.ci.diagnostics`
// {test}`requirements.ci.schema`
// {test}`requirements.ci.fixme_stale_input`
// {test}`requirements.references.selector_raw_lines`
// {test}`requirements.references.structural_hash`
#[test]
fn outline_inputs_survive_moves_and_unhashed_comments_but_not_edits() {
    let temp = fixture();
    let root = temp.path().join("project");
    // Citation reviews of the cited functions are checked elsewhere.
    let errors = |inputs: Vec<Value>| {
        write_inputs(&root, inputs);
        without_citation_reviews(validate_repository(&root).unwrap().errors).join("\n")
    };
    let rust = "// {cite}`rules.ready`\nfn alpha() { work(1); }\n\n/// Docs.\n// {cite}`rules.ready`\n#[allow(dead_code)]\nfn beta() {}\n";
    fs::write(root.join("src/lib.rs"), rust).unwrap();
    let inputs = vec![
        outline(&root, "src/lib.rs", "fn[alpha]"),
        outline(&root, "src/lib.rs", "fn[beta]"),
        habeas::outline_inputs_for_lines(&root, "data.txt", 2, 2)
            .unwrap()
            .remove(0),
    ];
    assert_eq!(errors(inputs.clone()), "");

    // Moving nodes and lines, and editing unhashed comments, keeps inputs valid.
    fs::write(
        root.join("src/lib.rs"),
        format!("// {{cite}}`rules.ready` moved below a new line\n\n{rust}")
            .replace("fn alpha() { work(1); }", "fn alpha() {\n    work(1);\n}"),
    )
    .unwrap();
    fs::write(root.join("data.txt"), "zero\nfirst\nsecond\n").unwrap();
    assert_eq!(errors(inputs.clone()), "");

    // Editing another node must not invalidate beta's recorded input.
    fs::write(root.join("src/lib.rs"), rust.replace("work(1)", "work(2)")).unwrap();
    assert_eq!(errors(vec![inputs[1].clone()]), "");

    // Editing a node's code or its doc comment makes the input stale, naming the
    // file, selector, and current line range.
    fs::write(
        root.join("src/lib.rs"),
        rust.replace("work(1)", "work(2)")
            .replace("/// Docs.", "/// Changed docs."),
    )
    .unwrap();
    let found = errors(inputs.clone());
    for expected in [
        "inputs[0]: outline input changed: src/lib.rs fn[alpha] (now lines 1-2) no longer has the recorded hash",
        "inputs[1]: outline input changed: src/lib.rs fn[beta] (now lines 4-7) no longer has the recorded hash",
    ] {
        assert!(found.contains(expected), "missing {expected:?}: {found}");
    }
    assert!(!found.contains("inputs[2]"), "{found}");
    assert!(!found.contains("work(2)"), "no diff: {found}");

    // An edited plain-text line is a different node.
    fs::write(root.join("data.txt"), "first\nchanged\n").unwrap();
    let found = errors(inputs[2..].to_vec());
    assert!(
        found.contains("data.txt: no outline node matches \"line@"),
        "{found}"
    );

    fs::write(
        root.join("src/lib.rs"),
        "// {cite}`rules.ready`\n#[cfg(a)]\nfn dup() {}\n// {cite}`rules.ready`\n#[cfg(b)]\nfn dup() {}\n",
    )
    .unwrap();
    let hash = "0".repeat(64);
    for (input, expected) in [
        (
            json!({"file":"src/lib.rs", "item":"fn[missing]", "hash":hash}),
            "src/lib.rs: no outline node matches \"fn[missing]\"",
        ),
        (
            json!({"file":"src/lib.rs", "item":"fn[dup]", "hash":hash}),
            "src/lib.rs: outline selector \"fn[dup]\" is ambiguous",
        ),
        (
            json!({"file":"src/lib.rs", "item":"fn[unclosed", "hash":hash}),
            "src/lib.rs: invalid outline selector \"fn[unclosed\"",
        ),
        (
            json!({"file":"src/lib.rs", "item":"fn[dup]#2", "hash":"ABC"}),
            "hash must be a lowercase hexadecimal SHA-256 digest",
        ),
        (
            json!({"file":"missing.txt", "item":"", "hash":hash}),
            "cannot open missing.txt",
        ),
        (
            json!({"file":"data.txt", "line_start":1, "line_end":1, "text":["first"]}),
            "unexpected field \"line_start\"",
        ),
        (
            json!({"rust_file":"src/lib.rs", "rust_item":"fn[dup]#1", "text":["fn dup() {}"]}),
            "unexpected field \"rust_file\"",
        ),
        (
            json!({"file":"src/lib.rs", "item":"fn[dup]#1", "hash":hash, "text":["fn dup() {}"]}),
            "unexpected field \"text\"",
        ),
    ] {
        let found = errors(vec![input]);
        assert!(found.contains(expected), "missing {expected:?}: {found}");
    }
    fs::write(root.join("src/broken.rs"), "fn {").unwrap();
    let found = errors(vec![
        json!({"file":"src/broken.rs", "item":"", "hash":hash}),
    ]);
    assert!(
        found.contains("src/broken.rs: cannot parse rust source"),
        "{found}"
    );
}
Input 13: outline tests/evidence_boundaries.rs fn[symlinks_may_resolve_inside_but_not_to_a_sibling_with_the_same_prefix]
// {test}`requirements.ci.input_containment`
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.ci.schema`
#[cfg(unix)]
#[test]
fn symlinks_may_resolve_inside_but_not_to_a_sibling_with_the_same_prefix() {
    use std::os::unix::fs::symlink;

    let temp = fixture();
    let root = temp.path().join("project");
    symlink(root.join("data.txt"), root.join("inside.txt")).unwrap();
    write_inputs(&root, vec![outline(&root, "inside.txt", "")]);
    assert!(validate_repository(&root).unwrap().errors.is_empty());

    let sibling = temp.path().join("project-sibling");
    fs::create_dir(&sibling).unwrap();
    fs::write(sibling.join("outside.rs"), "fn outside() {}\n").unwrap();
    symlink(sibling.join("outside.rs"), root.join("escape.rs")).unwrap();
    {
        let input = json!({"file":"escape.rs", "item":"fn[outside]", "hash":"0".repeat(64)});
        write_inputs(&root, vec![input]);
        let errors = validate_repository(&root).unwrap().errors.join("\n");
        assert!(
            errors.contains("escape.rs resolves outside the repository"),
            "{errors}"
        );
    }
}
Input 14: outline tests/evidence_boundaries.rs fn[definition_and_requirements_inputs_obey_containment_for_declaring_files]
// {test}`requirements.ci.input_containment`
// {test}`requirements.ci.schema`
#[test]
fn definition_and_requirements_inputs_obey_containment_for_declaring_files() {
    let temp = fixture();
    let root = temp.path().join("project");
    fs::create_dir(root.join("md/private")).unwrap();
    fs::write(
        root.join("md/private/terms.md"),
        ":::{req} secret\nSecret.\n:::\n\n:::{definition} term\n:phrase: term\n\nA term.\n:::\n",
    )
    .unwrap();
    let term = json!([
        ":::{definition} term",
        ":phrase: term",
        "",
        "A term.",
        ":::"
    ]);
    let inputs = vec![
        json!({"definition": "private.terms.term", "text": term}),
        json!({
            "requirements": "private.terms.*",
            "matches": ["private.terms.secret"],
            "text": [":::{req} secret", "Secret.", ":::"],
        }),
    ];
    write_inputs(&root, inputs.clone());
    let own_errors = |root: &Path| {
        validate_repository(root)
            .unwrap()
            .errors
            .into_iter()
            .filter(|error| error.starts_with("evidence/rules.ready.json"))
            .collect::<Vec<_>>()
    };
    assert!(own_errors(&root).is_empty(), "{:?}", own_errors(&root));

    fs::write(
        root.join("habeas.toml"),
        "version = 1\n[evidence]\ndisallow = ['md/private']\n",
    )
    .unwrap();
    let errors = own_errors(&root);
    assert_eq!(errors.len(), 2, "{errors:?}");
    assert!(errors[0].contains("inputs[0]") && errors[0].contains("disallowed"));
    assert!(errors[1].contains("inputs[1]") && errors[1].contains("disallowed"));
    assert!(
        errors
            .iter()
            .all(|error| error.contains("md/private/terms.md"))
    );
}
Input 15: outline tests/outcomes.rs fn[judgments_round_trip_and_reject_invalid_fixme_shapes]
// {test}`requirements.ci.outcomes`
// {test}`requirements.ci.schema`
#[test]
fn judgments_round_trip_and_reject_invalid_fixme_shapes() {
    for value in [
        json!(true),
        json!(false),
        json!({ "FIXME": ["#125", "rust-lang/rust#123"] }),
        json!({ "FIXME": ["cancellation races are not tested on Windows"] }),
    ] {
        assert_eq!(Judgment::from_value(&value).unwrap().to_value(), value);
    }
    for invalid in [
        Value::Null,
        json!("FIXME"),
        json!(["#125"]),
        json!({}),
        json!({ "FIXME": [] }),
        json!({ "FIXME": [""] }),
        json!({ "FIXME": ["   "] }),
        json!({ "FIXME": ["#125", 125] }),
        json!({ "FIXME": "#125" }),
        json!({ "FIXME": ["#125"], "extra": true }),
        json!({ "fixme": ["#125"] }),
    ] {
        assert!(Judgment::from_value(&invalid).is_err(), "{invalid}");
    }
}
Input 16: outline tests/outcomes.rs fn[malformed_fixme_is_invalid_and_reports_the_required_shape]
// {test}`requirements.ci.schema`
// {test}`requirements.ci.outcomes`
// {test}`requirements.index.state`
// {test}`requirements.cli.fixme_summary`
// {test}`requirements.ci.determination`
// {test}`requirements.examples.evidence`
#[test]
fn malformed_fixme_is_invalid_and_reports_the_required_shape() {
    let temp = fixture();
    replace_judgment(temp.path(), "timeout", json!({ "FIXME": [] }));
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("nonempty array"))
    );
    let status = habeas::status_markdown(temp.path(), false).unwrap();
    let row = status
        .lines()
        .find(|line| line.starts_with("| `requirements.timeout`"))
        .unwrap();
    assert!(row.contains("Invalid"), "{row}");
    assert!(status.contains("nonempty array"), "{status}");
    assert!(!status.contains("affects"), "{status}");
}

Referenced definitions

Input 2: requirements selection requirements.ci.reference_set
:::{req} reference_set
A definition's reference set MUST consist of its current incoming `{impl}`, `{test}`, and `{fixme}` edges, except a `{fixme}` inside a site of the definition under {cite}`requirements.references.site_review`, under {cite}`requirements.references.roles` and
{cite}`requirements.references.anchors`: for each edge, its role and the file and
outline selector of the node the reference belongs to under
{cite}`requirements.references.outline_comments`, or of the anchored file or
node, and, for a fenced reference in a source outside the book, the words of
its body under the word rule of {cite}`requirements.references.structural_hash`.
`{cite}` references MUST NOT contribute. The reference-set digest MUST be
the SHA-256 digest of an unambiguous encoding of those entries in sorted order,
so it does not depend on line numbers or on the order references are found.
Authoring MUST record the digest of the reference set it supplied, and
validation MUST recompute it and report a changed reference set as stale
evidence. Adding or removing an `{impl}`, `{test}`, or `{fixme}` reference or anchor,
changing its role, editing its commentary, or moving it to a different node
MUST therefore make the evidence stale even when no recorded input changed; moving a reference within
the node it belongs to MUST NOT.
:::
Input 3: requirements selection requirements.ci.outcomes
:::{req} outcomes
Every assessment judgment MUST use one of these outcomes, applying
{cite}`requirements.ci.review_criteria`:

- `true`: the reviewed tests adequately check a requirement or example under
  {cite}`requirements.ci.review_criteria`, including applicable testing
  exemptions and obligations assessed by a refining requirement or a site's
  own review. For a citation or site review, the review finds no gap under its
  own task.
- `false`: the sources do not support the subject, or information is missing,
  and the gaps are not all acknowledged by `{fixme}` references to it.
- `FIXME`: some aspects remain unmet or untested, and `{fixme}` references to
  the subject acknowledge every one of those gaps. The reviewer MUST explain the
  gaps and their source locations in the rationale and record their issue
  references or other identifying content from the supplied acknowledgments or
  inputs.

The JSON `determination` MUST be `true`, `false`, or an object containing exactly
`"FIXME"` with a nonempty array of nonempty strings, such as
`{"FIXME": ["example/queue#125", "rust-lang/rust#123"]}`. A gap MUST count as
acknowledged only by a `{fixme}` reference under
{cite}`requirements.references.roles` whose body describes that gap and that
references the assessed definition, or, for a site review, the distributed requirement from within that site; a citation review MUST NOT accept a `{fixme}`; a plain
`FIXME` comment, another marker such as `TODO`, or prose MUST NOT. The strings
MUST list each distinct issue reference the acknowledging `{fixme}` references
name in their option lines, as written after `:github:`, and, for a `{fixme}`
naming no issue, its body's words, without comment delimiters, joined by single
spaces. A `{fixme}` reference describing a gap that the review establishes no
longer exists within its task's scope MUST itself be treated as a gap. A reference
describing only an implementation defect MUST NOT create a test-adequacy gap or
require implementation review; it MUST acknowledge a testing gap only when its
body describes that same gap. A `{fixme}` naming a GitHub issue that
{cite}`requirements.authoring.github_reads` reports closed MUST NOT count as
acknowledging its gap. A FIXME judgment MUST be grounded in recorded evidence
inputs or, for an acknowledgment supplied under
{cite}`requirements.authoring.fixme_inputs`, the reference-set digest covering
that acknowledgment.
:::
Input 4: requirements selection requirements.ci.input_containment
:::{req} input_containment
Every file named directly by an evidence input or resolved from its selector MUST resolve within the project root unless permitted by workspace path configuration or discovered Cargo generated-output policy. Symlink targets MUST follow the same policy. Validation MUST enforce explicit workspace disallow entries and report missing, unreadable, or excluded files. It MUST check existing generated inputs without running a build. {cite}`requirements.configuration.evidence_paths` {cite}`requirements.authoring.generated_inputs`
:::

Other sources

Input 1: requirements selection requirements.ci.schema
:::{req} schema
A requirement or example evidence file at `evidence/<full-name>.json` MUST be a JSON object with exactly `requirement` or `example`, `determination`, `rationale`, `references`, and `inputs`. `references` MUST be the reference-set digest defined by {cite}`requirements.ci.reference_set`. The definition text and rationale MUST be nonempty strings, `determination` MUST use one of the outcomes defined by {cite}`requirements.ci.outcomes`, and `inputs` MUST be an array. Every evidence input MUST have exactly one of three forms: an outline input with `file`, `item`, and `hash`; a requirements input with `requirements`, `matches`, and `text`; or a definition input with `definition` and `text`. File paths MUST resolve to permitted inputs under {cite}`requirements.ci.input_containment`. Project-local paths SHOULD be recorded relative to the project for portability; absolute and parent-relative paths MAY be used when their resolved targets are permitted. `matches` MUST be an array of distinct full definition names, `hash` MUST be a lowercase hexadecimal SHA-256 digest, and `text` MUST be a nonempty array of strings. Evidence MUST NOT store source text for outline inputs.
:::