requirements.references.authoring_inputs
Requirements index · View definition
Requirement
When authoring evidence, the edges defined by
MUST determine the reference contributions to the mandatory input set defined by
. A
{cite}made by the subject MUST contribute the cited definition’s complete fenced declaration. A requirement or example declaration that references the subject with{impl}or{test}MUST contribute that complete declaration. For sources outside such declarations, an{impl}reference or:impl:anchor alone MUST NOT contribute source text; those sources MUST remain discoverable underand MAY be requested under
. Sources with only edges into the subject MUST NOT contribute and remain discoverable under
. A
:test:anchor underMUST contribute the complete anchored file, or for a
path#selectoranchor the anchored node. An in-source{test}reference to the subject MUST contribute the source containing it: for a reference in a supported language, the smallest enclosing outline node under; for a reference in a Markdown requirement, example, or terminology declaration, that complete declaration; for other references, the complete containing source file. Literal references, evidence copies, and generated output MUST remain excluded under the existing reference-discovery rules.
An in-source
{fixme}reference alone MUST NOT contribute the containing source to the mandatory input set. Its acknowledgment MUST instead be supplied under.
These contribution rules MUST apply only to the assessed subject’s direct references. Including another declaration or source MUST NOT by itself recursively expand that source’s own edges. Reference links MUST NOT be described as proof that all substantively relevant sources have been found.
Rationale
I judged the marked tests in src/authoring/inputs.rs and src/authoring/tools.rs against each obligation in requirements.references.authoring_inputs. I did not request any implementation source. Each obligation is exercised and its outcome asserted:
- Subject
{cite}contributes the cited declaration.bundle_combines_direct_references_terms_and_current_existing_selectorsandonly_edges_leaving_the_subject_contribute_inputsassert thatrequirements.base, whichrequirements.readycites, appears as a requirements input.cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_notchecks that a cited declaration (requirements.other) and a cited built-in (habeas:util, exactly once) are contributed. These tests check that the cited declaration is present, not its text. The cited declaration comes from the same requirements-input path whose textanchored_files_contribute_root_node_inputsdoes assert in full, so I did not count this as a gap. - Declarations referencing the subject with
{impl}or{test}contribute the complete declaration.- For
{test},bundle_…covers the examplecaseand its exact text, andonly_edges_…covers the exampletester. - For
{impl},only_edges_…assessesrequirements.parent, whose referencing requirementreadyrefines it with{impl}, andreadyis contributed. - The same test shows that a declaration with only a
{cite}edge into the subject (citer) is not contributed.
- For
- An
{impl}reference or:impl:anchor alone supplies no source text.- The
{impl}comment onfn[run]and onimpl[Thing]/fn[run]contributes nothing, inonly_edges_…andbundle_…. references_contribute_their_owning_outline_nodesuses an:impl: src/lib.rs#mod[inner]anchor and asserts that the contributed items are only the two{test}sources, so the anchored node is absent.tools.rs#fn[references_list_names_and_flattened_sites_without_recording_inputs]shows these sources stay discoverable throughreferences, withinputsempty.
- The
- Sources with only edges into the subject do not contribute. In
only_edges_…,fn[helper]carrying{cite}is not an input. :test:anchors contribute the whole file, or the anchored node forpath#selector.anchored_files_contribute_root_node_inputsasserts the whole-file input, andtest_anchors_supply_only_the_selected_nodeasserts only the selected node, with the sibling’s text absent from the prompt.- In-source
{test}contributes the smallest enclosing outline node, a Markdown declaration, or the whole file.- Rust nodes:
fn[test_ready]andfn[check]are contributed, and the enclosingimpl[Thing]is not. - Markdown:
section[Usage]indocs/guide.mdis contributed. - Plain text:
notes.txtis contributed as a whole file (itemis""). - Markdown terminology declaration:
references_in_terminology_declarations_contribute_that_declarationasserts the declaration is contributed, not the Markdown section. - Markdown requirement or example declaration: the
testerandcaseexamples above.
- Rust nodes:
- Exclusions.
generated_evidence_references_are_omitted_by_defaultchecks that references inevidence/copies and in string literals are excluded, including when an allow is configured. {fixme}alone contributes no source.cited_built_ins_…asserts that no item inputs are present and that the acknowledgment is supplied separately.references_contribute_…shows a named{fixme}yields an acknowledgment forfn[gap]without contributingfn[gap], and that an unnamed{fixme}is not an edge.- No recursive expansion.
basecitesdistant, butdistantis not contributed when assessingready.baseis not contributed when assessingparent, even thoughreadycarriesbase’s cite edge. - Statement that links are not proof of completeness. This is a documentation-level statement with no behavior to test.
No obligation is missing a test or a meaningful assertion, and no marking gaps appeared.
Inputs
Tests
Input 9: 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 10: outline src/authoring/inputs.rs mod[tests]/fn[mandatory_git_inputs_require_staging_declarations_sources_and_terms]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[mandatory_git_inputs_require_staging_declarations_sources_and_terms] - Kind:
fn src/authoring/inputs.rs:1120–1187
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.definitions.authoring_inputs`
// {test}`requirements.authoring_input`
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.references.discovery`
#[test]
fn mandatory_git_inputs_require_staging_declarations_sources_and_terms() {
let root = project();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "Cargo.toml", "book.toml"]);
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert!(
error.to_string().contains("md/requirements.md")
&& error.to_string().contains("git add"),
"{error}"
);
git(root.path(), &["add", "md"]);
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn ready() {{}}\n",
role("test", "requirements.ready")
),
)
.unwrap();
// Discovery does not consider an untracked source, so its reference is
// not yet an input; staging it makes the source mandatory.
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let supplied = serde_json::to_string(sources.mandatory_inputs()).unwrap();
assert!(!supplied.contains("src/lib.rs"), "{supplied}");
git(root.path(), &["add", "src"]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let supplied = serde_json::to_string(sources.mandatory_inputs()).unwrap();
assert!(supplied.contains("src/lib.rs"), "{supplied}");
fs::write(
root.path().join("md/terms.md"),
":::{definition} ready\n:phrase: ready\nReady to proceed.\n:::\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {} {}\nfn ready() {{}}\n",
role("test", "requirements.ready"),
role("term", "terms.ready")
),
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert!(
error.to_string().contains("md/terms.md") && error.to_string().contains("git add"),
"{error}"
);
git(root.path(), &["add", "md/terms.md"]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
sources
.mandatory_inputs()
.iter()
.any(|input| input["definition"] == "terms.ready")
);
}
Input 11: outline src/authoring/inputs.rs mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs] - Kind:
fn src/authoring/inputs.rs:1298–1362
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.roles`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.examples.definition`
#[test]
fn only_edges_leaving_the_subject_contribute_inputs() {
let root = project();
let declarations = format!(
":::{{req}} ready\nReady relies on {} and refines {}.\n:::\n\n:::{{req}} base\nBase MUST hold.\n:::\n\n:::{{req}} parent\nParent MUST hold.\n:::\n\n:::{{example}} citer\nA case relying on ready. {}\n:::\n\n:::{{example}} tester\nA ready case. {} {}\n:::\n",
role("cite", "requirements.base"),
role("impl", "requirements.parent"),
role("cite", "requirements.ready"),
role("cite", "requirements.base"),
role("test", "requirements.ready")
);
fs::write(root.path().join("md/requirements.md"), declarations).unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn run() {{}}\n// {}\nfn helper() {{}}\n// {}\nfn check() {{}}\n",
role("impl", "requirements.ready"),
role("cite", "requirements.ready"),
role("test", "requirements.ready")
),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
let has_requirements =
|name: &str| inputs.iter().any(|input| input["requirements"] == name);
let has_item = |item: &str| inputs.iter().any(|input| input["item"] == item);
assert!(has_requirements("requirements.ready"));
assert!(has_requirements("requirements.base"), "{inputs:#?}");
assert!(has_requirements("requirements.tester"), "{inputs:#?}");
assert!(!has_item("fn[run]"), "{inputs:#?}");
assert!(has_item("fn[check]"), "{inputs:#?}");
assert!(!has_item("fn[helper]"), "{inputs:#?}");
assert!(!has_requirements("requirements.citer"), "{inputs:#?}");
assert!(!has_requirements("requirements.parent"), "{inputs:#?}");
let example = AssessmentSources::prepare(root.path(), "requirements.citer").unwrap();
assert!(
example
.mandatory_inputs()
.iter()
.any(|input| input["requirements"] == "requirements.ready"),
"{:#?}",
example.mandatory_inputs()
);
let parent = AssessmentSources::prepare(root.path(), "requirements.parent").unwrap();
let inputs = parent.mandatory_inputs();
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.ready"),
"{inputs:#?}"
);
assert!(
!inputs
.iter()
.any(|input| input["requirements"] == "requirements.base"),
"{inputs:#?}"
);
}
Input 12: outline src/authoring/inputs.rs mod[tests]/fn[anchored_files_contribute_root_node_inputs]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[anchored_files_contribute_root_node_inputs] - Kind:
fn src/authoring/inputs.rs:1364–1405
// {test}`requirements.references.anchors`
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring_input`
// {test}`requirements.authoring.no_line_numbers`
#[test]
fn anchored_files_contribute_root_node_inputs() {
let root = project();
fs::create_dir_all(root.path().join("skills")).unwrap();
fs::write(root.path().join("skills/ready.md"), "# Skill\nBe ready.\n").unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: skills/ready.md\n:test: skills/ready.md\nThe project MUST be ready.\n\nKeep the whole body.\n:impl: this is body text\n:::\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
let hash =
crate::inputs::outline_input(root.path(), "skills/ready.md", "").unwrap()["hash"]
.clone();
assert_eq!(
inputs,
&[
json!({
"requirements": "requirements.ready",
"matches": ["requirements.ready"],
"text": [":::{req} ready", "The project MUST be ready.", "", "Keep the whole body.", ":impl: this is body text", ":::"]
}),
json!({
"file": "skills/ready.md",
"item": "",
"hash": hash,
"kind": "file",
"text": ["# Skill", "Be ready."]
}),
]
);
assert_eq!(
sources.subject_text,
"The project MUST be ready.\n\nKeep the whole body.\n:impl: this is body text"
);
}
Input 13: outline src/authoring/inputs.rs mod[tests]/fn[test_anchors_supply_only_the_selected_node]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[test_anchors_supply_only_the_selected_node] - Kind:
fn src/authoring/inputs.rs:1407–1440
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.anchors`
// {test}`requirements.authoring.mandatory_inputs`
#[test]
fn test_anchors_supply_only_the_selected_node() {
let root = project();
fs::write(
root.path().join("src/lib.rs"),
"fn target() { assert_eq!(1, 1); }\nfn sibling() { panic!(\"UNRELATED_SOURCE\"); }\n",
)
.unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:test: src/lib.rs#fn[target]\nThe project MUST be ready.\n:::\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
assert_eq!(inputs.len(), 2, "{inputs:?}");
let expected =
crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[target]").unwrap();
for key in ["file", "item", "hash"] {
assert_eq!(inputs[1][key], expected[key]);
}
assert_eq!(inputs[1]["kind"], "fn");
assert_eq!(
inputs[1]["text"],
json!(["fn target() { assert_eq!(1, 1); }"])
);
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(prompt.contains("assert_eq!(1, 1)"), "{prompt}");
assert!(!prompt.contains("UNRELATED_SOURCE"), "{prompt}");
assert!(!prompt.contains("fn sibling"), "{prompt}");
}
Input 14: outline src/authoring/inputs.rs mod[tests]/fn[cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not] - Kind:
fn src/authoring/inputs.rs:1626–1704
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.builtin_definitions`
// {test}`requirements.references.site_review`
// {test}`requirements.authoring.adaptive`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not() {
let project = crate::authoring::tests::citing_site_project();
let root = project.path();
let fixme = |issue: &str| {
format!(
" // :::{{fixme}} requirements.rule\n // :github: o/r#{issue}\n // Panics instead of reporting.\n // :::\n"
)
};
let source = crate::sites::tests::SOURCE
.replace(
"fn check_two() {}",
&format!("fn check_two() {{\n{}}}", fixme("1")),
)
.replace(
"fn other() { panic!(\"y\"); }",
&format!("fn other() {{\n{}}}", fixme("2")),
);
fs::write(root.join("src/lib.rs"), &source).unwrap();
let sources = AssessmentSources::prepare(root, "requirements.rule").unwrap();
assert!(sources.has_applicable_fixme);
let own_site = AssessmentSources::prepare_site(
root,
"requirements.rule",
"src/lib.rs",
"fn[check_two]",
)
.unwrap();
assert!(own_site.has_applicable_fixme);
let clean_site = AssessmentSources::prepare_site(
root,
"requirements.rule",
"src/lib.rs",
"fn[check_one]",
)
.unwrap();
assert!(!clean_site.has_applicable_fixme);
assert!(clean_site.model_acknowledgments().is_empty());
let only_site = source.replace(&fixme("2"), "");
fs::write(root.join("src/lib.rs"), only_site).unwrap();
assert!(
!AssessmentSources::prepare(root, "requirements.rule")
.unwrap()
.has_applicable_fixme
);
fs::write(root.join("src/lib.rs"), &source).unwrap();
let mandatory = sources.mandatory_inputs();
let items = mandatory
.iter()
.filter_map(|input| input["item"].as_str())
.collect::<Vec<_>>();
// Only the acknowledgment outside the subject's own sites belongs to
// this assessment, and it contributes no containing source.
assert!(items.is_empty(), "{mandatory:#?}");
let acknowledgments = sources.model_acknowledgments();
assert_eq!(acknowledgments.len(), 1, "{acknowledgments:#?}");
assert_eq!(acknowledgments[0]["item"], "fn[other]");
assert_eq!(acknowledgments[0]["issues"][0]["reference"], "o/r#2");
// A cited built-in contributes its fixed text once, and a cited
// declaration its own declaration.
assert_eq!(
mandatory
.iter()
.filter(|input| input["builtin"] == "habeas:util")
.collect::<Vec<_>>(),
[&builtin_input("habeas:util")]
);
assert!(
mandatory
.iter()
.any(|input| input["requirements"] == "requirements.other"),
"{mandatory:#?}"
);
}
Input 15: outline src/authoring/inputs.rs mod[tests]/fn[references_contribute_their_owning_outline_nodes]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[references_contribute_their_owning_outline_nodes] - Kind:
fn src/authoring/inputs.rs:1706–1766
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.outline_comments`
// {test}`requirements.references.anchors`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.fixme_inputs`
// {test}`requirements.references.roles`
#[test]
fn references_contribute_their_owning_outline_nodes() {
let root = project();
fs::create_dir_all(root.path().join("docs")).unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: src/lib.rs#mod[inner]\nThe project MUST be ready.\n:::\n",
)
.unwrap();
// A `{fixme}` contributes metadata for the node its comment belongs to;
// an unnamed one is not an acknowledgment edge.
fs::write(
root.path().join("src/lib.rs"),
"mod inner {\n fn unrelated() {}\n}\n\n// :::{fixme} requirements.ready\n// The gap.\n// :::\nfn gap() {}\n\n// :::{fixme}\n// :github: example/app#1\n// :::\nfn tracked() {}\n",
)
.unwrap();
fs::write(
root.path().join("docs/guide.md"),
format!(
"# Intro\n\nText.\n\n# Usage\n\nSee {}.\n",
role("test", "requirements.ready")
),
)
.unwrap();
fs::write(
root.path().join("notes.txt"),
format!("first\n{}\n", role("test", "requirements.ready")),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let items = sources
.mandatory_inputs()
.iter()
.filter(|input| input.get("item").is_some())
.map(|input| {
(
input["file"].as_str().unwrap(),
input["item"].as_str().unwrap(),
)
})
.collect::<Vec<_>>();
assert_eq!(
items,
[
("docs/guide.md", "section[Usage]"),
// A plain-text file contributes the complete file.
("notes.txt", ""),
]
);
let acknowledgments = sources.model_acknowledgments();
assert_eq!(acknowledgments.len(), 1, "{acknowledgments:#?}");
assert_eq!(acknowledgments[0]["file"], "src/lib.rs");
assert_eq!(acknowledgments[0]["item"], "fn[gap]");
assert_eq!(acknowledgments[0]["body"], "The gap.");
}
Input 16: outline src/authoring/inputs.rs mod[tests]/fn[references_in_terminology_declarations_contribute_that_declaration]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[references_in_terminology_declarations_contribute_that_declaration] - Kind:
fn src/authoring/inputs.rs:1768–1796
// {test}`requirements.references.authoring_inputs`
#[test]
fn references_in_terminology_declarations_contribute_that_declaration() {
let root = project();
fs::write(
root.path().join("md/requirements.md"),
format!(
":::{{req}} ready\nThe project MUST be ready.\n:::\n\n:::{{definition}} widget\n:phrase: widget\n\nA part that is ready, as {} shows.\n:::\n",
role("test", "requirements.ready")
),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let definitions = sources
.mandatory_inputs()
.iter()
.filter_map(|input| input.get("definition"))
.collect::<Vec<_>>();
assert_eq!(definitions, [&json!("requirements.widget")]);
// The declaration contributes as a whole, not as a Markdown section.
assert!(
!sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "md/requirements.md"),
"{:?}",
sources.mandatory_inputs()
);
}
Input 17: outline src/authoring/inputs.rs mod[tests]/fn[generated_evidence_references_are_omitted_by_default]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[generated_evidence_references_are_omitted_by_default] - Kind:
fn src/authoring/inputs.rs:1871–1943
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.references.authoring_inputs`
#[test]
fn generated_evidence_references_are_omitted_by_default() {
let root = project();
fs::create_dir_all(root.path().join("evidence")).unwrap();
fs::write(
root.path().join("evidence/notes.md"),
format!("# Notes\n\n{}\n", role("test", "requirements.ready")),
)
.unwrap();
fs::write(
root.path().join("src/literal.rs"),
format!(
"const REFERENCE: &str = {:?};\n",
role("test", "requirements.ready")
),
)
.unwrap();
fs::write(
root.path().join("evidence/copy.json"),
json!({"rationale":role("test", "requirements.ready")}).to_string(),
)
.unwrap();
fs::write(
root.path().join("notes.txt"),
role("test", "requirements.ready"),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "notes.txt")
);
assert!(
!sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "evidence/notes.md"),
"{:#?}",
sources.mandatory_inputs()
);
for excluded in ["src/literal.rs", "evidence/copy.json"] {
assert!(
!sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == excluded)
);
}
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['evidence/notes.md']\n",
)
.unwrap();
let allowed = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
// Reference discovery has fixed exclusions under references.discovery.
// Explicit allowances permit an anchor or requested read into evidence/,
// as the anchor test checks; they do not discover references there.
assert!(
!allowed
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "evidence/notes.md"),
"{:#?}",
allowed.mandatory_inputs()
);
assert!(!allowed.mandatory_inputs().iter().any(|input| input["file"]
== "evidence/copy.json"
|| input["file"] == "src/literal.rs"));
}
Input 18: outline src/authoring/tools.rs mod[tests]/fn[references_list_names_and_flattened_sites_without_recording_inputs]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[references_list_names_and_flattened_sites_without_recording_inputs] - Kind:
fn src/authoring/tools.rs:2732–2899
// {test}`requirements.authoring.reference_index`
// {test}`requirements.references.definition_globs`
// {test}`requirements.authoring.no_line_numbers`
// {test}`requirements.authoring.read_denial`
#[test]
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.authoring.read_denial`
fn references_list_names_and_flattened_sites_without_recording_inputs() {
let root = project();
fs::write(
root.path().join("md/requirements.md"),
format!(
":::{{req}} ready\nThe project MUST be ready.\n:::\n\n:::{{req}} other\nOther MUST hold.\n:::\n\n:::{{example}} case\nA ready case. {}\n:::\n\n:::{{definition}} word\n:phrase: word\n:impl: src/lib.rs#fn[work]\nA vocabulary term.\n:::\n",
role("cite", "requirements.ready")
),
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn zeta() {{}}\n\n// {}\nfn work() {{\n // {}\n // {}\n}}\n",
role("test", "requirements.ready"),
role("impl", "requirements.ready"),
role("cite", "requirements.other"),
role("term", "requirements.word"),
),
)
.unwrap();
fs::create_dir_all(root.path().join("private")).unwrap();
fs::write(
root.path().join("private/notes.md"),
format!("{}\n", role("cite", "requirements.ready")),
)
.unwrap();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n\n[evidence]\ndisallow = [\"private\"]\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let all = dispatch(&sources, "references", &json!({})).unwrap();
assert_eq!(
all.result,
json!({"definitions": [
{"name": "requirements.case", "kind": "example"},
{"name": "requirements.other", "kind": "requirement"},
{"name": "requirements.ready", "kind": "requirement"},
], "sites": []})
);
assert!(all.inputs.is_empty());
let ready = dispatch(
&sources,
"references",
&json!({"selection": "requirements.ready"}),
)
.unwrap();
let mut result = ready.result.clone();
let markdown = result["sites"][0]["item"].take();
assert!(
markdown.as_str().unwrap().starts_with("section@"),
"{markdown}"
);
assert_eq!(
result,
json!({"definitions": [{"name": "requirements.ready", "kind": "requirement"}], "sites": [
{"name": "requirements.ready", "role": "cite", "file": "md/requirements.md", "item": null},
{"name": "requirements.ready", "role": "test", "file": "src/lib.rs", "item": "fn[zeta]"},
{"name": "requirements.ready", "role": "impl", "file": "src/lib.rs", "item": "fn[work]"},
]})
);
assert!(ready.inputs.is_empty());
let implementations = dispatch(
&sources,
"references",
&json!({"selection":"requirements.ready", "roles":["impl", "impl"]}),
)
.unwrap();
assert_eq!(
implementations.result,
json!({"definitions":[{"name":"requirements.ready","kind":"requirement"}],
"sites":[{"name":"requirements.ready","role":"impl","file":"src/lib.rs","item":"fn[work]"}]})
);
assert!(implementations.inputs.is_empty());
let names = dispatch(
&sources,
"references",
&json!({"selection":"requirements.ready", "roles":[]}),
)
.unwrap();
assert_eq!(names.result["definitions"], ready.result["definitions"]);
assert_eq!(names.result["sites"], json!([]));
assert!(names.inputs.is_empty());
assert_eq!(
dispatch(&sources, "references", &json!({"roles":["impl"]}))
.unwrap()
.result,
all.result
);
for roles in [json!(null), json!("impl"), json!(["fixme"]), json!([1])] {
let error = dispatch(&sources, "references", &json!({"roles":roles}))
.err()
.unwrap();
assert!(error.to_string().contains("role"), "{roles}: {error}");
}
let flattened = dispatch(
&sources,
"references",
&json!({"selection": "requirements.*"}),
)
.unwrap();
let sites = flattened.result["sites"].as_array().unwrap();
assert_eq!(flattened.result["definitions"], all.result["definitions"]);
assert_eq!(sites.len(), 4);
assert_eq!(sites[0]["name"], "requirements.other");
assert_eq!(sites[0]["item"], "fn[work]");
assert!(flattened.inputs.is_empty());
// A fenced reference in a comment run is a site of the node the run
// belongs to; a `{fixme}` is not a site, nor is a fence that never
// closes.
fs::write(
root.path().join("src/fenced.rs"),
format!(
"// :::{} requirements.other\n// Commentary.\n// :::\nfn fenced() {{}}\n\n// :::{} requirements.other\n// Tracked by example/queue#1.\n// :::\nfn gap() {{}}\n\n// :::{} requirements.other\n// never closed\n\nfn open() {{}}\n",
"{impl}", "{fixme}", "{cite}"
),
)
.unwrap();
let other = dispatch(
&sources,
"references",
&json!({"selection": "requirements.other"}),
)
.unwrap();
assert_eq!(
other.result["sites"],
json!([
{"name": "requirements.other", "role": "impl", "file": "src/fenced.rs", "item": "fn[fenced]"},
{"name": "requirements.other", "role": "cite", "file": "src/lib.rs", "item": "fn[work]"},
])
);
fs::remove_file(root.path().join("src/fenced.rs")).unwrap();
for selection in ["requirements.missing", "requirements.word", "bad name", ""] {
assert!(
dispatch(&sources, "references", &json!({"selection": selection})).is_err(),
"accepted {selection:?}"
);
}
let error = dispatch(&sources, "references", &json!({"selection": 1}))
.err()
.unwrap();
assert!(
error.to_string().contains("selection must be a string"),
"{error}"
);
assert!(
dispatch(
&sources,
"references",
&json!({"name": "requirements.ready"})
)
.is_err()
);
}
Referenced definitions
Input 2: 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 3: requirements selection requirements.authoring.mandatory_inputs
requirements.authoring.mandatory_inputs:md/requirements/authoring.md:1285–1297
:::{req} mandatory_inputs
The harness MUST construct each assessment's mandatory input set by combining
the contributions specified by the requirements applicable to that subject and
its inputs. A requirement that contributes inputs MUST cite this requirement and
define which sources it contributes and when. The harness MUST include every
applicable contribution, deduplicate identical selections, and report
unresolvable mandatory inputs before inference. The complete set MUST be supplied
in the initial model request.
Generated output under project-root `evidence/`, including symlink aliases, MUST
be omitted from mandatory inputs when the default exclusion applies. An explicit
workspace allow MUST permit those selections; an explicit disallow MUST abort
under {cite}`requirements.authoring.read_denial.mandatory`.
:::
Input 4: requirements selection requirements.authoring.reference_index
requirements.authoring.reference_index:md/requirements/authoring.md:1126–1181
:::{req} reference_index
The harness MUST expose a `references` tool with this interface:
```text
references({ selection: String?, roles: Array<"impl" | "cite" | "test">? }) -> ReferenceIndex
ReferenceIndex {
definitions: Array<DefinitionName>,
sites: Array<ReferenceSite>,
}
DefinitionName { name: String, kind: "requirement" | "example" }
ReferenceSite {
name: String,
role: "impl" | "cite" | "test",
file: String,
item: String?,
}
```
`selection` MUST be a {term}`requirements.references.definition_selection`.
Without `selection`, the tool MUST return
the full name and kind of every requirement and named example in full-name
order, with empty `sites`. With `selection`, it MUST return the selected definitions
in full-name order and one flattened `sites` array containing every valid
reference to any match whose role is in `roles`, defaulting to
`["impl", "cite", "test"]`, under
{cite}`requirements.references.discovery`, each naming the definition it
references, ordered by name, file, and position in the file, without line
numbers. Roles MUST be treated as a set: repeating a permitted role MUST NOT
duplicate sites or change the result.
An anchor under {cite}`requirements.references.anchors` whose role is selected
by `roles` MUST be
reported as a site for its anchored file, with the anchored node's selector as
`item` when it names one and no `item` when it names the whole file. Every
other site MUST give as `item` the selector of its smallest enclosing outline
node under {cite}`requirements.references.outline_comments`. Only sources reference discovery considers under
{cite}`requirements.references.discovery` MUST contribute sites. If reading such a
source fails, the tool MUST return an explanatory tool error naming the source.
An invalid selection or one matching no definition MUST return an explanatory tool
error.
An empty `roles` array MUST return no sites while preserving the selected
definitions' names and kinds. An unknown role or a value other than an array of
permitted role strings MUST return an explanatory tool error. Without `selection`,
`roles` MUST NOT change the definition-name listing.
Results MUST contain no requirement text, example text, reference commentary,
or source text. Like directory listings, they MUST
NOT become evidence inputs; the model requests the sources it relies on with the
`habeas` tool. For example,
`references({selection: "requirements.cli.status", roles: ["impl"]})` MUST
locate only that subject's implementation references and anchors, without
supplying their source or recording evidence inputs.
:::
Input 5: requirements selection requirements.authoring.source_tools
requirements.authoring.source_tools:md/requirements/authoring.md:637–699
:::{req} source_tools
The harness MUST expose a `habeas` tool accepting exactly one of these request
forms. Each form MUST correspond to one existing evidence-input kind:
| Request fields | Evidence input returned | Definition |
| --- | --- | --- |
| `file: String`, `line_start: Integer`, optional `line_end: Integer` | Outline inputs for the innermost outline nodes covering the range | {cite}`requirements.ci.outline_inputs` |
| `file: String`, `item: String` | Outline input | {cite}`requirements.ci.outline_inputs` |
| `requirements: String` | Requirements input, including its matching names | {cite}`requirements.ci.requirements_inputs` |
| `definition: String` | Definition input | {cite}`requirements.definitions.inputs` |
Selector arguments MUST use the syntax defined by
{cite}`requirements.references.outline_selectors`. Reads MUST use the current
project working tree, including unstaged changes to tracked files and staged new
files. By default, source inputs MUST stay within the project root after
resolving symlinks; in a Git worktree, both the requested file and its resolved
target MUST be present in the Git index. Projects outside Git MUST use the same
containment rules without requiring an index. Failure to read an existing
repository's index MUST be reported as an error.
The project-root `evidence/` directory MUST be excluded from model reads by
default, including symlink aliases. Every source the harness supplies to the
model MUST be redacted under {cite}`requirements.authoring.redaction`. Generated build outputs MUST follow
{cite}`requirements.authoring.generated_inputs`. Workspace path overrides MUST
follow {cite}`requirements.configuration.evidence_paths`, including explicit
permission for otherwise excluded inputs. A denied mandatory input MUST abort
under {cite}`requirements.authoring.read_denial.mandatory`, and a denied model
read MUST return a tool error under {cite}`requirements.authoring.read_denial`.
Line numbers are only a way to request sources; recorded evidence MUST identify
sources by outline selector and structural hash, never by line number. Request
line numbers MUST be one-based and inclusive, and omitting `line_end` MUST read
through EOF. A line-range request MUST be resolved to the innermost outline
nodes covering the requested lines, which are `line` nodes in a file using the
plain-text profile; the result MUST show the model each node's selector and
source text, without line numbers, and the harness MUST record those nodes as
outline inputs. The model-facing tool description MUST include the argument conventions
from the cited requirements, including outline selector syntax, definition
selections, and full definition names, with a short request example for each form.
A successful call MUST return the requested evidence input, populated by the
harness with the selected source text, using the existing evidence schema.
{cite}`requirements.ci.schema`
Required terminology dependencies MUST be returned alongside it as additional
definition inputs under {cite}`requirements.definitions.authoring_inputs`.
For item, requirement, and definition selections, the result MUST have this shape:
```text
HabeasResult {
input: EvidenceInput,
definitions: Array<DefinitionInput>,
}
```
Line-range selections can contain multiple outline nodes. Their result MUST use
`inputs: Array<EvidenceInput>` instead of the singular `input` field, including
when only one node is selected.
`definitions` MUST be empty when no additional terminology is required. The
harness MUST record inputs supplied to the model in the assessment's evidence.
A failed read MUST add no evidence input. Access-policy denials MUST be handled
under {cite}`requirements.authoring.read_denial`; other failed reads MUST return
an explanatory tool error.
:::
Input 6: 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 7: 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 8: requirements selection requirements.authoring.fixme_inputs
requirements.authoring.fixme_inputs:md/requirements/authoring.md:1305–1345
:::{req} fixme_inputs
For a requirement or example assessment, the initial request MUST include every
valid named `{fixme}` reference to the subject found under
{cite}`requirements.references.discovery`, except a reference inside one of
the subject's sites under {cite}`requirements.references.site_review`, in this
form:
```text
Acknowledgment {
file: String,
item: String,
body: String,
issues: Array<{ reference: String, state: "open" | "closed" }>,
}
```
`file` and `item` MUST locate the containing source by project-relative path and
outline selector, using `<root>` for a whole file. `body` MUST contain the
reference's complete fenced commentary without its fences or source-comment
delimiters, including its option lines, redacted under
{cite}`requirements.authoring.redaction`. `issues` MUST give every distinct issue
its `:github:` lines name, in their order, with state supplied under
{cite}`requirements.authoring.github_reads`. Acknowledgments MUST be ordered by
file and position in the file and MUST carry no line numbers or containing
implementation source.
The locations and bodies MUST be protected against staleness by the reference-set
digest under {cite}`requirements.ci.reference_set`; the acknowledgment MUST NOT
create an outline input merely to cover its containing source. Actual reads of
that source MUST still be recorded under
{cite}`requirements.authoring.delivered_inputs`. Sources MUST satisfy
{cite}`requirements.authoring.source_tools`; an inaccessible acknowledgment
MUST be reported before inference.
Terminology definitions referenced by an acknowledgment's body MUST contribute
their complete, transitive declarations to the mandatory input set under
{cite}`requirements.definitions.authoring_inputs` and MUST be recorded as
definition inputs. Only the acknowledgment's body MUST contribute these
dependencies; its containing implementation source MUST NOT be supplied merely
to discover them.
:::
Input 19: definition requirements.references.definition_selection
requirements.references.definition_selection:md/requirements/references.md:335–342
:::{definition} definition_selection
:phrase: definition selection
A full requirement or example name, or a definition glob, identifying the
requirements and named examples it matches under
{cite}`requirements.references.definition_globs`. A name without `*` selects
exactly that definition.
:::
Other sources
Input 1: requirements selection requirements.references.authoring_inputs
requirements.references.authoring_inputs:md/requirements/references.md:563–595
:::{req} authoring_inputs
When authoring evidence, the edges defined by
{cite}`requirements.references.roles` MUST determine the reference
contributions to the mandatory input set defined by
{cite}`requirements.authoring.mandatory_inputs`. A `{cite}` made by the subject
MUST contribute the cited definition's complete fenced declaration. A requirement
or example declaration that references the subject with `{impl}` or `{test}`
MUST contribute that complete declaration. For sources outside such declarations,
an `{impl}` reference or `:impl:` anchor alone MUST NOT contribute source text;
those sources MUST remain discoverable under
{cite}`requirements.authoring.reference_index` and MAY be requested under
{cite}`requirements.authoring.source_tools`. Sources with only edges into the subject
MUST NOT contribute and remain discoverable under
{cite}`requirements.authoring.reference_index`. A `:test:` anchor under
{cite}`requirements.references.anchors` MUST contribute the complete anchored file,
or for a `path#selector` anchor the anchored node.
An in-source `{test}` reference to the subject MUST contribute the source
containing it: for a reference in a supported language, the smallest enclosing
outline node under {cite}`requirements.references.outline_comments`; for a reference in a Markdown requirement, example, or
terminology declaration, that complete declaration; for other references, the
complete containing source file. Literal references, evidence copies, and
generated output MUST remain excluded under the existing reference-discovery
rules.
An in-source `{fixme}` reference alone MUST NOT contribute the containing source
to the mandatory input set. Its acknowledgment MUST instead be supplied under
{cite}`requirements.authoring.fixme_inputs`.
These contribution rules MUST apply only to the assessed subject's direct
references. Including another declaration or source MUST NOT by itself recursively
expand that source's own edges. Reference links MUST NOT be described as proof
that all substantively relevant sources have been found.
:::