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

Requirements index · View definition

evidence Valid

Requirement

A rejected finish_search call MUST change neither recorded dependencies nor outstanding searches, including when only some supplied tags are valid.

Rationale

The subject has two obligations: a rejected finish_search call must leave recorded dependencies unchanged, and it must leave outstanding searches unchanged. This holds even when only some of the supplied tags are valid. Two tests carry a {test} reference to it, and together they cover both obligations.

  • src/authoring/searches.rs#mod[tests]/fn[invalid_completion_is_atomic_and_can_be_corrected] runs one real search, which produces tag “1”. It then submits many rejected calls: malformed arguments, bad or unknown UUIDs, bad used types, a non-string tag, and the mixed case ["1","missing"].
    • The mixed case has one valid tag and one invalid tag, which is the “only some supplied tags are valid” scenario the text names.
    • After every rejection it asserts that outstanding_searches() still equals the original id and that recorded_inputs() is empty.
    • A corrected call with ["1"] then succeeds, and its inputs are recorded. After that, a repeated mixed-tag call is rejected, and the test asserts that the outstanding set stays empty and the recorded inputs stay at one entry. So a rejection does not alter state in either direction.
  • src/authoring/mod.rs#mod[tests]/fn[a_bad_tag_returns_a_recoverable_error_without_closing_the_search] checks the same behaviour end to end through assess.
    • A ripgrep search for helper is followed by Finish(0, ["1","missing"]). The test asserts that this is rejected with “unknown tag”.
    • The next submit_judgment is rejected with a message mentioning “outstanding searches”. That shows the search was not closed by the rejected call.
    • After a corrected Finish(0, []) and a successful submit, the test asserts that the final evidence has no fn[helper] input. That shows the valid tag “1” in the rejected call was not recorded.

Assertion strength. In the searches.rs test, the recorded_inputs().is_empty() assertion is weak. finish_search there only returns inputs, and the caller records them. The mod.rs test fills that gap by checking the evidence from the real assessment loop, which is where the recording happens.

Remaining checks. I found no obligation without a test and no marking gap, and no FIXME applies.

Inputs

Tests

Input 2: outline src/authoring/mod.rs mod[tests]/fn[a_bad_tag_returns_a_recoverable_error_without_closing_the_search]
  • File: src/authoring/mod.rs
  • Selector: mod[tests]/fn[a_bad_tag_returns_a_recoverable_error_without_closing_the_search]
  • Kind: fn
  • src/authoring/mod.rs:2945–2982
    // {test}`requirements.authoring.finish_search.invalid`
    // {test}`requirements.authoring.finish_search.atomicity`
    #[tokio::test]
    async fn a_bad_tag_returns_a_recoverable_error_without_closing_the_search() {
        use SearchAction::{Call, Finish};
        let root = inputs::tests::project();
        fs::write(root.path().join("src/lib.rs"), "fn helper() {}\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 submit = json!({"determination":true,"rationale":"Complete."});
        let provider = SearchProvider {
            submit: "submit_judgment",
            turns: vec![
                vec![Call(
                    "ripgrep",
                    json!({"pattern":"helper","path":"src/lib.rs"}),
                )],
                vec![Finish(0, vec!["1", "missing"])],
                vec![Call("submit_judgment", submit.clone())],
                vec![Finish(0, vec![])],
                vec![Call("submit_judgment", submit)],
            ],
            requests: RefCell::default(),
        };
        let (_, evidence) = assess(&provider, &mut sources, &mut usage).await.unwrap();
        let requests = provider.requests.borrow();
        assert!(requests[2].to_string().contains("unknown tag"));
        assert!(requests[3].to_string().contains("outstanding searches"));
        assert_eq!(requests.len(), 5);
        assert!(
            !evidence["inputs"]
                .as_array()
                .unwrap()
                .iter()
                .any(|input| input["item"] == "fn[helper]")
        );
    }
Input 3: outline src/authoring/searches.rs mod[tests]/fn[invalid_completion_is_atomic_and_can_be_corrected]
    // {test}`requirements.authoring.finish_search.invalid`
    // {test}`requirements.authoring.finish_search.atomicity`
    // {test}`requirements.authoring.finish_search`
    #[test]
    fn invalid_completion_is_atomic_and_can_be_corrected() {
        let root = project();
        fs::write(root.path().join("src/lib.rs"), "fn first() {}\n").unwrap();
        let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let mut pages = ResultPages::default();
        let result = search(&sources, &mut pages, "first");
        let id = result["search_id"].clone();
        for (args, expected) in [
            (json!(null), "exactly search_id and used"),
            (json!([]), "exactly search_id and used"),
            (json!({}), "exactly search_id and used"),
            (json!({"search_id":id}), "exactly search_id and used"),
            (json!({"used":[]}), "exactly search_id and used"),
            (
                json!({"search_id":id,"used":[],"extra":0}),
                "exactly search_id and used",
            ),
            (
                json!({"search_id":0,"used":[]}),
                "search_id must be a UUID string",
            ),
            (
                json!({"search_id":"bad","used":[]}),
                "search_id must be a UUID string",
            ),
            (
                json!({"search_id":Uuid::new_v4().to_string(),"used":[]}),
                "only search results delivered in this assessment",
            ),
            (
                json!({"search_id":id,"used":null}),
                "used must be an array of tag strings",
            ),
            (
                json!({"search_id":id,"used":"1"}),
                "used must be an array of tag strings",
            ),
            (
                json!({"search_id":id,"used":["1",1]}),
                "used must contain only tag strings",
            ),
            (
                json!({"search_id":id,"used":["1","missing"]}),
                "unknown tag \"missing\"",
            ),
        ] {
            let error = pages.finish_search(&args).err().unwrap().to_string();
            assert!(error.contains(expected), "{args}: {error}");
            assert_eq!(pages.outstanding_searches(), [id.as_str().unwrap()]);
            assert!(sources.recorded_inputs().is_empty());
        }
        let good = pages
            .finish_search(&json!({"search_id":id,"used":["1"]}))
            .unwrap();
        sources.record_inputs(&good.inputs);
        assert_eq!(sources.recorded_inputs().len(), 1);
        assert!(pages.outstanding_searches().is_empty());
        assert!(
            pages
                .finish_search(&json!({"search_id":id,"used":["1","missing"]}))
                .is_err()
        );
        assert!(pages.outstanding_searches().is_empty());
        assert_eq!(sources.recorded_inputs().len(), 1);
    }

Other sources

Input 1: requirements selection requirements.authoring.finish_search.atomicity
:::{req} finish_search.atomicity
A rejected `finish_search` call MUST change neither recorded dependencies
nor outstanding searches, including when only some supplied tags are valid.
:::