requirements.authoring.finish_search.empty
Requirements index · View definition
Requirement
finish_searchMUST accept an emptyusedarray, including when the search has no matches, and finish the result without adding search-derived inputs.
Rationale
The requirement has three obligations: finish_search accepts an empty used array, it accepts one for a search with no matches, and it adds no search-derived inputs when it finishes.
All three are covered by src/authoring/searches.rs#mod[tests]/fn[delivered_searches_including_empty_results_need_explicit_completion], which is marked {test} for the subject:
- Empty
usedon searches with matches: the test runs a ripgrep search forfn, which has matches, and another for a repeatedfnsearch. It finishes each withused: []. Each call succeeds. - Empty
usedon a no-match search: theabsentsearch returnsmatches == []. It is finished withused: []and succeeds. - No search-derived inputs: every finish asserts
finished.inputs.is_empty(). The result must equal{"search_id": ..., "finished": true}. After all three are finished, the test assertspages.outstanding_searches()is empty andsources.recorded_inputs()is empty. So the finish adds nothing to the evidence. - Related checks: the test also finishes empty-result searches from the real
ripgrepandast_grepdispatch paths. Finishing an ID from a differentResultPagesfails, which shows the empty finish still validates the ID.
The search helper asserts that the delivery itself has no inputs. The CLI test tests/authoring_cli.rs#fn[ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free] is also marked. It exercises finishing a search end to end and counts a finish_search tool call. It isn’t needed for the verdict.
I found no gap in the tested inputs or assertions.
Inputs
Tests
Input 2: outline src/authoring/searches.rs mod[tests]/fn[delivered_searches_including_empty_results_need_explicit_completion]
- File:
src/authoring/searches.rs - Selector:
mod[tests]/fn[delivered_searches_including_empty_results_need_explicit_completion] - Kind:
fn src/authoring/searches.rs:178–267
// {test}`requirements.authoring.search_accounting.result_ids`
// {test}`requirements.authoring.search_accounting.entry_tags`
// {test}`requirements.authoring.search_accounting.outstanding`
// {test}`requirements.authoring.search_accounting.instructions`
// {test}`requirements.authoring.finish_search.empty`
// {test}`requirements.authoring.finish_search.invalid`
// {test}`requirements.authoring.finish_search`
#[test]
fn delivered_searches_including_empty_results_need_explicit_completion() {
let root = project();
fs::write(
root.path().join("src/lib.rs"),
"fn first() {}\nfn second() {}\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mut pages = ResultPages::default();
assert!(dispatch_paged(&sources, &mut pages, "ripgrep", &json!({"pattern":"("})).is_err());
assert!(pages.outstanding_searches().is_empty());
let first = search(&sources, &mut pages, "fn");
assert_eq!(
first["instructions"],
super::super::approved_text("search_accounting.instructions", 0)
);
let tags: Vec<_> = first["matches"]
.as_array()
.unwrap()
.iter()
.map(|entry| entry["tag"].as_str().unwrap())
.collect();
assert_eq!(tags, ["1", "2"]);
for entry in first["matches"].as_array().unwrap() {
assert!(entry.get("hash").is_none());
}
let empty = search(&sources, &mut pages, "absent");
assert_eq!(empty["matches"], json!([]));
assert!(empty.get("instructions").is_none());
let repeated = search(&sources, &mut pages, "fn");
assert!(repeated.get("instructions").is_none());
let ids = [&first, &empty, &repeated]
.map(|result| Uuid::parse_str(result["search_id"].as_str().unwrap()).unwrap());
assert_eq!(
ids.into_iter()
.collect::<std::collections::BTreeSet<_>>()
.len(),
3
);
assert_eq!(pages.outstanding_searches().len(), 3);
let mut other = ResultPages::default();
let error = other
.finish_search(&json!({"search_id":first["search_id"],"used":[]}))
.err()
.unwrap()
.to_string();
assert!(error.contains("delivered in this assessment"), "{error}");
for result in [&first, &empty, &repeated] {
let finished = pages
.finish_search(&json!({"search_id":result["search_id"],"used":[]}))
.unwrap();
assert!(finished.inputs.is_empty());
assert_eq!(
finished.result,
json!({"search_id":result["search_id"],"finished":true})
);
}
assert!(pages.outstanding_searches().is_empty());
assert!(sources.recorded_inputs().is_empty());
for (tool, args) in [
("ripgrep", json!({"pattern":"absent","path":"src/lib.rs"})),
(
"ast_grep",
json!({"language":"rust","rule":{"rule":{"pattern":"absent()"}}}),
),
] {
let mut fresh = ResultPages::default();
let result = dispatch_paged(&sources, &mut fresh, tool, &args)
.unwrap()
.result;
assert_eq!(result["matches"], json!([]));
assert_eq!(
result["instructions"],
super::super::approved_text("search_accounting.instructions", 0)
);
Uuid::parse_str(result["search_id"].as_str().unwrap()).unwrap();
let again = dispatch_paged(&sources, &mut fresh, tool, &args)
.unwrap()
.result;
assert_ne!(result["search_id"], again["search_id"]);
}
}
Input 3: outline tests/authoring_cli.rs fn[ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free]
- File:
tests/authoring_cli.rs - Selector:
fn[ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free] - Kind:
fn tests/authoring_cli.rs:366–676
// {test}`requirements.authoring.complete_initial_bundle`
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.additional_read`
// {test}`requirements.authoring.acknowledged_gap`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.initial_prompt`
// {test}`requirements.ci.review_criteria`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.usage_inputs`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.github_reads`
// {test}`requirements.authoring.invocation`
// {test}`requirements.configuration.serialization`
// {test}`requirements.ci.fixme_implementation_gap`
// {test}`requirements.authoring.finish_search.empty`
// {test}`requirements.authoring.finish_search.completion`
#[test]
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.reporting`
fn ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free() {
let server = Server::start(vec![
reply(vec![
call("list", "list_files", json!({})),
call(
"search",
"ripgrep",
json!({"path":"extra.txt","pattern":"needle"}),
),
call(
"read",
"habeas",
json!({"file":"extra.txt","line_start":10}),
),
call(
"repeat",
"habeas",
json!({"file":"extra.txt","line_start":10}),
),
call(
"missing",
"habeas",
json!({"file":"absent.txt","line_start":1}),
),
]),
json!({"__finish_latest_search":true}),
reply(vec![call(
"submit",
"submit_judgment",
json!({
"determination":{"FIXME":["example/app#125"]},"rationale":"SECRET_RATIONALE: `src/lib.rs#fn[ready]` documents the gap."}),
)]),
]);
let fixture = Fixture::new(&server.endpoint);
let user_config = fixture.config.join("habeas/config.toml");
let configured = fs::read(&user_config).unwrap();
let output = fixture.run(&["author-evidence", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
// The user configuration, with its environment-resolved key, is not
// rewritten.
assert_eq!(fs::read(&user_config).unwrap(), configured);
let requests = server.finish();
assert_eq!(requests.len(), 3);
for request in &requests {
assert!(request.headers.starts_with("POST /api/chat HTTP/1.1\r\n"));
assert!(request.headers.to_ascii_lowercase().contains(&format!(
"authorization: bearer {}",
AUTH.to_ascii_lowercase()
)));
assert_eq!(request.body["model"], MODEL);
assert_eq!(request.body["options"]["temperature"], 0.25);
assert_eq!(request.body["options"]["num_ctx"], 4096);
assert_eq!(request.body["think"], false);
assert_eq!(request.body["stream"], false);
}
let prompt = prompt_text(&requests[0].body);
for text in [
"Assess whether a project's tests adequately check one requirement.",
REQUIREMENT,
"SECRET_DEFINITION_TEXT",
"fn ready_test()",
"You MUST end by calling submit_judgment",
] {
assert!(prompt.contains(text), "prompt missing {text}");
}
assert!(!prompt.contains("pub fn ready()"), "{prompt}");
assert!(!prompt.contains("OLD_RATIONALE_MUST_NOT_REACH_MODEL"));
let mut tools = requests[0].body["tools"]
.as_array()
.unwrap()
.iter()
.map(|tool| tool["function"]["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 results = requests[1].body["messages"]
.as_array()
.unwrap()
.iter()
.filter(|message| message["role"] == "tool")
.collect::<Vec<_>>();
assert_eq!(results.len(), 5);
assert!(results.iter().any(|message| {
message["content"]
.as_str()
.unwrap()
.contains("SECRET_SOURCE_PAYLOAD")
}));
assert!(
results
.iter()
.any(|message| message["content"].as_str().unwrap().contains("absent.txt"))
);
let evidence: Value = serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(
evidence["determination"],
json!({"FIXME":["example/app#125"]})
);
assert_eq!(
evidence["rationale"],
"SECRET_RATIONALE: `src/lib.rs#fn[ready]` documents the gap."
);
assert_eq!(evidence["requirement"], REQUIREMENT);
let inputs = evidence["inputs"].as_array().unwrap();
assert!(
inputs
.iter()
.any(|input| input["file"] == "src/lib.rs" && input["item"] == "fn[ready_test]"),
"{inputs:#?}"
);
// The acknowledgment reaches the model as metadata, without the
// containing implementation. Its body is protected by the reference set.
assert!(prompt.contains(":github: example/app#125"));
assert!(prompt.contains("One acknowledged gap."));
// GitHub is unreachable, so the issue is supplied as open, but the state
// is not recorded.
assert!(
prompt.contains("\"reference\": \"example/app#125\"")
&& prompt.contains("\"state\": \"open\""),
"{prompt}"
);
assert!(!evidence.to_string().contains("github_issues"));
assert!(!fixture.usage().to_string().contains("github_issues"));
assert!(
!inputs
.iter()
.any(|input| input["file"] == "src/lib.rs" && input["item"] == "fn[ready]"),
"{inputs:#?}"
);
// CI accepts the FIXME judgment: its evidence has no validation error.
let report = habeas::validate_repository(&fixture.project).unwrap();
let label = format!("evidence/{SUBJECT}.json");
assert!(
!report.errors.iter().any(|error| error.contains(&label)),
"{:#?}",
report.errors
);
// The same record with a false determination is rejected.
let mut rejected = evidence.clone();
rejected["determination"] = json!(false);
let accepted = fs::read(&fixture.evidence).unwrap();
fs::write(&fixture.evidence, rejected.to_string()).unwrap();
let report = habeas::validate_repository(&fixture.project).unwrap();
assert!(
report.errors.iter().any(|error| error.contains(&label)),
"{:#?}",
report.errors
);
fs::write(&fixture.evidence, accepted).unwrap();
assert!(
inputs
.iter()
.any(|input| input["definition"] == "terms.readiness")
);
let extra = inputs
.iter()
.filter(|input| input["file"] == "extra.txt")
.collect::<Vec<_>>();
// The search only locates lines and records nothing; the reads cover
// lines 10-12, one plain-text line node each, and the repeated delivery
// is recorded once, by selector and hash only.
assert_eq!(
extra,
habeas::outline_inputs_for_lines(&fixture.project, "extra.txt", 10, 12)
.unwrap()
.iter()
.collect::<Vec<_>>(),
"repeated delivery is deduplicated in evidence"
);
assert!(
!evidence["inputs"]
.to_string()
.contains("SECRET_SOURCE_PAYLOAD")
);
assert!(
!inputs
.iter()
.any(|input| input["file"] == "absent.txt" || input["file"] == ".")
);
let usage = fixture.usage();
assert_eq!(usage["outcome"], "completed");
assert_eq!(usage["determination"], "FIXME");
assert_eq!(usage["evidence_written"], true);
assert_eq!(usage["request_count"], 3);
assert_eq!(usage["tool_call_count"], 7);
assert_eq!(usage["tool_calls"]["habeas"], 3);
assert_eq!(usage["tool_failures"]["habeas"], 1);
// The directory listing counts as a tool call but is not an input.
assert_eq!(usage["tool_calls"]["list_files"], 1);
assert_eq!(usage["tool_calls"]["ripgrep"], 1);
assert_eq!(usage["tool_calls"]["finish_search"], 1);
let usage_inputs = usage["inputs"].as_array().unwrap();
assert!(
!usage_inputs
.iter()
.any(|input| input["origin"] == "list_files"),
"{usage_inputs:?}"
);
// Search snippets count toward usage, without becoming evidence inputs.
assert!(
usage_inputs.iter().any(|input| input["origin"] == "ripgrep"
&& input["kind"] == "search"
&& input["bytes"].as_u64().unwrap() > 0
&& input["lines"].as_u64().unwrap() > 0),
"{usage_inputs:?}"
);
assert!(
usage_inputs
.iter()
.any(|input| input["origin"] == "habeas" && input["unique"] == true),
"{usage_inputs:?}"
);
assert_eq!(usage["tokens"]["input"], 33);
assert_eq!(usage["tokens"]["output"], 21);
assert_eq!(usage["tokens"]["complete"], true);
assert!(
usage["inputs"]
.as_array()
.unwrap()
.iter()
.any(|input| input["origin"] == "habeas"
&& input["unique"] == false
&& input["sent_in_request"] == 1)
);
assert!(
usage["inputs"]
.as_array()
.unwrap()
.iter()
.any(|input| input["origin"] == "mandatory"
&& input["kind"] == "definition"
&& input["bytes"].as_u64().unwrap() > 0)
);
let serialized = usage.to_string();
for secret in [
"SECRET_REQUIREMENT_TEXT",
"SECRET_DEFINITION_TEXT",
"SECRET_SOURCE_PAYLOAD",
"SECRET_RATIONALE",
AUTH,
"#125",
] {
assert!(
!serialized.contains(secret),
"usage contains source or credential content: {secret}"
);
}
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains(MODEL) && stdout.contains("Evidence:") && stdout.contains("Usage:"));
// By default the report names the subject and backend and identifies the
// evidence file it wrote.
assert!(
stdout.starts_with(&format!("{SUBJECT}: ollama / {MODEL}")),
"{stdout}"
);
let evidence = stdout
.lines()
.find_map(|line| line.strip_prefix("Evidence: "))
.unwrap();
assert!(
evidence.ends_with(&format!("evidence/{SUBJECT}.json")),
"{stdout}"
);
assert_eq!(
fs::canonicalize(evidence).unwrap(),
fs::canonicalize(fixture.project.join(format!("evidence/{SUBJECT}.json"))).unwrap()
);
}
Other sources
Input 1: requirements selection requirements.authoring.finish_search.empty
requirements.authoring.finish_search.empty:md/requirements/authoring.md:990–993
:::{req} finish_search.empty
`finish_search` MUST accept an empty `used` array, including when the search
has no matches, and finish the result without adding search-derived inputs.
:::
Input 4: outline src/authoring/searches.rs mod[tests]/fn[search]
- File:
src/authoring/searches.rs - Selector:
mod[tests]/fn[search] - Kind:
fn src/authoring/searches.rs:166–176
fn search(sources: &AssessmentSources, pages: &mut ResultPages, pattern: &str) -> Value {
let delivery = dispatch_paged(
sources,
pages,
"ripgrep",
&json!({"pattern":pattern,"path":"src/lib.rs","context":0}),
)
.unwrap();
assert!(delivery.inputs.is_empty());
delivery.result
}