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

Requirements index · View definition

evidence Valid

Requirement

The {term} role followed by a backtick-delimited full definition name MUST reference a named definition. In rendered Markdown, the reference MUST display the definition’s phrase as an ordinary hyperlink to its anchored declaration, without a badge. The phrase MUST be escaped appropriately for rendering.

Missing targets and targets of another kind MUST be reported. Escaped references and references in Markdown code examples MUST remain literal. A term reference MUST NOT satisfy a requirement citation or a Rust function’s requirement-coverage obligation.

Rationale

I judged this from the supplied test sources only and requested no implementation source. Each obligation in requirements.definitions.references maps to at least one marked test with assertions that enforce it.

Rendering as a plain hyperlink

  • tests/definitions.rs#fn[phrases_are_plain_links_and_markdown_literals_are_preserved] renders a glossary chapter and a deeper guide chapter.
  • It asserts the declaration anchor id="habeas-definition-glossary.a" exists.
  • It asserts the reference chapter has no shields.io, so there is no badge.
  • It asserts exactly one href="../glossary.html#habeas-definition-glossary.a", so the link is ordinary and anchored, with a correct relative path.
  • It asserts the phrase *alpha* & <beta> is escaped as &#42;alpha&#42; &amp; &lt;beta&gt;.

Missing targets and targets of another kind

  • tests/definitions.rs#fn[invalid_declarations_and_reference_targets_are_reported] asserts “term missing.name has no matching named definition”. It also asserts the same error for rules.ready, which is a requirement rather than a definition.
  • tests/definitions.rs#fn[references_to_a_definition_of_another_kind_are_reported] asserts the error for a {term} naming an example (cases.case), reported from a Rust source file with its file and line.
  • That test also checks the reverse direction: {impl}, {cite} and {test} references to a definition (glossary.a) are each reported as having no matching requirement or example.
  • tests/definitions.rs#fn[definition_schema_deletion_and_literal_references_are_checked] asserts a term reference whose definition has been deleted yields a “no matching named definition” error.

Escaped references and Markdown code examples stay literal

  • The rendering test covers inline code, a fenced code block and a backslash-escaped \{term}. In each case the literal text is preserved in the output.
  • The validation side is covered in tests/definitions.rs#fn[definition_schema_deletion_and_literal_references_are_checked]. A requirement body contains the same three literal forms naming the nonexistent missing.name, and validation produces no errors.

A term reference does not satisfy a citation or function coverage

  • src/evidence.rs#fn[examples_may_reference_their_requirement_with_cite_or_test] includes an example whose only reference is {term}rules.ready``. The test asserts that example still gets “must reference at least one requirement with {cite} or {test}”.
  • tests/definitions.rs#fn[references_to_a_definition_of_another_kind_are_reported] asserts a Rust function carrying a term reference still gets “has no recent coverage”.
  • tests/definitions.rs#fn[outline_inputs_capture_terms_without_counting_them_as_citations] asserts that after the {impl} comment is removed and only {term} remains, the function has no recent coverage.

I found no unaddressed obligation or boundary case, and no marking gap. All the relevant tests carry {test} references to the subject.

Inputs

Tests

Input 2: outline src/evidence.rs mod[tests]/fn[examples_may_reference_their_requirement_with_cite_or_test]
  • File: src/evidence.rs
  • Selector: mod[tests]/fn[examples_may_reference_their_requirement_with_cite_or_test]
  • Kind: fn
  • src/evidence.rs:3726–3758
    // {test}`requirements.examples.definition`
    // {test}`requirements.definitions.references`
    #[test]
    fn examples_may_reference_their_requirement_with_cite_or_test() {
        let temp = fixture();
        let chapter = ":::{req} ready\nReady.\n:::\n\n:::{example} tested\nGiven ready. {test}`rules.ready`\n:::\n\n:::{example} cited\nGiven ready. {cite}`rules.ready`\n:::\n\n:::{example} nested\nLike the tested case. {cite}`rules.tested`\n:::\n\n:::{example} implemented\nGiven ready. {impl}`rules.ready`\n:::\n\n:::{example} literal\nGiven ready. `{cite}`rules.ready`` and \\{cite}`rules.ready`\n:::\n\n:::{example} unknown\nGiven ready. {cite}`rules.absent`\n:::\n\n:::{example} termed\nGiven ready. {term}`rules.ready`\n:::\n";
        fs::write(temp.path().join("md/rules.md"), chapter).unwrap();
        let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
        assert!(
            !errors.contains("example rules.tested must reference"),
            "{errors}"
        );
        assert!(
            !errors.contains("example rules.cited must reference"),
            "{errors}"
        );
        assert!(
            errors.contains(
                "example rules.nested must reference at least one requirement with {cite} or {test}"
            ),
            "{errors}"
        );
        // Only `{cite}` or `{test}` counts, and only as a valid reference; a
        // `{term}` naming the requirement does not.
        for name in ["implemented", "literal", "unknown", "termed"] {
            assert!(
                errors.contains(&format!(
                    "example rules.{name} must reference at least one requirement with {{cite}} or {{test}}"
                )),
                "{name}: {errors}"
            );
        }
    }
Input 3: outline tests/definitions.rs fn[invalid_declarations_and_reference_targets_are_reported]
// {test}`requirements.definitions.declaration`
// {test}`requirements.definitions.references`
#[test]
fn invalid_declarations_and_reference_targets_are_reported() {
    for body in [
        "Body only.",
        ":phrase: \n\nBody.",
        ":phrase: one\n:phrase: two\n\nBody.",
        ":phrase: only",
    ] {
        let temp = fixture();
        fs::write(
            temp.path().join("md/bad.md"),
            format!(":::{{definition}} bad\n{body}\n:::\n"),
        )
        .unwrap();
        assert!(
            validate_repository(temp.path())
                .unwrap()
                .errors
                .iter()
                .any(|e| e.contains("definition bad.bad:"))
        );
    }
    let temp = fixture();
    fs::write(
        temp.path().join("md/bad.md"),
        ":::{definition} open\n:phrase: open\n\nNo closing fence.\n",
    )
    .unwrap();
    assert!(
        validate_repository(temp.path())
            .unwrap()
            .errors
            .iter()
            .any(|e| e.contains("missing a closing colon fence"))
    );
    fs::write(temp.path().join("md/bad.md"), ":::{req} x\nRequirement.\n:::\n:::{definition} x\n:phrase: x\n\nDefinition.\n:::\n{term}`rules.ready` {term}`missing.name`").unwrap();
    let errors = validate_repository(temp.path()).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|e| e.contains("duplicate definition bad.x"))
    );
    assert!(
        errors
            .iter()
            .any(|e| e.contains("term rules.ready has no matching named definition"))
    );
    assert!(
        errors
            .iter()
            .any(|e| e.contains("term missing.name has no matching named definition"))
    );
}
Input 4: outline tests/definitions.rs fn[references_to_a_definition_of_another_kind_are_reported]
// {test}`requirements.definitions.references`
#[test]
fn references_to_a_definition_of_another_kind_are_reported() {
    let temp = fixture();
    fs::write(
        temp.path().join("md/cases.md"),
        ":::{example} case\nA ready case. {cite}`rules.ready`\n:::\n",
    )
    .unwrap();
    let source = ["impl", "cite", "test"]
        .iter()
        .map(|role| format!("// {{{role}}}`glossary.a`\n"))
        .chain(["// {term}`cases.case`\n".to_owned()])
        .collect::<String>();
    fs::write(
        temp.path().join("src/lib.rs"),
        format!("{source}fn uses() {{}}\n"),
    )
    .unwrap();
    let mut errors = validate_repository(temp.path()).unwrap().errors;
    // Coverage is warned about, not a validation error.
    errors.extend(habeas::coverage_warnings(temp.path()).unwrap().items);
    for (line, role) in [(1, "impl"), (2, "cite"), (3, "test")] {
        let expected = format!(
            "src/lib.rs:{line}: {{{role}}}`glossary.a` has no matching requirement or example"
        );
        assert!(
            errors.iter().any(|error| error.contains(&expected)),
            "{expected}: {errors:#?}"
        );
    }
    assert!(
        errors.iter().any(|error| error
            .contains("src/lib.rs:4: term cases.case has no matching named definition")),
        "{errors:#?}"
    );
    // A reference to a term does not cover the Rust item.
    assert!(
        errors.iter().any(|error| error
            .contains("src/lib.rs:5: function uses has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it")),
        "{errors:#?}"
    );
}
Input 5: outline tests/definitions.rs fn[phrases_are_plain_links_and_markdown_literals_are_preserved]
// {test}`requirements.definitions.phrase_rendering`
// {test}`requirements.definitions.references`
// {test}`requirements.definitions.declaration`
#[test]
fn phrases_are_plain_links_and_markdown_literals_are_preserved() {
    let temp = fixture();
    let mut book = Book::new();
    book.push_item(Chapter::new(
        "Glossary",
        ":::{definition} a\n:phrase: *alpha* & <beta>\n\nThe body.\n:::\n".into(),
        "glossary.md",
        Vec::new(),
    ));
    let source = "Use {term}`glossary.a`.\n\n`{term}`glossary.a``\n\n```text\n{term}`glossary.a`\n```\n\n\\{term}`glossary.a`".to_owned();
    book.push_item(Chapter::new("Guide", source, "guide/deep.md", Vec::new()));
    habeas::preprocess_book(&mut book, temp.path()).unwrap();
    let chapters: Vec<_> = book.chapters().collect();
    assert!(
        chapters[0]
            .content
            .contains("id=\"habeas-definition-glossary.a\"")
    );
    assert!(!chapters[0].content.contains(":phrase:"));
    assert!(!chapters[1].content.contains("shields.io"));
    assert_eq!(
        chapters[1]
            .content
            .matches("href=\"../glossary.html#habeas-definition-glossary.a\"")
            .count(),
        1
    );
    assert!(
        chapters[1]
            .content
            .contains("&#42;alpha&#42; &amp; &lt;beta&gt;")
    );
    for literal in [
        "`{term}`glossary.a``",
        "```text\n{term}`glossary.a`\n```",
        r"\{term}`glossary.a`",
    ] {
        assert!(chapters[1].content.contains(literal), "{literal:?}");
    }
}
Input 6: 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 7: 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);
}

Other sources

Input 1: requirements selection requirements.definitions.references
:::{req} references
The `{term}` role followed by a backtick-delimited full definition name MUST reference a named definition. In rendered Markdown, the reference MUST display the definition's phrase as an ordinary hyperlink to its anchored declaration, without a badge. The phrase MUST be escaped appropriately for rendering.

Missing targets and targets of another kind MUST be reported. Escaped references and references in Markdown code examples MUST remain literal. A term reference MUST NOT satisfy a requirement citation or a Rust function's requirement-coverage obligation.
:::