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

Requirements index · View definition

evidence Valid

Requirement

The hash recorded for a selected tag MUST describe the source snapshot that produced its delivered excerpt, even if the file changes before finish_search.

Rationale

The reviewed tests adequately check requirements.authoring.finish_search.snapshot.

Obligation. The hash recorded for a selected tag must describe the source snapshot that produced the delivered excerpt. That must hold even if the file changes before finish_search.

Direct test. src/authoring/searches.rs#mod[tests]/fn[selected_dependencies_keep_the_delivered_hash_and_accumulate_without_reads] carries a {test} reference to the subject.

  • It writes src/lib.rs and runs a search, so the excerpt is delivered.
  • It computes original with outline_input for fn[first] from the delivered snapshot.
  • It then rewrites the file so that first has a different body, and only then calls finish_search with tag “1”.
  • It asserts finish.inputs == [original]. A finish-time re-hash would produce the new hash and fail this assertion.
  • It validates the recorded input against the mutated file with validate_input and asserts a “hash” error. This shows the recorded hash really is the old snapshot’s hash and is not silently refreshed.
  • It selects tag “2” after the same mutation. The recorded input equals the hash of fn[second], so the delivered hash is kept for later selections from the same search.
  • Repeated selection of tag “1” and an empty used list leave the recorded inputs unchanged.

Second test. src/authoring/mod.rs#mod[tests]/fn[a_helper_used_only_through_a_search_snippet_invalidates_saved_evidence_when_weakened] implements the search_accounting.helper_freshness example, which the subject’s text references.

  • A helper selected only through a search snippet is recorded with its outline input and hash.
  • The test asserts that the recorded hash validates against the original file.
  • After the helper is weakened, the same recorded hash fails validation with a “hash” error, while the marked test’s own hash is unchanged.
  • This covers the snapshot semantics for a search-only dependency.

Coverage across search tools. The mutation test uses a ripgrep-style search. In src/authoring/tools.rs#fn[dispatch_paged], ripgrep and ast_grep both go through the same pages.deliver path. Hash capture is therefore shared, and a separate ast_grep snapshot test would exercise no distinct required behavior.

No gaps were found, and no acknowledgments apply.

Inputs

Tests

Input 2: 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 3: 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 4: 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.snapshot
:::{req} finish_search.snapshot
The hash recorded for a selected tag MUST describe the source snapshot that
produced its delivered excerpt, even if the file changes before `finish_search`.
:::
Input 5: outline src/authoring/tools.rs fn[dispatch_paged]
// {impl}`requirements.authoring.file_discovery`
// {impl}`requirements.authoring.structural_search`
// {impl}`requirements.authoring.outline_tool`
// {impl}`requirements.authoring.reference_index`
// {impl}`requirements.authoring.github_reads`
pub(crate) fn dispatch_paged(
    sources: &AssessmentSources,
    pages: &mut ResultPages,
    name: &str,
    arguments: &Value,
) -> io::Result<ToolDelivery> {
    let arguments = arguments
        .as_object()
        .ok_or_else(|| io::Error::other("tool arguments must be an object"))?;
    let mut deliver = |listing: io::Result<Listing>| pages.deliver(sources, listing?);
    match name {
        "habeas" => read(sources, arguments).and_then(|read| match read {
            Ok(delivery) => Ok(delivery),
            Err(listing) => deliver(Ok(listing)),
        }),
        "list_files" => {
            deliver(list_files(sources, arguments).and_then(|listing| {
                with_not_listed(sources, arguments, NotListed::Children, listing)
            }))
        }
        "outline" => deliver(outline(sources, arguments)),
        "ripgrep" => deliver(search(sources, arguments).and_then(|listing| {
            let pattern = regex::Regex::new(string(arguments, "pattern")?).ok();
            with_not_listed(sources, arguments, NotListed::Text(pattern), listing)
        })),
        "ast_grep" => deliver(structural(sources, arguments).and_then(|listing| {
            let rule = arguments
                .get("language")
                .and_then(Value::as_str)
                .zip(arguments.get("rule").and_then(Value::as_object))
                .and_then(|(language, rule)| StructuralRule::compile(language, rule).ok());
            with_not_listed(sources, arguments, NotListed::Rule(rule), listing)
        })),
        "references" => deliver(references(sources, arguments)),
        "next_page" => check_keys(arguments, &["token"])
            .and_then(|()| pages.next_page(string(arguments, "token")?)),
        "finish_search" => pages.finish_search(&Value::Object(arguments.clone())),
        // GitHub reads are not evidence inputs.
        "github" => crate::github::tool(&sources.github, &Value::Object(arguments.clone()))
            .map(|result| ToolDelivery {
                result,
                inputs: Vec::new(),
            })
            .map_err(io::Error::other),
        _ => Err(io::Error::other(format!("unknown read tool {name:?}"))),
    }
    .map(|delivery| with_redaction_note(sources, delivery))
    .map_err(super::access::recoverable_os_denial)
    .map_err(super::access::recoverable_outside_request)
}