requirements.authoring.source_tools
Requirements index · View definition
Requirement
The harness MUST expose a
habeastool accepting exactly one of these request forms. Each form MUST correspond to one existing evidence-input kind:Selector arguments MUST use the syntax defined by
. 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. Generated build outputs MUST follow
. Workspace path overrides MUST follow
, including explicit permission for otherwise excluded inputs. A denied mandatory input MUST abort under
, and a denied model read MUST return a tool error under
.
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_endMUST read through EOF. A line-range request MUST be resolved to the innermost outline nodes covering the requested lines, which arelinenodes 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.
Required terminology dependencies MUST be returned alongside it as additional definition inputs under
. For item, requirement, and definition selections, the result MUST have this shape:
HabeasResult { input: EvidenceInput, definitions: Array<DefinitionInput>, }Line-range selections can contain multiple outline nodes. Their result MUST use
inputs: Array<EvidenceInput>instead of the singularinputfield, including when only one node is selected.
definitionsMUST 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; other failed reads MUST return an explanatory tool error.
Rationale
I judge the supplied tests adequate for requirements.authoring.source_tools. I did not request implementation source, because the supplied tests and their assertions were enough to map each obligation.
Request forms and argument validation
reading_records_only_delivered_sources_and_their_termsaccepts each valid form: file withline_start, file withitem,requirementsanddefinition.- The same test rejects incomplete, mixed and unknown forms. Examples are
{},filealone,line_startalone,itemalone, file with bothitemandline_start,requirementswithdefinition, and an extra field. - It also rejects
line_start0, aline_startbeyond EOF, and a missing item.
Line numbers
reading_records_only_delivered_sources_and_their_termsshows that an omittedline_endreads through EOF (line_start2).line_range_reads_record_the_innermost_covering_nodescovers the explicitline_endand inclusive endpoints. A 3–7 range yieldsfn[first]andmod[inner], and a 7–7 range yields the nestedmod[inner]/fn[second].- The same test covers plain-text
line@…nodes innotes.txt. - It checks that results and recorded inputs carry no
line_startorline_end, and that recorded outline inputs carry notext.
Result shape and recording
- A line-range read returns
inputs, including a single node. An item,requirementsordefinitionread returnsinput.declaration_text_reaches_the_model_redactedasserts thatinputsis absent for the latter two. requirements_reads_select_requirements_and_examples_but_not_definitionsasserts thatdefinitionsis[]when no terms are needed.declaration_text_reaches_the_model_redactedchecks the transitive terminology (terms.base,terms.value) returned alongside a read, and that the recorded inputs equal the delivered ones.- Duplicate recording is deduplicated, and failed reads record nothing. The tool-error tests assert
recorded_inputs().is_empty()after denials. requirements_reads_select_requirements_and_examples_but_not_definitionsshows that a selection matching only a definition returns an explanatory error.
Tool description
habeas_tool_describes_its_argument_conventions_with_an_example_per_formasserts the selector syntax, the definition-selection and full-name conventions, and a request example for each of the four forms.
Working tree, Git index and containment
git_tools_allow_staged_and_dirty_sources_but_hide_untracked_filescovers dirty tracked files, staged new files and untracked rejection.git_symlink_reads_require_both_the_alias_and_target_to_be_trackedcovers the requirement that both the requested file and its resolved target are in the index.outside_symlinks_are_excluded_from_reads_search_and_discoveryandunpermitted_requests_outside_the_project_are_recoverable_tool_errorscover project containment and symlinks.nested_project_uses_only_its_part_of_the_git_indexcovers a project nested inside a parent worktree.empty_git_directory_in_an_ancestor_does_not_make_a_project_a_worktreecovers a project outside Git, with containment but no index.unreadable_git_index_does_not_fall_back_to_untracked_accessandinvalid_git_configuration_does_not_fall_back_to_untracked_accessassert that an index or Git failure is reported as an error rather than silently falling back.
evidence/ exclusion, generated outputs and path overrides
generated_evidence_is_excluded_from_reads_search_and_discoverycoversevidence/exclusion acrosshabeas,list_files,ripgrepandast_grep, including symlink aliases.cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_filescovers build-output discovery without building. It also checks that othertargetfiles are not allowed, that the model’s root listing exposes the output directory, and that a disallow overrides the permission.inherited_out_dir_is_ignored_and_metadata_failure_preserves_ordinary_readscovers an inheritedOUT_DIRbeing ignored and invalid Cargo metadata being tolerated.explicit_allow_overrides_defaults_but_disallow_wins_for_alias_targets,disallowed_ancestors_cannot_redirect_reads_into_allowed_targets,policy_resolves_symlinks_before_parent_components_without_allowing_wrong_subtreesandallowed_ignored_and_external_sources_are_discoverable_but_disallowed_descendants_are_notcover allow and disallow precedence, symlink targets and external paths.
Redaction
model_inputs_reads_searches_and_citation_prompts_are_redactedanddeclaration_text_reaches_the_model_redactedcheck that every supplied source is redacted. The checked sources are mandatory inputs,habeasreads, line ranges, requirements and definition reads, and search results.
Read denial
- The tool-error behaviour is covered by the denial tests above and by
explicit_untracked_reads_return_an_untracked_error_and_the_assessment_continuesintests/authoring_cli.rs. mandatory_git_inputs_require_staging_declarations_sources_and_termscovers an abort when a mandatory input is untracked.- The details of
read_denialandread_denial.mandatorybelong to those cited requirements and are not reassessed here.
Remaining obligations
- Selector syntax and structural hashing are cited requirements. The tests use representative selectors:
kind[name], nested paths,use@…andline@….
I found no requirement-violating behaviour that these tests would accept.
Inputs
Tests
Input 13: outline src/authoring/access.rs mod[tests]/fn[nested_project_uses_only_its_part_of_the_git_index]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[nested_project_uses_only_its_part_of_the_git_index] - Kind:
fn src/authoring/access.rs:749–764
// {test}`requirements.authoring.source_tools`
#[test]
fn nested_project_uses_only_its_part_of_the_git_index() {
let parent = tempfile::tempdir().unwrap();
let root = parent.path().join("project");
fs::create_dir(&root).unwrap();
fs::write(root.join("inside.txt"), "inside\n").unwrap();
fs::write(parent.path().join("outside.txt"), "outside\n").unwrap();
git(parent.path(), &["init", "--quiet"]);
git(parent.path(), &["add", "."]);
let root = fs::canonicalize(root).unwrap();
let access = SourceAccess::load(&root).unwrap();
assert!(access.file(&root, Path::new("./inside.txt")).is_ok());
assert!(access.file(&root, Path::new("../outside.txt")).is_err());
assert!(access.file(&root, Path::new("outside.txt")).is_err());
}
Input 14: outline src/authoring/access.rs mod[tests]/fn[unreadable_git_index_does_not_fall_back_to_untracked_access]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[unreadable_git_index_does_not_fall_back_to_untracked_access] - Kind:
fn src/authoring/access.rs:817–830
// {test}`requirements.authoring.source_tools`
#[test]
fn unreadable_git_index_does_not_fall_back_to_untracked_access() {
let root = tempfile::tempdir().unwrap();
fs::write(root.path().join("source.txt"), "source\n").unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
fs::write(root.path().join(".git/index"), "invalid index\n").unwrap();
let error = SourceAccess::load(root.path()).err().unwrap();
assert!(
error.to_string().contains("cannot read Git index"),
"{error}"
);
}
Input 15: outline src/authoring/access.rs mod[tests]/fn[empty_git_directory_in_an_ancestor_does_not_make_a_project_a_worktree]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[empty_git_directory_in_an_ancestor_does_not_make_a_project_a_worktree] - Kind:
fn src/authoring/access.rs:832–845
// {test}`requirements.authoring.source_tools`
#[test]
fn empty_git_directory_in_an_ancestor_does_not_make_a_project_a_worktree() {
let parent = tempfile::tempdir().unwrap();
fs::create_dir(parent.path().join(".git")).unwrap();
let root = parent.path().join("project");
fs::create_dir(&root).unwrap();
fs::write(root.join("source.txt"), "source\n").unwrap();
let root = fs::canonicalize(root).unwrap();
let access = SourceAccess::load(&root).unwrap();
assert!(access.tracked.is_none());
assert!(access.file(&root, Path::new("source.txt")).is_ok());
assert!(access.file(&root, Path::new("../outside.txt")).is_err());
}
Input 16: outline src/authoring/access.rs mod[tests]/fn[invalid_git_configuration_does_not_fall_back_to_untracked_access]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[invalid_git_configuration_does_not_fall_back_to_untracked_access] - Kind:
fn src/authoring/access.rs:847–858
// {test}`requirements.authoring.source_tools`
#[test]
fn invalid_git_configuration_does_not_fall_back_to_untracked_access() {
let root = tempfile::tempdir().unwrap();
git(root.path(), &["init", "--quiet"]);
fs::write(root.path().join(".git/config"), "[invalid config\n").unwrap();
let error = SourceAccess::load(root.path()).err().unwrap();
assert!(
error.to_string().contains("cannot discover Git worktree"),
"{error}"
);
}
Input 17: outline src/authoring/access.rs mod[tests]/fn[explicit_allow_overrides_defaults_but_disallow_wins_for_alias_targets]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[explicit_allow_overrides_defaults_but_disallow_wins_for_alias_targets] - Kind:
fn src/authoring/access.rs:860–906
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.ci.input_containment`
#[test]
fn explicit_allow_overrides_defaults_but_disallow_wins_for_alias_targets() {
let root = tempfile::tempdir().unwrap();
let external = tempfile::tempdir().unwrap();
fs::create_dir_all(root.path().join("generated/private")).unwrap();
fs::create_dir(root.path().join("evidence")).unwrap();
fs::write(root.path().join("generated/ok.txt"), "generated\n").unwrap();
fs::write(root.path().join("generated/private/secret.txt"), "secret\n").unwrap();
fs::write(root.path().join("evidence/old.txt"), "old judgment\n").unwrap();
fs::write(external.path().join("outside.txt"), "outside\n").unwrap();
git(root.path(), &["init", "--quiet"]);
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', 'evidence', {external_toml}]\ndisallow = ['generated/private']\n"
)).unwrap();
let root = fs::canonicalize(root.path()).unwrap();
let access = SourceAccess::load(&root).unwrap();
for path in [
root.join("generated/ok.txt"),
root.join("evidence/old.txt"),
external.path().join("outside.txt"),
] {
assert!(access.file(&root, &path).is_ok(), "{}", path.display());
assert!(resolve_evidence_file(&root, path.to_str().unwrap()).is_ok());
}
let error = access
.file(&root, Path::new("generated/private/secret.txt"))
.unwrap_err();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied);
assert!(resolve_evidence_file(&root, "generated/private/secret.txt").is_err());
#[cfg(unix)]
{
std::os::unix::fs::symlink(
root.join("generated/private/secret.txt"),
root.join("generated/alias.txt"),
)
.unwrap();
let error = access
.file(&root, Path::new("generated/alias.txt"))
.unwrap_err();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied);
}
}
Input 18: outline src/authoring/access.rs mod[tests]/fn[workspace_configuration_with_credentials_is_readable_unless_disallowed]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[workspace_configuration_with_credentials_is_readable_unless_disallowed] - Kind:
fn src/authoring/access.rs:974–996
// {test}`requirements.authoring.credentials`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.source_tools`
#[test]
fn workspace_configuration_with_credentials_is_readable_unless_disallowed() {
let root = tempfile::tempdir().unwrap();
let config = "version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'fixture'\napi_key = 'TEST_KEY'\n";
fs::write(root.path().join("habeas.toml"), config).unwrap();
let access = SourceAccess::load(root.path()).unwrap();
assert!(access.file(root.path(), Path::new("habeas.toml")).is_ok());
fs::write(
root.path().join("habeas.toml"),
format!("{config}\n[evidence]\ndisallow = ['habeas.toml']\n"),
)
.unwrap();
let error = SourceAccess::load(root.path())
.unwrap()
.file(root.path(), Path::new("habeas.toml"))
.unwrap_err();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied);
assert!(!error.to_string().contains("TEST_KEY"));
}
Input 19: outline src/authoring/access.rs mod[tests]/fn[disallowed_ancestors_cannot_redirect_reads_into_allowed_targets]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[disallowed_ancestors_cannot_redirect_reads_into_allowed_targets] - Kind:
fn src/authoring/access.rs:998–1035
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.ci.input_containment`
#[cfg(unix)]
#[test]
fn disallowed_ancestors_cannot_redirect_reads_into_allowed_targets() {
let root = tempfile::tempdir().unwrap();
for directory in ["private", "public", "sub"] {
fs::create_dir(root.path().join(directory)).unwrap();
}
fs::write(root.path().join("public/file.txt"), "public source\n").unwrap();
std::os::unix::fs::symlink("../public", root.path().join("private/link")).unwrap();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['public']\ndisallow = ['private']\n",
)
.unwrap();
let access = SourceAccess::load(root.path()).unwrap();
assert!(
access
.file(root.path(), Path::new("public/file.txt"))
.is_ok()
);
for path in [
"private/link/file.txt",
"sub/../private/link/file.txt",
"private/link",
] {
let error = access.path(root.path(), Path::new(path)).unwrap_err();
assert_eq!(
error.kind(),
io::ErrorKind::PermissionDenied,
"{path}: {error}"
);
assert!(error.to_string().contains(path), "{error}");
}
}
Input 20: outline src/authoring/access.rs mod[tests]/fn[policy_resolves_symlinks_before_parent_components_without_allowing_wrong_subtrees]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[policy_resolves_symlinks_before_parent_components_without_allowing_wrong_subtrees] - Kind:
fn src/authoring/access.rs:1064–1140
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.ci.input_containment`
#[cfg(unix)]
#[test]
fn policy_resolves_symlinks_before_parent_components_without_allowing_wrong_subtrees() {
let root = tempfile::tempdir().unwrap();
for directory in ["actual/nested", "actual/private", "private"] {
fs::create_dir_all(root.path().join(directory)).unwrap();
}
fs::write(root.path().join("actual/private/file.txt"), "actual\n").unwrap();
fs::write(root.path().join("private/file.txt"), "wrong subtree\n").unwrap();
std::os::unix::fs::symlink(root.path().join("actual/nested"), root.path().join("alias"))
.unwrap();
git(root.path(), &["init", "--quiet"]);
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['alias/../private']\n",
)
.unwrap();
let access = SourceAccess::load(root.path()).unwrap();
assert!(
access
.file(root.path(), Path::new("actual/private/file.txt"))
.is_ok()
);
assert!(
access
.file(root.path(), Path::new("alias/../private/file.txt"))
.is_ok()
);
assert_eq!(
access
.file(root.path(), Path::new("private/file.txt"))
.unwrap_err()
.kind(),
io::ErrorKind::PermissionDenied
);
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['.']\ndisallow = ['alias/../private']\n",
)
.unwrap();
let access = SourceAccess::load(root.path()).unwrap();
for denied in ["actual/private/file.txt", "alias/../private/file.txt"] {
assert_eq!(
access
.file(root.path(), Path::new(denied))
.unwrap_err()
.kind(),
io::ErrorKind::PermissionDenied
);
assert!(resolve_evidence_file(root.path(), denied).is_err());
}
assert!(
access
.file(root.path(), Path::new("private/file.txt"))
.is_ok()
);
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['actual/private']\n",
)
.unwrap();
let access = SourceAccess::load(root.path()).unwrap();
assert_eq!(
access
.file(
root.path(),
Path::new("actual/private/../../private/file.txt")
)
.unwrap_err()
.kind(),
io::ErrorKind::PermissionDenied
);
}
Input 21: outline src/authoring/access.rs mod[tests]/fn[inherited_out_dir_is_ignored_and_metadata_failure_preserves_ordinary_reads]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[inherited_out_dir_is_ignored_and_metadata_failure_preserves_ordinary_reads] - Kind:
fn src/authoring/access.rs:1142–1185
// {test}`requirements.authoring.generated_inputs`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.read_denial`
#[test]
fn inherited_out_dir_is_ignored_and_metadata_failure_preserves_ordinary_reads() {
if let Some(root) = std::env::var_os("HABEAS_TEST_OUT_DIR_PROBE_ROOT") {
let root = PathBuf::from(root);
let access = SourceAccess::load(&root).unwrap();
assert!(access.generated.is_empty());
assert!(access.file(&root, Path::new("tracked.txt")).is_ok());
let inherited = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let error = access
.file(&root, &inherited.join("unrelated.txt"))
.unwrap_err();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
return;
}
let root = tempfile::tempdir().unwrap();
let unrelated = tempfile::tempdir().unwrap();
fs::write(root.path().join("tracked.txt"), "ordinary source\n").unwrap();
fs::write(
root.path().join("Cargo.toml"),
"deliberately invalid TOML [\n",
)
.unwrap();
fs::write(
unrelated.path().join("unrelated.txt"),
"unrelated generated data\n",
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let output = Command::new(std::env::current_exe().unwrap())
.args(["--exact", "authoring::access::tests::inherited_out_dir_is_ignored_and_metadata_failure_preserves_ordinary_reads", "--nocapture"])
.env("HABEAS_TEST_OUT_DIR_PROBE_ROOT", root.path())
.env("OUT_DIR", unrelated.path())
.output().unwrap();
assert!(
output.status.success(),
"{}\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
Input 22: 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 23: outline src/authoring/pages.rs mod[tests]/fn[paged_inputs_carry_their_definitions_and_deliver_only_their_own_inputs]
- File:
src/authoring/pages.rs - Selector:
mod[tests]/fn[paged_inputs_carry_their_definitions_and_deliver_only_their_own_inputs] - Kind:
fn src/authoring/pages.rs:806–896
// {test}`requirements.authoring.result_pages`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.definitions.authoring_inputs`
// {test}`requirements.authoring.read_denial`
#[test]
// {test}`requirements.authoring.source_tools`
fn paged_inputs_carry_their_definitions_and_deliver_only_their_own_inputs() {
let root = project();
fs::write(
root.path().join("md/terms.md"),
":::{definition} value\n:phrase: value\nA useful value.\n:::\n",
)
.unwrap();
let term = role("term", "terms.value");
let mut source = String::new();
for index in 0..400 {
// Only the last function uses the term, so only its page needs it.
let comment = if index == 399 { term.as_str() } else { "plain" };
source.push_str(&format!(
"// {comment}\nfn needle_{index}() {{\n let text = \"padding padding padding\";\n}}\n\n"
));
}
fs::write(root.path().join("src/lib.rs"), source).unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mut pages = ResultPages::default();
let error = dispatch_paged(&sources, &mut pages, "next_page", &json!({}))
.err()
.unwrap();
assert!(
error.to_string().contains("token must be a string"),
"{error}"
);
let first = dispatch_paged(
&sources,
&mut pages,
"habeas",
&json!({"file":"src/lib.rs","line_start":1}),
)
.unwrap();
let delivered = all_pages(&mut pages, first);
let mut items = Vec::new();
for (number, page) in delivered.iter().enumerate() {
assert!(page.result.to_string().len() <= PAGE_LIMIT);
let inputs = page.result["inputs"].as_array().unwrap();
let definitions = page.result["definitions"].as_array().unwrap();
// A page's delivery is exactly its own inputs and definitions.
let mut expected = inputs.clone();
expected.extend(definitions.iter().cloned());
assert_eq!(page.inputs, expected);
let last = number == delivered.len() - 1;
assert_eq!(
definitions
.iter()
.any(|definition| definition["definition"] == "terms.value"),
last,
"page {number}: {definitions:?}"
);
items.extend(
inputs
.iter()
.map(|input| input["item"].as_str().unwrap().to_owned()),
);
}
let expected = (0..400)
.map(|index| format!("fn[needle_{index}]"))
.collect::<Vec<_>>();
assert_eq!(items, expected);
// A token is unknown to another assessment, and an unknown token is
// an explanatory tool error.
let token = delivered[0].result["page"]["next"].as_str().unwrap();
let mut other = ResultPages::default();
let error = other.next_page(token).err().unwrap();
assert!(error.to_string().contains("unknown page token"), "{error}");
let error = dispatch_paged(
&sources,
&mut pages,
"next_page",
&json!({"token":"not-a-token"}),
)
.err()
.unwrap();
assert!(
error.to_string().contains("valid only in the assessment"),
"{error}"
);
// A token's page comes back in the same shape when asked again.
let again =
dispatch_paged(&sources, &mut pages, "next_page", &json!({"token": token})).unwrap();
assert_eq!(again.result, delivered[1].result);
}
Input 24: 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 25: outline src/authoring/tools.rs mod[tests]/fn[requirements_reads_select_requirements_and_examples_but_not_definitions]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[requirements_reads_select_requirements_and_examples_but_not_definitions] - Kind:
fn src/authoring/tools.rs:1651–1694
// {test}`requirements.definitions.selection`
// {test}`requirements.references.definition_globs`
// {test}`requirements.authoring.source_tools`
#[test]
fn requirements_reads_select_requirements_and_examples_but_not_definitions() {
let root = project();
fs::write(
root.path().join("md/requirements.md"),
format!(
":::{{req}} ready\nThe project MUST be ready.\n:::\n\n\
:::{{example}} case\nA ready case. {}\n:::\n\n\
:::{{definition}} unused\n:phrase: unused\n\nNot referenced.\n:::\n",
role("cite", "requirements.ready")
),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let delivery = dispatch(
&sources,
"habeas",
&json!({"requirements": "requirements.*"}),
)
.unwrap();
assert_eq!(
delivery.result["input"]["matches"],
json!(["requirements.case", "requirements.ready"]),
"{}",
delivery.result
);
assert_eq!(delivery.result["definitions"], json!([]));
let error = dispatch(
&sources,
"habeas",
&json!({"requirements": "requirements.unused"}),
)
.err()
.unwrap();
assert!(
error
.to_string()
.contains("matches no requirement or example"),
"{error}"
);
}
Input 26: outline src/authoring/tools.rs mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted] - Kind:
fn src/authoring/tools.rs:1696–1774
// {test}`requirements.authoring.redaction`
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn model_inputs_reads_searches_and_citation_prompts_are_redacted() {
let root = project();
let token = crate::redaction::tests::github_token();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 'plain ollama key'\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn client() -> &'static str {{\n \"{token}\"\n}}\n\n// :::{} requirements.ready\n// Defaults to {token}.\n// :::\nfn helper() {{}}\n\n// :::{{fixme}} requirements.ready\n// Missing check for {token}.\n// :::\nfn gap() {{}}\n",
role("test", "requirements.ready"),
"{cite}"
),
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let leaks = |value: &Value| {
let text = value.to_string();
text.contains(&token) || text.contains("plain ollama key")
};
// Mandatory inputs, and so the initial and verification prompts.
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mandatory = Value::Array(sources.mandatory_inputs().to_vec());
assert!(!leaks(&mandatory), "{mandatory:#}");
assert!(mandatory.to_string().contains("[REDACTED:GitHub Token]"));
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
assert!(
prompt.contains("Missing check for [REDACTED:GitHub Token]."),
"{prompt}"
);
assert!(!prompt.contains("fn gap()"), "{prompt}");
// A habeas read of the configuration file and a line range.
let read = dispatch(&sources, "habeas", &json!({"file":"habeas.toml","item":""})).unwrap();
assert!(!leaks(&read.result), "{:#}", read.result);
assert!(
read.result["input"]["text"]
.as_array()
.unwrap()
.contains(&json!("api_key = '[REDACTED:api_key]'"))
);
let lines = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":1}),
)
.unwrap();
assert!(!leaks(&lines.result), "{:#}", lines.result);
// Search results, even for a pattern matching the credential itself.
for pattern in ["ollama", "gh[p]_", "Defaults"] {
let search = dispatch(&sources, "ripgrep", &json!({"pattern": pattern})).unwrap();
assert!(
!search.result["matches"].as_array().unwrap().is_empty(),
"{pattern}"
);
assert!(!leaks(&search.result), "{pattern}: {:#}", search.result);
}
// A citation review's inputs and its commentary in the prompt.
let citation =
AssessmentSources::prepare_citation(root.path(), "src/lib.rs", "fn[helper]").unwrap();
assert!(!leaks(&Value::Array(citation.mandatory_inputs().to_vec())));
let prompt = super::super::initial_prompt(&citation).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
assert!(
prompt.contains("Defaults to [REDACTED:GitHub Token]."),
"{prompt}"
);
}
Input 27: outline src/authoring/tools.rs mod[tests]/fn[declaration_text_reaches_the_model_redacted]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[declaration_text_reaches_the_model_redacted] - Kind:
fn src/authoring/tools.rs:1776–1898
// {test}`requirements.authoring.redaction`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.definitions.authoring_inputs`
#[test]
fn declaration_text_reaches_the_model_redacted() {
let root = project();
let token = crate::redaction::tests::github_token();
fs::write(
root.path().join("md/terms.md"),
format!(":::{{definition}} value\n:phrase: value\nA value such as {token}, with a {}.\n:::\n\n:::{{definition}} base\n:phrase: base\nA foundation.\n:::\n", role("term", "terms.base")),
)
.unwrap();
fs::write(
root.path().join("md/requirements.md"),
format!(
":::{{req}} ready\nThe project MUST accept {token} as a {}.\n{}\n:::\n\n:::{{req}} other\nOther MUST reject\n{token}\non its own line.\n:::\n",
role("term", "terms.value"),
role("cite", "requirements.other"),
),
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
// The subject, a cited requirement, and a term in the mandatory
// inputs and so the prompt, with their line structure kept.
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mandatory = Value::Array(sources.mandatory_inputs().to_vec());
let text = mandatory.to_string();
assert!(!text.contains(&token), "{mandatory:#}");
for expected in [
"The project MUST accept [REDACTED:GitHub Token] as a",
"A value such as [REDACTED:GitHub Token], with a",
"\"Other MUST reject\",\"[REDACTED:GitHub Token]\",\"on its own line.\"",
] {
assert!(
text.contains(expected),
"missing {expected:?}: {mandatory:#}"
);
}
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
// Requirements and definition reads.
for arguments in [
json!({"requirements":"requirements.*"}),
json!({"definition":"terms.value"}),
] {
let read = dispatch(&sources, "habeas", &arguments).unwrap();
let text = read.result.to_string();
assert!(!text.contains(&token), "{arguments}: {:#}", read.result);
assert!(
text.contains("[REDACTED:GitHub Token]"),
"{arguments}: {:#}",
read.result
);
let definition = arguments.get("definition").is_some();
assert_eq!(read.result["input"].get("definition").is_some(), definition);
assert_eq!(
read.result["input"].get("requirements").is_some(),
!definition
);
assert!(read.result.get("inputs").is_none());
let expected_terms = if definition {
vec!["terms.base"]
} else {
vec!["terms.base", "terms.value"]
};
let terms: Vec<_> = read.result["definitions"]
.as_array()
.unwrap()
.iter()
.map(|input| input["definition"].as_str().unwrap())
.collect();
assert_eq!(terms, expected_terms);
if definition {
assert_eq!(read.result["input"]["definition"], "terms.value");
assert_eq!(
read.result["input"]["text"],
json!([
":::{definition} value",
":phrase: value",
"A value such as [REDACTED:GitHub Token], with a {term}`terms.base`.",
":::"
])
);
} else {
assert_eq!(read.result["input"]["requirements"], "requirements.*");
assert_eq!(
read.result["input"]["matches"],
json!(["requirements.other", "requirements.ready"])
);
assert_eq!(
read.result["input"]["text"],
json!([
":::{req} other",
"Other MUST reject",
"[REDACTED:GitHub Token]",
"on its own line.",
":::",
"",
":::{req} ready",
"The project MUST accept [REDACTED:GitHub Token] as a {term}`terms.value`.",
"{cite}`requirements.other`",
":::"
])
);
}
let mut fresh = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(fresh.recorded_inputs().is_empty());
fresh.record_inputs(&read.inputs);
fresh.record_inputs(&read.inputs);
let mut expected = vec![read.result["input"].clone()];
expected.extend(
read.result["definitions"]
.as_array()
.unwrap()
.iter()
.cloned(),
);
assert_eq!(fresh.recorded_inputs(), expected);
assert_eq!(read.inputs, expected);
}
}
Input 28: 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 29: 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 30: 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 31: 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 32: 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 33: 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 34: 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 35: outline src/authoring/tools.rs mod[tests]/fn[habeas_tool_describes_its_argument_conventions_with_an_example_per_form]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[habeas_tool_describes_its_argument_conventions_with_an_example_per_form] - Kind:
fn src/authoring/tools.rs:3227–3283
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.tool_descriptions.common_case`
#[test]
fn habeas_tool_describes_its_argument_conventions_with_an_example_per_form() {
let definitions = definitions();
let habeas = definitions
.iter()
.find(|definition| definition["name"] == "habeas")
.expect("habeas tool is advertised");
let description = habeas["description"].as_str().unwrap();
for phrase in [
// Request forms and line conventions.
"Read project source as evidence",
"Paths are project-relative",
"use the outline tool to list a file's selectors",
"exactly one request form",
"one-based and inclusive",
"omitted line_end reads through EOF",
"{inputs, definitions}",
"{input, definitions}",
// Outline selector syntax.
"kind[name]",
"impl[Thing/Trait]",
"kind@hash",
"#N",
"percent-encoded",
// Definition selections and full definition names.
"definition selection",
"* matches any characters including dots",
"full terminology name",
// A short request example for each form.
r#"{"file":"src/lib.rs","line_start":10,"line_end":20}"#,
r#"{"file":"src/lib.rs","item":"impl[Thing]/fn[run]"}"#,
r#"{"requirements":"requirements.cli.*"}"#,
r#"{"definition":"glossary.command"}"#,
] {
assert!(
description.contains(phrase),
"missing {phrase:?}: {description}"
);
}
assert_eq!(
habeas["parameters"]["properties"]
.as_object()
.unwrap()
.keys()
.collect::<Vec<_>>(),
[
"file",
"line_start",
"line_end",
"item",
"requirements",
"definition"
]
);
}
Input 36: outline src/authoring/tools.rs mod[tests]/fn[line_range_reads_record_the_innermost_covering_nodes]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[line_range_reads_record_the_innermost_covering_nodes] - Kind:
fn src/authoring/tools.rs:3422–3504
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.authoring.no_line_numbers`
#[test]
fn line_range_reads_record_the_innermost_covering_nodes() {
let root = project();
let source = "use std::fmt;\n\nfn first() {}\n\nmod inner {\n fn second() {\n let x = 1;\n }\n}\n";
fs::write(root.path().join("src/lib.rs"), source).unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
// Blank lines between nodes do not select their common ancestor.
let read = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":3,"line_end":7}),
)
.unwrap();
let items = read.result["inputs"]
.as_array()
.unwrap()
.iter()
.map(|input| {
assert!(input.get("line_start").is_none());
input["item"].as_str().unwrap()
})
.collect::<Vec<_>>();
assert_eq!(
items,
["fn[first]", "mod[inner]"],
"line 5 is mod inner's own line, so the module is selected"
);
let nested = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":7,"line_end":7}),
)
.unwrap();
assert_eq!(nested.result["inputs"][0]["item"], "mod[inner]/fn[second]");
assert_eq!(
nested.result["inputs"][0]["text"],
json!([" fn second() {", " let x = 1;", " }"])
);
sources.record_inputs(&nested.inputs);
assert_eq!(
sources.recorded_inputs(),
[
crate::inputs::outline_input(root.path(), "src/lib.rs", "mod[inner]/fn[second]")
.unwrap()
]
);
assert!(sources.recorded_inputs()[0].get("line_start").is_none());
assert!(sources.recorded_inputs()[0].get("text").is_none());
let whole = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":1}),
)
.unwrap();
assert!(
whole.result["inputs"][0]["item"]
.as_str()
.unwrap()
.starts_with("use@")
);
assert_eq!(whole.result["inputs"].as_array().unwrap().len(), 3);
fs::write(root.path().join("notes.txt"), "alpha\nbeta\ngamma\ndelta\n").unwrap();
let plain = dispatch(
&sources,
"habeas",
&json!({"file":"notes.txt","line_start":2,"line_end":3}),
)
.unwrap();
let inputs = plain.result["inputs"].as_array().unwrap();
assert_eq!(inputs.len(), 2);
assert_eq!(inputs[0]["text"], json!(["beta"]));
assert_eq!(inputs[1]["text"], json!(["gamma"]));
assert_ne!(inputs[0]["item"], inputs[1]["item"]);
for input in inputs {
assert!(input["item"].as_str().unwrap().starts_with("line@"));
assert!(input.get("line_start").is_none());
assert!(input.get("line_end").is_none());
}
}
Input 37: 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}");
}
}
Input 38: outline tests/authoring_cli.rs fn[bedrock_cli_uses_selected_profile_region_and_converse_tools]
- File:
tests/authoring_cli.rs - Selector:
fn[bedrock_cli_uses_selected_profile_region_and_converse_tools] - Kind:
fn tests/authoring_cli.rs:1727–1920
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.initial_prompt`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.submission`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.output_limit`
#[test]
fn bedrock_cli_uses_selected_profile_region_and_converse_tools() {
for typed in [false, true] {
let mut read_call = json!({"toolUseId":"bedrock-read","name":"habeas",
"input":{"file":"extra.txt","line_start":1,"line_end":2}});
let mut submit_call = json!({"toolUseId":"bedrock-submit","name":"submit_judgment",
"input":{"determination":true,"rationale":"The supplied sources support the subject."}});
if typed {
read_call["type"] = json!("tool_use");
submit_call["type"] = json!("tool_use");
}
let first_message = json!({"role":"assistant","content":[
{"text":"Reading source."},{"toolUse":read_call}
]});
let server = Server::start(vec![
json!({
"output":{"message":first_message.clone()},
"stopReason":"tool_use",
"usage":{"inputTokens":19,"outputTokens":5,"totalTokens":24},
"metrics":{"latencyMs":1}
}),
json!({
"output":{"message":{"role":"assistant","content":[{"toolUse":submit_call}]}},
"stopReason":"tool_use",
"usage":{"inputTokens":19,"outputTokens":5,"totalTokens":24},
"metrics":{"latencyMs":1}
}),
]);
let fixture = Fixture::new(&server.endpoint);
let credentials = fixture.temp.path().join("aws-credentials");
let aws_config = fixture.temp.path().join("aws-config");
fs::write(&credentials, "[default]\naws_access_key_id = WRONG_DEFAULT_ACCESS_KEY\naws_secret_access_key = wrong-default-secret\n[habeas-test]\naws_access_key_id = FAKE_PROFILE_ACCESS_KEY\naws_secret_access_key = fake-profile-secret-for-local-test-only\n").unwrap();
fs::write(&aws_config, "[profile habeas-test]\nregion = eu-west-1\n").unwrap();
fs::write(fixture.config.join("habeas/config.toml"), "version = 1\n[authoring]\ndefault = 'cloud'\n[authoring.configs.cloud]\npolicy = 'once'\nbackend = 'bedrock'\nmodel = 'fixture-bedrock-model'\naws_profile = 'habeas-test'\nregion = 'us-west-2'\n[authoring.configs.cloud.options]\ntemperature = 0.25\nmaxTokens = 321\ntopP = 0.75\nstopSequences = ['END']\ntop_k = 12\n").unwrap();
let mut command = fixture.command();
for key in [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_SESSION_TOKEN",
"AWS_SECURITY_TOKEN",
"AWS_PROFILE",
"AWS_DEFAULT_PROFILE",
"AWS_REGION",
"AWS_DEFAULT_REGION",
"AWS_ENDPOINT_URL",
"AWS_IGNORE_CONFIGURED_ENDPOINT_URLS",
"AWS_BEARER_TOKEN_BEDROCK",
] {
command.env_remove(key);
}
let output = command
.env("AWS_CONFIG_FILE", aws_config)
.env("AWS_SHARED_CREDENTIALS_FILE", credentials)
.env("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", &server.endpoint)
.env("AWS_EC2_METADATA_DISABLED", "true")
.args(["author-evidence", SUBJECT])
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 2);
assert_eq!(requests[1].body["messages"][1], first_message);
let result = &requests[1].body["messages"][2]["content"][0]["toolResult"];
assert_eq!(result["toolUseId"], "bedrock-read");
let delivered = result["content"][0]["text"].as_str().unwrap();
assert!(delivered.contains("extra.txt") && delivered.contains("context line 1"));
assert!(
requests[0]
.headers
.starts_with("POST /model/fixture-bedrock-model/converse HTTP/1.1\r\n")
);
assert!(
requests[0]
.headers
.contains("Credential=FAKE_PROFILE_ACCESS_KEY/")
);
assert!(
requests[0]
.headers
.contains("/us-west-2/bedrock/aws4_request")
);
assert!(!requests[0].headers.contains("WRONG_DEFAULT_ACCESS_KEY"));
let body = &requests[0].body;
assert_eq!(
body["inferenceConfig"],
json!({"temperature":0.25,"maxTokens":321,"topP":0.75,"stopSequences":["END"]})
);
// A configured maxTokens is used as given on every request.
assert_eq!(requests[1].body["inferenceConfig"]["maxTokens"], 321);
assert_eq!(body["additionalModelRequestFields"], json!({"top_k":12}));
let prompt = prompt_text(body);
assert!(
prompt.contains("Assess whether a project's tests adequately check")
&& prompt.contains(REQUIREMENT)
);
let tool_specs = body["toolConfig"]["tools"].as_array().unwrap();
for tool in tool_specs {
let schema = &tool["toolSpec"]["inputSchema"]["json"];
assert_eq!(schema["type"], "object");
for unsupported in ["oneOf", "allOf", "anyOf"] {
assert!(
schema.get(unsupported).is_none(),
"Bedrock rejects {unsupported} at the root of {}'s input schema",
tool["toolSpec"]["name"]
);
}
}
let habeas_schema = &tool_specs
.iter()
.find(|tool| tool["toolSpec"]["name"] == "habeas")
.unwrap()["toolSpec"]["inputSchema"]["json"];
assert_eq!(habeas_schema["additionalProperties"], false);
for field in ["file", "item", "requirements", "definition"] {
assert_eq!(habeas_schema["properties"][field]["type"], "string");
}
for field in ["line_start", "line_end"] {
assert_eq!(habeas_schema["properties"][field]["type"], "integer");
assert_eq!(habeas_schema["properties"][field]["minimum"], 1);
}
let judgment_schema = &tool_specs
.iter()
.find(|tool| tool["toolSpec"]["name"] == "submit_judgment")
.unwrap()["toolSpec"]["inputSchema"]["json"]["properties"]["determination"];
let outcomes = judgment_schema["oneOf"].as_array().unwrap();
assert!(outcomes.iter().any(|outcome| outcome["type"] == "boolean"));
let fixme = &outcomes
.iter()
.find(|outcome| outcome["type"] == "object")
.unwrap()["properties"]["FIXME"];
assert_eq!(fixme["type"], "array");
assert_eq!(fixme["minItems"], 1);
assert_eq!(fixme["items"]["type"], "string");
assert_eq!(fixme["items"]["minLength"], 1);
let mut tools = tool_specs
.iter()
.map(|tool| tool["toolSpec"]["name"].as_str().unwrap())
.collect::<Vec<_>>();
tools.sort();
assert_eq!(
tools,
[
"ast_grep",
"finish_search",
"github",
"habeas",
"list_files",
"next_page",
"outline",
"references",
"ripgrep",
"submit_judgment"
]
);
let evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(evidence["determination"], true);
assert!(
evidence["inputs"]
.as_array()
.unwrap()
.iter()
.filter(|input| input["file"] == "extra.txt")
.collect::<Vec<_>>()
== habeas::outline_inputs_for_lines(&fixture.project, "extra.txt", 1, 2)
.unwrap()
.iter()
.collect::<Vec<_>>()
);
let usage = fixture.usage();
assert_eq!(usage["backend"], "bedrock");
assert_eq!(usage["model"], "fixture-bedrock-model");
assert_eq!(usage["tokens"]["input"], 38);
assert_eq!(usage["tokens"]["output"], 10);
assert_eq!(usage["request_count"], 2);
assert_eq!(usage["tool_calls"]["habeas"], 1);
assert_eq!(usage["tool_calls"]["submit_judgment"], 1);
assert_eq!(usage["outcome"], "completed");
}
}
Input 39: outline tests/live_bedrock.rs fn[live_bedrock_authoring]
- File:
tests/live_bedrock.rs - Selector:
fn[live_bedrock_authoring] - Kind:
fn tests/live_bedrock.rs:188–301
// {test}`requirements.integration.live_bedrock_test`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.submission`
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.usage_storage`
// {impl}`requirements.integration.live_bedrock_test`
#[test]
fn live_bedrock_authoring() {
if std::env::var_os("CI").is_some() {
report("warning: skipping live Bedrock test: CI is set");
return;
}
let LiveSelection {
config: selected,
workspace,
} = selected_config()
.expect("cannot select live Bedrock configuration")
.expect("no Bedrock authoring configuration; add one to your Habeas user config (see md/reference.md), or set CI=1 to disable live testing");
let BackendConfig::Bedrock(backend) = &selected.backend else {
unreachable!("selection only returns Bedrock configurations");
};
if !credentials_available(backend) {
return;
}
report(format!(
"live Bedrock test: configuration {:?}, model {:?}",
selected.name, backend.model
));
let temp = tempfile::tempdir().unwrap();
let project = temp.path().join("project");
for directory in [project.join("md"), project.join("src")] {
fs::create_dir_all(directory).unwrap();
}
fs::write(
project.join("Cargo.toml"),
"[package]\nname = 'live-fixture'\nversion = '0.1.0'\nedition = '2024'\n",
)
.unwrap();
fs::write(project.join("book.toml"), "[book]\nsrc = 'md'\n").unwrap();
if let Some(workspace) = &workspace {
fs::write(project.join("habeas.toml"), workspace).unwrap();
}
fs::write(
project.join("md/SUMMARY.md"),
"# Summary\n\n- [Requirements](requirements.md)\n",
)
.unwrap();
fs::write(
project.join("md/requirements.md"),
format!(":::{{req}} parity\n{REQUIREMENT}\n:::\n"),
)
.unwrap();
// No citation points to this file, so assessing its implementation requires
// an additional source read instead of only the mandatory initial inputs.
fs::write(project.join("src/parity.rs"), "pub fn is_even(value: u32) -> bool {\n value % 2 == 0\n}\n\n#[test]\nfn parity_cases() {\n assert!(is_even(0));\n assert!(!is_even(1));\n assert!(is_even(2));\n assert!(!is_even(u32::MAX));\n}\n").unwrap();
let checkout_evidence = Path::new(env!("CARGO_MANIFEST_DIR")).join("evidence");
let before = evidence_snapshot(&checkout_evidence);
let output = Command::new(env!("CARGO_BIN_EXE_habeas"))
.current_dir(&project)
.args([
"author-evidence",
SUBJECT,
"--config",
&selected.name,
"--stdout",
])
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
report(&stderr);
assert!(
output.status.success(),
"live Bedrock authoring failed: {stderr}"
);
let evidence: Value = serde_json::from_slice(&output.stdout).expect("stdout is evidence JSON");
assert_eq!(evidence["requirement"], REQUIREMENT);
habeas::judgment::Judgment::from_value(&evidence["determination"]).unwrap();
assert!(!evidence["rationale"].as_str().unwrap().trim().is_empty());
assert!(
evidence["inputs"].as_array().unwrap().iter().any(|input| {
input["file"] == "src/parity.rs"
&& input["item"].is_string()
&& input["hash"].is_string()
&& input.get("text").is_none()
}),
"model must inspect the fixture's source through a read tool"
);
assert!(!project.join("evidence").exists());
assert_eq!(
evidence_snapshot(&checkout_evidence),
before,
"checkout evidence changed"
);
let usage_path = stderr
.lines()
.find_map(|line| line.strip_prefix("Usage: "))
.expect("reported usage path");
let usage: Value = serde_json::from_slice(&fs::read(usage_path).unwrap()).unwrap();
assert_eq!(usage["backend"], "bedrock");
assert_eq!(usage["model"], backend.model);
assert_eq!(usage["outcome"], "completed");
assert_eq!(usage["evidence_output"], "stdout");
assert_eq!(usage["evidence_written"], true);
assert!(usage["request_count"].as_u64().unwrap() >= 2);
assert!(usage["tool_calls"]["submit_judgment"].as_u64().unwrap() >= 1);
assert!(
usage["tool_calls"]["habeas"].as_u64().unwrap_or(0)
+ usage["tool_calls"]["ripgrep"].as_u64().unwrap_or(0)
> 0
);
}
Referenced definitions
Input 2: requirements selection requirements.ci.outline_inputs
requirements.ci.outline_inputs:md/requirements/ci.md:172–183
:::{req} outline_inputs
For an outline input, Habeas MUST parse `file` with its language's grammar under
{cite}`requirements.references.outlines` and resolve `item` to exactly one
outline node under {cite}`requirements.references.outline_selectors`. It MUST
compare `hash` with the node's current structural hash under
{cite}`requirements.references.structural_hash`. It MUST derive the node's
inclusive line range, including attached comments and attributes, during
validation for display and reference coverage. Moving the node, editing other
nodes, or editing comments its profile does not hash MUST NOT invalidate the
input. Habeas MUST report a missing file, unsupported language, parse failure,
invalid or ambiguous selector, or changed hash.
:::
Input 3: requirements selection requirements.ci.requirements_inputs
requirements.ci.requirements_inputs:md/requirements/ci.md:185–187
:::{req} requirements_inputs
For a requirements input, `requirements` MUST be a {term}`requirements.references.definition_selection`, and Habeas MUST match it against all defined requirements and named examples. It MUST recompute the matches during validation, sort their full names, and compare them with `matches`. It MUST take each match's complete raw fenced declaration, including its opening and closing lines, concatenate those declarations in full-name order with one blank line between them, and compare the resulting raw lines with `text`. It MUST retain every match's current source file and inclusive line range for display and reference coverage. A selection matching no definitions MUST be invalid. Adding, removing, renaming, or changing a matched definition MUST invalidate the stored input; moving an unchanged declaration within the book MUST NOT. Errors MUST identify the selection and affected definitions when available.
:::
Input 4: requirements selection requirements.definitions.inputs
requirements.definitions.inputs:md/requirements/definitions.md:15–19
:::{req} inputs
Evidence inputs MAY have a definition form containing exactly `definition` and `text`. `definition` MUST identify one named definition; `text` MUST contain its complete raw fenced declaration as source lines, including its phrase option and explanatory body.
Validation MUST reject missing definitions and changed snapshot text, identifying the definition and showing a compact diff when available. Moving an unchanged definition within its chapter MUST NOT invalidate its snapshot. Evidence displays MUST show the definition name, current source location, and recorded text.
:::
Input 5: requirements selection requirements.references.outline_selectors
requirements.references.outline_selectors:md/requirements/references.md:380–392
:::{req} outline_selectors
An outline selector MUST be a `/`-separated path of segments from the file's
root node to an outline node; the empty selector MUST select the root node. A
named node's segment MUST be `kind[name]`. An anonymous node's segment MUST be
`kind@hash`, where `hash` is the first twelve hexadecimal digits of its identity
hash under {cite}`requirements.references.structural_hash`. Siblings whose
segments would otherwise be identical MUST be disambiguated by `#N`, their
one-based position among those siblings in source order, except `line` nodes:
identical lines are interchangeable, so a `line` selector MUST resolve when any
line with that content exists in the file. In names, `%`, `[`, `]`, `/`, `#`,
`@`, and whitespace MUST be percent-encoded as UTF-8 bytes, so selectors are
reversible. Line numbers MUST NOT form part of a selector.
:::
Input 6: requirements selection requirements.authoring.redaction
requirements.authoring.redaction:md/requirements/authoring.md:1795–1817
:::{req} redaction
Every source text the harness supplies to a model, including mandatory inputs,
`habeas` reads, and `ripgrep` results, and every source text Habeas displays in
the book or `habeas info`, MUST be redacted:
1. In a workspace `habeas.toml` or user configuration file, the value of every
explicit credential field defined by {cite}`requirements.authoring.credentials`
MUST be replaced. Such a file that is not valid TOML MUST be replaced whole,
with `configuration` as the kind, because its fields cannot be located.
2. In every source, each match of a built-in rule of the `secretshape` crate MUST
be replaced. The replaced region MUST be extended through each adjacent region
that the crate's entropy heuristic flags and that only whitespace separates
from the region, repeating until no flagged region is adjacent. The heuristic
MUST NOT cause redaction on its own.
A replacement MUST read `[REDACTED:<kind>]`, where `<kind>` is the credential
field or the rule's name, and MUST keep every line break within the replaced
text, so line numbers are unchanged. Outlines MUST be built from the original
source, and the structural hash MUST hash each text piece that overlaps a
redacted region in its redacted form, so evidence never depends on a credential's
value and redaction never changes or breaks a file's outline. The `secretshape` version MUST be pinned exactly; upgrading
it MAY change redaction and hashes and MUST be treated as a deliberate change.
:::
Input 7: requirements selection requirements.authoring.generated_inputs
requirements.authoring.generated_inputs:md/requirements/authoring.md:736–752
:::{req} generated_inputs
Habeas MUST permit existing Cargo build-script output directories as an exception
to default Git tracking and containment restrictions. It MUST discover the Cargo
build directory using metadata and inspect existing build-script output records,
without running a build or executing build scripts. It MUST NOT treat its own
inherited `OUT_DIR` environment variable as the workspace's output directory.
Only discovered output directories and their contents MUST receive this default
permission; unrelated build artifacts MUST remain subject to ordinary rules.
Workspace disallow entries MUST override this permission.
Discovery MUST tolerate missing builds or unavailable metadata; callers MUST be
able to allow undiscovered outputs explicitly using `habeas.toml`. The model's
root directory listing MUST expose available generated-output directories,
including external ones. Generated inputs MUST use outline inputs and receive
ordinary freshness checks. Validation MUST NOT
invoke a build to materialize an input.
:::
Input 8: 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.
:::
Input 9: requirements selection requirements.authoring.read_denial.mandatory
requirements.authoring.read_denial.mandatory:md/requirements/authoring.md:725–734
:::{req} read_denial.mandatory
When source-access policy denies a mandatory input, the assessment MUST abort
before any model request and report the denied path and reason to its caller;
for an untracked file, the report MUST say what {cite}`requirements.authoring.read_denial.untracked`
says. The aborted assessment MUST NOT write evidence or emit evidence JSON, and
its usage record MUST identify the failure. In a batch, other assessments MUST
continue, including queued assessments, and their successful writes MUST be
retained; the command MUST return a nonzero exit status after the batch
finishes.
:::
Input 10: 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 11: requirements selection requirements.ci.schema
requirements.ci.schema:md/requirements/ci.md:11–13
:::{req} schema
A requirement or example evidence file at `evidence/<full-name>.json` MUST be a JSON object with exactly `requirement` or `example`, `determination`, `rationale`, `references`, and `inputs`. `references` MUST be the reference-set digest defined by {cite}`requirements.ci.reference_set`. The definition text and rationale MUST be nonempty strings, `determination` MUST use one of the outcomes defined by {cite}`requirements.ci.outcomes`, and `inputs` MUST be an array. Every evidence input MUST have exactly one of three forms: an outline input with `file`, `item`, and `hash`; a requirements input with `requirements`, `matches`, and `text`; or a definition input with `definition` and `text`. File paths MUST resolve to permitted inputs under {cite}`requirements.ci.input_containment`. Project-local paths SHOULD be recorded relative to the project for portability; absolute and parent-relative paths MAY be used when their resolved targets are permitted. `matches` MUST be an array of distinct full definition names, `hash` MUST be a lowercase hexadecimal SHA-256 digest, and `text` MUST be a nonempty array of strings. Evidence MUST NOT store source text for outline inputs.
:::
Input 12: requirements selection requirements.definitions.authoring_inputs
requirements.definitions.authoring_inputs:md/requirements/definitions.md:53–65
:::{req} authoring_inputs
When preparing the mandatory input set defined by
{cite}`requirements.authoring.mandatory_inputs`, every terminology definition
referenced by the subject, any contributed source, or an acknowledgment supplied
under {cite}`requirements.authoring.fixme_inputs` MUST contribute its complete
fenced declaration, including its phrase option. Definitions referenced by those
definitions MUST also be included transitively, without duplicates or
nontermination on cycles.
When an additional source read introduces a terminology dependency, the same
complete, transitive definition set MUST be supplied to the model and recorded
before accepting a submission.
:::
Input 40: 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.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.
:::