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.definitions.dependencies

Requirements index · View definition

evidence Valid

Requirement

Requirement and example evidence MUST include a definition input for every term referenced by its subject text, reviewed inputs, or acknowledgments supplied under cite requirements.authoring.fixme_inputs.

Habeas MUST repeatedly include definitions referenced by required definitions until the set reaches a fixed point. Each required definition MUST have exactly one definition input per evidence record. Cyclic references MUST be permitted and MUST NOT cause repeated expansion or nontermination.

Validation MUST report missing required definition inputs and MUST NOT silently refresh snapshots.

Rationale

The reviewed tests cover each obligation of requirements.definitions.dependencies.

Definition inputs for every term referenced by the subject text, reviewed inputs, or acknowledgments

  • tests/definitions.rs#fn[subjects_require_their_terms_without_a_requirements_input] covers subject text for both a requirement (rules.ready) and an example (rules.case). Each record lacks the definition inputs, and validation reports each missing term with “found 0”.
  • tests/definitions.rs#fn[example_subject_and_definition_display_use_the_same_dependencies] covers an example subject whose own term and cited requirement both need the glossary cycle.
  • Reviewed inputs are covered in several ways:
    • Markdown sections and plain-text lines in tests/definitions.rs#fn[markdown_and_plain_text_inputs_contribute_their_term_references].
    • Rust comments, with string-literal references ignored, in tests/definitions.rs#fn[a_term_referenced_only_by_a_rust_input_comment_needs_its_definition_input] and tests/definitions.rs#fn[outline_inputs_capture_terms_without_counting_them_as_citations].
    • Requirements inputs in tests/definitions.rs#fn[literal_term_roles_in_subject_and_requirements_inputs_need_no_definition].
    • Per-language comment extraction (Rust, Python, TOML) in src/terms.rs#mod[tests]/fn[term_dependencies_of_outlined_sources_come_only_from_comments].
    • Markdown extensions and the non-Markdown contrast in src/terms.rs#mod[tests]/fn[term_dependencies_of_every_markdown_extension_skip_literal_roles].
    • Comment scanning in src/rust_coverage.rs#mod[tests]/fn[comment_scan_skips_string_and_character_literals].
  • Acknowledgments are covered by src/authoring/inputs.rs#mod[tests]/fn[acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads]. It checks that a term used only in a {fixme} body, and its transitive term, appear in the prompt. It also checks that the implementation body is not supplied, and that removing terms.boundary yields “expected exactly one definition input for terms.boundary, found 0”.

Fixed-point (transitive) inclusion The glossary.a→b→c→d chain in subjects_require_their_terms_without_a_requirements_input requires expansion beyond the first hop. Each of the four terms is asserted missing when absent.

Exactly one definition input per record tests/definitions.rs#fn[cyclic_dependencies_are_required_once_and_changes_require_review] removes glossary.b and asserts “glossary.b, found 0”. It also duplicates an input and asserts “found 2”.

Cycles permitted, no nontermination or repeated expansion The fixture’s glossary.a/glossary.b cycle is captured and validated cleanly in the same test, so the cycle terminates and each term is required once. The src/authoring/inputs.rs test does the same for transitive terms in a different path.

Missing inputs reported, snapshots not silently refreshed subjects_require_their_terms_without_a_requirements_input asserts the record file bytes are unchanged after a validation that reports errors. The cyclic test asserts before == fs::read(&path) after each definition change that triggers “input text changed”.

No gap was found that the tests would accept as a violation.

Inputs

Tests

Input 3: outline src/authoring/inputs.rs mod[tests]/fn[acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads]
  • File: src/authoring/inputs.rs
  • Selector: mod[tests]/fn[acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads]
  • Kind: fn
  • src/authoring/inputs.rs:877–953
    // {test}`requirements.authoring.fixme_inputs`
    // {test}`requirements.definitions.dependencies`
    // {test}`requirements.ci.reference_set`
    // {test}`requirements.definitions.authoring_inputs`
    #[test]
    fn acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads() {
        let root = project();
        let (path, configuration) = crate::execution_coverage::configure(root.path()).unwrap();
        fs::create_dir_all(path.parent().unwrap()).unwrap();
        fs::write(path, configuration).unwrap();
        fs::create_dir(root.path().join("evidence")).unwrap();
        let terms = ":::{definition} unit\n:phrase: unit\nA unit.\n:::\n\n:::{definition} boundary\n:phrase: boundary\nA {term}`terms.unit` at the limit.\n:::\n";
        fs::write(root.path().join("md/terms.md"), terms).unwrap();
        let source = "// :::{fixme} requirements.ready\n// The {term}`terms.boundary` is untested.\n// :::\nfn gap() { panic!(\"IMPLEMENTATION_BODY\"); }\n";
        fs::write(root.path().join("src/lib.rs"), source).unwrap();
        let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let prompt = super::super::initial_prompt(&sources).unwrap().joined();
        assert!(prompt.contains("A unit."));
        assert!(prompt.contains("at the limit."));
        assert!(prompt.contains("is untested."));
        assert!(!prompt.contains("IMPLEMENTATION_BODY"));
        assert!(
            !sources
                .mandatory_inputs()
                .iter()
                .any(|input| input.get("item").is_some())
        );
        let mandatory = sources.mandatory_inputs().to_vec();
        sources.record_inputs(&mandatory);
        let record = json!({
            "requirement": "The project MUST be ready.",
            "determination": {"FIXME": ["The {term}`terms.boundary` is untested."]},
            "rationale": "The boundary test is acknowledged as missing.",
            "references": sources.reference_set,
            "inputs": sources.recorded_inputs(),
        });
        let path = root.path().join("evidence/requirements.ready.json");
        fs::write(&path, record.to_string()).unwrap();
        let check = || {
            crate::evidence::validate_repository(root.path())
                .unwrap()
                .errors
        };
        assert!(check().is_empty(), "{:?}", check());

        // An unread body can change without changing the judgment's inputs.
        fs::write(
            root.path().join("src/lib.rs"),
            source.replace("panic!(\"IMPLEMENTATION_BODY\")", "let _value = 1"),
        )
        .unwrap();
        assert!(check().is_empty(), "{:?}", check());

        // The acknowledgment introduces a real, transitive term dependency.
        fs::write(
            root.path().join("md/terms.md"),
            terms.replace("A unit.", "A changed unit."),
        )
        .unwrap();
        let errors = check().join("\n");
        assert!(
            errors.contains("input text changed for Definition { definition: \"terms.unit\" }"),
            "{errors}"
        );
        fs::write(root.path().join("md/terms.md"), terms).unwrap();
        let mut missing = record.clone();
        missing["inputs"]
            .as_array_mut()
            .unwrap()
            .retain(|input| input["definition"] != "terms.boundary");
        fs::write(&path, missing.to_string()).unwrap();
        let errors = check().join("\n");
        assert!(
            errors.contains("expected exactly one definition input for terms.boundary, found 0"),
            "{errors}"
        );
    }
Input 4: outline src/rust_coverage.rs mod[tests]/fn[comment_texts]
    /// The text of each comment `comments` finds in `source`.
    // {test}`requirements.definitions.dependencies`
    fn comment_texts(source: &str) -> Vec<&str> {
        comments(source)
            .into_iter()
            .map(|range| &source[range])
            .collect()
    }
Input 5: outline src/rust_coverage.rs mod[tests]/fn[comment_scan_skips_string_and_character_literals]
    // {test}`requirements.definitions.dependencies`
    #[test]
    fn comment_scan_skips_string_and_character_literals() {
        for (source, expected) in [
            // Strings, including escaped quotes and comment markers inside them.
            (r#"let s = "// no"; // yes"#, vec!["// yes"]),
            (r#"let s = "a \" // no"; /* yes */"#, vec!["/* yes */"]),
            (r#"let s = b"// no"; // yes"#, vec!["// yes"]),
            (r#"let s = c"/* no */"; // yes"#, vec!["// yes"]),
            // Raw strings, with and without hashes, may contain quotes.
            (r#"let s = r"// no"; // yes"#, vec!["// yes"]),
            (r##"let s = r#"" // no "#; // yes"##, vec!["// yes"]),
            (r###"let s = br##"#" // no"##; // yes"###, vec!["// yes"]),
            (r#"let s = cr"// no"; // yes"#, vec!["// yes"]),
            // Character literals, including quote characters and escapes.
            (r#"let c = '"'; // yes"#, vec!["// yes"]),
            (r"let c = '\''; // yes", vec!["// yes"]),
            (r#"let c = ('\\', "// no"); // yes"#, vec!["// yes"]),
            (
                r#"let c = ('\u{1F600}', '\x41', "// no"); // yes"#,
                vec!["// yes"],
            ),
            (r#"let c = ('é', "// no"); // yes"#, vec!["// yes"]),
            // A lifetime is not a character literal.
            (
                r#"fn f<'a>(x: &'a str) -> &'a str { "// no" } // yes"#,
                vec!["// yes"],
            ),
            // Block comments nest, and line comments end at the newline.
            (
                "/* a /* b */ c */ d // e\nf",
                vec!["/* a /* b */ c */", "// e"],
            ),
            (
                "/** doc */ //! inner\n/// outer",
                vec!["/** doc */", "//! inner", "/// outer"],
            ),
            // Unterminated literals and comments extend to the end of the source.
            (r#"let s = "// no"#, vec![]),
            (r##"let s = r#"// no"##, vec![]),
            (
                "/* open /* nested */ still",
                vec!["/* open /* nested */ still"],
            ),
            ("let c = '", vec![]),
        ] {
            assert_eq!(comment_texts(source), expected, "{source}");
        }
    }
Input 6: outline src/terms.rs mod[tests]/fn[term_dependencies_of_every_markdown_extension_skip_literal_roles]
  • File: src/terms.rs
  • Selector: mod[tests]/fn[term_dependencies_of_every_markdown_extension_skip_literal_roles]
  • Kind: fn
  • src/terms.rs:233–280
    // {test}`requirements.references.markdown_literals`
    // {test}`requirements.definitions.dependencies`
    #[test]
    fn term_dependencies_of_every_markdown_extension_skip_literal_roles() {
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();
        fs::create_dir_all(root.join("md")).unwrap();
        fs::create_dir_all(root.join("docs")).unwrap();
        fs::write(root.join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
        fs::write(
            root.join("md/terms.md"),
            ":::{definition} unit\n:phrase: unit\nA unit.\n:::\n",
        )
        .unwrap();
        let used = "{term}`terms.unit`".to_owned();
        let missing = "{term}`terms.missing`".to_owned();
        let notes = format!(
            "Uses {used}.\n\n`{missing}` and \\{missing}\n\n```text\n{missing}\n```\n\n<span title=\"{missing}\"></span>\n"
        );
        let declarations = crate::evidence::load_definitions(root).unwrap();
        let outlines = OutlineCache::default();
        let dependencies = |file: &str| {
            fs::write(root.join(file), &notes).unwrap();
            let record = json!({"inputs": [{"file": file, "item": ""}]});
            dependencies(
                root,
                &declarations,
                &outlines,
                record.as_object().unwrap(),
                None,
            )
        };
        for file in [
            "docs/a.md",
            "docs/b.markdown",
            "docs/C.MD",
            "docs/d.Markdown",
        ] {
            assert_eq!(
                dependencies(file),
                Ok(BTreeSet::from(["terms.unit".to_owned()])),
                "{file}"
            );
        }
        // The same text in a plain-text file is not Markdown.
        let error = dependencies("docs/e.txt").unwrap_err();
        assert!(error.contains("terms.missing"), "{error}");
    }
Input 7: outline src/terms.rs mod[tests]/fn[term_dependencies_of_outlined_sources_come_only_from_comments]
  • File: src/terms.rs
  • Selector: mod[tests]/fn[term_dependencies_of_outlined_sources_come_only_from_comments]
  • Kind: fn
  • src/terms.rs:282–325
    // {test}`requirements.references.reference_contexts`
    // {test}`requirements.definitions.dependencies`
    #[test]
    fn term_dependencies_of_outlined_sources_come_only_from_comments() {
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();
        fs::create_dir_all(root.join("md")).unwrap();
        fs::create_dir_all(root.join("src")).unwrap();
        fs::write(root.join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
        fs::write(
            root.join("md/terms.md"),
            ":::{definition} unit\n:phrase: unit\nA unit.\n:::\n",
        )
        .unwrap();
        let used = "{term}`terms.unit`".to_owned();
        let missing = "{term}`terms.missing`".to_owned();
        let declarations = crate::evidence::load_definitions(root).unwrap();
        let outlines = OutlineCache::default();
        for (file, text) in [
            (
                "src/lib.rs",
                format!("// Uses {used}.\nconst NAME: &str = \"{missing}\";\n"),
            ),
            ("tool.py", format!("# Uses {used}.\nNAME = \"{missing}\"\n")),
            (
                "config.toml",
                format!("# Uses {used}.\nname = \"{missing}\"\n"),
            ),
        ] {
            fs::write(root.join(file), text).unwrap();
            let record = json!({"inputs": [{"file": file, "item": ""}]});
            assert_eq!(
                dependencies(
                    root,
                    &declarations,
                    &outlines,
                    record.as_object().unwrap(),
                    None
                ),
                Ok(BTreeSet::from(["terms.unit".to_owned()])),
                "{file}"
            );
        }
    }
Input 8: outline tests/definitions.rs fn[subjects_require_their_terms_without_a_requirements_input]
// {test}`requirements.definitions.dependencies`
#[test]
fn subjects_require_their_terms_without_a_requirements_input() {
    for subject in ["rules.ready", "rules.case"] {
        let temp = fixture();
        let root = temp.path();
        // A noncyclic chain requires repeated expansion beyond the first hop.
        fs::write(
            root.join("md/glossary.md"),
            ":::{definition} a\n:phrase: alpha\nSee {term}`glossary.b`.\n:::\n\n:::{definition} b\n:phrase: beta\nSee {term}`glossary.c`.\n:::\n\n:::{definition} c\n:phrase: gamma\nSee {term}`glossary.d`.\n:::\n\n:::{definition} d\n:phrase: delta\nThe leaf.\n:::\n",
        ).unwrap();
        let rules = root.join("md/rules.md");
        fs::write(
            &rules,
            format!(
                "{}\n:::{{example}} case\nUse {{term}}`glossary.a`. {{cite}}`rules.ready`\n:::\n",
                fs::read_to_string(&rules).unwrap()
            ),
        )
        .unwrap();
        fs::write(
            root.join("src/lib.rs"),
            "// {test}`rules.case`\n#[test]\nfn test_case() { assert!(true); }\n",
        )
        .unwrap();
        let input = outline_input(root, "src/lib.rs", "fn[test_case]").unwrap();
        for name in ["rules.ready", "rules.case"] {
            let path = record(
                root,
                name,
                vec![
                    input.clone(),
                    definition(root, "glossary.a"),
                    definition(root, "glossary.b"),
                    definition(root, "glossary.c"),
                    definition(root, "glossary.d"),
                ],
            );
            approve(&path);
        }
        let errors = validate_repository(root).unwrap().errors;
        assert!(errors.is_empty(), "{errors:?}");
        let path = record(root, subject, vec![input.clone()]);
        approve(&path);
        let before = fs::read(&path).unwrap();
        let errors = validate_repository(root).unwrap().errors;
        for term in ["glossary.a", "glossary.b", "glossary.c", "glossary.d"] {
            assert!(
                errors.iter().any(
                    |error| error.starts_with(&format!("evidence/{subject}.json"))
                        && error.contains(&format!("{term}, found 0"))
                ),
                "{subject}: {errors:?}"
            );
        }
        assert_eq!(fs::read(&path).unwrap(), before);
    }
}
Input 9: outline tests/definitions.rs fn[cyclic_dependencies_are_required_once_and_changes_require_review]
// {test}`requirements.definitions.transitive_cycle`
// {test}`requirements.definitions.reassessment`
// {test}`requirements.definitions.dependencies`
// {test}`requirements.definitions.inputs`
#[test]
fn cyclic_dependencies_are_required_once_and_changes_require_review() {
    let temp = fixture();
    let root = temp.path();
    capture(root);
    let path = root.join("evidence/rules.ready.json");
    approve(&path);
    let report = validate_repository(root).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
    let before = fs::read(&path).unwrap();

    let glossary = root.join("md/glossary.md");
    let original = fs::read_to_string(&glossary).unwrap();
    fs::write(&glossary, format!("\n\n{original}")).unwrap();
    assert!(validate_repository(root).unwrap().errors.is_empty());
    for (changed, definition) in [
        (
            original.replace(":phrase: beta", ":phrase: new beta"),
            "glossary.b",
        ),
        (
            original
                .replace("See TERM", "Read TERM")
                .replace("See {term}", "Read {term}"),
            "glossary.a",
        ),
        (
            original.replace("See {term}`glossary.a`.", "Read {term}`glossary.a`."),
            "glossary.b",
        ),
    ] {
        fs::write(&glossary, changed).unwrap();
        let report = validate_repository(root).unwrap();
        assert!(
            report
                .errors
                .iter()
                .any(|e| e.contains("input text changed") && e.contains(definition)),
            "{:?}",
            report.errors
        );
        assert_eq!(before, fs::read(&path).unwrap());
    }
    // Reassessment records the current snapshots.
    capture(root);
    let refreshed: Value = serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap();
    approve(&path);
    assert!(validate_repository(root).unwrap().errors.is_empty());

    let mut missing = refreshed.clone();
    missing["inputs"]
        .as_array_mut()
        .unwrap()
        .retain(|i| i.get("definition") != Some(&json!("glossary.b")));
    fs::write(&path, missing.to_string()).unwrap();
    assert!(
        validate_repository(root)
            .unwrap()
            .errors
            .iter()
            .any(|e| e.contains("glossary.b, found 0"))
    );
    let mut duplicate = refreshed;
    let input = duplicate["inputs"][1].clone();
    duplicate["inputs"].as_array_mut().unwrap().push(input);
    fs::write(&path, duplicate.to_string()).unwrap();
    assert!(
        validate_repository(root)
            .unwrap()
            .errors
            .iter()
            .any(|e| e.contains("found 2"))
    );
}
Input 10: outline tests/definitions.rs fn[markdown_and_plain_text_inputs_contribute_their_term_references]
// {test}`requirements.definitions.dependencies`
#[test]
fn markdown_and_plain_text_inputs_contribute_their_term_references() {
    let temp = fixture();
    let root = temp.path();
    fs::write(
        root.join("md/more.md"),
        ":::{definition} prose\n:phrase: prose\n\nProse.\n:::\n\n\
         :::{definition} line\n:phrase: line\n\nA line.\n:::\n\n\
         :::{definition} literal\n:phrase: literal\n\nLiteral.\n:::\n",
    )
    .unwrap();
    fs::create_dir_all(root.join("docs")).unwrap();
    fs::write(
        root.join("docs/notes.md"),
        "# Notes\n\nThis uses {term}`more.prose` in prose.\n\n```text\n{term}`more.literal`\n```\n",
    )
    .unwrap();
    fs::write(root.join("notes.txt"), "plain {term}`more.line` text\n").unwrap();
    // The heading's section covers both the paragraph and the code block.
    let section = outline_input(root, "docs/notes.md", "section[Notes]").unwrap();
    let line = outline_inputs_for_lines(root, "notes.txt", 1, 1).unwrap();
    assert_eq!(line.len(), 1, "{line:?}");
    let sources = [section, line[0].clone()];
    // The fixture's requirement text needs the glossary cycle; the Markdown
    // paragraph and the text line add their terms, and the code block does not.
    let terms = |names: &[&str]| {
        sources
            .iter()
            .cloned()
            .chain(names.iter().map(|name| definition(root, name)))
            .collect::<Vec<_>>()
    };
    let path = record(
        root,
        "rules.ready",
        terms(&["glossary.a", "glossary.b", "more.line", "more.prose"]),
    );
    approve(&path);
    let errors = validate_repository(root).unwrap().errors;
    assert!(errors.is_empty(), "{errors:?}");
    for (names, missing) in [
        (&["glossary.a", "glossary.b", "more.line"][..], "more.prose"),
        (&["glossary.a", "glossary.b", "more.prose"][..], "more.line"),
    ] {
        record(root, "rules.ready", terms(names));
        approve(&path);
        let errors = validate_repository(root).unwrap().errors;
        assert!(
            errors
                .iter()
                .any(|error| error.contains(&format!("{missing}, found 0"))),
            "{missing}: {errors:?}"
        );
    }
}
Input 11: outline tests/definitions.rs fn[literal_term_roles_in_subject_and_requirements_inputs_need_no_definition]
  • File: tests/definitions.rs
  • Selector: fn[literal_term_roles_in_subject_and_requirements_inputs_need_no_definition]
  • Kind: fn
  • tests/definitions.rs:812–872
// {test}`requirements.references.markdown_literals`
// {test}`requirements.definitions.dependencies`
#[test]
fn literal_term_roles_in_subject_and_requirements_inputs_need_no_definition() {
    let temp = fixture();
    let root = temp.path();
    let glossary = root.join("md/glossary.md");
    let mut text = fs::read_to_string(&glossary).unwrap();
    text.push_str("\n:::{definition} c\n:phrase: gamma\n\nA third term.\n:::\n");
    fs::write(&glossary, text).unwrap();
    let literal = "Write `{term}`glossary.c`` as code, \\{term}`glossary.c` escaped, and <span title=\"{term}`glossary.c`\">html</span>.\n\n```text\n{term}`glossary.c`\n```\n";
    let chapter = |extra: &str| {
        format!(
            ":::{{req}} ready\nUse {{term}}`glossary.a`.\n:::\n\n:::{{req}} literal\n{literal}{extra}:::\n"
        )
    };
    fs::write(root.join("md/rules.md"), chapter("")).unwrap();
    let glossary_ab = || {
        vec![
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
        ]
    };
    let write = |root: &Path| {
        // The literal requirement as subject, and as a requirements input of
        // another requirement.
        approve(&record(
            root,
            "rules.literal",
            vec![requirements(root, "rules.literal", &["rules.literal"])],
        ));
        let mut inputs = vec![requirements(
            root,
            "rules.*",
            &["rules.literal", "rules.ready"],
        )];
        inputs.extend(glossary_ab());
        approve(&record(root, "rules.ready", inputs));
    };
    write(root);
    let errors = validate_repository(root).unwrap().errors;
    assert!(errors.is_empty(), "{errors:#?}");

    // The same role written as a reference needs the definition in both.
    fs::write(
        root.join("md/rules.md"),
        chapter("\nAnd {term}`glossary.c` itself.\n"),
    )
    .unwrap();
    write(root);
    let errors = validate_repository(root).unwrap().errors;
    for record in ["rules.literal", "rules.ready"] {
        assert!(
            errors
                .iter()
                .any(|e| e.starts_with(&format!("evidence/{record}.json"))
                    && e.contains("expected exactly one definition input for glossary.c, found 0")),
            "{record}: {errors:#?}"
        );
    }
}
Input 12: outline tests/definitions.rs fn[a_term_referenced_only_by_a_rust_input_comment_needs_its_definition_input]
  • File: tests/definitions.rs
  • Selector: fn[a_term_referenced_only_by_a_rust_input_comment_needs_its_definition_input]
  • Kind: fn
  • tests/definitions.rs:874–925
// {test}`requirements.definitions.dependencies`
#[test]
fn a_term_referenced_only_by_a_rust_input_comment_needs_its_definition_input() {
    let temp = fixture();
    let root = temp.path();
    let glossary = root.join("md/glossary.md");
    let mut text = fs::read_to_string(&glossary).unwrap();
    text.push_str("\n:::{definition} c\n:phrase: gamma\n\nA third term.\n:::\n");
    fs::write(&glossary, text).unwrap();
    // Only the function's comment references glossary.c; a reference in a
    // string literal is not a comment and needs nothing.
    fs::write(
        root.join("src/lib.rs"),
        "// {impl}`rules.ready`\n// Uses {term}`glossary.c`.\npub fn run() {}\n\n// {impl}`rules.ready`\npub fn quoted() -> &'static str {\n    \"{term}`glossary.c`\"\n}\n",
    )
    .unwrap();
    let base = |items: &[&str]| {
        let mut inputs = vec![requirements(root, "rules.*", &["rules.ready"])];
        for item in items {
            inputs.push(outline_input(root, "src/lib.rs", item).unwrap());
        }
        inputs.push(definition(root, "glossary.a"));
        inputs.push(definition(root, "glossary.b"));
        inputs
    };
    let missing = "expected exactly one definition input for glossary.c, found 0";
    // Reading only the function with the string literal needs no glossary.c.
    approve(&record(root, "rules.ready", base(&["fn[quoted]"])));
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        !errors.iter().any(|e| e.contains("glossary.c")),
        "{errors:#?}"
    );
    // Reading the function whose comment references it requires it.
    approve(&record(
        root,
        "rules.ready",
        base(&["fn[run]", "fn[quoted]"]),
    ));
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|e| e.starts_with("evidence/rules.ready.json") && e.contains(missing)),
        "{errors:#?}"
    );
    let mut inputs = base(&["fn[run]", "fn[quoted]"]);
    inputs.push(definition(root, "glossary.c"));
    approve(&record(root, "rules.ready", inputs));
    let errors = validate_repository(root).unwrap().errors;
    assert!(errors.is_empty(), "{errors:#?}");
}
Input 13: outline tests/definitions.rs fn[outline_inputs_capture_terms_without_counting_them_as_citations]
// {test}`requirements.definitions.transitive_cycle`
// {test}`requirements.definitions.dependencies`
// {test}`requirements.definitions.references`
#[test]
fn outline_inputs_capture_terms_without_counting_them_as_citations() {
    let temp = fixture();
    let root = temp.path();
    fs::write(
        root.join("src/lib.rs"),
        "// {impl}`rules.ready`\n// {term}`glossary.a`\npub fn run() {}\n",
    )
    .unwrap();
    // The function's term reference needs the same glossary cycle as the
    // requirement text, captured once.
    let path = record(
        root,
        "rules.ready",
        vec![
            requirements(root, "rules.*", &["rules.ready"]),
            outline_input(root, "src/lib.rs", "fn[run]").unwrap(),
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
        ],
    );
    approve(&path);
    let errors = validate_repository(root).unwrap().errors;
    assert!(errors.is_empty(), "{errors:?}");
    let glossary = root.join("md/glossary.md");
    fs::write(
        &glossary,
        fs::read_to_string(&glossary)
            .unwrap()
            .replace(":phrase: beta", ":phrase: changed"),
    )
    .unwrap();
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|e| e.contains("evidence/rules.ready.json")
                && e.contains("input text changed")
                && e.contains("glossary.b")),
        "{errors:?}"
    );
    fs::write(
        root.join("src/lib.rs"),
        "// {term}`glossary.a`\npub fn run() {}\n",
    )
    .unwrap();
    // Removing a citation comment leaves the node's hash unchanged, so the
    // record reading it would still cover it.
    fs::remove_file(&path).unwrap();
    assert!(
        habeas::coverage_warnings(root)
            .unwrap()
            .items
            .iter()
            .any(|e| e.contains("run") && e.contains("has no recent coverage"))
    );
}
Input 14: outline tests/definitions.rs fn[definition_schema_deletion_and_literal_references_are_checked]
// {test}`requirements.definitions.inputs`
// {test}`requirements.definitions.references`
// {test}`requirements.definitions.dependencies`
#[test]
fn definition_schema_deletion_and_literal_references_are_checked() {
    let temp = fixture();
    let root = temp.path();
    capture(root);
    let path = root.join("evidence/rules.ready.json");
    approve(&path);
    let original: Value = serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap();
    let mut invalid = original.clone();
    invalid["inputs"][1]["unexpected"] = json!(true);
    fs::write(&path, invalid.to_string()).unwrap();
    assert!(
        validate_repository(root)
            .unwrap()
            .errors
            .iter()
            .any(|e| e.contains("unexpected field"))
    );
    fs::write(&path, original.to_string()).unwrap();
    fs::remove_file(root.join("md/glossary.md")).unwrap();
    assert!(
        validate_repository(root)
            .unwrap()
            .errors
            .iter()
            .any(|e| e.contains("glossary.a") && e.contains("no matching named definition"))
    );

    let temp = fixture();
    let root = temp.path();
    let body = "Literal `{term}`missing.name``.\n\n```text\n{term}`missing.name`\n```\n\n\\{term}`missing.name`";
    fs::write(
        root.join("md/rules.md"),
        format!(":::{{req}} ready\n{body}\n:::\n"),
    )
    .unwrap();
    // Literal and escaped references require no definition inputs.
    let path = record(
        root,
        "rules.ready",
        vec![requirements(root, "rules.*", &["rules.ready"])],
    );
    approve(&path);
    let report = validate_repository(root).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 15: outline tests/definitions.rs fn[example_subject_and_definition_display_use_the_same_dependencies]
// {test}`requirements.definitions.dependencies`
#[test]
fn example_subject_and_definition_display_use_the_same_dependencies() {
    let temp = fixture();
    let root = temp.path();
    let path = root.join("md/rules.md");
    let text = fs::read_to_string(&path).unwrap()
        + "\n:::{example} case\n{cite}`rules.ready` with {term}`glossary.a`.\n:::\n";
    fs::write(path, text).unwrap();
    // The example's own term reference and its selected requirement need the
    // same glossary cycle, recorded once.
    record(
        root,
        "rules.case",
        vec![
            requirements(root, "rules.ready", &["rules.ready"]),
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
        ],
    );
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .all(|error| !error.contains("definition input")),
        "{errors:?}"
    );
    let display = habeas::info_markdown(root, "rules.case").unwrap();
    assert!(display.contains("definition glossary.a"));
    assert!(display.contains("md/glossary.md"));
    assert!(display.contains(":phrase: alpha"));
}

Referenced definitions

Input 2: 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.
:::

Other sources

Input 1: requirements selection requirements.definitions.dependencies
:::{req} dependencies
Requirement and example evidence MUST include a definition input for every term
referenced by its subject text, reviewed inputs, or acknowledgments supplied
under {cite}`requirements.authoring.fixme_inputs`.

Habeas MUST repeatedly include definitions referenced by required definitions until the set reaches a fixed point. Each required definition MUST have exactly one definition input per evidence record. Cyclic references MUST be permitted and MUST NOT cause repeated expansion or nontermination.

Validation MUST report missing required definition inputs and MUST NOT silently refresh snapshots.
:::