requirements.authoring.search_accounting.page_replay
Requirements index · View definition
Requirement
Repeated retrieval of the same search page MUST preserve its UUID and tags and MUST NOT reopen it if it has already been finished.
Rationale
Obligations in requirements.authoring.search_accounting.page_replay:
- Repeated retrieval of the same page MUST preserve its UUID and tags.
- Repeated retrieval MUST NOT reopen the page’s search if it has already been finished.
Test. src/authoring/pages.rs#mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed] is marked {test} for this requirement. It runs against both ripgrep and ast_grep, each producing a multi-page result.
- Setup. It fetches page 2 with
next_page(&token)and finishes it withfinish_search. Before that finish,pages.outstanding_searches().len()is 2, so both searches are outstanding. - Replay. It then calls
pages.next_page(&token)again.assert_eq!(replay, second)compares the whole JSON result. That covers the UUID (search_id) and every entry tag, so both are preserved.assert_eq!(pages.outstanding_searches(), [first["search_id"]])shows the finished page-2 search was not reopened. Only page 1 is still outstanding.
- Cleanup. It finishes page 1 and asserts that no searches remain outstanding. This confirms the replay left no stray open search.
Unfinished replay. The test does not replay a page that is still unfinished. I checked the implementation only to see whether that case needs its own test. ResultPages::next_page returns the stored result and calls Searches::delivered. Searches::delivered only sets delivered = true. It has no branch on finished versus unfinished and does not change the UUID or finished state. The unfinished case therefore takes the same path as the finished one that is tested, so it needs no separate test.
I found no gap.
Inputs
Implementation
Input 3: outline src/authoring/pages.rs impl[ResultPages]/fn[next_page]
- File:
src/authoring/pages.rs - Selector:
impl[ResultPages]/fn[next_page] - Kind:
fn src/authoring/pages.rs:251–264
/// The page a `next_page` token names, in the shape of the first.
// {impl}`requirements.authoring.search_accounting.page_replay`
pub(crate) fn next_page(&mut self, token: &str) -> io::Result<ToolDelivery> {
let (result, inputs) = self.pages.get(token).ok_or_else(|| {
io::Error::other(format!(
"unknown page token {token:?}: a token is valid only in the assessment whose paged result returned it; repeat that tool call to page through its result again"
))
})?;
self.searches.delivered(result);
Ok(ToolDelivery {
result: result.clone(),
inputs: inputs.clone(),
})
}
Input 4: outline src/authoring/searches.rs impl[Searches]/fn[delivered]
- File:
src/authoring/searches.rs - Selector:
impl[Searches]/fn[delivered] - Kind:
fn src/authoring/searches.rs:80–91
// {impl}`requirements.authoring.search_accounting.outstanding`
// {impl}`requirements.authoring.search_accounting.page_replay`
pub(super) fn delivered(&mut self, result: &Value) {
if let Some(id) = result.get("search_id").and_then(Value::as_str) {
let id = Uuid::parse_str(id).expect("prepared search UUID");
self.results
.get_mut(&id)
.expect("prepared search")
.delivered = true;
self.delivered_any = true;
}
}
Tests
Input 2: 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);
}
}
Other sources
Input 1: requirements selection requirements.authoring.search_accounting.page_replay
requirements.authoring.search_accounting.page_replay:md/requirements/authoring.md:945–948
:::{req} search_accounting.page_replay
Repeated retrieval of the same search page MUST preserve its UUID and tags
and MUST NOT reopen it if it has already been finished.
:::