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

Requirements index · View definition

evidence Valid

Requirement

Each delivered search page under cite requirements.authoring.result_pages MUST have its own search_id and independently require finish_search. Fetching another page MUST NOT require finishing an earlier page.

Rationale

The subject requirements.authoring.search_accounting.pagination has three testable obligations. The test src/authoring/pages.rs#mod[tests]/fn[search_pages_are_accounted_only_when_delivered_and_replay_stays_closed] is marked {test} for it and covers all three. I did not read the implementation, so I did not check whether outstanding_searches and finish_search behave as the test assumes.

  1. Each delivered page has its own search_id.

    • The test parses first["search_id"] and second["search_id"] as UUIDs.
    • It asserts assert_ne!(first["search_id"], second["search_id"]).
    • It runs for both search tools that produce a search_id, ripgrep and ast_grep. Each runs over 600 matches, so the result is paged.
  2. Each page independently requires finish_search.

    • After page 1 is delivered, outstanding_searches() equals [first id].
    • After page 2 is delivered, outstanding_searches().len() is 2. So each delivered page adds its own outstanding entry.
    • Finishing page 2 alone, with a valid tag, succeeds and returns one recorded input.
    • After that, outstanding_searches() is still [first id]. So finishing page 2 does not clear page 1.
    • Finishing page 1 afterwards empties the outstanding list. Each page’s accounting is therefore independent.
    • Undelivered page ids and tags are rejected by finish_search. This supports the point that only delivered pages are accounted.
  3. Fetching another page does not require finishing an earlier page.

    • pages.next_page(&token) is called while page 1 is still unfinished, and it succeeds.
    • Page 2 is also fetched a second time (the replay) while page 1 is still unfinished.

The cited requirements.authoring.result_pages context is exercised too. The test checks that page.next is a token, and that both pages stay within PAGE_LIMIT. Replay and instruction text are covered by other requirements the test also cites, so they are not part of this subject.

I found no plausible requirement-violating behavior that this test would accept. For example, a shared search_id across pages, a rejected next_page while page 1 is unfinished, or a finish_search on one page clearing the others would each fail an assertion.

Inputs

Tests

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);
        }
    }

Referenced definitions

Input 2: requirements selection requirements.authoring.result_pages
:::{req} result_pages
A result of the `habeas` line-range form, `list_files`, `outline`, `ripgrep`,
`ast_grep`, or `references` whose serialized JSON exceeds 32 KiB MUST be
returned in pages. The size limit MUST include search UUIDs, tags, and instructions.
Each page MUST hold whole entries of the result's arrays, such
as inputs, matches, nodes, or sites, with its accompanying definitions, in the
result's order, and MUST NOT exceed 32 KiB unless a single entry does, which
then forms a page of its own. Every paged result MUST include:

```text
page: {
    total_entries: Integer,
    returned_entries: Integer,
    next: String?,
}
```

`next` MUST be an opaque token when entries remain and null on the last page.
While entries remain, the page MUST also include a `note` saying that more
entries remain and that `next_page` with `next` returns them. The
harness MUST expose a `next_page({ token: String })` tool returning the following
page of the same result, in the same shape. Pages MUST be kept only until the
assessment that requested them finishes; an unknown token, including one from
another assessment, MUST return an explanatory tool error. A result within the
limit MUST be returned whole, without `page`. Only inputs on pages delivered to
the model MUST be recorded under {cite}`requirements.authoring.delivered_inputs`.
:::

Other sources

Input 1: requirements selection requirements.authoring.search_accounting.pagination
:::{req} search_accounting.pagination
Each delivered search page under {cite}`requirements.authoring.result_pages`
MUST have its own `search_id` and independently require `finish_search`.
Fetching another page MUST NOT require finishing an earlier page.
:::