requirements.ci.reference_set
Requirements index · View definition
Requirement
A definition’s reference set MUST consist of its current incoming
{impl},{test}, and{fixme}edges, except a{fixme}inside a site of the definition under, under
and
: for each edge, its role and the file and outline selector of the node the reference belongs to under
, or of the anchored file or node, and, for a fenced reference in a source outside the book, the words of its body under the word rule of
.
{cite}references MUST NOT contribute. The reference-set digest MUST be the SHA-256 digest of an unambiguous encoding of those entries in sorted order, so it does not depend on line numbers or on the order references are found. Authoring MUST record the digest of the reference set it supplied, and validation MUST recompute it and report a changed reference set as stale evidence. Adding or removing an{impl},{test}, or{fixme}reference or anchor, changing its role, editing its commentary, or moving it to a different node MUST therefore make the evidence stale even when no recorded input changed; moving a reference within the node it belongs to MUST NOT.
Rationale
I found no adequacy gap. I did not request any implementation source. Each obligation in requirements.ci.reference_set maps to at least one marked test with assertions that enforce it.
Membership: {impl}, {test} and {fixme} edges count, and {cite} does not
src/evidence.rs#mod[tests]/fn[reference_set_digest_tracks_impl_and_test_edges_by_node]builds{impl}and{test}references in Rust, a text file and Markdown. It asserts that adding{cite}references leaves the digest unchanged.- The same test asserts that these changes alter the digest:
- adding a reference;
- adding a second reference on the same node;
- removing a reference;
- changing a role;
- moving a reference to a different node;
- removing the
notes.txtreference; - adding an
{impl}reference under a different Markdown section.
tests/references.rs#fn[fixme_edges_and_their_bodies_are_part_of_the_reference_set]shows that a{fixme}changes the digest. It also shows that a different role on the same node is a different edge. Inline{fixme}and unnamed{fixme}are not edges.
Anchors
reference_set_digest_tracks_impl_and_test_edges_by_nodeadds:impl:and:test:anchors, for a whole file and for a node (src/lib.rs#fn[run]). Each addition produces a new, distinct digest.
Entry content: role, file, node selector, and the body’s words for a fenced reference outside the book
tests/references.rs#fn[fenced_commentary_outside_the_book_contributes_to_the_reference_set]shows that reflowing the commentary keeps the digest. It also shows that changing the words, or dropping the fence to an inline reference, changes it. In the book, commentary does not contribute.fixme_edges_and_their_bodies_are_part_of_the_reference_setshows that editing the issue number or the description changes the digest, and that reflowing keeps it.src/evidence.rs#mod[tests]/fn[the_reference_set_digest_does_not_depend_on_the_order_entries_are_found]shows that the word lists["ab","c"]and["a","bc"]give different digests. It also shows that file/item splits("a","bc")and("ab","c")give different digests, which checks the encoding is unambiguous.
Independence from line numbers and discovery order
reference_set_digest_tracks_impl_and_test_edges_by_nodeadds unrelated lines, moves a reference within its node, and prepends text to notes and guide files. The digest is unchanged in each case.- The unit test above asserts that reversing the entry order gives the same digest.
Site {fixme} exclusion
src/sites.rs#mod[tests]/fn[a_fixme_inside_a_site_belongs_to_that_sites_review_only]edits an in-site{fixme}and asserts the requirement’s digest is unchanged. It edits a{fixme}outside any site and asserts the digest changes.
Authoring records the digest
src/authoring/inputs.rs#mod[tests]/fn[bundle_combines_direct_references_terms_and_current_existing_selectors]assertssources.reference_setequalsreference_set_digest_for.src/authoring/mod.rs#mod[tests]/fn[throttled_requests_retry_unchanged_and_record_every_attempt]asserts the submitted record’sreferencesequalssources.reference_set.tests/authoring_batch.rs#fn[batch_reauthors_a_false_judgment_when_its_reference_set_changes]asserts the recorded digest after authoring.
Validation recomputes the digest and reports staleness
src/evidence.rs#mod[tests]/fn[validation_requires_a_current_reference_set_digest]accepts the current digest. It reports a missing, non-string, uppercase or truncatedreferencesfield. It reports “reference set changed” when a new reference appears inside a node whose recorded inputs are unchanged.tests/outcomes.rs#fn[editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads]shows staleness when a{fixme}body is edited or a new{fixme}is added. It asserts no outline-input change is reported, so the staleness comes from the reference set.tests/authoring_batch.rs#fn[batch_reauthors_a_false_judgment_when_its_reference_set_changes]shows a new{test}reference makes the record stale.
The helpers src/evidence.rs#mod[tests]/fn[validate_repository] and tests/evidence_boundaries.rs#fn[write_inputs] stamp the current digest so other tests are not made stale by it.
Minor observation, not a gap
- In
fenced_commentary_outside_the_book_contributes_to_the_reference_set, the book case only asserts that commentary edits do not alter the digest. The Markdown{impl}contribution is established separately in the guide cases ofreference_set_digest_tracks_impl_and_test_edges_by_node.
Inputs
Tests
Input 7: outline src/authoring/inputs.rs mod[tests]/fn[acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads] - Kind:
fn src/authoring/inputs.rs:877–953
// {test}`requirements.authoring.fixme_inputs`
// {test}`requirements.definitions.dependencies`
// {test}`requirements.ci.reference_set`
// {test}`requirements.definitions.authoring_inputs`
#[test]
fn acknowledgment_only_terms_are_supplied_and_validated_without_implementation_reads() {
let root = project();
let (path, configuration) = crate::execution_coverage::configure(root.path()).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, configuration).unwrap();
fs::create_dir(root.path().join("evidence")).unwrap();
let terms = ":::{definition} unit\n:phrase: unit\nA unit.\n:::\n\n:::{definition} boundary\n:phrase: boundary\nA {term}`terms.unit` at the limit.\n:::\n";
fs::write(root.path().join("md/terms.md"), terms).unwrap();
let source = "// :::{fixme} requirements.ready\n// The {term}`terms.boundary` is untested.\n// :::\nfn gap() { panic!(\"IMPLEMENTATION_BODY\"); }\n";
fs::write(root.path().join("src/lib.rs"), source).unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(prompt.contains("A unit."));
assert!(prompt.contains("at the limit."));
assert!(prompt.contains("is untested."));
assert!(!prompt.contains("IMPLEMENTATION_BODY"));
assert!(
!sources
.mandatory_inputs()
.iter()
.any(|input| input.get("item").is_some())
);
let mandatory = sources.mandatory_inputs().to_vec();
sources.record_inputs(&mandatory);
let record = json!({
"requirement": "The project MUST be ready.",
"determination": {"FIXME": ["The {term}`terms.boundary` is untested."]},
"rationale": "The boundary test is acknowledged as missing.",
"references": sources.reference_set,
"inputs": sources.recorded_inputs(),
});
let path = root.path().join("evidence/requirements.ready.json");
fs::write(&path, record.to_string()).unwrap();
let check = || {
crate::evidence::validate_repository(root.path())
.unwrap()
.errors
};
assert!(check().is_empty(), "{:?}", check());
// An unread body can change without changing the judgment's inputs.
fs::write(
root.path().join("src/lib.rs"),
source.replace("panic!(\"IMPLEMENTATION_BODY\")", "let _value = 1"),
)
.unwrap();
assert!(check().is_empty(), "{:?}", check());
// The acknowledgment introduces a real, transitive term dependency.
fs::write(
root.path().join("md/terms.md"),
terms.replace("A unit.", "A changed unit."),
)
.unwrap();
let errors = check().join("\n");
assert!(
errors.contains("input text changed for Definition { definition: \"terms.unit\" }"),
"{errors}"
);
fs::write(root.path().join("md/terms.md"), terms).unwrap();
let mut missing = record.clone();
missing["inputs"]
.as_array_mut()
.unwrap()
.retain(|input| input["definition"] != "terms.boundary");
fs::write(&path, missing.to_string()).unwrap();
let errors = check().join("\n");
assert!(
errors.contains("expected exactly one definition input for terms.boundary, found 0"),
"{errors}"
);
}
Input 8: outline src/authoring/inputs.rs mod[tests]/fn[bundle_combines_direct_references_terms_and_current_existing_selectors]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[bundle_combines_direct_references_terms_and_current_existing_selectors] - Kind:
fn src/authoring/inputs.rs:955–1058
// {test}`requirements.authoring.complete_initial_bundle`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring_input`
// {test}`requirements.examples.authoring_inputs`
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.definitions.authoring_inputs`
// {test}`requirements.ci.authoring_inputs`
// {test}`requirements.ci.reference_set`
#[test]
fn bundle_combines_direct_references_terms_and_current_existing_selectors() {
let root = project();
let terms = format!(
":::{{definition}} unit\n:phrase: unit\nA {}.\n:::\n\n:::{{definition}} value\n:phrase: value\nA {}.\n:::\n",
role("term", "terms.value"),
role("term", "terms.unit")
);
fs::write(root.path().join("md/terms.md"), terms).unwrap();
let declarations = format!(
":::{{req}} ready\nReady uses {} and {}.\n:::\n\n:::{{req}} base\nBase cites {}.\n:::\n\n:::{{req}} distant\nDistant MUST work.\n:::\n\n:::{{example}} case\nReady example. {} {}\n:::\n",
role("cite", "requirements.base"),
role("term", "terms.unit"),
role("cite", "requirements.distant"),
role("cite", "requirements.ready"),
role("test", "requirements.ready")
);
fs::write(root.path().join("md/requirements.md"), declarations).unwrap();
fs::write(root.path().join("src/lib.rs"), format!("struct Thing;\nimpl Thing {{\n // {}\n fn run(&self) {{}}\n fn unrelated(&self) {{}}\n}}\n// {}\nfn test_ready() {{}}\n", role("impl", "requirements.ready"), role("test", "requirements.ready"))).unwrap();
fs::write(root.path().join("notes.txt"), "new source text\n").unwrap();
fs::create_dir(root.path().join("evidence")).unwrap();
fs::write(
root.path().join("evidence/requirements.ready.json"),
json!({
"determination": false, "rationale": "old secret judgment",
"inputs": [{"file":"notes.txt", "line_start":1, "line_end":1, "text":["old text"]}]
})
.to_string(),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
// The recorded digest covers the same `{impl}` and `{test}` edges.
assert_eq!(
sources.reference_set,
crate::evidence::reference_set_digest_for(root.path(), "requirements.ready").unwrap()
);
let inputs = sources.mandatory_inputs();
assert!(sources.recorded_inputs().is_empty());
assert!(
!inputs
.iter()
.any(|input| input["item"] == "impl[Thing]/fn[run]")
);
assert!(inputs.iter().any(|input| input["item"] == "fn[test_ready]"));
assert!(!inputs.iter().any(|input| input["item"] == "impl[Thing]"));
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.case")
);
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.base")
);
assert!(
!inputs
.iter()
.any(|input| input["requirements"] == "requirements.distant")
);
assert_eq!(
inputs
.iter()
.filter(|input| input.get("definition").is_some())
.count(),
2
);
// Earlier evidence inputs are not carried forward.
assert!(!inputs.iter().any(|input| input["file"] == "notes.txt"));
assert!(
!serde_json::to_string(inputs)
.unwrap()
.contains("old secret judgment")
);
let example = AssessmentSources::prepare(root.path(), "requirements.case").unwrap();
assert!(matches!(
example.subject_kind,
AssessmentKind::Definition(DefinitionKind::Example, false)
));
assert_eq!(
example.mandatory_inputs()[0]["requirements"],
"requirements.case"
);
assert_eq!(
example.mandatory_inputs()[0]["text"],
json!([
":::{example} case",
format!(
"Ready example. {} {}",
role("cite", "requirements.ready"),
role("test", "requirements.ready")
),
":::"
])
);
}
Input 9: outline src/authoring/mod.rs mod[tests]/fn[throttled_requests_retry_unchanged_and_record_every_attempt]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[throttled_requests_retry_unchanged_and_record_every_attempt] - Kind:
fn src/authoring/mod.rs:2228–2268
// {test}`requirements.authoring.provider_backoff`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.usage_requests.failures`
// {test}`requirements.authoring.usage_inputs`
// {test}`requirements.ci.reference_set`
#[tokio::test(start_paused = true)]
async fn throttled_requests_retry_unchanged_and_record_every_attempt() {
let (_project, _state, mut sources, mut usage) = retry_fixture();
let provider = ThrottledProvider {
failures: 5,
status: 429,
code: "ThrottlingException",
requests: RefCell::default(),
};
let started = tokio::time::Instant::now();
let (_, record) = assess(&provider, &mut sources, &mut usage).await.unwrap();
assert!(started.elapsed() >= Duration::from_millis(500));
let requests = provider.requests.borrow();
assert_eq!(requests.len(), 6);
assert!(requests.iter().all(|request| request == &requests[0]));
assert_eq!(record["inputs"], json!(sources.mandatory_inputs()));
assert_eq!(record["references"], json!(sources.reference_set));
let log: Value = serde_json::from_slice(&fs::read(&usage.path).unwrap()).unwrap();
assert_eq!(log["request_count"], 6);
for attempt in 0..5 {
assert_eq!(log["requests"][attempt]["outcome"], "failed");
assert_eq!(log["requests"][attempt]["tokens"]["complete"], false);
assert_eq!(
log["requests"][attempt]["failure"],
json!({"http_status": 429, "error_code": "ThrottlingException", "retried": true})
);
}
assert!(log["requests"][5].get("failure").is_none());
assert_eq!(log["requests"][5]["outcome"], "completed");
assert_eq!(log["tool_calls"]["submit_judgment"], 1);
for input in log["inputs"].as_array().unwrap() {
assert_eq!(input["submitted_in_request"], 0);
assert_eq!(input["sent_in_request"], 5);
}
}
Input 10: outline src/evidence.rs mod[tests]/fn[the_reference_set_digest_does_not_depend_on_the_order_entries_are_found]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[the_reference_set_digest_does_not_depend_on_the_order_entries_are_found] - Kind:
fn src/evidence.rs:2150–2187
// {test}`requirements.ci.reference_set`
#[test]
fn the_reference_set_digest_does_not_depend_on_the_order_entries_are_found() {
let entry = |role: &'static str, file: &str, item: &str| ReferenceSetEntry {
origin: "reference",
role,
file: file.to_owned(),
item: item.to_owned(),
words: Vec::new(),
};
let entries = || {
vec![
entry("impl", "src/a.rs", "fn[a]"),
entry("test", "src/b.rs", "fn[b]"),
entry("impl", "src/b.rs", ""),
]
};
let mut reversed = entries();
reversed.reverse();
assert_eq!(digest_entries(entries()), digest_entries(reversed));
let mut other = entries();
other[0].item = "fn[c]".to_owned();
assert_ne!(digest_entries(entries()), digest_entries(other));
assert_ne!(
digest_entries(vec![entry("test", "a", "bc")]),
digest_entries(vec![entry("test", "ab", "c")]),
);
let mut words_one = entry("fixme", "src/lib.rs", "fn[f]");
words_one.origin = "fenced-reference";
words_one.words = vec!["ab".to_owned(), "c".to_owned()];
let mut words_two = entry("fixme", "src/lib.rs", "fn[f]");
words_two.origin = "fenced-reference";
words_two.words = vec!["a".to_owned(), "bc".to_owned()];
assert_ne!(
digest_entries(vec![words_one]),
digest_entries(vec![words_two])
);
}
Input 11: outline src/evidence.rs mod[tests]/fn[validate_repository]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[validate_repository] - Kind:
fn src/evidence.rs:2239–2245
/// Validates after stamping hand-written records with their current
/// reference-set digests.
// {test}`requirements.ci.reference_set`
fn validate_repository(root: &Path) -> std::io::Result<super::EvidenceReport> {
stamp_reference_sets(root);
super::validate_repository(root)
}
Input 12: outline src/evidence.rs mod[tests]/fn[reference_set_digest_tracks_impl_and_test_edges_by_node]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[reference_set_digest_tracks_impl_and_test_edges_by_node] - Kind:
fn src/evidence.rs:3980–4107
// {test}`requirements.ci.reference_set`
// {test}`requirements.references.outline_comments`
#[test]
fn reference_set_digest_tracks_impl_and_test_edges_by_node() {
let temp = fixture();
let root = temp.path();
let role = |kind: &str| format!("{{{kind}}}`requirements.ready`");
let declaration = |options: &str| {
format!(
":::{{req}} ready\n{options}Ready MUST hold.\n:::\n\n:::{{req}} other\nOther MUST hold.\n:::\n"
)
};
fs::write(root.join("md/requirements.md"), declaration("")).unwrap();
let digest = |lib: &str, notes: &str, guide: &str| {
fs::write(root.join("src/lib.rs"), lib).unwrap();
fs::write(root.join("notes.txt"), notes).unwrap();
fs::write(root.join("md/guide.md"), guide).unwrap();
super::reference_set_digest_for(root, "requirements.ready").unwrap()
};
let lib = format!(
"// {}\nfn run() {{\n work();\n}}\n\nfn other() {{}}\n",
role("impl")
);
let notes = format!("{}\n", role("test"));
let guide = format!("# Guide\n\nIntro.\n\n## Usage\n\nSee {}.\n", role("impl"));
let base = digest(&lib, ¬es, &guide);
assert_eq!(base.len(), 64);
assert!(super::is_sha256_hex(&base));
assert_eq!(
digest(&lib, ¬es, &guide),
base,
"the digest is deterministic"
);
// Line moves within the reference's node, unrelated lines, and
// `{cite}` references leave the digest unchanged.
for (lib, notes, guide) in [
(
format!("// unrelated\n\n{lib}"),
notes.clone(),
guide.clone(),
),
(
format!(
"fn run() {{\n // {}\n work();\n}}\n\nfn other() {{}}\n",
role("impl")
),
notes.clone(),
guide.clone(),
),
(
lib.clone(),
format!("first\n\nsecond\n{notes}"),
guide.clone(),
),
(
lib.clone(),
notes.clone(),
guide.replace("See ", "Intro line.\n\nSee "),
),
(
format!("{lib}// {}\nfn cited() {{}}\n", role("cite")),
format!("{notes}{}\n", role("cite")),
guide.clone(),
),
] {
assert_eq!(
digest(&lib, ¬es, &guide),
base,
"{lib}\n{notes}\n{guide}"
);
}
// Adding, removing, re-roling, or moving a reference to another node
// changes it.
let mut seen = std::collections::BTreeSet::from([base.clone()]);
for (lib, notes, guide) in [
(
format!("{lib}// {}\nfn more() {{}}\n", role("impl")),
notes.clone(),
guide.clone(),
),
(
format!(
"fn run() {{\n // {}\n // {}\n work();\n}}\n\nfn other() {{}}\n",
role("impl"),
role("impl")
),
notes.clone(),
guide.clone(),
),
(
lib.replace(&role("impl"), "removed"),
notes.clone(),
guide.clone(),
),
(lib.replace("impl", "test"), notes.clone(), guide.clone()),
(
format!(
"fn run() {{\n work();\n}}\n\n// {}\nfn other() {{}}\n",
role("impl")
),
notes.clone(),
guide.clone(),
),
(lib.clone(), String::new(), guide.clone()),
(
lib.clone(),
notes.clone(),
guide.replace("Intro.", &format!("Intro {}.", role("impl"))),
),
] {
let changed = digest(&lib, ¬es, &guide);
assert!(seen.insert(changed), "{lib}\n{notes}\n{guide}");
}
// Adding an anchor changes it, as does changing the anchored node.
digest(&lib, ¬es, &guide);
for options in [
":impl: notes.txt\n",
":test: notes.txt\n",
":impl: src/lib.rs#fn[run]\n",
] {
fs::write(root.join("md/requirements.md"), declaration(options)).unwrap();
let changed = super::reference_set_digest_for(root, "requirements.ready").unwrap();
assert!(seen.insert(changed), "{options}");
}
}
Input 13: outline src/evidence.rs mod[tests]/fn[validation_requires_a_current_reference_set_digest]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[validation_requires_a_current_reference_set_digest] - Kind:
fn src/evidence.rs:4109–4186
// {test}`requirements.ci.reference_set`
// {test}`requirements.ci.schema`
#[test]
fn validation_requires_a_current_reference_set_digest() {
let temp = fixture();
let root = temp.path();
fs::write(
root.join("md/requirements.md"),
":::{req} ready\nReady MUST hold.\n:::\n",
)
.unwrap();
let impl_role = "{impl}`requirements.ready`";
let cite_role = "{cite}`requirements.ready`";
fs::write(
root.join("src/lib.rs"),
format!(
"// {impl_role}\nfn run() {{}}\n\n// {cite_role}\nfn other() {{\n work();\n}}\n"
),
)
.unwrap();
let path = root.join("evidence/requirements.ready.json");
let write = |references: Option<Value>| {
let mut record = json!({
"requirement": "Ready MUST hold.",
"determination": true,
"rationale": "Checked.",
"inputs": [outline(root, "src/lib.rs", "")],
});
if let Some(references) = references {
record["references"] = references;
}
fs::write(&path, record.to_string()).unwrap();
};
let errors = || without_citation_reviews(super::validate_repository(root).unwrap().errors);
let current = super::reference_set_digest_for(root, "requirements.ready").unwrap();
write(Some(json!(current)));
assert!(errors().is_empty(), "{:?}", errors());
for (references, expected) in [
(
None,
"evidence/requirements.ready.json: missing field \"references\"",
),
(
Some(json!(7)),
"evidence/requirements.ready.json: references must be a string",
),
(
Some(json!(current.to_uppercase())),
"evidence/requirements.ready.json: references must be a lowercase hexadecimal SHA-256 digest",
),
(
Some(json!(¤t[1..])),
"evidence/requirements.ready.json: references must be a lowercase hexadecimal SHA-256 digest",
),
] {
write(references);
assert_eq!(errors(), [expected]);
}
// A new reference inside a node the inputs already cover changes no
// recorded hash, but makes the evidence stale.
write(Some(json!(current)));
fs::write(
root.join("src/lib.rs"),
format!(
"// {impl_role}\nfn run() {{}}\n\n// {cite_role}\nfn other() {{\n // {impl_role}\n work();\n}}\n"
),
)
.unwrap();
let reported = errors();
assert_eq!(reported.len(), 1, "{reported:?}");
assert!(
reported[0].starts_with("evidence/requirements.ready.json: reference set changed"),
"{reported:?}"
);
}
Input 14: outline src/sites.rs mod[tests]/fn[a_fixme_inside_a_site_belongs_to_that_sites_review_only]
- File:
src/sites.rs - Selector:
mod[tests]/fn[a_fixme_inside_a_site_belongs_to_that_sites_review_only] - Kind:
fn src/sites.rs:1398–1505
// {test}`requirements.references.site_review`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.ci.reference_set`
#[test]
fn a_fixme_inside_a_site_belongs_to_that_sites_review_only() {
let fixme = |issue: &str| {
format!(
" // :::{{fixme}} requirements.rule\n // :github: o/r#{issue}\n // Panics instead of reporting.\n // :::\n"
)
};
let source = SOURCE
.replace(
"fn check_two() {}",
&format!("fn check_two() {{\n{}}}", fixme("1")),
)
.replace(
"fn other() { panic!(\"y\"); }",
&format!("fn other() {{\n{}}}", fixme("2")),
);
let temp = project(RULE, &source);
let root = temp.path();
fs::write(
root.join("evidence/requirements.rule.json"),
json!({"requirement": "x", "determination": true, "rationale": "Fine.", "inputs": []})
.to_string(),
)
.unwrap();
crate::evidence::tests::stamp_reference_sets(root);
write_review(
root,
"fn[check_two]",
json!({"determination": {"FIXME": ["o/r#1"]}}),
);
let (errors, _) = inspect(root);
let coverage = errors
.iter()
.filter(|error| error.contains("no input covers {fixme}"))
.collect::<Vec<_>>();
assert!(coverage.is_empty(), "{errors:#?}");
let two = review_errors(&errors, "fn[check_two]").join("\n");
assert!(
two.contains("{fixme} references to requirements.rule inside src/lib.rs fn[check_two] changed: recorded [], now [{\"item\":\"fn[check_two]\",\"commentary\":\":github: o/r#1\\n Panics instead of reporting.\"}]"),
"{two}"
);
assert!(!two.contains("FIXME entry"), "{two}");
// Editing the in-site `{fixme}` leaves the requirement's reference
// set unchanged; editing the other changes it.
let digest = crate::evidence::reference_set_digest_for(root, "requirements.rule").unwrap();
fs::write(
root.join("src/lib.rs"),
source.replacen("Panics instead", "Still panics instead", 1),
)
.unwrap();
assert_eq!(
crate::evidence::reference_set_digest_for(root, "requirements.rule").unwrap(),
digest
);
fs::write(
root.join("src/lib.rs"),
source.replace(
"// Panics instead of reporting.\n // :::\n}\nmod",
"// Edited.\n // :::\n}\nmod",
),
)
.unwrap();
assert_ne!(
crate::evidence::reference_set_digest_for(root, "requirements.rule").unwrap(),
digest
);
// A review recording the in-site `{fixme}` is current; reflowing its
// body keeps it current, and changing its words makes it stale.
fs::write(root.join("src/lib.rs"), &source).unwrap();
crate::evidence::tests::stamp_reference_sets(root);
write_review(
root,
"fn[check_two]",
json!({
"determination": {"FIXME": ["o/r#1"]},
"fixmes": [{"item": "fn[check_two]", "commentary": ":github: o/r#1\n Panics instead of reporting."}],
}),
);
let changed = |root: &Path| {
let (errors, _) = inspect(root);
review_errors(&errors, "fn[check_two]")
.into_iter()
.filter(|error| error.contains("{fixme} references"))
.collect::<Vec<_>>()
};
assert_eq!(changed(root), Vec::<String>::new());
fs::write(
root.join("src/lib.rs"),
source.replacen(
" // Panics instead of reporting.\n",
" // Panics instead\n // of reporting.\n",
1,
),
)
.unwrap();
assert_eq!(changed(root), Vec::<String>::new());
fs::write(
root.join("src/lib.rs"),
source.replacen("Panics instead", "Still panics instead", 1),
)
.unwrap();
assert_eq!(changed(root).len(), 1);
}
Input 15: outline tests/authoring_batch.rs fn[batch_reauthors_a_false_judgment_when_its_reference_set_changes]
- File:
tests/authoring_batch.rs - Selector:
fn[batch_reauthors_a_false_judgment_when_its_reference_set_changes] - Kind:
fn tests/authoring_batch.rs:1413–1480
/// A new test reference changes the reference set and requires its source
/// to be supplied on reassessment, even when the old assessment read no code.
// {test}`requirements.authoring.batch`
// {test}`requirements.ci.reference_set`
// {test}`requirements.authoring.refresh`
#[test]
fn batch_reauthors_a_false_judgment_when_its_reference_set_changes() {
let server = Server::start(false, None);
let fixture = Fixture::new(&server.endpoint, Some(2));
let output = fixture.run(&["author", "--all"]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(server.subjects().len(), 6);
for name in ["requirements.alpha", "requirements.delta"] {
assert_eq!(
fixture.evidence(name)["references"],
habeas::reference_set_digest_for(&fixture.project, name).unwrap()
);
}
let path = fixture.project.join("evidence/requirements.delta.json");
let mut record = fixture.evidence("requirements.delta");
record["determination"] = json!(false);
record["rationale"] = json!("The behavior has no {test} reference.");
fs::write(&path, serde_json::to_vec_pretty(&record).unwrap()).unwrap();
let source = fixture.project.join("src/lib.rs");
fs::write(
&source,
fs::read_to_string(&source).unwrap().replace(
"pub fn delta() -> u8 { 4 }",
"pub fn delta() -> u8 {\n // {test}`requirements.delta`\n 4\n}",
),
)
.unwrap();
let errors = habeas::validate_repository(&fixture.project)
.unwrap()
.errors;
assert_eq!(errors.len(), 3, "{errors:?}");
assert!(
errors[0].starts_with("evidence/requirements.delta.json: determination is false")
&& errors[1].starts_with("evidence/requirements.delta.json: reference set changed"),
"{errors:?}"
);
assert!(errors[2].contains("no input covers {test}"), "{errors:?}");
let stale = fixture.run(&["author", "--all"]);
assert!(
stale.status.success(),
"{}",
String::from_utf8_lossy(&stale.stderr)
);
let subjects = server.subjects();
assert_eq!(subjects.len(), 7, "{subjects:?}");
assert_eq!(subjects[6], "requirement requirements.delta");
assert_eq!(
String::from_utf8_lossy(&stale.stdout).trim(),
"1 authored; 5 skipped as current; 0 failed; policy once"
);
assert_eq!(
fixture.evidence("requirements.delta")["references"],
habeas::reference_set_digest_for(&fixture.project, "requirements.delta").unwrap()
);
let report = habeas::validate_repository(&fixture.project).unwrap();
assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 16: outline tests/evidence_boundaries.rs fn[write_inputs]
- File:
tests/evidence_boundaries.rs - Selector:
fn[write_inputs] - Kind:
fn tests/evidence_boundaries.rs:30–47
// {test}`requirements.ci.reference_set`
fn write_inputs(root: &Path, inputs: Vec<Value>) {
fs::write(
root.join("evidence/rules.ready.json"),
json!({
"requirement": "Read the data.",
"determination": true,
"rationale": "The fixture records the data being checked.",
// An unreadable source makes the reference set unknowable; such
// fixtures are invalid regardless.
"references": habeas::reference_set_digest_for(root, "rules.ready")
.unwrap_or_else(|_| "0".repeat(64)),
"inputs": inputs,
})
.to_string(),
)
.unwrap();
}
Input 17: outline tests/outcomes.rs fn[editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads]
- File:
tests/outcomes.rs - Selector:
fn[editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads] - Kind:
fn tests/outcomes.rs:529–572
// {test}`requirements.ci.reference_set`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn editing_or_adding_a_fixme_makes_evidence_stale_without_requiring_source_reads() {
let temp = fixture();
let observed = temp.path().join("observed.rs");
let source = fs::read_to_string(&observed).unwrap();
// Comments do not change the input's hash, but the `{fixme}` body is
// part of the reference set.
fs::write(&observed, source.replace("are untested", "remain untested")).unwrap();
let errors = habeas::validate_repository(temp.path()).unwrap().errors;
assert!(
errors.iter().any(
|error| error.contains("evidence/requirements.timeout.json: reference set changed")
),
"{errors:?}"
);
assert!(
!errors
.iter()
.any(|error| error.contains("outline input changed")),
"{errors:?}"
);
fs::write(&observed, &source).unwrap();
fs::write(
temp.path().join("other.rs"),
fixme("requirements.timeout", &[], "Another gap."),
)
.unwrap();
let errors = habeas::validate_repository(temp.path()).unwrap().errors;
assert!(
errors.iter().any(
|error| error.contains("evidence/requirements.timeout.json: reference set changed")
),
"{errors:?}"
);
assert!(
!errors
.iter()
.any(|error| error.contains("no input covers {fixme}")),
"{errors:?}"
);
}
Input 18: outline tests/references.rs fn[fenced_commentary_outside_the_book_contributes_to_the_reference_set]
- File:
tests/references.rs - Selector:
fn[fenced_commentary_outside_the_book_contributes_to_the_reference_set] - Kind:
fn tests/references.rs:274–313
// {test}`requirements.ci.reference_set`
#[test]
fn fenced_commentary_outside_the_book_contributes_to_the_reference_set() {
let temp = project();
let root = temp.path();
let fenced = |body: &str| {
format!(
"// :::{} rules.ready\n{body}// :::\nfn run() {{}}\n",
role("impl")
)
};
let base = digest(root, &fenced("// Handles the empty case.\n"));
// Reflowing the commentary keeps the digest; changing its words does not.
assert_eq!(
digest(root, &fenced("// Handles the\n// empty case.\n")),
base
);
assert_ne!(digest(root, &fenced("// Handles the full case.\n")), base);
assert_ne!(
digest(
root,
&format!("// {}`rules.ready`\nfn run() {{}}\n", role("impl"))
),
base
);
// In the book, commentary is part of the declaration text instead.
let book = |body: &str| {
fs::write(
root.join("md/rules.md"),
format!(
"# Rules\n\n::::{{req}} ready\nReady.\n::::\n\n::::{{req}} other\nOther.\n\n:::{} rules.ready\n{body}\n:::\n::::\n",
role("impl")
),
)
.unwrap();
habeas::reference_set_digest_for(root, "rules.ready").unwrap()
};
assert_eq!(book("Refines the check."), book("Refines another check."));
}
Input 19: outline tests/references.rs fn[fixme_edges_and_their_bodies_are_part_of_the_reference_set]
- File:
tests/references.rs - Selector:
fn[fixme_edges_and_their_bodies_are_part_of_the_reference_set] - Kind:
fn tests/references.rs:391–450
// {test}`requirements.ci.reference_set`
#[test]
fn fixme_edges_and_their_bodies_are_part_of_the_reference_set() {
let temp = project();
let root = temp.path();
let fx = role("fixme");
let fixme = |body: &str| format!("// :::{fx} rules.ready\n{body}// :::\nfn run() {{}}\n");
let none = digest(root, "fn run() {}\n");
let base = digest(
root,
&fixme("// :github: example/rules#1\n// The empty case fails.\n"),
);
assert_ne!(base, none, "adding a {{fixme}} changes the reference set");
// Reflowing keeps the digest; editing an issue or the description does not.
assert_eq!(
digest(
root,
&fixme("// :github: example/rules#1\n// The empty\n// case fails.\n")
),
base
);
assert_ne!(
digest(
root,
&fixme("// :github: example/rules#2\n// The empty case fails.\n")
),
base
);
assert_ne!(
digest(
root,
&fixme("// :github: example/rules#1\n// The full case fails.\n")
),
base
);
// A different role on the same node is a different edge.
assert_ne!(
digest(
root,
&format!(
"// :::{} rules.ready\n// :github: example/rules#1\n// The empty case fails.\n// :::\nfn run() {{}}\n",
role("impl")
)
),
base
);
// An inline `{fixme}` is invalid and is not an edge either.
assert_eq!(
digest(root, &format!("// {fx}`rules.ready`\nfn run() {{}}\n")),
none
);
// An unnamed `{fixme}` is not an edge.
assert_eq!(
digest(
root,
&format!("// :::{fx}\n// :github: example/rules#1\n// :::\nfn run() {{}}\n")
),
none
);
}
Referenced definitions
Input 2: requirements selection requirements.references.site_review
requirements.references.site_review:md/requirements/references.md:521–559
:::{req} site_review
Every site of a distributed requirement under
{cite}`requirements.references.distributed` MUST have a site review: an
assessment of whether that site upholds the requirement, recorded at
`evidence/sites/<full-name>/<file>/<selector>.json`, where `<file>` and
`<selector>` are encoded as under
{cite}`requirements.references.citation_review`. The review MUST use the prompt
defined by {cite}`requirements.authoring.site_prompt`. Mandatory inputs, under
{cite}`requirements.authoring.mandatory_inputs`, MUST be the site's outline
node, the requirement's complete declaration, and each declaration the
requirement cites. The record MUST contain the requirement's full name, the
site's file and selector, `queries`, the sorted names of the queries with a
match at the site, `applies`, `determination`, `rationale`, and `inputs`, with
determinations under {cite}`requirements.ci.outcomes`. `applies` MUST be a
Boolean recording whether the requirement applies to the site. A site to which
the requirement does not apply MUST be judged `true`, and the rationale MUST
explain why it does not apply. `habeas info` MUST report, for each selected
distributed requirement, how many of its sites the requirement does not apply
to.
Validation MUST require a current, accepted review for every site, MUST report a
false review with its rationale, and MUST report stale, missing, or orphaned
reviews; a review is orphaned when its file and selector no longer name a site
of the requirement. A `{fixme}` naming the requirement inside a site
acknowledges a gap at that site only: it MUST be an input to that site's review
and MUST NOT contribute to the requirement's own review, coverage, or reference
set. A review MUST become stale when the site's hash, the requirement's
declaration, a cited declaration, its `queries`, or the `{fixme}` references
naming the requirement inside the site, with the words of their bodies, change.
Each site review's determination MUST be checked on its own, independently of
the requirement's evidence. Authoring with `--all` MUST include site reviews,
`habeas author sites:<full-name>` MUST author the site reviews of the named
requirement, and `habeas author sites:<full-name>/<file>#<selector>` MUST author
the review of the one site it names, under
{cite}`requirements.authoring.refresh`, where omitting `#<selector>` names the
file's root node. `habeas status` MUST report missing, stale, invalid, and false
site reviews with their requirement, file, and selector, and `habeas info` MUST
list each selected requirement's sites with their determinations.
:::
Input 3: requirements selection requirements.references.roles
requirements.references.roles:md/requirements/references.md:3–49
:::{req} roles
Project text files MAY use the `{impl}`, `{cite}`, and `{test}` roles with a backtick-delimited full requirement or example name, or with a built-in name under {cite}`requirements.references.builtin_definitions`, and MAY use the `{fixme}` role in fenced form. A reference MAY instead be written in fenced form, `:::{role} name` on one line, a body, and a closing fence, following the fence rules of {cite}`requirements.ci.span` and {cite}`requirements.ci.fence_lengths`; the fenced form is the same edge with attached commentary, and the inline form carries none. In a source comment, fence lines MUST be recognized after removing each line's comment delimiters within one comment run under {cite}`requirements.references.outline_comments`, and a fence that does not close within its comment run MUST be a validation error. Each reference is a directed edge between its source and the named definition. A source is a project source item or a requirement or example declaration. The roles MUST mean:
- `{cite}`: the source relies on, supports, or refers to the definition. It is an
edge from the source to the definition.
- `{impl}`: the source implements part of the definition: it makes a decision,
performs a check, produces an output, or handles a case that the definition
specifies. A requirement MAY implement part of another requirement by refining
one of its obligations. Calling code that implements a definition, or
producing a result a caller uses to meet it, MUST NOT by itself count as
implementing it. A check MUST count only if the definition states it, or the
source could not meet one of the definition's obligations without it; source
that checks it is consistent with a definition, such as recognizing a form the
definition specifies in order to decide whether to run other behavior, relies
on that definition and calls for `{cite}`. A requirement stating a convention
for every output of a kind, such as every validation error, is implemented by
the source that carries out the convention as a whole, such as the step that
collects and reports those outputs.
- `{test}`: the source is designed to verify behavior the definition specifies:
a test through its scenario and the assertions about that scenario's outcome,
or a named example through the concrete case it describes.
- `{fixme}`: the source acknowledges a known gap in fulfilling the definition. It
MUST use the fenced form, and its body MUST describe the gap. The body MAY
begin with option lines naming issues that track the gap, one per line, in the
form `:github: <owner>/<repo>#<number>`, such as
`:github: rust-lang/rust#123`. `github` MUST be the only recognized option.
A named `{fixme}` MAY appear only in sources outside the book. Validation MUST report
any other option line, a `:github:` value not in that form, an inline
`{fixme}`, a `{fixme}` in a requirement or example declaration, and a
`{fixme}` whose body, without option lines and comment delimiters, is empty.
An unnamed `{fixme}`, a fence of `:::{fixme}` with no name, MAY appear in any
project text, including a requirement or example body, to tie that place to
the issues it names. It MUST have at least one `:github:` option line and MAY
have a description; it is not a reference edge, acknowledges no gap, needs no
coverage, and does not count as a reference for Rust item coverage. Its
issues are checked under {cite}`requirements.cli.fixme_issues`.
`{impl}`, `{test}`, and `{fixme}` are edges from the definition to the source.
Only requirements and examples are assessed; code is reviewed as part of the
definitions it implements or tests.
```text
{impl}`requirements.references.roles`
{cite}`requirements.references.roles`
{test}`requirements.references.roles`
```
:::
Input 4: requirements selection requirements.references.anchors
requirements.references.anchors:md/requirements/references.md:176–197
:::{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.
:::
Input 5: requirements selection requirements.references.outline_comments
requirements.references.outline_comments:md/requirements/references.md:415–430
:::{req} outline_comments
Each documented profile defines which grammar nodes are comments; the Markdown
profile's comments are HTML comment blocks, so an inline HTML comment within a
paragraph is text of its section. In every supported language, comments on consecutive lines with no other source
between them MUST form one comment run. A comment that follows other source on
the same line, including another comment, MUST form a run by itself and MUST belong to the innermost outline node
containing that line. Any other run MUST belong to the next outline node that
starts after it within the smallest node containing it; when that container has
no such node, the run MUST belong to the container, which is the root node at top
level. A profile MAY bind a comment kind to its container
instead: such a run MUST belong to the smallest node containing it. The Rust
profile MUST bind inner doc comments (`//!`, `/*!`) to their container, so a
file-level inner doc comment belongs to the root node. A reference in a comment MUST count for the node its run belongs to under
{cite}`requirements.references.rust_item_coverage` and
{cite}`requirements.references.authoring_inputs`.
:::
Input 6: requirements selection requirements.references.structural_hash
requirements.references.structural_hash:md/requirements/references.md:394–413
:::{req} structural_hash
A node's structural hash MUST be the SHA-256 digest of an unambiguous encoding of
its outline-relevant structure, including siblings its profile attaches to it:
the kinds of its named grammar nodes and, in source order, its text pieces. A
text piece MUST be the text of a leaf token, or text inside a node that no child
token covers. Each text piece MUST be hashed as its ordered list of words, where
words are separated by whitespace, the whitespace itself, including leading and
trailing whitespace, is never hashed, and each word is encoded separately, so
`ab cd` and `abcd` differ. The same rule MUST apply in every language. Comments
MUST be excluded, except comment kinds the profile includes; the Rust profile MUST include doc comments. For an included comment, only its text and its
profile's comment group MUST be hashed, not its delimiter tokens such as `//`,
`///`, `//!`, `/*`, `*/`, or a leading `*`; the Rust profile's groups are inner
and outer doc comments. The words of consecutive included comments of one group
MUST be hashed as one ordered list, so reflowing them across more or fewer lines
or comments does not change the hash, while moving text between groups does. A `line`
node's hash MUST be computed by the same word rule over the line's text. A node's
identity hash MUST be computed the same way but MUST also exclude its outline
descendants and their attached siblings, so editing a descendant does not change
its ancestors' selectors.
:::
Other sources
Input 1: requirements selection requirements.ci.reference_set
requirements.ci.reference_set:md/requirements/ci.md:154–170
:::{req} reference_set
A definition's reference set MUST consist of its current incoming `{impl}`, `{test}`, and `{fixme}` edges, except a `{fixme}` inside a site of the definition under {cite}`requirements.references.site_review`, under {cite}`requirements.references.roles` and
{cite}`requirements.references.anchors`: for each edge, its role and the file and
outline selector of the node the reference belongs to under
{cite}`requirements.references.outline_comments`, or of the anchored file or
node, and, for a fenced reference in a source outside the book, the words of
its body under the word rule of {cite}`requirements.references.structural_hash`.
`{cite}` references MUST NOT contribute. The reference-set digest MUST be
the SHA-256 digest of an unambiguous encoding of those entries in sorted order,
so it does not depend on line numbers or on the order references are found.
Authoring MUST record the digest of the reference set it supplied, and
validation MUST recompute it and report a changed reference set as stale
evidence. Adding or removing an `{impl}`, `{test}`, or `{fixme}` reference or anchor,
changing its role, editing its commentary, or moving it to a different node
MUST therefore make the evidence stale even when no recorded input changed; moving a reference within
the node it belongs to MUST NOT.
:::