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.submission.searches.accompanying_calls

Requirements index · View definition

evidence Valid

Requirement

Non-submission tool calls accompanying a submission, including finish_search, MUST be skipped, even when the submission is rejected for outstanding searches.

Rationale

The tests adequately check requirements.authoring.submission.searches.accompanying_calls.

Obligations

  1. Non-submission calls in the same response as a submission are skipped. This includes finish_search, and it holds even when the submission is rejected for outstanding searches.
  2. Skipped calls have no effect. They finish no search, add no recorded inputs, and deliver no new search.

Coverage

  • Rejection for outstanding searches. mod[tests]/fn[every_submission_kind_waits_for_all_searches_and_can_recover] runs the scenario the requirement names, once for submit_judgment and once for submit_verification.
    • Turn 1 delivers two searches.
    • Turn 2 puts finish_search (Finish(0, [“1”])), habeas, ripgrep and the submission in one response.
    • The test asserts that the blocked reply says “not run: the response also made a submission”. It also asserts that the reply lists both search IDs and says to call finish_search for every listed ID and then resubmit.
    • Because the accompanying finish_search is skipped, the later outstanding-searches message (requests[4]) must still list the second search. It must not list the first, which a later non-accompanying finish closes. The test asserts exactly that.
    • Usage counters show tool_skipped of 1 for each of finish_search, habeas and ripgrep.
    • fn[untouched], which the skipped habeas call would have read, is absent from the recorded inputs. The fn[helper] input is recorded exactly once.
    • If the skipped ripgrep had run, it would have delivered a third search. The test checks that only two searches existed and that the request count is exactly 6.
    • If the accompanying finish_search had run, the blocked-reply and counter assertions would fail.
  • Rejection for a second line-number rationale. mod[tests]/fn[a_second_line_number_rationale_fails_only_after_searches_are_finished] covers a rejected submission accompanied by habeas. It asserts the reply contains “not run” and that fn[untouched] is not in the recorded inputs.
  • Accepted submission. mod[tests]/fn[a_submission_finishes_the_assessment_wherever_it_arrives] covers the accepted case with the other call placed before and after the submission.
    • It asserts exactly one skipped call and no tool failures.
    • It asserts that no src/lib.rs input was delivered.
    • It asserts the request counts.

Conclusion The accompanying-call kinds, both submission tools, both orderings and the rejected and accepted outcomes are all exercised. The assertions check the observable effects: skip counters, unchanged search state, no recorded inputs and the diagnostic text. I found no unaddressed obligation or boundary case.

Inputs

Tests

Input 2: 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 3: outline src/authoring/mod.rs mod[tests]/fn[a_second_line_number_rationale_fails_only_after_searches_are_finished]
  • File: src/authoring/mod.rs
  • Selector: mod[tests]/fn[a_second_line_number_rationale_fails_only_after_searches_are_finished]
  • Kind: fn
  • src/authoring/mod.rs:3031–3095
    // {test}`requirements.authoring.line_numbers.resubmission`
    // {test}`requirements.authoring.submission.searches.line_numbers`
    // {test}`requirements.authoring.submission.searches.accompanying_calls`
    #[tokio::test]
    async fn a_second_line_number_rationale_fails_only_after_searches_are_finished() {
        use SearchAction::{Call, Finish};
        let root = inputs::tests::project();
        fs::write(root.path().join("src/lib.rs"), "fn 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 second = json!({"determination":true,"rationale":"src/lib.rs:2 is fine."});
        let provider = SearchProvider {
            submit: "submit_judgment",
            turns: vec![
                vec![
                    Call(
                        "habeas",
                        json!({"file":"src/lib.rs","item":"fn[untouched]"}),
                    ),
                    Call(
                        "submit_judgment",
                        json!({"determination":false,"rationale":"src/lib.rs:1 fails."}),
                    ),
                ],
                vec![Call("ripgrep", json!({"pattern":"absent"}))],
                vec![Call("submit_judgment", second.clone())],
                vec![Finish(0, vec![])],
                vec![Call("submit_judgment", second)],
            ],
            requests: RefCell::default(),
        };
        let error = assess(&provider, &mut sources, &mut usage)
            .await
            .unwrap_err()
            .to_string();
        assert!(error.contains("after a rejection"), "{error}");
        let requests = provider.requests.borrow();
        assert_eq!(requests.len(), 5);
        assert!(
            requests[1]
                .as_array()
                .unwrap()
                .last()
                .unwrap()
                .to_string()
                .contains("not run")
        );
        assert!(
            requests[3]
                .as_array()
                .unwrap()
                .last()
                .unwrap()
                .to_string()
                .contains("outstanding searches")
        );
        assert!(usage.record.determination.is_none());
        assert!(
            !sources
                .recorded_inputs()
                .iter()
                .any(|input| input["item"] == "fn[untouched]")
        );
    }
Input 4: outline src/authoring/mod.rs mod[tests]/fn[a_submission_finishes_the_assessment_wherever_it_arrives]
    // {test}`requirements.authoring.submission`
    // {test}`requirements.authoring.line_numbers.rejection`
    // {test}`requirements.authoring.submission.searches.accompanying_calls`
    #[tokio::test]
    async fn a_submission_finishes_the_assessment_wherever_it_arrives() {
        let read = json!({"file": "src/lib.rs", "item": "fn[work]"});
        let submit = json!({"determination": false, "rationale": "Gaps remain."});
        let invalid = json!({"determination": "false", "rationale": "Gaps remain."});
        let cited = json!({"determination": false, "rationale": "See line 10."});
        let invalid_cited = json!({"determination": "false", "rationale": "See line 10."});
        for (turns, accepted, requests) in [
            // After earlier tool turns.
            (
                vec![
                    vec![("habeas", read.clone())],
                    vec![("habeas", read.clone())],
                    vec![("submit_judgment", submit.clone())],
                ],
                true,
                3,
            ),
            // Alongside other tool calls in the same response, before or after
            // them: the submission finishes and the other calls are skipped.
            (
                vec![vec![
                    ("habeas", read.clone()),
                    ("submit_judgment", submit.clone()),
                ]],
                true,
                1,
            ),
            (
                vec![vec![
                    ("submit_judgment", submit.clone()),
                    ("ripgrep", json!({"pattern": "work"})),
                ]],
                true,
                1,
            ),
            // Multiple submissions anywhere in one response fail even when the
            // first is valid, and invalid arguments fail without a retry.
            (
                vec![vec![
                    ("submit_judgment", submit.clone()),
                    ("habeas", read.clone()),
                    ("submit_judgment", submit.clone()),
                ]],
                false,
                1,
            ),
            (
                vec![
                    vec![("habeas", read.clone())],
                    vec![("submit_judgment", invalid.clone())],
                    vec![("submit_judgment", submit.clone())],
                ],
                false,
                2,
            ),
            (
                vec![vec![
                    ("submit_judgment", cited.clone()),
                    ("submit_judgment", cited.clone()),
                ]],
                false,
                1,
            ),
            (vec![vec![("submit_judgment", invalid_cited)]], false, 1),
        ] {
            let project = inputs::tests::project();
            fs::write(project.path().join("src/lib.rs"), "fn work() {}\n").unwrap();
            let mut sources =
                AssessmentSources::prepare(project.path(), "requirements.ready").unwrap();
            let state = tempfile::tempdir().unwrap();
            let mut usage =
                UsageLog::start(state.path(), project.path(), &sources.subject_name).unwrap();
            let provider = ScriptedProvider {
                turns: turns.clone(),
                requests: RefCell::default(),
            };
            let result = assess(&provider, &mut sources, &mut usage).await;
            assert_eq!(*provider.requests.borrow(), requests, "{turns:?}");
            let record = serde_json::to_value(&usage.record).unwrap();
            if accepted {
                let (judgment, evidence) = result.unwrap();
                assert_eq!(judgment, Judgment::False);
                assert_eq!(evidence["rationale"], "Gaps remain.");
                let last = turns.last().unwrap();
                if last.len() > 1 {
                    // The other calls in the submitting response were skipped,
                    // not run, so they delivered no inputs.
                    let skipped = record["tool_skipped"].as_object().unwrap();
                    assert_eq!(
                        skipped.values().filter_map(Value::as_u64).sum::<u64>(),
                        1,
                        "{record:#}"
                    );
                    assert!(record["tool_failures"].as_object().unwrap().is_empty());
                    assert!(
                        evidence["inputs"]
                            .as_array()
                            .unwrap()
                            .iter()
                            .all(|input| input["file"] != "src/lib.rs"),
                        "{evidence}"
                    );
                }
            } else {
                let error = result.unwrap_err().to_string();
                assert!(!error.contains("line numbers"), "{turns:?}: {error}");
                if turns.last().unwrap().len() > 1 {
                    assert!(error.contains("exactly once"), "{error}");
                } else {
                    assert!(error.contains("expected true, false"), "{error}");
                }
            }
        }
    }

Other sources

Input 1: requirements selection requirements.authoring.submission.searches.accompanying_calls
:::{req} submission.searches.accompanying_calls
Non-submission tool calls accompanying a submission, including `finish_search`,
MUST be skipped, even when the submission is rejected for outstanding searches.
:::