Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.authoring.finish_search.unselected

Requirements index · View definition

evidence Valid

Requirement

A finish_search call MUST NOT add inputs for tags it does not select. It MUST retain all previously recorded inputs, including inputs recorded by earlier finish_search calls.

Rationale

The tests adequately check both obligations in requirements.authoring.finish_search.unselected. I did not read the implementation, and none was needed to judge the tests.

Obligation 1: a finish_search call MUST NOT add inputs for tags it does not select.

  • src/authoring/mod.rs#mod[tests]/fn[multiple_selected_tags_are_recorded_before_acknowledgment_and_survive_a_failed_turn] runs a ripgrep search over three functions: first, unused and third. It then finishes with tags ["3","1","3"], so the unused snippet is unselected.
    • It asserts that the recorded inputs contain no item fn[unused].
    • It asserts that each selected input appears exactly once.
    • It runs both with and without a failure after the finish, so the unselected tag stays out of the recorded inputs in both cases.
  • src/authoring/searches.rs#mod[tests]/fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads] finishes with used:["1","1"]. It asserts that finish.inputs equals exactly [original], the fn[first] input, so the unselected fn[second] is not added. A later finish with used:[] also adds nothing, and the recorded count stays at 2.

Obligation 2: it MUST retain all previously recorded inputs, including those from earlier finish_search calls.

  • The selected_dependencies… test makes several successive finish calls on the same search.
    • After the first finish, it records fn[first].
    • The second finish selects tag "2". The test then asserts that two inputs are recorded, with fn[first] at index 0 and fn[second] at index 1, so the earlier input survives.
    • A repeated finish with "2" and an empty finish follow. The test asserts that the count stays at 2 and that both items stay in their original order.
    • The test also records an input from a separate habeas read, and the recorded set still holds.
  • The multiple_selected_tags… test checks that recorded inputs survive a failed turn, which covers retention across the session.

The assertions enforce the required outcomes, and both tests carry {test} references to the subject. I found no gap.

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.unselected
:::{req} finish_search.unselected
A `finish_search` call MUST NOT add inputs for tags it does not select.
It MUST retain all previously recorded inputs, including inputs recorded
by earlier `finish_search` calls.
:::