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.inputs

Requirements index · View definition

evidence Valid

Requirement

For each tag selected by a valid finish_search call, the harness MUST record its file, item, and structural hash as an outline input under cite requirements.ci.outline_inputs before acknowledging that call.

Rationale

I judge the reviewed tests adequate for requirements.authoring.finish_search.inputs. I did not request implementation source, because the tests’ assertions were enough to map each obligation.

The requirement has three testable obligations. For every tag selected by a valid finish_search call, the harness records an outline input holding file, item and the structural hash. That recording happens before the call is acknowledged. Selected tags need no extra read.

  • Recorded input has file, item and hash.
    • src/authoring/searches.rs#mod[tests]/fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads] selects tag “1” after the source file has been mutated. It asserts that finish.inputs equals the outline input computed from the original source (crate::inputs::outline_input(..., "fn[first]")). That value is the delivered file, item and hash.
    • The same test then validates the input against the changed file and expects a hash error. That shows the recorded hash is the delivered one and not a fresh one.
    • It asserts that sources.recorded_inputs() holds fn[first], and later fn[second].
    • It also asserts that finish.result has no source text.
  • Several tags, and only selected tags.
    • src/authoring/mod.rs#mod[tests]/fn[multiple_selected_tags_are_recorded_before_acknowledgment_and_survive_a_failed_turn] selects tags ["3","1","3"] from a search that also returned fn[unused].
    • It asserts that the outline inputs for fn[third] and fn[first] are recorded exactly once each.
    • It asserts that fn[unused] is not recorded.
  • Recorded before acknowledgment.
    • In the fail_after_finish variant, the provider checks that the acknowledgment sent back contains “finished” and no source text. It then aborts the turn.
    • The test still finds both inputs recorded exactly once afterwards. The recording therefore happened before, or independently of, the acknowledgment being consumed.
    • In the normal variant the inputs also appear in the evidence.
  • No habeas read needed.
    • src/authoring/mod.rs#mod[tests]/fn[a_helper_used_only_through_a_search_snippet_invalidates_saved_evidence_when_weakened] finishes a ripgrep search with a helper’s tag. It asserts that the helper’s outline input is recorded and that the log has no habeas calls.
    • It also checks that the saved input validates, then goes stale when the helper is replaced by a no-op. This matches the search_accounting.helper_freshness example.
  • Interaction with submissions and recovery. src/authoring/mod.rs#mod[tests]/fn[every_submission_kind_waits_for_all_searches_and_can_recover] checks that fn[helper] is recorded once for both submit_judgment and submit_verification. The tag was selected by a valid finish_search call. The test also checks that fn[untouched], which was read only in a skipped call, is not recorded.

The requirement only obliges recording for valid calls. Invalid calls are not required to record anything, so their absence from the tests is not a gap. I found no plausible violating behavior that these tests would accept.

Inputs

Tests

Input 3: requirements selection requirements.authoring.search_accounting.helper_freshness
:::{example} search_accounting.helper_freshness
A marked test calls `assert_refusal`. A search excerpt of that helper supplies
the refusal and byte-preservation assertions used to justify the judgment.
The model finishes the search with the helper's tag without reading it with
`habeas`. Saved evidence MUST include the helper's outline input.

Replacing the helper with a no-op MUST make that evidence stale, even when
the marked test source is unchanged.
{test}`requirements.authoring.finish_search.inputs`
{test}`requirements.authoring.finish_search.snapshot`
:::
Input 4: outline src/authoring/mod.rs mod[tests]/fn[every_submission_kind_waits_for_all_searches_and_can_recover]
    // {test}`requirements.authoring.submission.searches`
    // {test}`requirements.authoring.submission.searches.diagnostic`
    // {test}`requirements.authoring.submission.searches.recovery`
    // {test}`requirements.authoring.submission.searches.accompanying_calls`
    // {test}`requirements.authoring.finish_search.inputs`
    // {test}`requirements.authoring.search_accounting.recovery`
    #[tokio::test]
    async fn every_submission_kind_waits_for_all_searches_and_can_recover() {
        use SearchAction::{Call, Finish};
        for submit in ["submit_judgment", "submit_verification"] {
            let root = inputs::tests::project();
            fs::write(
                root.path().join("src/lib.rs"),
                "fn helper() { assert!(true); }\nfn untouched() {}\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 arguments = if submit == "submit_judgment" {
                json!({"determination":true,"rationale":"Helper checks its assertion."})
            } else {
                json!({"real":false,"acknowledged":false,"acknowledgments":[],
                    "rationale":"Helper checks its assertion."})
            };
            let provider = SearchProvider {
                submit,
                turns: vec![
                    vec![
                        Call("ripgrep", json!({"pattern":"assert","path":"src/lib.rs"})),
                        Call(
                            "ast_grep",
                            json!({"language":"rust","rule":{"rule":{"pattern":"absent()"}}}),
                        ),
                    ],
                    // Accompanying completion is skipped, so both IDs remain open.
                    vec![
                        Finish(0, vec!["1"]),
                        Call(
                            "habeas",
                            json!({"file":"src/lib.rs","item":"fn[untouched]"}),
                        ),
                        Call("ripgrep", json!({"pattern":"absent","path":"src/lib.rs"})),
                        Call(submit, arguments.clone()),
                    ],
                    vec![Finish(0, vec!["1"])],
                    vec![Call(submit, arguments.clone())],
                    vec![Finish(1, vec![])],
                    vec![Call(submit, arguments)],
                ],
                requests: RefCell::default(),
            };
            if submit == "submit_judgment" {
                let (_, evidence) = assess(&provider, &mut sources, &mut usage).await.unwrap();
                assert!(
                    evidence["inputs"]
                        .as_array()
                        .unwrap()
                        .iter()
                        .any(|input| input["item"] == "fn[helper]" && input.get("hash").is_some())
                );
            } else {
                let result = verify(
                    &provider,
                    &mut sources,
                    &mut usage,
                    &Judgment::False,
                    "Alleged gap",
                )
                .await
                .unwrap();
                assert!(!result.real);
            }
            let requests = provider.requests.borrow();
            assert_eq!(requests.len(), 6);
            let mut searches = Vec::new();
            delivered_searches(&requests[1], &mut searches);
            assert_eq!(searches.len(), 2);
            let blocked = requests[2].as_array().unwrap().last().unwrap().to_string();
            assert!(blocked.contains("not run: the response also made a submission"));
            assert!(blocked.contains(searches[0]["search_id"].as_str().unwrap()));
            assert!(blocked.contains(searches[1]["search_id"].as_str().unwrap()));
            assert!(blocked.contains("Call finish_search for every listed search_id"));
            assert!(blocked.contains("then resubmit"));
            let latest = requests[4].as_array().unwrap().last().unwrap().to_string();
            assert!(latest.contains("outstanding searches"));
            assert!(!latest.contains(searches[0]["search_id"].as_str().unwrap()));
            assert!(latest.contains(searches[1]["search_id"].as_str().unwrap()));
            assert_eq!(
                sources
                    .recorded_inputs()
                    .iter()
                    .filter(|input| input["item"] == "fn[helper]")
                    .count(),
                1
            );
            let log: Value =
                serde_json::from_str(&fs::read_to_string(&usage.path).unwrap()).unwrap();
            assert_eq!(log["tool_calls"]["finish_search"], 3);
            assert_eq!(log["tool_skipped"]["finish_search"], 1);
            assert_eq!(log["tool_skipped"]["habeas"], 1);
            assert_eq!(log["tool_skipped"]["ripgrep"], 1);
            assert!(
                !sources
                    .recorded_inputs()
                    .iter()
                    .any(|input| input["item"] == "fn[untouched]")
            );
            assert_eq!(
                log["tool_failures"]
                    .as_object()
                    .unwrap()
                    .values()
                    .filter_map(Value::as_u64)
                    .sum::<u64>(),
                2
            );
        }
    }
Input 5: 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 6: outline src/authoring/mod.rs mod[tests]/fn[a_helper_used_only_through_a_search_snippet_invalidates_saved_evidence_when_weakened]
  • File: src/authoring/mod.rs
  • Selector: mod[tests]/fn[a_helper_used_only_through_a_search_snippet_invalidates_saved_evidence_when_weakened]
  • Kind: fn
  • src/authoring/mod.rs:3153–3235
    // {test}`requirements.authoring.search_accounting.helper_freshness`
    // {test}`requirements.authoring.finish_search.snapshot`
    // {test}`requirements.authoring.finish_search.inputs`
    // {test}`requirements.authoring.delivered_inputs`
    #[tokio::test]
    async fn a_helper_used_only_through_a_search_snippet_invalidates_saved_evidence_when_weakened()
    {
        use SearchAction::{Call, Finish};
        let root = inputs::tests::project();
        let helper_source = "fn assert_refusal(bytes: &mut Vec<u8>) {\n    let before = bytes.clone();\n    assert!(!try_insert(bytes));\n    assert_eq!(*bytes, before);\n}";
        let source = format!(
            "{helper_source}\nfn try_insert(_bytes: &mut Vec<u8>) -> bool {{ false }}\n\
            // {{test}}`requirements.ready`\n#[test]\nfn refuses_without_change() {{\n\
                let mut bytes = vec![1, 2];\n    assert_refusal(&mut bytes);\n}}\nfn unrelated() {{}}\n"
        );
        fs::write(root.path().join("src/lib.rs"), &source).unwrap();
        let marked_test =
            crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[refuses_without_change]")
                .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 = SearchProvider {
            submit: "submit_judgment",
            turns: vec![
                vec![Call(
                    "ripgrep",
                    json!({"pattern":"assert_refusal","path":"src/lib.rs","context":5}),
                )],
                vec![Finish(0, vec!["1"])],
                vec![Call(
                    "submit_judgment",
                    json!({"determination":true,
                    "rationale":"The assert_refusal snippet asserts refusal and byte preservation."}),
                )],
            ],
            requests: RefCell::default(),
        };
        let (_, evidence) = assess(&provider, &mut sources, &mut usage).await.unwrap();
        let inputs = evidence["inputs"].as_array().unwrap();
        let helper = inputs
            .iter()
            .find(|input| input["item"] == "fn[assert_refusal]")
            .unwrap();
        assert!(inputs.contains(&marked_test));
        assert!(!inputs.iter().any(|input| input["item"] == "fn[unrelated]"));
        assert!(helper.get("text").is_none());
        let mut errors = Vec::new();
        crate::evidence::validate_input(
            root.path(),
            &std::collections::BTreeMap::new(),
            &crate::inputs::OutlineCache::default(),
            helper,
            "helper",
            &mut errors,
        );
        assert!(errors.is_empty(), "{errors:?}");
        fs::write(
            root.path().join("src/lib.rs"),
            source.replace(helper_source, "fn assert_refusal(_bytes: &mut Vec<u8>) {}"),
        )
        .unwrap();
        assert_eq!(
            crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[refuses_without_change]")
                .unwrap(),
            marked_test
        );
        crate::evidence::validate_input(
            root.path(),
            &std::collections::BTreeMap::new(),
            &crate::inputs::OutlineCache::default(),
            helper,
            "helper",
            &mut errors,
        );
        assert!(
            errors.iter().any(|error| error.contains("hash")),
            "{errors:?}"
        );
        let log: Value = serde_json::from_str(&fs::read_to_string(&usage.path).unwrap()).unwrap();
        assert!(log["tool_calls"].get("habeas").is_none());
        assert_eq!(log["tool_calls"]["finish_search"], 1);
    }
Input 7: 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]");
    }

Referenced definitions

Input 2: requirements selection requirements.ci.outline_inputs
:::{req} outline_inputs
For an outline input, Habeas MUST parse `file` with its language's grammar under
{cite}`requirements.references.outlines` and resolve `item` to exactly one
outline node under {cite}`requirements.references.outline_selectors`. It MUST
compare `hash` with the node's current structural hash under
{cite}`requirements.references.structural_hash`. It MUST derive the node's
inclusive line range, including attached comments and attributes, during
validation for display and reference coverage. Moving the node, editing other
nodes, or editing comments its profile does not hash MUST NOT invalidate the
input. Habeas MUST report a missing file, unsupported language, parse failure,
invalid or ambiguous selector, or changed hash.
:::

Other sources

Input 1: requirements selection requirements.authoring.finish_search.inputs
:::{req} finish_search.inputs
For each tag selected by a valid `finish_search` call, the harness MUST record
its `file`, `item`, and structural hash as an outline input under
{cite}`requirements.ci.outline_inputs` before acknowledging that call.
:::