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.search_accounting.result_ids

Requirements index · View definition

evidence Valid

Requirement

Each successfully delivered ripgrep or ast_grep result MUST contain a search_id UUID identifying only that result in the current assessment. A new search call MUST use new UUIDs.

Rationale

The tests adequately cover requirements.authoring.search_accounting.result_ids. I judged this from the supplied test source alone and did not request any implementation source.

The requirement has three obligations:

  1. Each delivered ripgrep or ast_grep result contains a search_id that is a UUID.
  2. That UUID identifies only that result.
  3. A new search call uses new UUIDs.

1. Each delivered result has a UUID, for both tools.

  • src/authoring/pages.rs#mod[tests]/fn[text_and_structural_search_results_page_whole_ordered_matches] loops over ripgrep and ast_grep. For every page it parses search_id with Uuid::parse_str(...).unwrap().
  • src/authoring/pages.rs#mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed] also covers both tools. It parses the search_id of the first and second pages.
  • src/authoring/searches.rs#mod[tests]/fn[delivered_searches_including_empty_results_need_explicit_completion] parses search_id for non-empty and empty results. It does this for ripgrep and ast_grep in the final loop.

2. A UUID identifies only that result.

  • In the whole-ordered-matches test, every page of a 600-entry paged result must yield a fresh UUID (assert!(ids.insert(id), "reused search UUID ...")), for both tools.
  • In the accounting test, assert_ne!(first["search_id"], second["search_id"]) checks that pages differ.
  • The same test uses outstanding_searches() to show that the first and second pages are distinct, separately tracked results.
  • Replaying a page returns the same result, with the same id, as the delivered page, and the id is not reassigned. A page that has not been delivered cannot be finished.
  • In the searches test, three results (first, empty, repeated) must all have distinct UUIDs, which the test checks through a BTreeSet of size 3.
  • The same test checks that each id is finishable individually, and that a different ResultPages instance rejects an id it did not deliver.

3. A new search call uses new UUIDs.

  • In the searches test, a repeated identical fn search gets a different id from the first one.
  • In the final loop, for each tool, a second identical call on the same ResultPages gives an id different from the first (assert_ne!(result["search_id"], again["search_id"])). This covers ripgrep and ast_grep and the empty-result case.

An erroring search, such as an invalid pattern, delivers no id, and outstanding_searches() is empty afterwards. This matches the “successfully delivered” qualifier.

I found no plausible violation that these assertions would accept. A reused id across pages, calls, or repeated identical searches would fail them, as would a non-UUID value or a missing id in either tool. Every test cites the requirement with {test}.

Inputs

Tests

Input 2: outline src/authoring/pages.rs mod[tests]/fn[text_and_structural_search_results_page_whole_ordered_matches]
    // {test}`requirements.authoring.result_pages`
    // {test}`requirements.authoring.search_accounting.result_ids`
    #[test]
    fn text_and_structural_search_results_page_whole_ordered_matches() {
        let root = project();
        let source: String = (0..600)
            .map(|i| format!("fn needle_{i:04}() {{ let marker = 1; }}\n"))
            .collect();
        fs::write(root.path().join("src/lib.rs"), source).unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        for (tool, arguments) in [
            ("ripgrep", json!({"pattern":"marker", "path":"src/lib.rs"})),
            (
                "ast_grep",
                json!({"language":"rust","rule":{"rule":{"pattern":"let marker = 1;"}},"path":"src/lib.rs"}),
            ),
        ] {
            let mut pages = ResultPages::default();
            let first = dispatch_paged(&sources, &mut pages, tool, &arguments).unwrap();
            let mut items = Vec::new();
            let mut ids = std::collections::BTreeSet::new();
            for page in all_pages(&mut pages, first) {
                let id = uuid::Uuid::parse_str(page.result["search_id"].as_str().unwrap()).unwrap();
                assert!(ids.insert(id), "reused search UUID for {tool}");
                assert!(page.result.to_string().len() <= PAGE_LIMIT, "{tool}");
                let matches = page.result["matches"].as_array().unwrap();
                assert_eq!(page.result["page"]["total_entries"], 600);
                assert_eq!(page.result["page"]["returned_entries"], matches.len());
                items.extend(
                    matches
                        .iter()
                        .map(|m| m["item"].as_str().unwrap().to_owned()),
                );
            }
            assert_eq!(
                items,
                (0..600)
                    .map(|i| format!("fn[needle_{i:04}]"))
                    .collect::<Vec<_>>(),
                "{tool}"
            );
        }
    }
Input 3: outline src/authoring/pages.rs mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed]
  • File: src/authoring/pages.rs
  • Selector: mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed]
  • Kind: fn
  • src/authoring/pages.rs:662–738
    // {test}`requirements.authoring.search_accounting.pagination`
    // {test}`requirements.authoring.search_accounting.page_replay`
    // {test}`requirements.authoring.search_accounting.outstanding`
    // {test}`requirements.authoring.search_accounting.entry_tags`
    // {test}`requirements.authoring.search_accounting.result_ids`
    // {test}`requirements.authoring.search_accounting.instructions`
    // {test}`requirements.authoring.finish_search.completion`
    // {test}`requirements.authoring.finish_search.invalid`
    // {test}`requirements.authoring.result_pages`
    #[test]
    fn search_pages_are_accounted_only_when_delivered_and_replay_stays_closed() {
        let root = project();
        let source: String = (0..600)
            .map(|i| format!("fn needle_{i:04}() {{ let marker = 1; }}\n"))
            .collect();
        fs::write(root.path().join("src/lib.rs"), source).unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        for (tool, arguments) in [
            ("ripgrep", json!({"pattern":"marker","path":"src/lib.rs"})),
            (
                "ast_grep",
                json!({"language":"rust","rule":{"rule":{"pattern":"let marker = 1;"}}}),
            ),
        ] {
            let mut pages = ResultPages::default();
            let first = dispatch_paged(&sources, &mut pages, tool, &arguments)
                .unwrap()
                .result;
            let token = first["page"]["next"].as_str().unwrap().to_owned();
            assert_eq!(
                first["instructions"],
                super::super::approved_text("search_accounting.instructions", 0)
            );
            uuid::Uuid::parse_str(first["search_id"].as_str().unwrap()).unwrap();
            assert_eq!(
                pages.outstanding_searches(),
                [first["search_id"].as_str().unwrap()]
            );
            let undelivered = pages.pages[&token].0.clone();
            assert!(
                pages
                    .finish_search(&json!({"search_id":undelivered["search_id"],"used":[]}))
                    .is_err()
            );
            assert!(
                pages
                    .finish_search(&json!({"search_id":first["search_id"],
                "used":[undelivered["matches"][0]["tag"]]}))
                    .is_err()
            );
            let second = pages.next_page(&token).unwrap().result;
            uuid::Uuid::parse_str(second["search_id"].as_str().unwrap()).unwrap();
            assert_eq!(second, undelivered);
            assert_ne!(first["search_id"], second["search_id"]);
            assert!(second.get("instructions").is_none());
            assert_eq!(pages.outstanding_searches().len(), 2);
            let finished = pages
                .finish_search(&json!({"search_id":second["search_id"],
                "used":[second["matches"][0]["tag"]]}))
                .unwrap();
            assert_eq!(finished.inputs.len(), 1);
            assert_eq!(finished.inputs[0]["item"], second["matches"][0]["item"]);
            let replay = pages.next_page(&token).unwrap().result;
            assert_eq!(replay, second);
            assert_eq!(
                pages.outstanding_searches(),
                [first["search_id"].as_str().unwrap()]
            );
            pages
                .finish_search(&json!({"search_id":first["search_id"],"used":[]}))
                .unwrap();
            assert!(pages.outstanding_searches().is_empty());
            assert!(sources.recorded_inputs().is_empty());
            assert!(first.to_string().len() <= PAGE_LIMIT);
            assert!(second.to_string().len() <= PAGE_LIMIT);
        }
    }
Input 4: outline src/authoring/searches.rs mod[tests]/fn[delivered_searches_including_empty_results_need_explicit_completion]
    // {test}`requirements.authoring.search_accounting.result_ids`
    // {test}`requirements.authoring.search_accounting.entry_tags`
    // {test}`requirements.authoring.search_accounting.outstanding`
    // {test}`requirements.authoring.search_accounting.instructions`
    // {test}`requirements.authoring.finish_search.empty`
    // {test}`requirements.authoring.finish_search.invalid`
    // {test}`requirements.authoring.finish_search`
    #[test]
    fn delivered_searches_including_empty_results_need_explicit_completion() {
        let root = project();
        fs::write(
            root.path().join("src/lib.rs"),
            "fn first() {}\nfn second() {}\n",
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let mut pages = ResultPages::default();
        assert!(dispatch_paged(&sources, &mut pages, "ripgrep", &json!({"pattern":"("})).is_err());
        assert!(pages.outstanding_searches().is_empty());
        let first = search(&sources, &mut pages, "fn");
        assert_eq!(
            first["instructions"],
            super::super::approved_text("search_accounting.instructions", 0)
        );
        let tags: Vec<_> = first["matches"]
            .as_array()
            .unwrap()
            .iter()
            .map(|entry| entry["tag"].as_str().unwrap())
            .collect();
        assert_eq!(tags, ["1", "2"]);
        for entry in first["matches"].as_array().unwrap() {
            assert!(entry.get("hash").is_none());
        }
        let empty = search(&sources, &mut pages, "absent");
        assert_eq!(empty["matches"], json!([]));
        assert!(empty.get("instructions").is_none());
        let repeated = search(&sources, &mut pages, "fn");
        assert!(repeated.get("instructions").is_none());
        let ids = [&first, &empty, &repeated]
            .map(|result| Uuid::parse_str(result["search_id"].as_str().unwrap()).unwrap());
        assert_eq!(
            ids.into_iter()
                .collect::<std::collections::BTreeSet<_>>()
                .len(),
            3
        );
        assert_eq!(pages.outstanding_searches().len(), 3);
        let mut other = ResultPages::default();
        let error = other
            .finish_search(&json!({"search_id":first["search_id"],"used":[]}))
            .err()
            .unwrap()
            .to_string();
        assert!(error.contains("delivered in this assessment"), "{error}");
        for result in [&first, &empty, &repeated] {
            let finished = pages
                .finish_search(&json!({"search_id":result["search_id"],"used":[]}))
                .unwrap();
            assert!(finished.inputs.is_empty());
            assert_eq!(
                finished.result,
                json!({"search_id":result["search_id"],"finished":true})
            );
        }
        assert!(pages.outstanding_searches().is_empty());
        assert!(sources.recorded_inputs().is_empty());
        for (tool, args) in [
            ("ripgrep", json!({"pattern":"absent","path":"src/lib.rs"})),
            (
                "ast_grep",
                json!({"language":"rust","rule":{"rule":{"pattern":"absent()"}}}),
            ),
        ] {
            let mut fresh = ResultPages::default();
            let result = dispatch_paged(&sources, &mut fresh, tool, &args)
                .unwrap()
                .result;
            assert_eq!(result["matches"], json!([]));
            assert_eq!(
                result["instructions"],
                super::super::approved_text("search_accounting.instructions", 0)
            );
            Uuid::parse_str(result["search_id"].as_str().unwrap()).unwrap();
            let again = dispatch_paged(&sources, &mut fresh, tool, &args)
                .unwrap()
                .result;
            assert_ne!(result["search_id"], again["search_id"]);
        }
    }

Other sources

Input 1: requirements selection requirements.authoring.search_accounting.result_ids
:::{req} search_accounting.result_ids
Each successfully delivered `ripgrep` or `ast_grep` result MUST contain a
`search_id` UUID identifying only that result in the current assessment.
A new search call MUST use new UUIDs.
:::