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

Requirements index · View definition

evidence Valid

Requirement

The requirement string in each evidence file MUST match all Markdown inside its fenced {req} directive, excluding leading and trailing whitespace and the header option lines of cite requirements.references.anchors. Habeas MUST report changed requirement text.

Rationale

The reviewed tests adequately cover requirements.ci.requirement_text.

Obligations derived from the text

  1. The evidence requirement string must equal all Markdown inside the {req} body.
    • Leading and trailing whitespace is excluded.
    • The header option lines of requirements.references.anchors are excluded.
  2. Habeas must report changed requirement text.

Coverage

  • Full-body match, including whitespace trimming. src/evidence.rs#mod[tests]/fn[validates_full_names_requirement_text_and_input_lines] has an indented, multi-block body: a leading-indented sentence, a blank line, and a fenced code block containing {req}example``. The evidence string is the trimmed full body, and the test asserts no errors. A truncated or first-paragraph-only comparison would fail it, as would one that mishandles the nested fence or the whitespace.
  • Option lines excluded. src/evidence.rs#mod[tests]/fn[anchored_files_must_be_completely_covered_and_resolvable] declares a {req} with :test: option lines before its body. It records evidence containing only Ready MUST hold. and asserts the errors do not contain “text changed”. The same test does this for an {example} with a :test: option line.
  • Changed text reported. src/evidence.rs#mod[tests]/fn[collects_missing_orphan_format_false_and_changed_line_errors] records “Old text.” against a body of “First.” and asserts the error contains “requirement text changed”, “- Old text.” and “+ First.”.
    • A second test, changed_requirement_text_names_the_record_and_location_with_a_diff, checks the exact message for a one-word change (SHOULD to MUST).
    • It has no {test} reference for this requirement. That is a marking gap only, and the marked tests already cover the obligation.

Residual points

  • No test changes only a later paragraph of a multi-block body and expects a report.
  • Equality of the full multi-block body is asserted positively.
  • Differences are reported through a general diff.
  • These two facts make a partial-comparison defect implausible, so I don’t count this as a gap.

Inputs

Tests

Input 3: outline src/evidence.rs mod[tests]/fn[validates_full_names_requirement_text_and_input_lines]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[validates_full_names_requirement_text_and_input_lines]
  • Kind: fn
  • src/evidence.rs:2533–2564
    // {test}`requirements.integration.report_api`
    // {test}`requirements.ci.book_source`
    // {test}`requirements.ci.coverage`
    // {test}`requirements.ci.requirement_text`
    // {test}`requirements.ci.outline_inputs`
    // {test}`requirements.ci.identifiers`
    // {test}`requirements.ci.span`
    #[test]
    fn validates_full_names_requirement_text_and_input_lines() {
        let temp = fixture();
        fs::write(
            temp.path().join("md/reqs/foo/bar.md"),
            "# Requirements\n\n:::{req} ready\n\n  The check MUST pass.\n\n```text\n{req}`example`\n```\n:::\n",
        )
        .unwrap();
        fs::write(
            temp.path().join("evidence/foo.bar.ready.json"),
            json!({
                "requirement": "The check MUST pass.\n\n```text\n{req}`example`\n```",
                "determination": true,
                "rationale": "The inspected file has the expected lines.",
                "inputs": [outline(temp.path(), "src/main.rs", "")]
            })
            .to_string(),
        )
        .unwrap();

        let report = validate_repository(temp.path()).unwrap();
        assert_eq!(report.requirements, 1);
        assert_eq!(report.evidence_files, 1);
        assert!(report.errors.is_empty(), "{:?}", report.errors);
    }
Input 4: 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 5: 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:?}"
        );
    }

Referenced definitions

Input 2: requirements selection requirements.references.anchors
:::{req} anchors
A `{req}` declaration MAY list `:impl:` and `:test:` options, and an `{example}`
declaration MAY list `:test:` options, immediately after its opening fence and
before its body, one per option line, naming a project file path or
`path#selector` for one outline node under
{cite}`requirements.references.outline_selectors`. Each anchor MUST be an `{impl}` or `{test}` edge, under
{cite}`requirements.references.roles`, from the definition to the anchored file or
node, for files that cannot or should not carry a reference themselves.
Paths MUST follow the path rules in {cite}`requirements.ci.schema`. Option lines
MUST NOT form part of the definition's text for evidence comparison or for
requirements inputs, and MUST NOT render as body text.

For each `:test:` anchor, the harness MUST include the selected file or node's
source text in the initial model request under
{cite}`requirements.authoring.mandatory_inputs` and MUST record that selection
as an evidence input under {cite}`requirements.references.evidence_coverage`,
so changing that source makes the evidence stale.
A `:impl:` anchor alone MUST NOT require an input selecting its source. A path or selector that
does not resolve to a readable, permitted file or node MUST be a validation error naming the
definition and the path; authoring MUST report it before inference. Any other option line in a `{req}` or
`{example}` declaration MUST be a validation error.
:::

Other sources

Input 1: requirements selection requirements.ci.requirement_text
:::{req} requirement_text
The `requirement` string in each evidence file MUST match all Markdown inside its fenced `{req}` directive, excluding leading and trailing whitespace and the header option lines of {cite}`requirements.references.anchors`. Habeas MUST report changed requirement text.
:::