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.diagnostics

Requirements index · View definition

evidence Valid

Requirement

When stored requirement text differs from the current chapter text, the validation error MUST name the requirement and show a compact line-oriented diff, with - for recorded lines and + for current lines. When an outline input’s hash differs from its node’s current hash, the validation error MUST name the file, the selector, and the node’s current line range.

evidence/requirements.ci.outline_inputs.json: requirement text changed (md/requirements.md:43)
- Habeas SHOULD check input lines.
+ Habeas MUST check input lines.

Rationale

The reviewed tests cover both obligations in requirements.ci.diagnostics. I did not read any implementation source.

Obligation 1: changed requirement text. The validation error must name the requirement and show a compact line diff, with - for recorded lines and + for current lines.

  • src/evidence.rs#mod[tests]/fn[changed_requirement_text_names_the_record_and_location_with_a_diff] checks the whole error list with assert_eq!. The only error names the evidence file, says the requirement text changed, gives the markdown location, and is followed by a - line with the recorded text and a + line with the current text. This pins the format of the requirement’s example, including the sign convention.

  • src/evidence.rs#mod[tests]/fn[compact_diffs_elide_common_lines_and_truncate_long_runs] tests compact_diff directly. It covers these cases:

    • Changed lines, with common lines elided.
    • Pure additions.
    • Pure removals.
    • Identical input, which gives an empty diff.
    • Truncation of a long run of removed lines.

    This supports the “compact, line-oriented” property.

  • src/evidence.rs#mod[tests]/fn[collects_missing_orphan_format_false_and_changed_line_errors] also checks the changed-text error with its - and + lines.

Obligation 2: changed outline input hash. The validation error must name the file, the selector, and the node’s current line range.

  • tests/evidence_boundaries.rs#fn[outline_inputs_survive_moves_and_unhashed_comments_but_not_edits] asserts the full “outline input changed” message for fn[alpha] and fn[beta]. Each message has the file, the selector, and the current line range. The range for fn[beta] includes its doc comment and attributes. The test also checks that an unchanged input produces no error and that no diff is shown for outline inputs.
  • The same test covers inputs that stay valid after moves and unhashed edits, so the stale-input error is not triggered spuriously.
  • src/evidence.rs#mod[tests]/fn[collects_missing_orphan_format_false_and_changed_line_errors] asserts the root-node case, where the selector shown is <root>.

Both obligations have exact-text assertions on file, selector, line range, requirement, and diff content. I found no uncovered scenario the text names, so there are no gaps.

Inputs

Tests

Input 2: 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 3: outline src/evidence.rs mod[tests]/fn[changed_requirement_text_names_the_record_and_location_with_a_diff]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[changed_requirement_text_names_the_record_and_location_with_a_diff]
  • Kind: fn
  • src/evidence.rs:3224–3251
    // {test}`requirements.ci.diagnostics`
    #[test]
    fn changed_requirement_text_names_the_record_and_location_with_a_diff() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/requirements.md"),
            "# Requirements\n\n:::{req} one\nHabeas MUST check input lines.\n:::\n",
        )
        .unwrap();
        fs::write(
            temp.path().join("evidence/requirements.one.json"),
            json!({
                "requirement": "Habeas SHOULD check input lines.",
                "determination": true,
                "rationale": "Examined.",
                "inputs": []
            })
            .to_string(),
        )
        .unwrap();
        let report = validate_repository(temp.path()).unwrap();
        assert_eq!(
            report.errors,
            [
                "evidence/requirements.one.json: requirement text changed (md/requirements.md:3)\n- Habeas SHOULD check input lines.\n+ Habeas MUST check input lines."
            ]
        );
    }
Input 4: outline src/evidence.rs mod[tests]/fn[compact_diffs_elide_common_lines_and_truncate_long_runs]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[compact_diffs_elide_common_lines_and_truncate_long_runs]
  • Kind: fn
  • src/evidence.rs:3253–3273
    // {test}`requirements.ci.diagnostics`
    #[test]
    fn compact_diffs_elide_common_lines_and_truncate_long_runs() {
        let diff = |old: &[&str], new: &[&str]| super::compact_diff(old, new);
        assert_eq!(
            diff(&["a", "b", "c", "d"], &["a", "B", "C", "d"]),
            "\n- b\n- c\n+ B\n+ C"
        );
        assert_eq!(diff(&["a", "c"], &["a", "b", "c"]), "\n+ b");
        assert_eq!(diff(&["a", "b", "c"], &["a", "c"]), "\n- b");
        assert_eq!(diff(&["same"], &["same"]), "");
        let old = (0..10).map(|n| format!("old {n}")).collect::<Vec<_>>();
        let old = old.iter().map(String::as_str).collect::<Vec<_>>();
        let truncated = diff(&old, &["new"]);
        assert_eq!(truncated.matches("\n- old").count(), 8, "{truncated}");
        assert!(
            truncated.contains("\n- old 7\n- ... 2 more lines\n+ new"),
            "{truncated}"
        );
        assert!(!truncated.contains("old 8"), "{truncated}");
    }
Input 5: 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}"
    );
}

Referenced definitions

Input 6: definition requirements.ci.validation_error
:::{definition} validation_error
:phrase: validation error

One message in a repository validation report, describing a single failed check.
It begins with the affected evidence file, requirement, or source location, names
the failed check, and states the specific missing, invalid, or changed value,
with the expected value when available. It is concise because agents are its
primary readers.
:::

Other sources

Input 1: requirements selection requirements.ci.diagnostics
:::{req} diagnostics
When stored requirement text differs from the current chapter text, the
{term}`requirements.ci.validation_error` MUST name the requirement and show a
compact line-oriented diff, with `-` for recorded lines and `+` for current lines.
When an outline input's hash differs from its node's current hash, the validation
error MUST name the file, the selector, and the node's current line range.

```text
evidence/requirements.ci.outline_inputs.json: requirement text changed (md/requirements.md:43)
- Habeas SHOULD check input lines.
+ Habeas MUST check input lines.
```
:::