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.references.evidence_coverage

Requirements index · View definition

evidence Valid

Requirement

For every {test} reference in a project source file, including one in a requirement or example declaration, the evidence file for the referenced requirement or example MUST contain an input whose resolved source ranges cover the reference’s file and line. An {impl}, {cite}, or {fixme} reference alone MUST NOT require an input selecting its source. {impl} and {cite} sources remain discoverable through cite requirements.authoring.reference_index; {fixme} acknowledgments are supplied under cite requirements.authoring.fixme_inputs and tracked by cite requirements.ci.reference_set. Habeas MUST report every uncovered reference requiring coverage with its role, full name, source file, and line number.

Rationale

The reviewed tests adequately check requirements.references.evidence_coverage. I judged this from the supplied test source and did not request implementation source. Mapping to the clauses:

1. Every {test} reference needs a covering input in the referenced definition’s evidence.

  • src/evidence.rs mod[tests]/fn[reports_unknown_references_and_uncovered_lines] has two {test} references in a plain-text source. The evidence selects only the first line. The test asserts that the second is reported as uncovered and the first is not, since exactly two errors appear and the other is the unknown-reference error. That checks coverage by file and line.
  • fn[source_references_are_covered_by_evidence_inputs] covers the positive case. A whole-file input on the Rust source and a single-line input on the markdown notes give no errors. The markdown {test} in prose therefore needs coverage, and the literal and code-fence forms do not.
  • fn[cited_example_with_a_test_and_matching_evidence_validates] covers {test} references inside an example declaration in the book.
    • Emptying rules.ready’s inputs produces an error. It contains “no input covers”, {test}, rules.ready and the book file and line. This holds even though the rules.case evidence still selects that region, so coverage must come from the referenced definition’s own evidence file.
    • Emptying rules.case’s inputs reports the source-file test reference.
  • fn[a_false_determination_fails_only_its_own_record_with_its_rationale] has a {test} reference inside a requirement declaration. It is covered by the referenced definition’s evidence, and the only error is the determination error.
  • fn[anchored_files_must_be_completely_covered_and_resolvable] and fn[selector_anchors_are_covered_by_inputs_selecting_the_node_or_an_ancestor] cover :test: anchors. Coverage by the node or an ancestor is accepted, and an uncovered anchor is reported.

2. {impl}, {cite} and {fixme} references alone must not require an input.

  • fn[only_test_references_require_recorded_source_coverage] has cite, impl and test references with empty inputs. Exactly one “no input covers” error appears, for the test reference, and nothing is reported for the cite. Selecting only fn[check] clears all errors. Changing the unread impl body does not make the evidence stale.
  • tests/outcomes.rs fn[editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads] asserts that no “no input covers {fixme}” error appears when a {fixme} is edited or added.
  • src/sites.rs mod[tests]/fn[a_fixme_inside_a_site_belongs_to_that_sites_review_only] asserts that no “no input covers {fixme}” error appears for in-site fixmes.
  • tests/outcomes.rs fn[fixme_does_not_hide_stale_inputs_or_uncovered_references] shows a new uncovered {test} is still reported alongside an existing fixme.

3. Each uncovered reference is reported with role, full name, file and line. The assertions in fn[reports_unknown_references_and_uncovered_lines] (no input covers {test}foo.bar.ready at <file>:<line>), fn[cited_example_with_a_test_and_matching_evidence_validates] ({test}, rules.ready, book file and line), fn[only_test_references_require_recorded_source_coverage] and tests/outcomes.rs fn[fixme_does_not_hide_stale_inputs_or_uncovered_references] check these elements.

4. Discoverability and tracking. The text delegates this to requirements.authoring.reference_index, requirements.authoring.fixme_inputs and requirements.ci.reference_set. Those are cited, so they need no test here.

Residual observation. No test makes an uncovered {test} inside a requirement declaration fail. The example-declaration case is tested, and the requirement-declaration case is only shown covered. I judge this a minor omission, not a gap.

Inputs

Tests

Input 5: outline src/evidence.rs mod[tests]/fn[source_references_are_covered_by_evidence_inputs]
    // {test}`requirements.references.evidence_coverage`
    // {test}`requirements.references.markdown_literals`
    #[test]
    fn source_references_are_covered_by_evidence_inputs() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/reqs/foo/bar.md"),
            "# Requirements\n\n:::{req} ready\nReady.\n:::\n",
        )
        .unwrap();
        let implementation = "{impl}`foo.bar.ready`".to_owned();
        let citation = "{cite}`foo.bar.ready`".to_owned();
        let test = "{test}`foo.bar.ready`".to_owned();
        let example = "{cite}`missing.example`".to_owned();
        let source = format!("// {implementation}\n// {citation}\n");
        let notes = format!("# Notes\n\n{test}\n\n`{example}`\n\n```text\n{example}\n```\n");
        fs::write(temp.path().join("src/main.rs"), &source).unwrap();
        fs::write(temp.path().join("md/notes.md"), &notes).unwrap();
        fs::write(
            temp.path().join("evidence/foo.bar.ready.json"),
            json!({
                "requirement": "Ready.",
                "determination": true,
                "rationale": "The source and notes were examined.",
                "inputs": [
                    outline(temp.path(), "src/main.rs", ""),
                    crate::inputs::outline_inputs_for_lines(temp.path(), "md/notes.md", 3, 3)
                        .unwrap()[0]
                ]
            })
            .to_string(),
        )
        .unwrap();

        let errors = without_citation_reviews(validate_repository(temp.path()).unwrap().errors);
        assert!(errors.is_empty(), "{errors:?}");
    }
Input 6: outline src/evidence.rs mod[tests]/fn[reports_unknown_references_and_uncovered_lines]
    // {test}`requirements.references.discovery`
    // {test}`requirements.references.evidence_coverage`
    #[test]
    fn reports_unknown_references_and_uncovered_lines() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/reqs/foo/bar.md"),
            "# Requirements\n\n:::{req} ready\nReady.\n:::\n",
        )
        .unwrap();
        let known = "{test}`foo.bar.ready`".to_owned();
        let unknown = "{impl}`missing.requirement`".to_owned();
        let source = format!("// {known}\n// {known}\n// {unknown}\n");
        fs::write(temp.path().join("src/notes.txt"), &source).unwrap();
        // Identical plain-text lines are interchangeable, so this selects the
        // first line only.
        let first = crate::inputs::outline_inputs_for_lines(temp.path(), "src/notes.txt", 1, 1)
            .unwrap()
            .remove(0);
        fs::write(
            temp.path().join("evidence/foo.bar.ready.json"),
            json!({
                "requirement": "Ready.",
                "determination": true,
                "rationale": "Only the first line was examined.",
                "inputs": [first]
            })
            .to_string(),
        )
        .unwrap();

        let report = validate_repository(temp.path()).unwrap();
        let errors = report.errors.join("\n");
        assert_eq!(report.errors.len(), 2, "{errors}");
        assert!(
            errors.contains(&format!(
                "src/notes.txt:3: {unknown} has no matching requirement"
            )),
            "{errors}"
        );
        assert!(
            errors.contains(&format!("no input covers {known} at src/notes.txt:2")),
            "{errors}"
        );
    }
Input 7: outline src/evidence.rs mod[tests]/fn[a_false_determination_fails_only_its_own_record_with_its_rationale]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[a_false_determination_fails_only_its_own_record_with_its_rationale]
  • Kind: fn
  • src/evidence.rs:3184–3222
    // {test}`requirements.ci.determination`
    #[test]
    // {test}`requirements.references.evidence_coverage`
    fn a_false_determination_fails_only_its_own_record_with_its_rationale() {
        let temp = fixture();
        let chapter = "# Rules\n\n:::{req} ready\nReady.\n:::\n\n:::{req} refined\nRefines {impl}`rules.ready`, {test}`rules.ready`, and {cite}`rules.ready`.\n:::\n";
        fs::write(temp.path().join("md/rules.md"), chapter).unwrap();
        fs::write(
            temp.path().join("evidence/rules.ready.json"),
            json!({
                "requirement": "Ready.",
                "determination": true,
                "rationale": "The refining requirement was examined.",
                "inputs": crate::inputs::outline_inputs_for_lines(temp.path(), "md/rules.md", 8, 8)
                    .unwrap()
            })
            .to_string(),
        )
        .unwrap();
        fs::write(
            temp.path().join("evidence/rules.refined.json"),
            json!({
                "requirement": chapter.lines().nth(7).unwrap(),
                "determination": false,
                "rationale": "  Work remains: the refinement is untested.  ",
                "inputs": []
            })
            .to_string(),
        )
        .unwrap();
        let report = validate_repository(temp.path()).unwrap();
        assert_eq!(
            report.errors,
            [
                "evidence/rules.refined.json: determination is false: Work remains: the refinement is untested."
            ],
            "the implemented, tested, and cited requirement is unaffected"
        );
    }
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[only_test_references_require_recorded_source_coverage]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[only_test_references_require_recorded_source_coverage]
  • Kind: fn
  • src/evidence.rs:3634–3691
    // {test}`requirements.references.evidence_coverage`
    // {test}`requirements.references.roles`
    #[test]
    fn only_test_references_require_recorded_source_coverage() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/rules.md"),
            ":::{req} ready\nReady.\n:::\n",
        )
        .unwrap();
        let source = "// {cite}`rules.ready`\nfn helper() {}\n// {impl}`rules.ready`\nfn run() {}\n// {test}`rules.ready`\nfn check() {}\n";
        fs::write(temp.path().join("src/main.rs"), source).unwrap();
        let record = |inputs: serde_json::Value| {
            json!({
                "requirement": "Ready.",
                "determination": true,
                "rationale": "The implementation and test were examined.",
                "inputs": inputs
            })
            .to_string()
        };
        let path = temp.path().join("evidence/rules.ready.json");
        fs::write(&path, record(json!([]))).unwrap();
        let errors = without_citation_reviews(validate_repository(temp.path()).unwrap().errors);
        let uncovered: Vec<_> = errors
            .iter()
            .filter(|error| error.contains("no input covers"))
            .collect();
        assert_eq!(uncovered.len(), 1, "{errors:#?}");
        assert!(
            uncovered
                .iter()
                .any(|error| error.contains("test") && error.contains("src/main.rs:5")),
            "{errors:#?}"
        );
        assert!(
            !errors.iter().any(|error| error.contains("src/main.rs:1")),
            "{errors:#?}"
        );

        fs::write(
            &path,
            record(json!([outline(temp.path(), "src/main.rs", "fn[check]")])),
        )
        .unwrap();
        let errors = without_citation_reviews(validate_repository(temp.path()).unwrap().errors);
        assert!(errors.is_empty(), "{errors:?}");

        // The unread implementation's body can change without invalidating
        // this assessment; its reference set still describes the same roots.
        fs::write(
            temp.path().join("src/main.rs"),
            source.replace("fn run() {}", "fn run() { panic!(\"changed\"); }"),
        )
        .unwrap();
        let errors = without_citation_reviews(validate_repository(temp.path()).unwrap().errors);
        assert!(errors.is_empty(), "{errors:?}");
    }
Input 10: outline src/evidence.rs mod[tests]/fn[anchored_files_must_be_completely_covered_and_resolvable]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[anchored_files_must_be_completely_covered_and_resolvable]
  • Kind: fn
  • src/evidence.rs:3760–3851
    // {test}`requirements.references.anchors`
    // {test}`requirements.ci.requirement_text`
    // {test}`requirements.references.evidence_coverage`
    // {test}`requirements.ci.span`
    // {test}`requirements.examples.definition`
    #[test]
    fn anchored_files_must_be_completely_covered_and_resolvable() {
        let temp = fixture();
        let root = temp.path();
        fs::create_dir_all(root.join("skills")).unwrap();
        fs::write(root.join("skills/ready.md"), "# Skill\nUse ready.\n").unwrap();
        fs::write(
            root.join("md/requirements.md"),
            ":::{req} ready\n:test: skills/ready.md\n:test: missing.sh\nReady MUST hold.\n:::\n\n:::{example} case\n:test: skills/ready.md\nA ready case. {cite}`requirements.ready`\n:::\n",
        )
        .unwrap();
        // The root node is the whole file; its heading's section is not.
        let skill = |item: &str| outline(root, "skills/ready.md", item);
        let write = |name: &str, field: &str, text: &str, inputs: Value| {
            fs::write(
                root.join(format!("evidence/{name}.json")),
                json!({
                    field: text,
                    "determination": true,
                    "rationale": "Checked.",
                    "inputs": inputs,
                })
                .to_string(),
            )
            .unwrap();
        };
        // The option lines are not part of the definition text.
        write(
            "requirements.ready",
            "requirement",
            "Ready MUST hold.",
            json!([skill("section[Skill]")]),
        );
        write(
            "requirements.case",
            "example",
            "A ready case. {cite}`requirements.ready`",
            json!([skill("")]),
        );
        let errors = validate_repository(root).unwrap().errors.join("\n");
        assert!(!errors.contains("text changed"), "{errors}");
        assert!(
            errors.contains("evidence/requirements.ready.json: no input selects skills/ready.md (lines 1-2) anchored by :test: on requirement requirements.ready"),
            "{errors}"
        );
        assert!(
            errors.contains("evidence/requirements.ready.json: :test: anchor missing.sh on requirement requirements.ready at md/requirements.md:1 does not resolve"),
            "{errors}"
        );
        assert!(!errors.contains("requirements.case.json"), "{errors}");

        fs::write(
            root.join("md/requirements.md"),
            ":::{req} ready\n:test: skills/ready.md\nReady MUST hold.\n:::\n\n:::{example} case\n:test: skills/ready.md\nA ready case. {cite}`requirements.ready`\n:::\n",
        )
        .unwrap();
        write(
            "requirements.ready",
            "requirement",
            "Ready MUST hold.",
            json!([skill("")]),
        );
        let report = validate_repository(root).unwrap();
        assert!(report.errors.is_empty(), "{:?}", report.errors);

        // Changing the anchored file makes the evidence stale.
        fs::write(root.join("skills/ready.md"), "# Skill\nUse ready now.\n").unwrap();
        let errors = validate_repository(root).unwrap().errors.join("\n");
        assert!(
            errors.contains("evidence/requirements.ready.json: inputs[0]: outline input changed: skills/ready.md <root> (now lines 1-2) no longer has the recorded hash"),
            "{errors}"
        );
        fs::write(
            root.join("habeas.toml"),
            "version = 1\n[evidence]\ndisallow = ['skills/ready.md']\n",
        )
        .unwrap();
        let errors = validate_repository(root).unwrap().errors;
        assert!(
            errors
                .iter()
                .any(|error| error.contains("anchor skills/ready.md")
                    && error.contains("requirements.ready")
                    && error.contains("disallow")),
            "{errors:?}"
        );
    }
Input 11: outline src/evidence.rs mod[tests]/fn[selector_anchors_are_covered_by_inputs_selecting_the_node_or_an_ancestor]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[selector_anchors_are_covered_by_inputs_selecting_the_node_or_an_ancestor]
  • Kind: fn
  • src/evidence.rs:3853–3920
    // {test}`requirements.references.anchors`
    // {test}`requirements.ci.outline_inputs`
    // {test}`requirements.references.evidence_coverage`
    #[test]
    fn selector_anchors_are_covered_by_inputs_selecting_the_node_or_an_ancestor() {
        let temp = fixture();
        let root = temp.path();
        fs::write(
            root.join("src/lib.rs"),
            "mod inner {\n    fn run() {}\n    fn other() {}\n}\n",
        )
        .unwrap();
        fs::write(
            root.join("md/requirements.md"),
            ":::{req} ready\n:test: src/lib.rs#mod[inner]/fn[run]\nReady MUST hold.\n:::\n",
        )
        .unwrap();
        let write = |inputs: Value| {
            fs::write(
                root.join("evidence/requirements.ready.json"),
                json!({
                    "requirement": "Ready MUST hold.",
                    "determination": true,
                    "rationale": "Checked.",
                    "inputs": inputs,
                })
                .to_string(),
            )
            .unwrap();
        };
        let anchor_errors = || {
            validate_repository(root)
                .unwrap()
                .errors
                .into_iter()
                .filter(|error| error.contains("anchor"))
                .collect::<Vec<_>>()
        };
        write(json!([outline(root, "src/lib.rs", "mod[inner]/fn[other]")]));
        let errors = anchor_errors();
        assert_eq!(
            errors,
            [
                "evidence/requirements.ready.json: no input selects src/lib.rs#mod[inner]/fn[run] (lines 2-2) anchored by :test: on requirement requirements.ready"
            ],
        );
        for item in ["mod[inner]/fn[run]", "mod[inner]", ""] {
            write(json!([outline(root, "src/lib.rs", item)]));
            assert!(anchor_errors().is_empty(), "{item}: {:?}", anchor_errors());
        }
        fs::write(
            root.join("md/requirements.md"),
            ":::{req} ready\n:impl: src/lib.rs#mod[inner]/fn[run]\nReady MUST hold.\n:::\n",
        )
        .unwrap();
        write(json!([]));
        assert!(anchor_errors().is_empty(), "{:?}", anchor_errors());
        fs::write(
            root.join("md/requirements.md"),
            ":::{req} ready\n:impl: src/lib.rs#fn[missing]\nReady MUST hold.\n:::\n",
        )
        .unwrap();
        let errors = anchor_errors().join("\n");
        assert!(
            errors.contains(":impl: anchor src/lib.rs#fn[missing] on requirement requirements.ready at md/requirements.md:1 does not resolve to a readable, permitted file or node: src/lib.rs: no outline node matches \"fn[missing]\""),
            "{errors}"
        );
    }
Input 12: outline src/sites.rs mod[tests]/fn[a_fixme_inside_a_site_belongs_to_that_sites_review_only]
  • File: src/sites.rs
  • Selector: mod[tests]/fn[a_fixme_inside_a_site_belongs_to_that_sites_review_only]
  • Kind: fn
  • src/sites.rs:1398–1505
    // {test}`requirements.references.site_review`
    // {test}`requirements.references.evidence_coverage`
    // {test}`requirements.ci.reference_set`
    #[test]
    fn a_fixme_inside_a_site_belongs_to_that_sites_review_only() {
        let fixme = |issue: &str| {
            format!(
                "    // :::{{fixme}} requirements.rule\n    // :github: o/r#{issue}\n    // Panics instead of reporting.\n    // :::\n"
            )
        };
        let source = SOURCE
            .replace(
                "fn check_two() {}",
                &format!("fn check_two() {{\n{}}}", fixme("1")),
            )
            .replace(
                "fn other() { panic!(\"y\"); }",
                &format!("fn other() {{\n{}}}", fixme("2")),
            );
        let temp = project(RULE, &source);
        let root = temp.path();
        fs::write(
            root.join("evidence/requirements.rule.json"),
            json!({"requirement": "x", "determination": true, "rationale": "Fine.", "inputs": []})
                .to_string(),
        )
        .unwrap();
        crate::evidence::tests::stamp_reference_sets(root);
        write_review(
            root,
            "fn[check_two]",
            json!({"determination": {"FIXME": ["o/r#1"]}}),
        );
        let (errors, _) = inspect(root);
        let coverage = errors
            .iter()
            .filter(|error| error.contains("no input covers {fixme}"))
            .collect::<Vec<_>>();
        assert!(coverage.is_empty(), "{errors:#?}");
        let two = review_errors(&errors, "fn[check_two]").join("\n");
        assert!(
            two.contains("{fixme} references to requirements.rule inside src/lib.rs fn[check_two] changed: recorded [], now [{\"item\":\"fn[check_two]\",\"commentary\":\":github: o/r#1\\n Panics instead of reporting.\"}]"),
            "{two}"
        );
        assert!(!two.contains("FIXME entry"), "{two}");

        // Editing the in-site `{fixme}` leaves the requirement's reference
        // set unchanged; editing the other changes it.
        let digest = crate::evidence::reference_set_digest_for(root, "requirements.rule").unwrap();
        fs::write(
            root.join("src/lib.rs"),
            source.replacen("Panics instead", "Still panics instead", 1),
        )
        .unwrap();
        assert_eq!(
            crate::evidence::reference_set_digest_for(root, "requirements.rule").unwrap(),
            digest
        );
        fs::write(
            root.join("src/lib.rs"),
            source.replace(
                "// Panics instead of reporting.\n    // :::\n}\nmod",
                "// Edited.\n    // :::\n}\nmod",
            ),
        )
        .unwrap();
        assert_ne!(
            crate::evidence::reference_set_digest_for(root, "requirements.rule").unwrap(),
            digest
        );

        // A review recording the in-site `{fixme}` is current; reflowing its
        // body keeps it current, and changing its words makes it stale.
        fs::write(root.join("src/lib.rs"), &source).unwrap();
        crate::evidence::tests::stamp_reference_sets(root);
        write_review(
            root,
            "fn[check_two]",
            json!({
                "determination": {"FIXME": ["o/r#1"]},
                "fixmes": [{"item": "fn[check_two]", "commentary": ":github: o/r#1\n Panics instead of reporting."}],
            }),
        );
        let changed = |root: &Path| {
            let (errors, _) = inspect(root);
            review_errors(&errors, "fn[check_two]")
                .into_iter()
                .filter(|error| error.contains("{fixme} references"))
                .collect::<Vec<_>>()
        };
        assert_eq!(changed(root), Vec::<String>::new());
        fs::write(
            root.join("src/lib.rs"),
            source.replacen(
                "    // Panics instead of reporting.\n",
                "    // Panics instead\n    // of reporting.\n",
                1,
            ),
        )
        .unwrap();
        assert_eq!(changed(root), Vec::<String>::new());
        fs::write(
            root.join("src/lib.rs"),
            source.replacen("Panics instead", "Still panics instead", 1),
        )
        .unwrap();
        assert_eq!(changed(root).len(), 1);
    }
Input 13: outline tests/outcomes.rs fn[fixme_does_not_hide_stale_inputs_or_uncovered_references]
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.ci.determination`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.ci.fixme_stale_input`
// {test}`requirements.index.state`
// {test}`requirements.cli.fixme_summary`
#[test]
fn fixme_does_not_hide_stale_inputs_or_uncovered_references() {
    let temp = fixture();
    let observed = temp.path().join("observed.rs");
    let source = fs::read_to_string(&observed).unwrap();
    fs::write(&observed, source.replace("= 1;", "= 2;")).unwrap();
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("outline input changed: observed.rs <root>")),
        "{:?}",
        report.errors
    );
    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("example/io#125"), "{status}");
    assert!(status.contains("outline input changed"), "{status}");
    fs::write(
        temp.path().join("other.txt"),
        "{test}`requirements.timeout`",
    )
    .unwrap();
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("no input covers") && error.contains("other.txt:1"))
    );
}
Input 14: outline tests/outcomes.rs fn[editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads]
  • File: tests/outcomes.rs
  • Selector: fn[editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads]
  • Kind: fn
  • tests/outcomes.rs:529–572
// {test}`requirements.ci.reference_set`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads() {
    let temp = fixture();
    let observed = temp.path().join("observed.rs");
    let source = fs::read_to_string(&observed).unwrap();
    // Comments do not change the input's hash, but the `{fixme}` body is
    // part of the reference set.
    fs::write(&observed, source.replace("are untested", "remain untested")).unwrap();
    let errors = habeas::validate_repository(temp.path()).unwrap().errors;
    assert!(
        errors.iter().any(
            |error| error.contains("evidence/requirements.timeout.json: reference set changed")
        ),
        "{errors:?}"
    );
    assert!(
        !errors
            .iter()
            .any(|error| error.contains("outline input changed")),
        "{errors:?}"
    );
    fs::write(&observed, &source).unwrap();
    fs::write(
        temp.path().join("other.rs"),
        fixme("requirements.timeout", &[], "Another gap."),
    )
    .unwrap();
    let errors = habeas::validate_repository(temp.path()).unwrap().errors;
    assert!(
        errors.iter().any(
            |error| error.contains("evidence/requirements.timeout.json: reference set changed")
        ),
        "{errors:?}"
    );
    assert!(
        !errors
            .iter()
            .any(|error| error.contains("no input covers {fixme}")),
        "{errors:?}"
    );
}

Referenced definitions

Input 2: requirements selection requirements.authoring.reference_index
:::{req} reference_index
The harness MUST expose a `references` tool with this interface:

```text
references({ selection: String?, roles: Array<"impl" | "cite" | "test">? }) -> ReferenceIndex

ReferenceIndex {
    definitions: Array<DefinitionName>,
    sites: Array<ReferenceSite>,
}

DefinitionName { name: String, kind: "requirement" | "example" }

ReferenceSite {
    name: String,
    role: "impl" | "cite" | "test",
    file: String,
    item: String?,
}
```

`selection` MUST be a {term}`requirements.references.definition_selection`.
Without `selection`, the tool MUST return
the full name and kind of every requirement and named example in full-name
order, with empty `sites`. With `selection`, it MUST return the selected definitions
in full-name order and one flattened `sites` array containing every valid
reference to any match whose role is in `roles`, defaulting to
`["impl", "cite", "test"]`, under
{cite}`requirements.references.discovery`, each naming the definition it
references, ordered by name, file, and position in the file, without line
numbers. Roles MUST be treated as a set: repeating a permitted role MUST NOT
duplicate sites or change the result.
An anchor under {cite}`requirements.references.anchors` whose role is selected
by `roles` MUST be
reported as a site for its anchored file, with the anchored node's selector as
`item` when it names one and no `item` when it names the whole file. Every
other site MUST give as `item` the selector of its smallest enclosing outline
node under {cite}`requirements.references.outline_comments`. Only sources reference discovery considers under
{cite}`requirements.references.discovery` MUST contribute sites. If reading such a
source fails, the tool MUST return an explanatory tool error naming the source.
An invalid selection or one matching no definition MUST return an explanatory tool
error.

An empty `roles` array MUST return no sites while preserving the selected
definitions' names and kinds. An unknown role or a value other than an array of
permitted role strings MUST return an explanatory tool error. Without `selection`,
`roles` MUST NOT change the definition-name listing.

Results MUST contain no requirement text, example text, reference commentary,
or source text. Like directory listings, they MUST
NOT become evidence inputs; the model requests the sources it relies on with the
`habeas` tool. For example,
`references({selection: "requirements.cli.status", roles: ["impl"]})` MUST
locate only that subject's implementation references and anchors, without
supplying their source or recording evidence inputs.
:::
Input 3: requirements selection requirements.authoring.fixme_inputs
:::{req} fixme_inputs
For a requirement or example assessment, the initial request MUST include every
valid named `{fixme}` reference to the subject found under
{cite}`requirements.references.discovery`, except a reference inside one of
the subject's sites under {cite}`requirements.references.site_review`, in this
form:

```text
Acknowledgment {
    file: String,
    item: String,
    body: String,
    issues: Array<{ reference: String, state: "open" | "closed" }>,
}
```

`file` and `item` MUST locate the containing source by project-relative path and
outline selector, using `<root>` for a whole file. `body` MUST contain the
reference's complete fenced commentary without its fences or source-comment
delimiters, including its option lines, redacted under
{cite}`requirements.authoring.redaction`. `issues` MUST give every distinct issue
its `:github:` lines name, in their order, with state supplied under
{cite}`requirements.authoring.github_reads`. Acknowledgments MUST be ordered by
file and position in the file and MUST carry no line numbers or containing
implementation source.

The locations and bodies MUST be protected against staleness by the reference-set
digest under {cite}`requirements.ci.reference_set`; the acknowledgment MUST NOT
create an outline input merely to cover its containing source. Actual reads of
that source MUST still be recorded under
{cite}`requirements.authoring.delivered_inputs`. Sources MUST satisfy
{cite}`requirements.authoring.source_tools`; an inaccessible acknowledgment
MUST be reported before inference.

Terminology definitions referenced by an acknowledgment's body MUST contribute
their complete, transitive declarations to the mandatory input set under
{cite}`requirements.definitions.authoring_inputs` and MUST be recorded as
definition inputs. Only the acknowledgment's body MUST contribute these
dependencies; its containing implementation source MUST NOT be supplied merely
to discover them.
:::
Input 4: 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 15: definition requirements.references.definition_selection
:::{definition} definition_selection
:phrase: definition selection

A full requirement or example name, or a definition glob, identifying the
requirements and named examples it matches under
{cite}`requirements.references.definition_globs`. A name without `*` selects
exactly that definition.
:::

Other sources

Input 1: requirements selection requirements.references.evidence_coverage
:::{req} evidence_coverage
For every `{test}` reference in a project source file, including one in a
requirement or example declaration, the evidence file for the referenced
requirement or example MUST contain an input whose resolved source ranges cover
the reference's file and line. An `{impl}`, `{cite}`, or `{fixme}` reference alone
MUST NOT require an input selecting its source. `{impl}` and `{cite}` sources
remain discoverable through {cite}`requirements.authoring.reference_index`;
`{fixme}` acknowledgments are supplied under
{cite}`requirements.authoring.fixme_inputs` and tracked by
{cite}`requirements.ci.reference_set`. Habeas MUST report every uncovered
reference requiring coverage with its role, full name, source file, and line
number.
:::