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

Requirements index · View definition

evidence Valid

Example

Requirement R references definition A. A references B, and B references A. R’s evidence contains one definition input for A and one for B. Dependency collection terminates. Changing B’s phrase or body invalidates R’s snapshot of B. cite requirements.definitions.dependencies cite requirements.definitions.inputs

Rationale

The tests adequately check the example. Two tests in tests/definitions.rs carry {test} references to it.

Scenario. The fixture helper builds exactly the example’s cycle. The requirement rules.ready says “Use {term}glossary.a.” In md/glossary.md, definition a says “See {term}glossary.b.” and definition b says “See {term}glossary.a.”. So R references A, A references B, and B references A.

Outcomes the example states, and the assertions that check them:

  • One definition input for A and one for B, with termination.
    • cyclic_dependencies_are_required_once_and_changes_require_review records evidence through capture. capture holds one definition input each for glossary.a and glossary.b, plus the requirements input.
    • The test approves that evidence and asserts validate_repository returns with no errors. The call returns, so cycle handling terminates. The clean result means B is required through A, with no missing input and no extra one.
    • It then removes the glossary.b input and asserts the error “glossary.b, found 0”.
    • It also duplicates an input and asserts an error containing “found 2”. Together these check the “exactly one per definition” rule.
    • outline_inputs_capture_terms_without_counting_them_as_citations repeats the exact-once check for an outline input. Its {term} reference to glossary.a needs the same A/B cycle, and validation is clean with one input each.
  • Changing B’s phrase or body invalidates R’s snapshot of B. In cyclic_dependencies_are_required_once_and_changes_require_review, one case changes :phrase: beta to :phrase: new beta. Another changes B’s body from “See” to “Read”. Each asserts an error containing both “input text changed” and glossary.b. After each change the test also asserts the evidence file is byte-identical, so snapshots are not silently refreshed. The outline_inputs… test also changes B’s phrase and asserts an error that names evidence/rules.ready.json, “input text changed” and glossary.b.
  • Moving a definition does not invalidate it. This is from the cited inputs requirement. The test prepends blank lines to the glossary and asserts there are no errors.
  • Reassessment. After capture runs again, the refreshed evidence validates cleanly.

Possible gaps considered. Nothing asserts that the evidence contains no inputs beyond A and B, so the tests would accept an extra unrelated definition input. The example only requires one input each for A and B, and the duplicate and missing checks cover that. I do not count this as a gap.

I found no unresolved questions and no applicable {fixme} acknowledgments.

Inputs

Tests

Input 4: 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 5: 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"))
    );
}

Referenced definitions

Input 2: 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.
:::
Input 3: requirements selection requirements.definitions.inputs
:::{req} inputs
Evidence inputs MAY have a definition form containing exactly `definition` and `text`. `definition` MUST identify one named definition; `text` MUST contain its complete raw fenced declaration as source lines, including its phrase option and explanatory body.

Validation MUST reject missing definitions and changed snapshot text, identifying the definition and showing a compact diff when available. Moving an unchanged definition within its chapter MUST NOT invalidate its snapshot. Evidence displays MUST show the definition name, current source location, and recorded text.
:::

Other sources

Input 1: requirements selection requirements.definitions.transitive_cycle
:::{example} transitive_cycle
Requirement R references definition A. A references B, and B references A. R's evidence contains one definition input for A and one for B. Dependency collection terminates. Changing B's phrase or body invalidates R's snapshot of B. {cite}`requirements.definitions.dependencies` {cite}`requirements.definitions.inputs`
:::
Input 6: outline tests/definitions.rs fn[capture]
/// Records the fixture requirement with its selection and the complete
/// definition cycle it depends on.
fn capture(root: &Path) {
    record(
        root,
        "rules.ready",
        vec![
            requirements(root, "rules.*", &["rules.ready"]),
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
        ],
    );
}
Input 7: outline tests/definitions.rs fn[definition]
fn definition(root: &Path, name: &str) -> Value {
    json!({ "definition": name, "text": declaration(root, name) })
}