Files
sift/docs/plans/p6/_files/cmd_sift/batch_test.go
T
kyleandClaude Opus 5.5 218eaa8b53 P6 plan, owner review folded in: caller travels with the job, 1–2 round-robin workers, busy retry, summary reads, local-only tests, 8 tasks
Kyle: "Fold them into the plan." What changed and why is in docs/P6.md §14. In short:
- FetchFunc gets the *auth.Caller (the given api test could not compile, and a fetch with no
  caller would bypass per-caller gates, the pool limit, the cache class and redaction);
- store reads never bump the lease (task 01's rule contradicted its own test); the API Touches;
- 1-2 workers round-robin over live jobs, so a batch holds at most 2 of the 8 global slots;
  busy targets retry in the runner (bounded); batch PDFs use their own pool name; 210 s deadline;
- the api tests no longer touch the network or race the cancel; private names via fake DNS;
- failed/cancelled jobs are not reused; GET is a summary plus GET …/{idx} and ?results=1;
- the 256 KiB body cap moves into ServeHTTP; a fixed metrics label for /v1/batch/{id};
- guard.PreCheck (given verbatim) replaces guard.ParseURL at submit;
- 5 tasks became 8 (refactor, wiring, endpoints and serve/config split), each restating the
  APIs it uses; every given test compiles against a panic-only skeleton and fails on it.

P6 starts after P5c: task 04 moves v1fetch, which P5b changes. Recheck the api given tests
against post-P5c master before the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 17:55:50 -07:00

47 lines
1.4 KiB
Go

package main
import (
"slices"
"testing"
)
func TestParseBatchArgs(t *testing.T) {
cases := []struct {
args []string
verb string
rest []string
ok bool
}{
{[]string{"submit", "targets.json"}, "submit", []string{"targets.json"}, true},
{[]string{"submit", "-"}, "submit", []string{"-"}, true},
{[]string{"status", "job-123"}, "status", []string{"job-123"}, true},
{[]string{"status", "--results", "job-123"}, "status", []string{"--results", "job-123"}, true},
{[]string{"get", "job-123", "4"}, "get", []string{"job-123", "4"}, true},
{[]string{"cancel", "job-123"}, "cancel", []string{"job-123"}, true},
{[]string{}, "", nil, false},
{[]string{"submit"}, "", nil, false},
{[]string{"status"}, "", nil, false},
{[]string{"status", "a", "b"}, "", nil, false},
{[]string{"status", "--results"}, "", nil, false},
{[]string{"get", "job-123"}, "", nil, false},
{[]string{"get", "job-123", "x"}, "", nil, false},
{[]string{"get", "job-123", "-1"}, "", nil, false},
{[]string{"cancel"}, "", nil, false},
{[]string{"bogus", "x"}, "", nil, false},
}
for _, c := range cases {
verb, rest, err := parseBatchArgs(c.args)
if c.ok {
if err != nil {
t.Errorf("%v: unexpected error %v", c.args, err)
continue
}
if verb != c.verb || !slices.Equal(rest, c.rest) {
t.Errorf("%v: got verb=%q rest=%q", c.args, verb, rest)
}
} else if err == nil {
t.Errorf("%v: want an error", c.args)
}
}
}