requirements.definitions.transitive_cycle
Requirements index · View definition
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.
![]()
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_reviewrecords evidence throughcapture.captureholds onedefinitioninput each forglossary.aandglossary.b, plus the requirements input.- The test approves that evidence and asserts
validate_repositoryreturns 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.binput 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_citationsrepeats the exact-once check for an outline input. Its{term}reference toglossary.aneeds 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: betato:phrase: new beta. Another changes B’s body from “See” to “Read”. Each asserts an error containing both “input text changed” andglossary.b. After each change the test also asserts the evidence file is byte-identical, so snapshots are not silently refreshed. Theoutline_inputs…test also changes B’s phrase and asserts an error that namesevidence/rules.ready.json, “input text changed” andglossary.b. - Moving a definition does not invalidate it. This is from the cited
inputsrequirement. The test prepends blank lines to the glossary and asserts there are no errors. - Reassessment. After
captureruns 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]
- File:
tests/definitions.rs - Selector:
fn[cyclic_dependencies_are_required_once_and_changes_require_review] - Kind:
fn tests/definitions.rs:173–250
// {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]
- File:
tests/definitions.rs - Selector:
fn[outline_inputs_capture_terms_without_counting_them_as_citations] - Kind:
fn tests/definitions.rs:927–986
// {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
requirements.definitions.dependencies:md/requirements/definitions.md:21–29
:::{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
requirements.definitions.inputs:md/requirements/definitions.md:15–19
:::{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
requirements.definitions.transitive_cycle:md/requirements/definitions.md:39–41
:::{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]
- File:
tests/definitions.rs - Selector:
fn[capture] - Kind:
fn tests/definitions.rs:93–105
/// 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]
- File:
tests/definitions.rs - Selector:
fn[definition] - Kind:
fn tests/definitions.rs:55–57
fn definition(root: &Path, name: &str) -> Value {
json!({ "definition": name, "text": declaration(root, name) })
}