requirements.authoring.finish_search.deduplication
Requirements index · View definition
Requirement
Duplicate selected tags and identical recorded inputs MUST have no additional effect.
Rationale
The requirement requirements.authoring.finish_search.deduplication has two obligations. Duplicate selected tags MUST have no additional effect. Identical recorded inputs MUST have no additional effect. Both are tested with assertions on the outcome.
Duplicate selected tags
src/authoring/searches.rs#mod[tests]/fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads]callsfinish_searchwithused: ["1","1"]. It assertsfinish.inputs == [original], so the duplicated tag yields exactly one input.src/authoring/mod.rs#mod[tests]/fn[multiple_selected_tags_are_recorded_before_acknowledgment_and_survive_a_failed_turn]runs a fullassessturn withFinish(0, ["3","1","3"]).- Each expected input (
fn[third],fn[first]) is asserted to appear exactly once insources.recorded_inputs(). - The unselected
fn[unused]is asserted absent. - This runs both with and without a failed turn after the acknowledgment, so the single-recording result also holds when the turn fails.
- Each expected input (
Identical recorded inputs
- In
fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads], the samefn[second]input reachesrecord_inputsthree more times.- It arrives once from a separate
habeasread of the same item. - It arrives once from a repeated
finish_searchwith["2"]. - It arrives once from a
finish_searchwith[]. - After these the test asserts
recorded_inputs().len() == 2, with itemsfn[first]andfn[second]in order. This shows that re-recording an identical input adds nothing.
- It arrives once from a separate
- The test also checks that the recorded input keeps the originally delivered hash after the file is mutated. That is not part of this requirement, but it confirms the recorded input is the one deduplicated.
Gaps
- A violating implementation would record a duplicate tag twice. Another would append an identical input again. Both would fail the count and length assertions above.
- I found no unmarked or missing scenario for either obligation.
Inputs
Tests
Input 2: outline src/authoring/mod.rs mod[tests]/fn[multiple_selected_tags_are_recorded_before_acknowledgment_and_survive_a_failed_turn]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[multiple_selected_tags_are_recorded_before_acknowledgment_and_survive_a_failed_turn] - Kind:
fn src/authoring/mod.rs:2857–2943
// {test}`requirements.authoring.finish_search.inputs`
// {test}`requirements.authoring.finish_search.unselected`
// {test}`requirements.authoring.finish_search.deduplication`
#[tokio::test]
async fn multiple_selected_tags_are_recorded_before_acknowledgment_and_survive_a_failed_turn() {
use SearchAction::{Call, Finish};
struct Provider {
scripted: SearchProvider,
fail_after_finish: bool,
}
impl CompletionProvider for Provider {
async fn complete(&self, request: CompletionRequest) -> io::Result<CompletionResponse> {
if self.fail_after_finish && self.scripted.requests.borrow().len() == 2 {
let history = serde_json::to_value(&request.chat_history).unwrap();
let acknowledgment = history.as_array().unwrap().last().unwrap().to_string();
assert!(acknowledgment.contains("finished"));
assert!(!acknowledgment.contains("fn first"));
self.scripted.requests.borrow_mut().push(history);
return Err(io::Error::other("fixture stopped after acknowledgment"));
}
self.scripted.complete(request).await
}
}
for fail_after_finish in [false, true] {
let root = inputs::tests::project();
fs::write(
root.path().join("src/lib.rs"),
"fn first() { assert!(true); }\nfn unused() {}\nfn third() { assert_eq!(1, 1); }\n",
)
.unwrap();
let expected = ["fn[third]", "fn[first]"]
.map(|item| crate::inputs::outline_input(root.path(), "src/lib.rs", item).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 provider = Provider {
fail_after_finish,
scripted: SearchProvider {
submit: "submit_judgment",
turns: vec![
vec![Call("ripgrep", json!({"pattern":"fn","path":"src/lib.rs"}))],
vec![Finish(0, vec!["3", "1", "3"])],
vec![Call(
"submit_judgment",
json!({"determination":true,
"rationale":"Both selected snippets contain assertions."}),
)],
],
requests: RefCell::default(),
},
};
let outcome = assess(&provider, &mut sources, &mut usage).await;
if fail_after_finish {
assert!(
outcome
.err()
.unwrap()
.to_string()
.contains("fixture stopped")
);
} else {
let (_, evidence) = outcome.unwrap();
for input in &expected {
assert!(evidence["inputs"].as_array().unwrap().contains(input));
}
}
for input in &expected {
assert_eq!(
sources
.recorded_inputs()
.iter()
.filter(|seen| *seen == input)
.count(),
1
);
}
assert!(
!sources
.recorded_inputs()
.iter()
.any(|input| input["item"] == "fn[unused]")
);
assert_eq!(provider.scripted.requests.borrow().len(), 3);
}
}
Input 3: outline src/authoring/searches.rs mod[tests]/fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads]
- File:
src/authoring/searches.rs - Selector:
mod[tests]/fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads] - Kind:
fn src/authoring/searches.rs:269–353
// {test}`requirements.authoring.finish_search.completion`
// {test}`requirements.authoring.finish_search.no_additional_source`
// {test}`requirements.authoring.finish_search.inputs`
// {test}`requirements.authoring.finish_search.snapshot`
// {test}`requirements.authoring.finish_search.unselected`
// {test}`requirements.authoring.finish_search.deduplication`
// {test}`requirements.authoring.finish_search.repetition`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.finish_search`
#[test]
fn selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads() {
let root = project();
fs::write(
root.path().join("src/lib.rs"),
"fn first() { assert!(true); }\nfn second() {}\n",
)
.unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mut pages = ResultPages::default();
let result = search(&sources, &mut pages, "fn");
let original =
crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[first]").unwrap();
// Mutation after delivery must not silently substitute a new hash.
fs::write(
root.path().join("src/lib.rs"),
"fn first() {}\nfn second() {}\n",
)
.unwrap();
let finish = pages
.finish_search(&json!({"search_id":result["search_id"],"used":["1","1"]}))
.unwrap();
assert_eq!(finish.inputs, [original]);
assert_eq!(
finish.result,
json!({"search_id":result["search_id"],"finished":true})
);
assert!(finish.result.get("text").is_none());
assert!(pages.outstanding_searches().is_empty());
sources.record_inputs(&finish.inputs);
assert_eq!(sources.recorded_inputs().len(), 1);
assert_eq!(sources.recorded_inputs()[0]["item"], "fn[first]");
let mut errors = Vec::new();
crate::evidence::validate_input(
root.path(),
&BTreeMap::new(),
&crate::inputs::OutlineCache::default(),
&finish.inputs[0],
"selected",
&mut errors,
);
assert!(
errors.iter().any(|error| error.contains("hash")),
"{errors:?}"
);
let second = pages
.finish_search(&json!({"search_id":result["search_id"],"used":["2"]}))
.unwrap();
assert_eq!(
second.inputs,
[crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[second]").unwrap()]
);
sources.record_inputs(&second.inputs);
assert_eq!(sources.recorded_inputs().len(), 2);
// A separately read item can be included harmlessly, or omitted.
let read = dispatch_paged(
&sources,
&mut pages,
"habeas",
&json!({"file":"src/lib.rs","item":"fn[second]"}),
)
.unwrap();
sources.record_inputs(&read.inputs);
let repeated = pages
.finish_search(&json!({"search_id":result["search_id"],"used":["2"]}))
.unwrap();
sources.record_inputs(&repeated.inputs);
let empty = pages
.finish_search(&json!({"search_id":result["search_id"],"used":[]}))
.unwrap();
sources.record_inputs(&empty.inputs);
assert_eq!(sources.recorded_inputs().len(), 2);
assert_eq!(sources.recorded_inputs()[0]["item"], "fn[first]");
assert_eq!(sources.recorded_inputs()[1]["item"], "fn[second]");
}
Other sources
Input 1: requirements selection requirements.authoring.finish_search.deduplication
requirements.authoring.finish_search.deduplication:md/requirements/authoring.md:1017–1020
:::{req} finish_search.deduplication
Duplicate selected tags and identical recorded inputs MUST have no
additional effect.
:::