requirements.authoring.file_discovery
Requirements index · View definition
Requirement
The harness MUST expose a
list_filestool with this interface:list_files({ path: String = "." }) -> Array<DirectoryEntry> DirectoryEntry { path: String, kind: "file" | "directory", }The tool MUST list the immediate children of the requested directory, returning project-relative paths where possible and absolute paths for permitted external files. Its root listing MUST also expose available generated-output directories and configured external allow paths. The model can list a returned directory in another call to explore further. A failed listing MUST return an explanatory tool error unless access was denied, which MUST be handled under
. Directory listings MUST NOT become evidence inputs. Listings MUST omit files excluded by
. In a Git worktree, directories MUST have at least one eligible source descendant to be listed unless explicitly allowed or discovered as generated output. Explicitly requesting an excluded path MUST be handled as a denial under
.
Rationale
The reviewed tests cover every obligation in requirements.authoring.file_discovery, and their assertions enforce the expected outcomes. I did not request implementation source.
- Interface and default path.
additional_read_flow_searches_outlines_and_reads_a_rust_filecallslist_fileswith{}. That is the default.path, and the test asserts the root entries havekind“directory”. It then listssrcand asserts the exact result[{"path":"src/lib.rs","kind":"file"}].large_listings_and_outlines_page_whole_entries_in_orderchecks each entry’spath, and the tests above checkkind. - Immediate children only.
listed_git_directories_need_an_eligible_descendant_at_any_depthlistsaand gets exactlya/b, nota/b/file.txt. Thegeneratedand external listings also return exact arrays. - Project-relative and absolute paths.
allowed_ignored_and_external_sources_are_discoverable_but_disallowed_descendants_are_notchecks both forms. Entries undergenerated/are relative. The external listing returns absoluteexternal.path().join(...)paths. - Root listing exposes generated-output and external allow paths.
cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_filesasserts the root listing containstarget/debug/build/fixture-hash/out. It also asserts that adisallowentry removes it.- The allowed-sources test asserts the root listing contains the external allow path and
generated.
- Failed listings.
failed_listings_return_explanatory_tool_errorscovers a missing path (“cannot”), a file as the path (“cannot list”), a wrongly typed path, and an extra argument. It asserts each is notPermissionDeniedand that the message contains the expected text.unpermitted_requests_outside_the_project_are_recoverable_tool_errorsadds the outside-project error. - Not evidence inputs.
listing.inputs.is_empty()is asserted in many tests, including the root, nested, generated, external and build-output listings. - Omission of excluded files.
generated_evidence_is_excluded_from_reads_search_and_discoveryshowsevidenceand its symlink aliases are absent from the root listing.outside_symlinks_are_excluded_from_reads_search_and_discoveryshows outside symlinks are absent.git_symlink_reads_require_both_the_alias_and_target_to_be_trackedshows untracked symlink aliases and targets are absent.git_tools_allow_staged_and_dirty_sources_but_hide_untracked_filesasserts the exact root listing, which omits untracked files and the untracked directory.
- Git directories need an eligible descendant.
listed_git_directories_need_an_eligible_descendant_at_any_depthshowsblocked-only(whose only file is disallowed) is omitted.ais listed because it has an eligible descendant at depth two. The exceptions for explicitly allowed and generated-output directories are covered by the allowed-sources and Cargo output tests. - Explicit requests for excluded paths are denials.
generated_evidence_is_excluded_from_reads_search_and_discoveryassertsPermissionDenied, the path, and the reason “generated evidence”. It does so forevidenceand for theold-outputsymlink alias.- The allowed-sources test covers a disallowed subdirectory, and the Cargo output test covers a disallowed build-output directory. Both assert
PermissionDenied. - The Cargo output test also asserts the message names the path and contains “disallowed”.
git_tools_allow_staged_and_dirty_sources_but_hide_untracked_filescovers an untracked directory.explicit_untracked_reads_return_an_untracked_error_and_the_assessment_continuescovers the end-to-end case. It checks that the error text reaches the model, that the assessment continues, and that nothing is recorded.
I found no plausible requirement-violating behavior that these tests would accept.
Inputs
Tests
Input 4: outline src/authoring/pages.rs mod[tests]/fn[large_listings_and_outlines_page_whole_entries_in_order]
- File:
src/authoring/pages.rs - Selector:
mod[tests]/fn[large_listings_and_outlines_page_whole_entries_in_order] - Kind:
fn src/authoring/pages.rs:740–804
// {test}`requirements.authoring.tool_descriptions.special_cases`
// {test}`requirements.authoring.result_pages`
#[test]
// {test}`requirements.authoring.file_discovery`
fn large_listings_and_outlines_page_whole_entries_in_order() {
let root = project();
let names = (0..800)
.map(|index| format!("src/file_with_a_rather_long_name_{index:04}.rs"))
.collect::<Vec<_>>();
for name in &names {
fs::write(root.path().join(name), "fn f() {}\n").unwrap();
}
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mut pages = ResultPages::default();
let first =
dispatch_paged(&sources, &mut pages, "list_files", &json!({"path":"src"})).unwrap();
let delivered = all_pages(&mut pages, first);
let mut listed = Vec::new();
for page in &delivered {
assert!(page.result.to_string().len() <= PAGE_LIMIT);
assert!(page.inputs.is_empty());
assert_eq!(page.result.as_object().unwrap().len(), 2, "{}", page.result);
let entries = page.result["entries"].as_array().unwrap();
assert_eq!(
page.result["page"]["returned_entries"],
entries.len() as u64
);
listed.extend(
entries
.iter()
.map(|entry| entry["path"].as_str().unwrap().to_owned()),
);
}
// Whole entries, in the listing's order, each once.
let mut sorted = names.clone();
sorted.sort();
assert_eq!(listed, sorted);
// A page is filled before the next starts.
let first = delivered[0].result.to_string().len();
assert!(first > PAGE_LIMIT - 200, "{first}");
// An outline pages its top-level nodes, each with its children.
let mut source = String::new();
for index in 0..600 {
source.push_str(&format!("mod module_{index} {{\n fn inner() {{}}\n}}\n"));
}
fs::write(root.path().join("src/lib.rs"), source).unwrap();
let first = dispatch_paged(
&sources,
&mut pages,
"outline",
&json!({"file":"src/lib.rs"}),
)
.unwrap();
let delivered = all_pages(&mut pages, first);
let nodes = delivered
.iter()
.flat_map(|page| page.result["entries"].as_array().unwrap().clone())
.collect::<Vec<_>>();
assert_eq!(nodes.len(), 600);
for (index, node) in nodes.iter().enumerate() {
assert_eq!(node["name"], format!("module_{index}"));
assert_eq!(node["children"].as_array().unwrap().len(), 1);
}
}
Input 5: outline src/authoring/tools.rs mod[tests]/fn[additional_read_flow_searches_outlines_and_reads_a_rust_file]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[additional_read_flow_searches_outlines_and_reads_a_rust_file] - Kind:
fn src/authoring/tools.rs:1351–1495
// {test}`requirements.authoring.additional_read`
// {test}`requirements.authoring.github_reads`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.read_denial`
#[test]
fn additional_read_flow_searches_outlines_and_reads_a_rust_file() {
let root = project();
fs::write(
root.path().join("md/terms.md"),
":::{definition} value\n:phrase: value\nA useful value.\n:::\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn work() {{}}\n\nfn other() {{}}\n",
role("term", "terms.value")
),
)
.unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
for arguments in [json!({}), json!({"issue": 7})] {
let error = dispatch(&sources, "github", &arguments).err().unwrap();
assert!(
error
.to_string()
.contains("github expects exactly an issue field"),
"{error}"
);
}
// GitHub reads return tool errors here, since unit tests never contact
// GitHub, and are never evidence inputs.
for (issue, message) in [
("example/app#1", "cannot read GitHub issue example/app#1"),
("example/app", "is not an issue reference"),
] {
let error = dispatch(&sources, "github", &json!({ "issue": issue }))
.err()
.unwrap();
assert!(error.to_string().contains(message), "{error}");
}
let directories = dispatch(&sources, "list_files", &json!({})).unwrap();
let directory = directories
.result
.as_array()
.unwrap()
.iter()
.find(|entry| entry["path"] == "src")
.unwrap();
assert_eq!(directory["kind"], "directory");
assert!(directories.inputs.is_empty());
// The listing finds the directory's file and records nothing.
let listing = dispatch(&sources, "list_files", &json!({"path":directory["path"]})).unwrap();
assert_eq!(listing.result, json!([{"path":"src/lib.rs","kind":"file"}]));
assert!(listing.inputs.is_empty());
// Searching the Rust file returns the innermost item containing the match.
let search = dispatch(
&sources,
"ripgrep",
&json!({"path":"src/lib.rs","pattern":"work","context":0}),
)
.unwrap();
// It only locates the item: nothing is recorded and no definitions
// accompany it.
assert!(search.inputs.is_empty());
assert_eq!(
search.result["matches"],
json!([{
"file": "src/lib.rs", "item": "fn[work]", "kind": "fn", "tag":"1",
"lines": [{"text": "fn work() {}", "matched": true}],
}])
);
// Outlining it lists its items without content and records nothing.
let outline = dispatch(&sources, "outline", &json!({"file":"src/lib.rs"})).unwrap();
assert!(outline.inputs.is_empty());
let items = outline
.result
.get("entries")
.unwrap_or(&outline.result)
.as_array()
.unwrap()
.iter()
.map(|entry| entry["item"].as_str().unwrap())
.collect::<Vec<_>>();
assert_eq!(items, ["fn[work]", "fn[other]"]);
assert!(!outline.result.to_string().contains("fn other()"));
// Reading one item by selector returns it with its terminology.
let item = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","item":"fn[work]"}),
)
.unwrap();
assert_eq!(item.result["input"]["item"], "fn[work]");
assert!(
item.result["input"]["text"]
.as_array()
.unwrap()
.iter()
.any(|line| line == "fn work() {}")
);
assert_eq!(item.result["definitions"].as_array().unwrap().len(), 1);
assert_eq!(item.result["definitions"][0]["definition"], "terms.value");
assert!(
item.inputs
.iter()
.any(|input| input["definition"] == "terms.value")
);
assert_eq!(item.inputs.len(), 2);
sources.record_inputs(&item.inputs);
assert!(sources.recorded_inputs().contains(
&crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[work]").unwrap()
));
assert_eq!(sources.recorded_inputs().len(), 2);
// A line range without line_end reads through EOF.
let eof = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":2}),
)
.unwrap();
let covered = eof.result["inputs"]
.as_array()
.unwrap()
.iter()
.map(|input| input["item"].as_str().unwrap())
.collect::<Vec<_>>();
assert_eq!(covered, ["fn[work]", "fn[other]"]);
sources.record_inputs(&eof.inputs);
let recorded = sources.recorded_inputs();
for item in ["fn[work]", "fn[other]"] {
assert!(
recorded.contains(
&crate::inputs::outline_input(root.path(), "src/lib.rs", item).unwrap()
),
"{item} recorded: {recorded:?}"
);
}
assert!(
recorded
.iter()
.any(|input| input["definition"] == "terms.value"),
"terminology recorded: {recorded:?}"
);
}
Input 6: outline src/authoring/tools.rs mod[tests]/fn[listed_git_directories_need_an_eligible_descendant_at_any_depth]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[listed_git_directories_need_an_eligible_descendant_at_any_depth] - Kind:
fn src/authoring/tools.rs:1497–1530
// {test}`requirements.authoring.additional_read`
// {test}`requirements.authoring.file_discovery`
#[test]
fn listed_git_directories_need_an_eligible_descendant_at_any_depth() {
let root = project();
fs::create_dir_all(root.path().join("a/b")).unwrap();
fs::create_dir(root.path().join("blocked-only")).unwrap();
fs::write(root.path().join("a/b/file.txt"), "eligible\n").unwrap();
fs::write(root.path().join("blocked-only/hidden.txt"), "blocked\n").unwrap();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['blocked-only/hidden.txt']\n",
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let root_listing = dispatch(&sources, "list_files", &json!({})).unwrap();
let entries = root_listing.result.as_array().unwrap();
assert!(
entries
.iter()
.any(|e| e["path"] == "a" && e["kind"] == "directory"),
"{entries:?}"
);
assert!(
!entries.iter().any(|e| e["path"] == "blocked-only"),
"{entries:?}"
);
let nested = dispatch(&sources, "list_files", &json!({"path":"a"})).unwrap();
assert_eq!(nested.result, json!([{"path":"a/b","kind":"directory"}]));
assert!(root_listing.inputs.is_empty());
assert!(nested.inputs.is_empty());
}
Input 7: outline src/authoring/tools.rs mod[tests]/fn[reading_records_only_delivered_sources_and_their_terms]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[reading_records_only_delivered_sources_and_their_terms] - Kind:
fn src/authoring/tools.rs:1532–1649
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.definitions.authoring_inputs`
// {test}`requirements.authoring.no_line_numbers`
#[test]
fn reading_records_only_delivered_sources_and_their_terms() {
let root = project();
fs::write(
root.path().join("md/terms.md"),
":::{definition} value\n:phrase: value\nA useful value.\n:::\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!("// {}\nfn work() {{}}\n", role("term", "terms.value")),
)
.unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&sources, "list_files", &json!({"path":"src"})).unwrap();
assert_eq!(listing.result, json!([{"path":"src/lib.rs","kind":"file"}]));
assert!(listing.inputs.is_empty());
let read = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","item":"fn[work]"}),
)
.unwrap();
assert_eq!(read.inputs.len(), 2);
assert_eq!(read.result["input"]["item"], "fn[work]");
assert_eq!(read.result["input"]["kind"], "fn");
// Results give the selector, never line numbers.
assert!(read.result["input"].get("line_start").is_none());
assert!(read.result["input"].get("line_end").is_none());
assert_eq!(read.result["input"]["text"][1], "fn work() {}");
assert_eq!(read.result["definitions"][0]["definition"], "terms.value");
assert!(sources.recorded_inputs().is_empty());
sources.record_inputs(&read.inputs);
sources.record_inputs(&read.inputs);
assert_eq!(sources.recorded_inputs().len(), 2);
// Recorded outline inputs carry only the file, selector, and hash.
assert_eq!(
sources.recorded_inputs()[0],
crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[work]").unwrap()
);
let eof = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":2}),
)
.unwrap();
assert_eq!(eof.result["inputs"].as_array().unwrap().len(), 1);
assert_eq!(eof.result["inputs"][0]["item"], "fn[work]");
assert!(eof.result["inputs"][0].get("line_end").is_none());
// A line-range read supplies the terminology of what it delivers.
let fresh = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let lines = dispatch(
&fresh,
"habeas",
&json!({"file":"src/lib.rs","line_start":1}),
)
.unwrap();
assert_eq!(lines.result["definitions"][0]["definition"], "terms.value");
assert_eq!(lines.result["definitions"][0]["text"][1], ":phrase: value");
assert_eq!(lines.inputs.len(), 2);
assert!(
dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":3})
)
.is_err()
);
assert!(
dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","item":"fn[missing]"})
)
.is_err()
);
assert!(
dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":0})
)
.is_err()
);
// The provider-facing schema leaves selector fields optional; the
// harness still rejects incomplete, mixed, and unknown request forms.
for arguments in [
json!({}),
json!({"file":"src/lib.rs"}),
json!({"line_start":1}),
json!({"rust_file":"src/lib.rs","rust_item":"fn[work]"}),
json!({"item":"fn[work]"}),
json!({"file":"src/lib.rs","line_start":1,"definition":"terms.value"}),
json!({"file":"src/lib.rs","item":"fn[work]","line_start":1}),
json!({"file":"src/lib.rs","item":"fn[work]","requirements":"requirements.*"}),
json!({"requirements":"requirements.*","definition":"terms.value"}),
json!({"definition":"terms.value","extra":true}),
] {
assert!(
dispatch(&sources, "habeas", &arguments).is_err(),
"unexpectedly accepted {arguments}"
);
}
assert!(
dispatch(
&sources,
"habeas",
&json!({"requirements":"requirements.*"})
)
.is_ok()
);
assert!(dispatch(&sources, "habeas", &json!({"definition":"terms.value"})).is_ok());
}
Input 8: outline src/authoring/tools.rs mod[tests]/fn[search_merges_context_windows_and_respects_ignore_rules]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[search_merges_context_windows_and_respects_ignore_rules] - Kind:
fn src/authoring/tools.rs:1900–1976
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.additional_read`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.no_line_numbers`
#[test]
fn search_merges_context_windows_and_respects_ignore_rules() {
let root = project();
git(root.path(), &["init", "--quiet"]);
fs::write(root.path().join(".gitignore"), "ignored.txt\n").unwrap();
fs::write(root.path().join("ignored.txt"), "needle\n").unwrap();
fs::write(root.path().join(".hidden.txt"), "needle\n").unwrap();
let lines = (1..=20)
.map(|number| {
if number == 2 || number == 6 {
"needle".to_owned()
} else {
format!("line {number}")
}
})
.collect::<Vec<_>>();
fs::write(root.path().join("sample.txt"), lines.join("\n")).unwrap();
git(root.path(), &["add", "--force", "."]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let search = dispatch(&sources, "ripgrep", &json!({"pattern":"needle"})).unwrap();
// Each plain-text line is an item. Even a large context window must
// not include neighboring items.
assert!(search.inputs.is_empty());
let matches = search.result["matches"].as_array().unwrap();
assert_eq!(matches.len(), 2, "{matches:#?}");
let shown = matches
.iter()
.map(|entry| {
assert_eq!(entry["file"], "sample.txt");
assert_eq!(entry["kind"], "line");
assert!(entry.get("line_start").is_none());
entry["lines"]
.as_array()
.unwrap()
.iter()
.map(|line| {
assert!(line.get("line").is_none());
(
line["text"].as_str().unwrap(),
line["matched"].as_bool().unwrap(),
)
})
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
assert_eq!(shown, [vec![("needle", true)], vec![("needle", true)]]);
let exact = dispatch(
&sources,
"ripgrep",
&json!({"pattern":"needle","path":"sample.txt","context":0}),
)
.unwrap();
assert_eq!(
exact.result["matches"][0]["lines"],
json!([{"text": "needle", "matched": true}])
);
assert_eq!(
exact.result["matches"][1]["lines"],
json!([{"text": "needle", "matched": true}])
);
let absent = dispatch(&sources, "ripgrep", &json!({"pattern":"NEEDLE"})).unwrap();
assert_eq!(absent.result["matches"], json!([]));
assert!(dispatch(&sources, "ripgrep", &json!({"pattern":"["})).is_err());
assert!(
dispatch(
&sources,
"ripgrep",
&json!({"pattern":"needle","context":-1})
)
.is_err()
);
assert!(dispatch(&sources, "list_files", &json!({"path":"../"})).is_err());
}
Input 9: outline src/authoring/tools.rs mod[tests]/fn[generated_evidence_is_excluded_from_reads_search_and_discovery]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[generated_evidence_is_excluded_from_reads_search_and_discovery] - Kind:
fn src/authoring/tools.rs:1978–2115
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.structural_search`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.tool_descriptions.special_cases`
#[test]
fn generated_evidence_is_excluded_from_reads_search_and_discovery() {
let root = project();
fs::create_dir(root.path().join("evidence")).unwrap();
fs::create_dir(root.path().join("src/evidence")).unwrap();
fs::write(
root.path().join("evidence/old.json"),
"needle in a previous judgment\n",
)
.unwrap();
fs::write(
root.path().join("evidence/generated.rs"),
"fn generated() {}\n",
)
.unwrap();
fs::write(root.path().join("source.txt"), "needle in source\n").unwrap();
fs::write(
root.path().join("src/evidence/source.txt"),
"needle in nested source\n",
)
.unwrap();
#[cfg(unix)]
{
std::os::unix::fs::symlink(
root.path().join("evidence"),
root.path().join("old-output"),
)
.unwrap();
std::os::unix::fs::symlink(
root.path().join("evidence/old.json"),
root.path().join("old.json"),
)
.unwrap();
}
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let search = dispatch(
&sources,
"ripgrep",
&json!({"pattern":"needle", "context":0}),
)
.unwrap();
let files = matched(&search)
.iter()
.map(|input| input["file"].as_str().unwrap())
.collect::<Vec<_>>();
assert_eq!(files, vec!["source.txt", "src/evidence/source.txt"]);
let structural = dispatch(
&sources,
"ast_grep",
&json!({"language":"rust","rule":{"rule":{"kind":"function_item"}}}),
)
.unwrap();
assert!(matched(&structural).is_empty(), "{:?}", structural.result);
assert!(
dispatch(
&sources,
"ast_grep",
&json!({"language":"rust","rule":{"rule":{"kind":"function_item"}},"path":"evidence"}),
)
.err()
.unwrap()
.to_string()
.contains("generated evidence")
);
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
assert!(listing.result.as_array().unwrap().iter().all(|entry| {
!["evidence", "old-output", "old.json"].contains(&entry["path"].as_str().unwrap())
}));
for path in ["evidence/old.json", "./evidence/old.json"] {
let error = dispatch(&sources, "habeas", &json!({"file":path, "line_start":1}))
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied);
assert!(error.to_string().contains("evidence/old.json"), "{error}");
assert!(error.to_string().contains("generated evidence"), "{error}");
assert!(sources.recorded_inputs().is_empty());
}
for (name, arguments) in [
(
"habeas",
json!({"file":"evidence/generated.rs", "item":"fn[generated]"}),
),
("list_files", json!({"path":"evidence"})),
("ripgrep", json!({"path":"evidence", "pattern":"needle"})),
(
"ast_grep",
json!({"path":"evidence", "language":"rust","rule":{"rule":{"kind":"function_item"}}}),
),
] {
let error = dispatch(&sources, name, &arguments).err().unwrap();
let path = arguments["file"]
.as_str()
.or_else(|| arguments["path"].as_str())
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied);
assert!(error.to_string().contains(path), "{error}");
assert!(error.to_string().contains("generated evidence"), "{error}");
assert!(sources.recorded_inputs().is_empty());
}
#[cfg(unix)]
{
for path in ["old.json", "old-output/old.json"] {
assert!(
dispatch(&sources, "habeas", &json!({"file":path, "line_start":1}))
.err()
.unwrap()
.to_string()
.contains("generated evidence")
);
assert!(
dispatch(
&sources,
"ripgrep",
&json!({"path":path, "pattern":"needle"})
)
.err()
.unwrap()
.to_string()
.contains("generated evidence")
);
}
assert!(
dispatch(&sources, "list_files", &json!({"path":"old-output"}))
.err()
.unwrap()
.to_string()
.contains("generated evidence")
);
}
}
Input 10: outline src/authoring/tools.rs mod[tests]/fn[outside_symlinks_are_excluded_from_reads_search_and_discovery]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[outside_symlinks_are_excluded_from_reads_search_and_discovery] - Kind:
fn src/authoring/tools.rs:2117–2157
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
#[cfg(unix)]
#[test]
fn outside_symlinks_are_excluded_from_reads_search_and_discovery() {
let root = project();
let outside = tempfile::tempdir().unwrap();
fs::write(outside.path().join("secret.rs"), "fn outside_needle() {}\n").unwrap();
std::os::unix::fs::symlink(outside.path(), root.path().join("outside")).unwrap();
std::os::unix::fs::symlink(
outside.path().join("secret.rs"),
root.path().join("outside.rs"),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
assert!(listing.result.as_array().unwrap().iter().all(|entry| {
!["outside", "outside.rs"].contains(&entry["path"].as_str().unwrap())
}));
let search = dispatch(&sources, "ripgrep", &json!({"pattern":"outside_needle"})).unwrap();
assert!(matched(&search).is_empty());
for path in ["outside/secret.rs", "outside.rs"] {
for arguments in [
json!({"file":path, "line_start":1}),
json!({"file":path, "line_start":1, "line_end":1}),
json!({"file":path, "item":"fn[outside_needle]"}),
] {
assert!(dispatch(&sources, "habeas", &arguments).is_err());
}
assert!(
dispatch(
&sources,
"ripgrep",
&json!({"path":path, "pattern":"needle"})
)
.is_err()
);
}
assert!(dispatch(&sources, "list_files", &json!({"path":"outside"})).is_err());
}
Input 11: outline src/authoring/tools.rs mod[tests]/fn[git_tools_allow_staged_and_dirty_sources_but_hide_untracked_files]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[git_tools_allow_staged_and_dirty_sources_but_hide_untracked_files] - Kind:
fn src/authoring/tools.rs:2285–2356
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.read_denial`
#[test]
fn git_tools_allow_staged_and_dirty_sources_but_hide_untracked_files() {
let root = project();
fs::create_dir(root.path().join("tracked-dir")).unwrap();
fs::write(root.path().join("tracked-dir/file.txt"), "original\n").unwrap();
fs::write(root.path().join("staged.txt"), "needle staged\n").unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
fs::write(root.path().join("tracked-dir/file.txt"), "needle dirty\n").unwrap();
fs::create_dir(root.path().join("untracked-dir")).unwrap();
fs::write(
root.path().join("untracked-dir/file.txt"),
"needle hidden\n",
)
.unwrap();
fs::write(root.path().join("untracked.rs"), "fn needle() {}\n").unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
assert_eq!(
listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.map(|entry| entry["path"].as_str().unwrap())
.collect::<Vec<_>>(),
vec!["Cargo.toml", "book.toml", "md", "staged.txt", "tracked-dir"]
);
for (path, text) in [
("staged.txt", "needle staged"),
("tracked-dir/file.txt", "needle dirty"),
] {
let read = dispatch(&sources, "habeas", &json!({"file":path, "line_start":1})).unwrap();
assert_eq!(read.result["inputs"][0]["text"], json!([text]));
}
let search = dispatch(&sources, "ripgrep", &json!({"pattern":"needle"})).unwrap();
assert_eq!(
matched(&search)
.iter()
.map(|input| input["file"].as_str().unwrap())
.collect::<Vec<_>>(),
vec!["staged.txt", "tracked-dir/file.txt"]
);
for arguments in [
json!({"file":"untracked.rs", "line_start":1}),
json!({"file":"untracked.rs", "line_start":1, "line_end":1}),
json!({"file":"untracked.rs", "item":"fn[needle]"}),
] {
let error = dispatch(&sources, "habeas", &arguments).err().unwrap();
assert!(error.to_string().contains("git add"), "{error}");
}
let error = dispatch(&sources, "outline", &json!({"file":"untracked.rs"}))
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("git add"), "{error}");
assert!(dispatch(&sources, "list_files", &json!({"path":"untracked-dir"})).is_err());
assert!(
dispatch(
&sources,
"ripgrep",
&json!({"path":"untracked.rs", "pattern":"needle"})
)
.is_err()
);
}
Input 12: outline src/authoring/tools.rs mod[tests]/fn[git_symlink_reads_require_both_the_alias_and_target_to_be_tracked]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[git_symlink_reads_require_both_the_alias_and_target_to_be_tracked] - Kind:
fn src/authoring/tools.rs:2358–2430
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.read_denial`
#[cfg(unix)]
#[test]
fn git_symlink_reads_require_both_the_alias_and_target_to_be_tracked() {
let root = project();
fs::write(root.path().join("tracked.txt"), "needle allowed\n").unwrap();
fs::write(root.path().join("untracked.txt"), "needle hidden\n").unwrap();
for (alias, target) in [
("tracked-alias.txt", "tracked.txt"),
("untracked-target.txt", "untracked.txt"),
("untracked-alias.txt", "tracked.txt"),
] {
std::os::unix::fs::symlink(target, root.path().join(alias)).unwrap();
}
git(root.path(), &["init", "--quiet"]);
git(
root.path(),
&[
"add",
"Cargo.toml",
"book.toml",
"md",
"tracked.txt",
"tracked-alias.txt",
"untracked-target.txt",
],
);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let allowed = dispatch(
&sources,
"habeas",
&json!({"file":"tracked-alias.txt", "line_start":1}),
)
.unwrap();
assert_eq!(
allowed.result["inputs"][0]["text"],
json!(["needle allowed"])
);
for alias in ["untracked-target.txt", "untracked-alias.txt"] {
assert!(
dispatch(&sources, "habeas", &json!({"file":alias, "line_start":1}))
.err()
.unwrap()
.to_string()
.contains("git add")
);
assert!(
dispatch(
&sources,
"ripgrep",
&json!({"path":alias, "pattern":"needle"})
)
.is_err()
);
}
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
let paths = listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.map(|entry| entry["path"].as_str().unwrap())
.collect::<Vec<_>>();
assert!(paths.contains(&"tracked-alias.txt"));
assert!(!paths.contains(&"untracked-target.txt"));
assert!(!paths.contains(&"untracked-alias.txt"));
assert!(!paths.contains(&"untracked.txt"));
}
Input 13: outline src/authoring/tools.rs mod[tests]/fn[allowed_ignored_and_external_sources_are_discoverable_but_disallowed_descendants_are_not]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[allowed_ignored_and_external_sources_are_discoverable_but_disallowed_descendants_are_not] - Kind:
fn src/authoring/tools.rs:2432–2566
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.structural_search`
#[test]
fn allowed_ignored_and_external_sources_are_discoverable_but_disallowed_descendants_are_not() {
let root = project();
let external = tempfile::tempdir().unwrap();
fs::create_dir_all(root.path().join("generated/private")).unwrap();
fs::write(
root.path().join("generated/visible.txt"),
"needle allowed\n",
)
.unwrap();
fs::write(
root.path().join("generated/private/hidden.txt"),
"needle denied\n",
)
.unwrap();
fs::write(external.path().join("outside.txt"), "needle external\n").unwrap();
fs::write(external.path().join("outside.rs"), "fn external() {}\n").unwrap();
fs::write(
root.path().join("generated/visible.rs"),
"fn visible() {}\n",
)
.unwrap();
fs::write(
root.path().join("generated/private/denied.rs"),
"fn denied() {}\n",
)
.unwrap();
fs::write(root.path().join(".hidden.rs"), "fn hidden() {}\n").unwrap();
fs::write(root.path().join(".gitignore"), "generated/\n").unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let external_toml = toml::Value::String(external.path().display().to_string());
fs::write(root.path().join("habeas.toml"), format!(
"version = 1\n[evidence]\nallow = ['generated', '.hidden.rs', {external_toml}]\ndisallow = ['generated/private']\n"
)).unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
let paths = listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.map(|entry| entry["path"].as_str().unwrap())
.collect::<Vec<_>>();
assert!(paths.contains(&"generated"));
assert!(paths.contains(&external.path().to_str().unwrap()));
let generated = dispatch(&sources, "list_files", &json!({"path":"generated"})).unwrap();
assert_eq!(
generated.result,
json!([
{"path":"generated/visible.rs", "kind":"file"},
{"path":"generated/visible.txt", "kind":"file"}
])
);
assert!(generated.inputs.is_empty());
let external_listing =
dispatch(&sources, "list_files", &json!({"path":external.path()})).unwrap();
assert_eq!(
external_listing.result,
json!([
{"path":external.path().join("outside.rs"),"kind":"file"},
{"path":external.path().join("outside.txt"),"kind":"file"}
])
);
assert!(external_listing.inputs.is_empty());
let structural = dispatch(
&sources,
"ast_grep",
&json!({"language":"rust","rule":{"rule":{"kind":"function_item"}}}),
)
.unwrap();
let structural_files = matched(&structural)
.iter()
.map(|entry| entry["file"].as_str().unwrap())
.collect::<Vec<_>>();
for expected in [
".hidden.rs",
"generated/visible.rs",
external.path().join("outside.rs").to_str().unwrap(),
] {
assert!(structural_files.contains(&expected), "{structural_files:?}");
}
assert!(!structural_files.contains(&"generated/private/denied.rs"));
assert!(structural.inputs.is_empty());
let search = dispatch(
&sources,
"ripgrep",
&json!({"pattern":"needle", "context":0}),
)
.unwrap();
assert_eq!(matched(&search).len(), 2);
assert!(
matched(&search)
.iter()
.any(|input| input["file"] == "generated/visible.txt")
);
assert!(matched(&search).iter().any(|input| input["file"] == external.path().join("outside.txt").to_str().unwrap()));
let read = dispatch(
&sources,
"habeas",
&json!({"file":external.path().join("outside.txt"), "line_start":1}),
)
.unwrap();
assert_eq!(read.result["inputs"][0]["text"], json!(["needle external"]));
for (name, args) in [
(
"habeas",
json!({"file":"generated/private/hidden.txt", "line_start":1}),
),
("list_files", json!({"path":"generated/private"})),
(
"ripgrep",
json!({"path":"generated/private", "pattern":"needle"}),
),
(
"ast_grep",
json!({"path":"generated/private","language":"rust","rule":{"rule":{"kind":"function_item"}}}),
),
] {
assert_eq!(
dispatch(&sources, name, &args).err().unwrap().kind(),
io::ErrorKind::PermissionDenied
);
}
}
Input 14: outline src/authoring/tools.rs mod[tests]/fn[cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files] - Kind:
fn src/authoring/tools.rs:2568–2703
// {test}`requirements.authoring.generated_inputs`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.read_denial.build_output`
// {test}`requirements.authoring.structural_search`
#[test]
fn cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files() {
let root = project();
fs::write(root.path().join("src/lib.rs"), "pub fn ready() {}\n").unwrap();
fs::write(
root.path().join("Cargo.lock"),
"version = 4\n\n[[package]]\nname = 'fixture'\nversion = '0.1.0'\n",
)
.unwrap();
fs::write(root.path().join(".gitignore"), "target/\n").unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let unbuilt = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
dispatch(
&unbuilt,
"habeas",
&json!({"file":"src/lib.rs", "line_start":1})
)
.is_ok()
);
assert!(!root.path().join("target").exists());
let out = root.path().join("target/debug/build/fixture-hash/out");
fs::create_dir_all(&out).unwrap();
fs::write(out.join("generated.rs"), "pub fn generated_needle() {}\n").unwrap();
fs::write(
out.parent().unwrap().join("root-output"),
out.to_str().unwrap(),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
assert!(
listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.any(|entry| entry["path"] == "target/debug/build/fixture-hash/out")
);
let search = dispatch(&sources, "ripgrep", &json!({"pattern":"generated_needle"})).unwrap();
let generated = dispatch(
&sources,
"list_files",
&json!({"path":"target/debug/build/fixture-hash/out"}),
)
.unwrap();
assert_eq!(
generated.result,
json!([{"path":"target/debug/build/fixture-hash/out/generated.rs","kind":"file"}])
);
assert!(generated.inputs.is_empty());
assert_eq!(matched(&search).len(), 1);
let structural_arguments =
json!({"language":"rust","rule":{"rule":{"pattern":"pub fn generated_needle() {}"}}});
let structural = dispatch(&sources, "ast_grep", &structural_arguments).unwrap();
assert_eq!(
found(&structural),
["target/debug/build/fixture-hash/out/generated.rs#fn[generated_needle]"]
);
assert!(structural.inputs.is_empty());
let read = dispatch(&sources, "habeas", &json!({"file":"target/debug/build/fixture-hash/out/generated.rs", "item":"fn[generated_needle]"})).unwrap();
assert_eq!(
read.result["input"]["text"],
json!(["pub fn generated_needle() {}"])
);
// Other build output under target is an ordinary read failure.
let error = dispatch(
&sources,
"habeas",
&json!({"file":"target/debug/build/fixture-hash/root-output", "line_start":1}),
)
.err()
.unwrap();
assert_ne!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("holds build output"), "{error}");
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['target/debug/build/fixture-hash/out']\n",
)
.unwrap();
let denied = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&denied, "list_files", &json!({})).unwrap();
assert!(
!listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.any(|entry| entry["path"] == "target/debug/build/fixture-hash/out")
);
assert!(
matched(&dispatch(&denied, "ripgrep", &json!({"pattern":"generated_needle"})).unwrap())
.is_empty()
);
assert!(matched(&dispatch(&denied, "ast_grep", &structural_arguments).unwrap()).is_empty());
for (name, arguments) in [
(
"habeas",
json!({"file":"target/debug/build/fixture-hash/out/generated.rs", "line_start":1}),
),
(
"list_files",
json!({"path":"target/debug/build/fixture-hash/out"}),
),
(
"ripgrep",
json!({"path":"target/debug/build/fixture-hash/out", "pattern":"generated_needle"}),
),
(
"ast_grep",
json!({"path":"target/debug/build/fixture-hash/out","language":"rust","rule":{"rule":{"kind":"function_item"}}}),
),
] {
let error = dispatch(&denied, name, &arguments).err().unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("disallowed"), "{error}");
let path = arguments["file"]
.as_str()
.or_else(|| arguments["path"].as_str())
.unwrap();
assert!(error.to_string().contains(path), "{error}");
}
}
Input 15: outline src/authoring/tools.rs mod[tests]/fn[unpermitted_requests_outside_the_project_are_recoverable_tool_errors]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[unpermitted_requests_outside_the_project_are_recoverable_tool_errors] - Kind:
fn src/authoring/tools.rs:3086–3144
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.outline_tool`
// {test}`requirements.authoring.tool_descriptions.special_cases`
#[test]
fn unpermitted_requests_outside_the_project_are_recoverable_tool_errors() {
let root = project();
let external = tempfile::tempdir().unwrap();
fs::write(external.path().join("lib.rs"), "fn external() {}\n").unwrap();
let file = external.path().join("lib.rs");
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let requests = [
("habeas", json!({"file": file, "line_start": 1})),
("habeas", json!({"file": file, "item": "fn[external]"})),
("list_files", json!({"path": external.path()})),
("outline", json!({"file": file})),
(
"ripgrep",
json!({"path": external.path(), "pattern": "external"}),
),
];
for (name, arguments) in &requests {
let error = dispatch(&sources, name, arguments).err().unwrap();
assert_ne!(
error.kind(),
io::ErrorKind::PermissionDenied,
"{name}: {error}"
);
assert!(error.to_string().contains("outside the project"), "{error}");
}
assert!(sources.recorded_inputs().is_empty());
// A matching disallow still aborts, as do in-project denials.
fs::write(
root.path().join("habeas.toml"),
format!(
"version = 1\n[evidence]\ndisallow = [{:?}]\n",
external.path().to_str().unwrap()
),
)
.unwrap();
fs::create_dir_all(root.path().join("evidence")).unwrap();
fs::write(root.path().join("evidence/old.json"), "{}\n").unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
for (name, arguments) in &requests[..1] {
let error = dispatch(&sources, name, arguments).err().unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
}
let error = dispatch(
&sources,
"habeas",
&json!({"file": "evidence/old.json", "item": ""}),
)
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
}
Input 16: outline src/authoring/tools.rs mod[tests]/fn[failed_listings_return_explanatory_tool_errors]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[failed_listings_return_explanatory_tool_errors] - Kind:
fn src/authoring/tools.rs:4379–4398
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.read_denial`
#[test]
fn failed_listings_return_explanatory_tool_errors() {
let root = project();
fs::write(root.path().join("src/lib.rs"), "fn work() {}\n").unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
for (arguments, message) in [
(json!({"path": "missing"}), "cannot"),
(json!({"path": "src/lib.rs"}), "cannot list"),
(json!({"path": 3}), "path"),
(json!({"path": ".", "extra": true}), "extra"),
] {
let error = dispatch(&sources, "list_files", &arguments)
.err()
.unwrap_or_else(|| panic!("{arguments} fails"));
assert_ne!(error.kind(), io::ErrorKind::PermissionDenied, "{arguments}");
assert!(error.to_string().contains(message), "{arguments}: {error}");
}
}
Input 17: outline tests/authoring_cli.rs fn[explicit_untracked_reads_return_an_untracked_error_and_the_assessment_continues]
- File:
tests/authoring_cli.rs - Selector:
fn[explicit_untracked_reads_return_an_untracked_error_and_the_assessment_continues] - Kind:
fn tests/authoring_cli.rs:853–922
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.structural_search`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.read_denial.untracked`
// {test}`requirements.authoring.read_denial`
#[test]
fn explicit_untracked_reads_return_an_untracked_error_and_the_assessment_continues() {
for (tool, arguments) in [
("habeas", json!({"file":"untracked.txt", "line_start":1})),
(
"ripgrep",
json!({"path":"untracked.txt", "pattern":"hidden"}),
),
(
"ast_grep",
json!({"path":"untracked.txt", "language":"rust", "rule":{"rule":{"pattern":"hidden"}}}),
),
("list_files", json!({"path":"untracked-directory"})),
] {
let server = Server::start(vec![
reply(vec![call("denied", tool, arguments)]),
reply(vec![call(
"submit",
"submit_judgment",
json!({"determination": true, "rationale": "The tracked sources support it."}),
)]),
]);
let fixture = Fixture::new(&server.endpoint);
for args in [["init", "--quiet"], ["add", "."]] {
let git = Command::new("git")
.current_dir(&fixture.project)
.args(args)
.output()
.unwrap();
assert!(git.status.success(), "{git:?}");
}
fs::write(fixture.project.join("untracked.txt"), "hidden source\n").unwrap();
fs::create_dir(fixture.project.join("untracked-directory")).unwrap();
fs::write(
fixture.project.join("untracked-directory/hidden.txt"),
"hidden source\n",
)
.unwrap();
let output = fixture.run(&["author", SUBJECT, "--stdout"]);
assert!(output.status.success(), "{tool}: {output:?}");
// The model was told the path is untracked and how to fix it, and
// the file was neither delivered nor recorded.
let requests = server.finish();
assert_eq!(requests.len(), 2, "{tool}");
let second = requests[1].body.to_string();
assert!(
second.contains("is untracked") || second.contains("untracked, so"),
"{tool}: {second}"
);
assert!(second.contains("git add"), "{tool}: {second}");
assert!(!second.contains("hidden source"), "{tool}: {second}");
let evidence = String::from_utf8_lossy(&output.stdout);
assert!(!evidence.contains("untracked"), "{tool}: {evidence}");
let usage = fixture.usage();
assert_eq!(usage["outcome"], "completed", "{tool}: {usage}");
assert_eq!(usage["request_count"], 2, "{tool}: {usage}");
assert_eq!(usage["tool_failures"][tool], 1, "{tool}: {usage}");
}
}
Referenced definitions
Input 2: requirements selection requirements.authoring.read_denial
requirements.authoring.read_denial:md/requirements/authoring.md:701–708
:::{req} read_denial
When source-access policy denies a path that a model tool call names
explicitly, the harness MUST return a tool error naming the path and the reason
it cannot be read, add no evidence input, and continue the assessment.
Discovery and search MUST leave denied candidates out of their entries,
reporting untracked ones under {cite}`requirements.authoring.not_listed`. Malformed tool
arguments and ordinary read failures MUST also return explanatory tool errors.
:::
Input 3: 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.
:::
Other sources
Input 1: requirements selection requirements.authoring.file_discovery
requirements.authoring.file_discovery:md/requirements/authoring.md:762–786
:::{req} file_discovery
The harness MUST expose a `list_files` tool with this interface:
```text
list_files({ path: String = "." }) -> Array<DirectoryEntry>
DirectoryEntry {
path: String,
kind: "file" | "directory",
}
```
The tool MUST list the immediate children of the requested directory, returning
project-relative paths where possible and absolute paths for permitted external
files. Its root listing MUST also expose available generated-output directories
and configured external allow paths. The model can list a returned
directory in another call to explore further. A failed listing MUST return an
explanatory tool error unless access was denied, which MUST be handled under
{cite}`requirements.authoring.read_denial`. Directory listings MUST NOT become evidence inputs.
Listings MUST omit files excluded by {cite}`requirements.authoring.source_tools`.
In a Git worktree, directories MUST have at least one eligible source
descendant to be listed unless explicitly allowed or discovered as generated
output. Explicitly requesting an excluded path MUST be handled as a denial under
{cite}`requirements.authoring.read_denial`.
:::