requirements.authoring.finish_search.invalid
Requirements index · View definition
Requirement
Missing, extra, or wrongly typed arguments, an invalid or unknown UUID, a UUID from another assessment, or a tag outside that UUID’s delivered
matchesMUST return an explanatory tool error. The assessment MUST continue so the model can correct the call.
Rationale
The tests cover every case requirements.authoring.finish_search.invalid names, and they assert the error and the continuation of the assessment.
- Argument shape (missing, extra, wrongly typed).
src/authoring/searches.rs#mod[tests]/fn[invalid_completion_is_atomic_and_can_be_corrected]runs a table of bad calls throughfinish_search. Each call must return an error whose text contains an expected explanation.- Wrong top-level type: null and an array.
- Missing fields: an empty object, only
search_id, and onlyused. - Extra field:
extraalongside the two required ones. - Wrong field types: numeric
search_id,usedas null or a string, and a non-string element inused. - Each call asserts the expected message, such as “exactly search_id and used” or “used must be an array of tag strings”.
- Invalid or unknown UUID. The same table includes
"bad"(expected “search_id must be a UUID string”) and a fresh random UUID (expected “only search results delivered in this assessment”). - UUID from another assessment.
delivered_searches_including_empty_results_need_explicit_completionfinishes a realsearch_idagainst a separateResultPages. It asserts the error contains “delivered in this assessment”. - Tag outside the UUID’s delivered matches.
- The table uses
["1","missing"], which must giveunknown tag "missing". search_pages_are_accounted_only_when_delivered_and_replay_stays_closedpasses a tag from an undelivered page under the first page’s id and asserts an error.- It also finishes with an undelivered page’s id and asserts an error.
- The table uses
- Assessment continues.
- In the table test, after each error the search stays outstanding and no input is recorded. A corrected call then succeeds.
src/authoring/mod.rs#mod[tests]/fn[a_bad_tag_returns_a_recoverable_error_without_closing_the_search]runs the fullassessloop. A bad tag produces a tool result containing “unknown tag”, and the loop continues. The next turn is told about “outstanding searches”, and the assessment finishes after 5 requests. The unusedhelperitem is not recorded as evidence.
The error cases differ only in their message and share one code path. The end-to-end test uses the bad-tag case, so the other cases are covered at the finish_search level only. I found no plausible violating behavior that these tests would accept.
Inputs
Tests
Input 2: outline src/authoring/mod.rs mod[tests]/fn[a_bad_tag_returns_a_recoverable_error_without_closing_the_search]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[a_bad_tag_returns_a_recoverable_error_without_closing_the_search] - Kind:
fn src/authoring/mod.rs:2945–2982
// {test}`requirements.authoring.finish_search.invalid`
// {test}`requirements.authoring.finish_search.atomicity`
#[tokio::test]
async fn a_bad_tag_returns_a_recoverable_error_without_closing_the_search() {
use SearchAction::{Call, Finish};
let root = inputs::tests::project();
fs::write(root.path().join("src/lib.rs"), "fn helper() {}\n").unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), root.path(), &sources.subject_name).unwrap();
let submit = json!({"determination":true,"rationale":"Complete."});
let provider = SearchProvider {
submit: "submit_judgment",
turns: vec![
vec![Call(
"ripgrep",
json!({"pattern":"helper","path":"src/lib.rs"}),
)],
vec![Finish(0, vec!["1", "missing"])],
vec![Call("submit_judgment", submit.clone())],
vec![Finish(0, vec![])],
vec![Call("submit_judgment", submit)],
],
requests: RefCell::default(),
};
let (_, evidence) = assess(&provider, &mut sources, &mut usage).await.unwrap();
let requests = provider.requests.borrow();
assert!(requests[2].to_string().contains("unknown tag"));
assert!(requests[3].to_string().contains("outstanding searches"));
assert_eq!(requests.len(), 5);
assert!(
!evidence["inputs"]
.as_array()
.unwrap()
.iter()
.any(|input| input["item"] == "fn[helper]")
);
}
Input 3: outline src/authoring/pages.rs mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed]
- File:
src/authoring/pages.rs - Selector:
mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed] - Kind:
fn src/authoring/pages.rs:662–738
// {test}`requirements.authoring.search_accounting.pagination`
// {test}`requirements.authoring.search_accounting.page_replay`
// {test}`requirements.authoring.search_accounting.outstanding`
// {test}`requirements.authoring.search_accounting.entry_tags`
// {test}`requirements.authoring.search_accounting.result_ids`
// {test}`requirements.authoring.search_accounting.instructions`
// {test}`requirements.authoring.finish_search.completion`
// {test}`requirements.authoring.finish_search.invalid`
// {test}`requirements.authoring.result_pages`
#[test]
fn search_pages_are_accounted_only_when_delivered_and_replay_stays_closed() {
let root = project();
let source: String = (0..600)
.map(|i| format!("fn needle_{i:04}() {{ let marker = 1; }}\n"))
.collect();
fs::write(root.path().join("src/lib.rs"), source).unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
for (tool, arguments) in [
("ripgrep", json!({"pattern":"marker","path":"src/lib.rs"})),
(
"ast_grep",
json!({"language":"rust","rule":{"rule":{"pattern":"let marker = 1;"}}}),
),
] {
let mut pages = ResultPages::default();
let first = dispatch_paged(&sources, &mut pages, tool, &arguments)
.unwrap()
.result;
let token = first["page"]["next"].as_str().unwrap().to_owned();
assert_eq!(
first["instructions"],
super::super::approved_text("search_accounting.instructions", 0)
);
uuid::Uuid::parse_str(first["search_id"].as_str().unwrap()).unwrap();
assert_eq!(
pages.outstanding_searches(),
[first["search_id"].as_str().unwrap()]
);
let undelivered = pages.pages[&token].0.clone();
assert!(
pages
.finish_search(&json!({"search_id":undelivered["search_id"],"used":[]}))
.is_err()
);
assert!(
pages
.finish_search(&json!({"search_id":first["search_id"],
"used":[undelivered["matches"][0]["tag"]]}))
.is_err()
);
let second = pages.next_page(&token).unwrap().result;
uuid::Uuid::parse_str(second["search_id"].as_str().unwrap()).unwrap();
assert_eq!(second, undelivered);
assert_ne!(first["search_id"], second["search_id"]);
assert!(second.get("instructions").is_none());
assert_eq!(pages.outstanding_searches().len(), 2);
let finished = pages
.finish_search(&json!({"search_id":second["search_id"],
"used":[second["matches"][0]["tag"]]}))
.unwrap();
assert_eq!(finished.inputs.len(), 1);
assert_eq!(finished.inputs[0]["item"], second["matches"][0]["item"]);
let replay = pages.next_page(&token).unwrap().result;
assert_eq!(replay, second);
assert_eq!(
pages.outstanding_searches(),
[first["search_id"].as_str().unwrap()]
);
pages
.finish_search(&json!({"search_id":first["search_id"],"used":[]}))
.unwrap();
assert!(pages.outstanding_searches().is_empty());
assert!(sources.recorded_inputs().is_empty());
assert!(first.to_string().len() <= PAGE_LIMIT);
assert!(second.to_string().len() <= PAGE_LIMIT);
}
}
Input 4: 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 5: outline src/authoring/searches.rs mod[tests]/fn[invalid_completion_is_atomic_and_can_be_corrected]
- File:
src/authoring/searches.rs - Selector:
mod[tests]/fn[invalid_completion_is_atomic_and_can_be_corrected] - Kind:
fn src/authoring/searches.rs:355–423
// {test}`requirements.authoring.finish_search.invalid`
// {test}`requirements.authoring.finish_search.atomicity`
// {test}`requirements.authoring.finish_search`
#[test]
fn invalid_completion_is_atomic_and_can_be_corrected() {
let root = project();
fs::write(root.path().join("src/lib.rs"), "fn first() {}\n").unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mut pages = ResultPages::default();
let result = search(&sources, &mut pages, "first");
let id = result["search_id"].clone();
for (args, expected) in [
(json!(null), "exactly search_id and used"),
(json!([]), "exactly search_id and used"),
(json!({}), "exactly search_id and used"),
(json!({"search_id":id}), "exactly search_id and used"),
(json!({"used":[]}), "exactly search_id and used"),
(
json!({"search_id":id,"used":[],"extra":0}),
"exactly search_id and used",
),
(
json!({"search_id":0,"used":[]}),
"search_id must be a UUID string",
),
(
json!({"search_id":"bad","used":[]}),
"search_id must be a UUID string",
),
(
json!({"search_id":Uuid::new_v4().to_string(),"used":[]}),
"only search results delivered in this assessment",
),
(
json!({"search_id":id,"used":null}),
"used must be an array of tag strings",
),
(
json!({"search_id":id,"used":"1"}),
"used must be an array of tag strings",
),
(
json!({"search_id":id,"used":["1",1]}),
"used must contain only tag strings",
),
(
json!({"search_id":id,"used":["1","missing"]}),
"unknown tag \"missing\"",
),
] {
let error = pages.finish_search(&args).err().unwrap().to_string();
assert!(error.contains(expected), "{args}: {error}");
assert_eq!(pages.outstanding_searches(), [id.as_str().unwrap()]);
assert!(sources.recorded_inputs().is_empty());
}
let good = pages
.finish_search(&json!({"search_id":id,"used":["1"]}))
.unwrap();
sources.record_inputs(&good.inputs);
assert_eq!(sources.recorded_inputs().len(), 1);
assert!(pages.outstanding_searches().is_empty());
assert!(
pages
.finish_search(&json!({"search_id":id,"used":["1","missing"]}))
.is_err()
);
assert!(pages.outstanding_searches().is_empty());
assert_eq!(sources.recorded_inputs().len(), 1);
}
Other sources
Input 1: requirements selection requirements.authoring.finish_search.invalid
requirements.authoring.finish_search.invalid:md/requirements/authoring.md:1027–1032
:::{req} finish_search.invalid
Missing, extra, or wrongly typed arguments, an invalid or unknown UUID,
a UUID from another assessment, or a tag outside that UUID's delivered
`matches` MUST return an explanatory tool error. The assessment MUST
continue so the model can correct the call.
:::