requirements.authoring.search_accounting.instructions
Requirements index · View definition
Requirement
The first delivered search result in each assessment MUST include an
instructionsfield containing this text:Before submitting your assessment, close every delivered search with finish_search({search_id, used:[tags]}). Submission fails while any search remains open. Include a tag only when you used information in its snippet to justify your conclusion without an additional source read. Entries whose source you subsequently read with habeas may be omitted; including them is harmless. Use used:[] when no entries qualify, including for an empty search. finish_search records dependencies and does not request more source.
Rationale
The subject’s one obligation is that the first delivered search result in each assessment MUST carry an instructions field holding the quoted text.
Tests reviewed
src/authoring/pages.rs#mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed]starts a freshResultPagesfor each ofripgrepandast_grep. It asserts that the first paged result’sinstructionsequalsapproved_text("search_accounting.instructions", 0). It also asserts that the second page has noinstructionsfield.src/authoring/searches.rs#mod[tests]/fn[delivered_searches_including_empty_results_need_explicit_completion]checks the first result of a session for aripgrepsearch that has matches. It also covers an empty first result for bothripgrepandast_grep, each on a freshResultPages(an “each assessment” case). In each of those it asserts theinstructionsequal the approved text. It asserts that the later empty and repeated results in the same session have noinstructions. It also checks that a failed search, which delivers nothing, does not use up the instructions: the first successful search still carries them.
Expected text
approved_textinsrc/authoring/mod.rsreads the first```textblock of thesearch_accounting.instructionsrequirement directly frommd/requirements/authoring.md. The expected value is therefore the book’s own text, not a copy that could drift. The same test would catch any change to the delivered wording.
Coverage
- This covers the field’s presence, its exact content, the first result of an assessment (including an empty result and a result that has further pages), and a new assessment starting a new session. I found no relevant input class left untested, and no acknowledgments apply.
Inputs
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);
}
}
Input 3: 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"]);
}
}
Other sources
Input 1: requirements selection requirements.authoring.search_accounting.instructions
requirements.authoring.search_accounting.instructions:md/requirements/authoring.md:950–957
:::{req} search_accounting.instructions
The first delivered search result in each assessment MUST include an
`instructions` field containing this text:
```text
Before submitting your assessment, close every delivered search with finish_search({search_id, used:[tags]}). Submission fails while any search remains open. Include a tag only when you used information in its snippet to justify your conclusion without an additional source read. Entries whose source you subsequently read with habeas may be omitted; including them is harmless. Use used:[] when no entries qualify, including for an empty search. finish_search records dependencies and does not request more source.
```
:::
Input 4: outline src/authoring/mod.rs fn[approved_text]
- File:
src/authoring/mod.rs - Selector:
fn[approved_text] - Kind:
fn src/authoring/mod.rs:729–744
/// The `index`th text block of approved requirement `name` in the authoring
/// chapter, which is the sole source of these instructions.
// {impl}`requirements.authoring.initial_prompt`
// {impl}`requirements.authoring.habeas_background`
// {impl}`requirements.authoring.judgment_rules`
fn approved_text(name: &str, index: usize) -> &'static str {
let chapter = include_str!("../../md/requirements/authoring.md");
let opening = format!(":::{{req}} {name}\n");
let start = chapter.find(&opening).expect("approved requirement") + opening.len();
let body = &chapter[start..];
let body = &body[..body.find("\n:::\n").expect("requirement closing fence")];
body.split("```text\n")
.nth(index + 1)
.and_then(|block| block.split("\n```").next())
.expect("approved text block")
}