requirements.references.discovery
Requirements index · View definition
Requirement
Habeas MUST find the references of
in project source files, where
says they count, and MUST fail with the source file and line if a name has no matching
{req}or{example}definition. In Markdown, escaped roles and roles in code examples MUST remain literal. Reference discovery MUST consider exactly the project sources that source-access policy permits under: in a Git worktree, files present in the Git index, including staged new files; outside Git, all project files; in both cases excluding the project-root
bookandevidencedirectories,.gitandtargetdirectories at any depth, and paths disallowed by. Evidence snapshots and generated build output MUST therefore not be counted as source references.
Rationale
The reviewed tests cover each obligation in requirements.references.discovery. I judged this from the supplied test text only. I did not request any implementation source.
1. Finding references where the contexts requirement says they count
src/evidence.rs#mod[tests]/fn[roles_count_only_in_comments_of_outlined_files]covers comments and doc comments in Rust, comments in TOML and Python, and string literals. Strings, docstrings and a fenced role spanning a string literal stay literal. Plain text counts anywhere, and Markdown keeps its own rules. It asserts the exact list of names found.src/lib.rs#mod[tests]/fn[references_in_requirement_bodies_are_scanned_as_markdown]shows that references in requirement bodies are found, while those in code examples are not.tests/references.rs#fn[fixme_references_are_fenced_described_and_named_only_outside_the_book]covers fenced and inline role forms.
2. Failing with file and line for an unknown name
src/evidence.rs#mod[tests]/fn[reports_unknown_references_and_uncovered_lines]asserts the exact error text for an unknown{impl}name. The error names the source file and line and says there is no matching requirement.- The
{fixme}test asserts the same file-and-line error for a missing name, ending “has no matching requirement or example”.
3. Markdown escaped roles and code examples stay literal
src/lib.rs#mod[tests]/fn[markdown_examples_and_escaped_references_stay_literal]covers inline code, a fenced code block, and an escaped role. It also covers an escaped backslash not escaping the role.src/evidence.rs#mod[tests]/fn[every_markdown_extension_keeps_escaped_and_code_roles_literal]repeats these cases across the.md,.markdown,.MDand.Markdownextensions. A.txtcontrol file shows the same text is not treated as Markdown.
4. The set of sources considered
- Git worktree:
src/authoring/access.rs#mod[tests]/fn[discovery_considers_indexed_files_except_exclusions_including_credential_configuration]shows indexed and staged files are included. Unindexed and deleted files,evidence/, and a nestedtargetare excluded, and a nesteddocs/bookis kept.tests/references.rs#fn[untracked_sources_are_not_validated_until_staged_and_status_lists_them]shows an untracked file is ignored, then counted once staged.src/authoring/tools.rs#mod[tests]/fn[references_report_only_sites_in_considered_sources]andsrc/authoring/inputs.rs#mod[tests]/fn[mandatory_git_inputs_require_staging_declarations_sources_and_terms]show the same behaviour through the tools.
- Outside Git:
tests/references.rs#fn[disallowed_paths_are_skipped_and_projects_outside_git_scan_every_file]shows all files are scanned.- The same test shows disallowed paths, a nested
target, and the rootbookare skipped.
- Excluded directories:
src/evidence.rs#mod[tests]/fn[reference_discovery_skips_evidence_snapshots_and_build_output]covers rootevidenceandbook, and.gitandtargetat depth.- It confirms that nested
bookandevidencedirectories are still counted. - It also covers a binary file.
evidence_pathsdisallow is exercised in both Git and non-Git modes.
I found no obligation without a test and no marking gap.
Inputs
Tests
Input 6: outline src/authoring/access.rs mod[tests]/fn[discovery_considers_indexed_files_except_exclusions_including_credential_configuration]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[discovery_considers_indexed_files_except_exclusions_including_credential_configuration] - Kind:
fn src/authoring/access.rs:766–815
// {test}`requirements.references.discovery`
// {test}`requirements.authoring.credentials`
#[test]
fn discovery_considers_indexed_files_except_exclusions_including_credential_configuration() {
let root = tempfile::tempdir().unwrap();
let root = fs::canonicalize(root.path()).unwrap();
for file in [
"src/lib.rs",
"src/staged.rs",
"src/deleted.rs",
"src/untracked.rs",
"crates/a/target/out.rs",
"evidence/x.json",
"docs/book/page.md",
] {
let path = root.join(file);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, "text\n").unwrap();
}
fs::write(
root.join("habeas.toml"),
"version = 1\n[authoring.configs.cloud]\nprovider = \"bedrock\"\napi_key = \"secret\"\n",
)
.unwrap();
git(&root, &["init", "--quiet"]);
git(&root, &["add", "-f", "."]);
git(&root, &["rm", "--cached", "--quiet", "src/untracked.rs"]);
fs::remove_file(root.join("src/deleted.rs")).unwrap();
let sources = DiscoverySources::load(&root).unwrap();
let mut errors = Vec::new();
let files: Vec<_> = sources
.files(&mut errors)
.into_iter()
.map(|path| path.strip_prefix(&root).unwrap().to_owned())
.collect();
assert!(errors.is_empty(), "{errors:?}");
assert_eq!(
files,
[
Path::new("docs/book/page.md"),
Path::new("habeas.toml"),
Path::new("src/lib.rs"),
Path::new("src/staged.rs"),
]
);
assert_eq!(
sources.untracked().unwrap(),
[root.join("src/untracked.rs")]
);
}
Input 7: 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 8: outline src/authoring/tools.rs mod[tests]/fn[references_report_only_sites_in_considered_sources]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[references_report_only_sites_in_considered_sources] - Kind:
fn src/authoring/tools.rs:3014–3053
// {test}`requirements.authoring.reference_index`
// {test}`requirements.references.discovery`
#[test]
fn references_report_only_sites_in_considered_sources() {
let root = project();
let reference = format!(
"// {}\nfn site() {{}}\n",
role("impl", "requirements.ready")
);
for file in ["src/tracked.rs", "src/untracked.rs", "private/tracked.rs"] {
let path = root.path().join(file);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, &reference).unwrap();
}
fs::write(
root.path().join("habeas.toml"),
"version = 1\n\n[evidence]\ndisallow = [\"private\"]\n",
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
git(
root.path(),
&["rm", "--cached", "--quiet", "src/untracked.rs"],
);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let result = dispatch(
&sources,
"references",
&json!({"selection": "requirements.ready"}),
)
.unwrap();
let files: Vec<_> = result.result["sites"]
.as_array()
.unwrap()
.iter()
.map(|site| site["file"].as_str().unwrap().to_owned())
.collect();
assert_eq!(files, ["src/tracked.rs"]);
}
Input 9: outline src/evidence.rs mod[tests]/fn[roles_count_only_in_comments_of_outlined_files]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[roles_count_only_in_comments_of_outlined_files] - Kind:
fn src/evidence.rs:2076–2146
// {test}`requirements.references.reference_contexts`
// {test}`requirements.references.discovery`
#[test]
fn roles_count_only_in_comments_of_outlined_files() {
// The role's brace is built at run time, so this source holds none.
let role = |name: &str| format!("{{impl}}`{name}`");
let names = |file: &str, content: String| {
super::file_references(Path::new(file), &content, false)
.into_iter()
.map(|reference| reference.name)
.collect::<Vec<_>>()
};
assert_eq!(
names(
"src/lib.rs",
format!(
"// {}\n/// {}\nfn f() -> &'static str {{ \"{}\" }}\n",
role("a.comment"),
role("a.doc"),
role("a.string")
)
),
["a.comment", "a.doc"]
);
assert_eq!(
names(
"config.toml",
format!("# {}\nkey = \"{}\"\n", role("b.comment"), role("b.string"))
),
["b.comment"]
);
assert_eq!(
names(
"tool.py",
format!(
"# {}\ndef f():\n \"\"\"{}\"\"\"\n",
role("c.comment"),
role("c.docstring")
)
),
["c.comment"]
);
// A fenced role spanning lines of a string literal is literal too.
assert_eq!(
names(
"src/lib.rs",
format!(
"// :::{0}impl}} f.comment\n// Body.\n// :::\nconst S: &str = \"\n:::{0}impl}} f.string\nBody.\n:::\n\";\n",
'{'
)
),
["f.comment"]
);
// Plain text has no comments: roles count anywhere.
assert_eq!(
names("notes.txt", format!("see {}\n", role("d.text"))),
["d.text"]
);
// Markdown keeps its own rules.
assert_eq!(
names(
"md/rules.md",
format!(
"Uses {}.\n\n```text\n{}\n```\n",
role("e.prose"),
role("e.code")
)
),
["e.prose"]
);
}
Input 10: outline src/evidence.rs mod[tests]/fn[every_markdown_extension_keeps_escaped_and_code_roles_literal]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[every_markdown_extension_keeps_escaped_and_code_roles_literal] - Kind:
fn src/evidence.rs:2776–2809
// {test}`requirements.references.discovery`
// {test}`requirements.references.markdown_literals`
#[test]
fn every_markdown_extension_keeps_escaped_and_code_roles_literal() {
let temp = fixture();
let role = "{cite}`code.role`".to_owned();
let fence = ":::{cite} fenced.role\nBody.\n:::".to_owned();
let notes = format!(
"`{role}` and \\{role}\n\n```text\n{role}\n{fence}\n```\n\n<span title=\"{role}\"></span>\n"
);
fs::create_dir_all(temp.path().join("docs")).unwrap();
for file in [
"docs/a.md",
"docs/b.markdown",
"docs/C.MD",
"docs/d.Markdown",
] {
fs::write(temp.path().join(file), ¬es).unwrap();
}
// The same text in a plain-text file is not Markdown.
fs::write(temp.path().join("docs/e.txt"), ¬es).unwrap();
let mut errors = Vec::new();
let references = super::collect_references(temp.path(), &mut errors);
assert!(errors.is_empty(), "{errors:?}");
let files = references
.iter()
.map(|reference| super::display_path(temp.path(), &reference.file))
.collect::<std::collections::BTreeSet<_>>();
assert_eq!(
files.into_iter().collect::<Vec<_>>(),
["docs/e.txt"],
"{references:#?}"
);
}
Input 11: outline src/evidence.rs mod[tests]/fn[reports_unknown_references_and_uncovered_lines]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[reports_unknown_references_and_uncovered_lines] - Kind:
fn src/evidence.rs:2811–2855
// {test}`requirements.references.discovery`
// {test}`requirements.references.evidence_coverage`
#[test]
fn reports_unknown_references_and_uncovered_lines() {
let temp = fixture();
fs::write(
temp.path().join("md/reqs/foo/bar.md"),
"# Requirements\n\n:::{req} ready\nReady.\n:::\n",
)
.unwrap();
let known = "{test}`foo.bar.ready`".to_owned();
let unknown = "{impl}`missing.requirement`".to_owned();
let source = format!("// {known}\n// {known}\n// {unknown}\n");
fs::write(temp.path().join("src/notes.txt"), &source).unwrap();
// Identical plain-text lines are interchangeable, so this selects the
// first line only.
let first = crate::inputs::outline_inputs_for_lines(temp.path(), "src/notes.txt", 1, 1)
.unwrap()
.remove(0);
fs::write(
temp.path().join("evidence/foo.bar.ready.json"),
json!({
"requirement": "Ready.",
"determination": true,
"rationale": "Only the first line was examined.",
"inputs": [first]
})
.to_string(),
)
.unwrap();
let report = validate_repository(temp.path()).unwrap();
let errors = report.errors.join("\n");
assert_eq!(report.errors.len(), 2, "{errors}");
assert!(
errors.contains(&format!(
"src/notes.txt:3: {unknown} has no matching requirement"
)),
"{errors}"
);
assert!(
errors.contains(&format!("no input covers {known} at src/notes.txt:2")),
"{errors}"
);
}
Input 12: outline src/evidence.rs mod[tests]/fn[reference_discovery_skips_evidence_snapshots_and_build_output]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[reference_discovery_skips_evidence_snapshots_and_build_output] - Kind:
fn src/evidence.rs:3331–3371
// {test}`requirements.references.discovery`
#[test]
fn reference_discovery_skips_evidence_snapshots_and_build_output() {
let temp = fixture();
let reference = "{impl}`foo.bar.ready`".to_owned();
let line = format!("// {reference}\n");
for file in [
"src/counted.rs",
"nested/book/counted.txt",
"nested/evidence/counted.txt",
"evidence/copy.json",
"book/chapter.html",
"target/debug/out.rs",
"crates/sub/target/out.rs",
".git/info/notes",
"nested/.git/info/notes",
] {
let path = temp.path().join(file);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, &line).unwrap();
}
fs::write(temp.path().join("src/binary.dat"), b"\0\0{impl}").unwrap();
let mut errors = Vec::new();
let mut found = super::collect_references(temp.path(), &mut errors)
.into_iter()
.map(|reference| {
let file = reference.file.strip_prefix(temp.path()).unwrap();
format!("{}:{}", file.display(), reference.line)
})
.collect::<Vec<_>>();
found.sort();
assert!(errors.is_empty(), "{errors:?}");
assert_eq!(
found,
[
"nested/book/counted.txt:1",
"nested/evidence/counted.txt:1",
"src/counted.rs:1",
]
);
}
Input 13: outline src/lib.rs mod[tests]/fn[markdown_examples_and_escaped_references_stay_literal]
- File:
src/lib.rs - Selector:
mod[tests]/fn[markdown_examples_and_escaped_references_stay_literal] - Kind:
fn src/lib.rs:1800–1828
// {test}`requirements.references.markdown_literals`
// {test}`requirements.references.discovery`
#[test]
fn markdown_examples_and_escaped_references_stay_literal() {
let marker = "{impl}`requirements.ready`".to_owned();
let content = format!("`{marker}`\n\n```text\n{marker}\n```\n\n\\{marker}");
let mut book = Book::new();
book.push_item(Chapter::new(
"Requirements",
":::{req} ready\nReady.\n:::".to_owned(),
"requirements.md",
Vec::new(),
));
book.push_item(Chapter::new("Guide", content, "guide.md", Vec::new()));
let root = book_root();
preprocess_book(&mut book, root.path()).unwrap();
let guide = book
.chapters()
.find(|chapter| chapter.name == "Guide")
.unwrap();
assert_eq!(guide.content.matches(&marker).count(), 3);
assert!(!guide.content.contains("habeas-req-ref-impl"));
// An escaped backslash does not escape the role.
let content = format!("\\\\{marker} \\\\\\{marker}");
let roles = reference_roles(&content, true);
assert_eq!(roles.len(), 1);
assert_eq!(roles[0].start, 2);
}
Input 14: outline src/lib.rs mod[tests]/fn[references_in_requirement_bodies_are_scanned_as_markdown]
- File:
src/lib.rs - Selector:
mod[tests]/fn[references_in_requirement_bodies_are_scanned_as_markdown] - Kind:
fn src/lib.rs:1878–1888
// {test}`requirements.references.discovery`
// {test}`requirements.references.markdown_literals`
#[test]
fn references_in_requirement_bodies_are_scanned_as_markdown() {
let known = "{cite}`requirements.ready`".to_owned();
let example = "{cite}`missing.example`".to_owned();
let content = format!(":::{{req}} ready\nSee {known}.\n\n```text\n{example}\n```\n:::");
let references = reference_roles(&content, true);
assert_eq!(references.len(), 1);
assert_eq!(references[0].name, "requirements.ready");
}
Input 15: outline tests/references.rs fn[fixme_references_are_fenced_described_and_named_only_outside_the_book]
- File:
tests/references.rs - Selector:
fn[fixme_references_are_fenced_described_and_named_only_outside_the_book] - Kind:
fn tests/references.rs:315–361
// {test}`requirements.references.roles`
// {test}`requirements.references.discovery`
#[test]
fn fixme_references_are_fenced_described_and_named_only_outside_the_book() {
let temp = project();
let root = temp.path();
let fx = role("fixme");
fs::write(
root.join("src/gaps.rs"),
format!(
"// {fx}`rules.ready`\n\n\
// :::{fx} rules.ready\n// :github: example/rules#1\n// :gitlab: example/rules#2\n// :github: example/rules\n// The gap.\n// :::\n\n\
// :::{fx} rules.ready\n// :github: example/rules#1\n// :::\n\n\
// :::{fx}\n// Only words.\n// :::\n\n\
// :::{fx}\n// :github: example/rules#4\n// Tracked here.\n// :::\n\n\
// :::{fx} rules.missing\n// Gap.\n// :::\n"
),
)
.unwrap();
fs::write(
root.join("md/rules.md"),
format!(
"::::{{req}} ready\nReady.\n\n:::{fx} rules.ready\nIn a declaration.\n:::\n\n:::{fx}\n:github: example/rules#3\n:::\n::::\n\n:::{fx} rules.ready\nIn the book.\n:::\n"
),
)
.unwrap();
let errors = errors(root);
for expected in [
"src/gaps.rs:1: inline {fixme} reference to rules.ready must use the fenced form",
"src/gaps.rs:3: unsupported {fixme} option :gitlab:",
"src/gaps.rs:3: :github: value \"example/rules\" is not of the form <owner>/<repo>#<number>",
"src/gaps.rs:10: {fixme} to rules.ready has an empty body",
"src/gaps.rs:14: an unnamed {fixme} must name at least one issue",
"src/gaps.rs:23: {fixme}`rules.missing` has no matching requirement or example",
"md/rules.md:4: a named {fixme} to rules.ready must not appear in a requirement or example declaration",
"md/rules.md:13: a named {fixme} to rules.ready must appear in a source outside the book",
] {
assert!(has(&errors, expected), "missing {expected:?}: {errors:#?}");
}
// An unnamed `{fixme}` with an issue is valid anywhere, including a
// requirement body, and is not an edge needing coverage.
for line in ["src/gaps.rs:18", "md/rules.md:8"] {
assert!(!has(&errors, line), "{line}: {errors:#?}");
}
// A misplaced named `{fixme}` is reported once, not also as uncovered.
assert!(!has(&errors, "` at md/"), "{errors:#?}");
}
Input 16: outline tests/references.rs fn[untracked_sources_are_not_validated_until_staged_and_status_lists_them]
- File:
tests/references.rs - Selector:
fn[untracked_sources_are_not_validated_until_staged_and_status_lists_them] - Kind:
fn tests/references.rs:702–746
// {test}`requirements.references.discovery`
// {test}`requirements.references.rust_item_coverage`
// {test}`requirements.cli.status`
#[test]
fn untracked_sources_are_not_validated_until_staged_and_status_lists_them() {
let temp = project();
let root = temp.path();
let source = format!(
"// {}`rules.missing`\nfn referenced() {{}}\n\nfn uncited() {{}}\n",
role("impl")
);
fs::write(root.join("src/extra.rs"), &source).unwrap();
// An untracked file without references needs no reminder.
fs::write(root.join("notes.txt"), "No references here.\n").unwrap();
git(root, &["init", "--quiet"]);
git(root, &["add", "md", "book.toml", "Cargo.toml"]);
let untracked = errors(root);
assert!(!has(&untracked, "src/extra.rs"), "{untracked:#?}");
let status = habeas::status_markdown(root, false).unwrap();
let section = &status[status
.find("## Untracked files with references")
.unwrap_or_else(|| panic!("{status}"))..];
assert!(section.contains("git add"), "{status}");
assert!(section.contains("- `src/extra.rs`"), "{status}");
assert!(!section.contains("notes.txt"), "{status}");
// Staging the new file brings its references and items back.
git(root, &["add", "src/extra.rs"]);
let errors = errors(root);
assert!(has(&errors, "src/extra.rs:1"), "{errors:#?}");
assert!(has(&errors, "rules.missing"), "{errors:#?}");
assert!(
has(
&errors,
"src/extra.rs:4: function uncited has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it"
),
"{errors:#?}"
);
let status = habeas::status_markdown(root, false).unwrap();
assert!(
!status.contains("Untracked files with references"),
"{status}"
);
}
Input 17: outline tests/references.rs fn[disallowed_paths_are_skipped_and_projects_outside_git_scan_every_file]
- File:
tests/references.rs - Selector:
fn[disallowed_paths_are_skipped_and_projects_outside_git_scan_every_file] - Kind:
fn tests/references.rs:748–799
// {test}`requirements.references.discovery`
// {test}`requirements.references.rust_item_coverage`
// {test}`requirements.configuration.evidence_paths`
#[test]
fn disallowed_paths_are_skipped_and_projects_outside_git_scan_every_file() {
let temp = project();
let root = temp.path();
let source = format!("// {}`rules.missing`\nfn uncited() {{}}\n", role("impl"));
for file in [
"private/hidden.rs",
"src/secret.rs",
"notes/other.rs",
"vendor/dep/lib.rs",
"crates/sub/target/out.rs",
"book/out.rs",
] {
let path = root.join(file);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, &source).unwrap();
}
fs::write(
root.join("habeas.toml"),
"version = 1\n\n[evidence]\ndisallow = [\"private\", \"src/secret.rs\"]\n",
)
.unwrap();
let errors = errors(root);
for skipped in [
"private/hidden.rs",
"src/secret.rs",
"crates/sub/target/out.rs",
"book/out.rs",
] {
assert!(!has(&errors, skipped), "{skipped}: {errors:#?}");
}
// Outside Git every other project file is considered, untracked or not;
// vendored Rust sources still carry references but are not covered.
assert!(has(&errors, "notes/other.rs:1"), "{errors:#?}");
assert!(
has(&errors, "notes/other.rs:2: function uncited"),
"{errors:#?}"
);
assert!(has(&errors, "vendor/dep/lib.rs:1"), "{errors:#?}");
assert!(
!has(&errors, "vendor/dep/lib.rs:2: function uncited"),
"{errors:#?}"
);
let status = habeas::status_markdown(root, false).unwrap();
assert!(
!status.contains("Untracked files with references"),
"{status}"
);
}
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.references.reference_contexts
requirements.references.reference_contexts:md/requirements/references.md:114–124
:::{req} reference_contexts
Each supported language profile MUST define where in its files roles count as
references, and SHOULD exclude places that hold code or data rather than prose,
such as string literals. In a file with a language outline under
{cite}`requirements.references.outlines`, inline and fenced roles MUST count
only within comments as its profile defines them, including doc comments; a
role anywhere else, including in a string literal, MUST remain literal. In
Markdown, escaped roles and roles in code examples remain literal under
{cite}`requirements.references.discovery`. In a plain-text file, roles MUST
count anywhere.
:::
Input 4: 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 5: requirements selection requirements.configuration.evidence_paths
requirements.configuration.evidence_paths:md/requirements/configuration.md:126–150
:::{req} evidence_paths
The workspace `[evidence]` table MUST serialize EvidenceConfig. `allow` and
`disallow` MUST be arrays of nonempty literal paths, each naming a file or a
directory subtree. Relative paths MUST resolve from the selected `habeas.toml`
directory; absolute paths MUST be supported. These paths are not glob patterns.
An omitted `allow` or `disallow` MUST mean an empty array, and an absent
`[evidence]` table MUST mean both are empty, so only the default source-access
rules apply. No operation requires the section. The table has no user-file
counterpart, and these rules have no invocation options. This section refines
{impl}`requirements.configuration.feature_sections` for the evidence feature.
For authoring reads, a matching disallow MUST reject the path; otherwise a
matching allow MUST permit it; otherwise the default source-access rules MUST
apply. Explicit allow MUST override every default, including Git tracking,
project containment, generated-evidence exclusion, and automatic generated-output
rules. Disallow MUST win even when an allow or generated-output rule also matches.
Both the requested path and its resolved symlink target MUST be checked for
disallow, so an allowed alias cannot expose a disallowed target.
The same explicit disallow rules and external-path exceptions MUST apply when
resolving recorded evidence inputs, including ordinary validation. Validation MUST
remain independent of Git index membership: it
checks the recorded inputs' existence and contents. Loading path policy MUST NOT
resolve credentials or validate unused authoring settings.
:::
Other sources
Input 1: requirements selection requirements.references.discovery
requirements.references.discovery:md/requirements/references.md:99–112
:::{req} discovery
Habeas MUST find the references of {cite}`requirements.references.roles`
in project source files, where {cite}`requirements.references.reference_contexts`
says they count, and MUST fail with the source file and line if a
name has no matching `{req}` or `{example}` definition. In Markdown, escaped
roles and roles in code examples MUST remain literal. Reference discovery MUST
consider exactly the project sources that source-access policy permits under
{cite}`requirements.authoring.source_tools`: in a Git worktree, files present in
the Git index, including staged new files; outside Git, all project files; in
both cases excluding the project-root `book` and `evidence` directories, `.git`
and `target` directories at any depth, and paths disallowed by
{cite}`requirements.configuration.evidence_paths`. Evidence snapshots and
generated build output MUST therefore not be counted as source references.
:::