Abilities phase 2: Astra round 5 P2s (tests that prove the fixes)
- The taskless resume test gives the job a context and checks the resumed request carries it, that other taps and a nudge add nothing, that a later hold resumes once more, and that an open question waits. - The stale-board test checks the act's own transaction reads the board fetched first: off, the old copy after a failed fetch, on again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+104
−19
.rastrillo/budgets.txt+2 −2internal/equipo/chat/abilities_refresh_test.go+37 −4internal/thintest/ability_hold_contract_test.go+65 −13
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 593bb244..2ae95051 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -57,7 +57,7 @@ perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| perf GET /api/v1/assistant/abilities skip Assistant person API: bearer-only JSON for Base's Settings line, not a browser screen. |
| -size internal/equipo/chat 39565 13317 File facts/diffs, previews, merge authority, unfinished work, CI feedback, receipts, Assistant files, places, waiting cards, Assistant abilities; measured 39565/13317. |
| +size internal/equipo/chat 39565 13350 File facts/diffs, previews, merge authority, unfinished work, CI feedback, receipts, Assistant files, places, waiting cards, Assistant abilities; measured 39565/13350. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
| @@ -72,7 +72,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| size internal/headless - 11873 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files end to end; the restart wait; the live site waits for a place; a card answer settles at the bottom; measured 11873 test lines. |
| -size internal/thintest - 37749 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, abilities; measured 37749 test lines. |
| +size internal/thintest - 37801 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, abilities; measured 37801 test lines. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
diff --git a/internal/equipo/chat/abilities_refresh_test.go b/internal/equipo/chat/abilities_refresh_test.go| index b3b0c8c4..7a42d71c 100644 |
| --- a/internal/equipo/chat/abilities_refresh_test.go |
| +++ b/internal/equipo/chat/abilities_refresh_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "time" |
| "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| ) |
| // The hint fetches from the person's Base within the call: data only ever |
| @@ -117,26 +118,58 @@ func TestOwnAbilitiesRoute(t *testing.T) { |
| // Acts outside a turn fetch a stale board first, as a turn's start does: |
| // Carry on now, a card's answer (the Equipo page's and a device's) and a |
| -// merge, whatever then happens to the act (Astra phase 2 round 4, P2). |
| +// merge. What the act's own transaction then reads is the fetched board: |
| +// off once Base turned building off, the copy it had when the fetch |
| +// failed, and on again once Base turned it back on (Astra phase 2 round |
| +// 4, P2; round 5, P2). |
| func TestActsRefreshStaleBoard(t *testing.T) { |
| h, base := boardBase(t) |
| refresh(t, h) |
| ctx := context.Background() |
| + canBuild := func() bool { |
| + var sw Switches |
| + if err := h.s.read(ctx, func(tx *gorm.DB) error { |
| + var err error |
| + sw, err = (&txn{s: h.s, ctx: ctx, db: tx}).switches(abPerson) |
| + return err |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + return sw.Can(wire.AbilityBuild) |
| + } |
| acts := map[string]func(){ |
| "carry on": func() { _, _ = h.s.CarryOn(ctx, abPerson, "nope", wire.CarryOn{IdempotencyKey: "k"}) }, |
| "answer": func() { _, _, _ = h.s.AnswerDevice(ctx, abPerson, "", "nope", wire.AnswerCard{Choice: "Yes"}) }, |
| "merge": func() { _, _ = h.s.MergeTask(ctx, abPerson, "nope") }, |
| } |
| + rev := int64(1) |
| + board := func(build bool, status int) { |
| + rev++ |
| + base.set(func(f *fakeBoardBase) { f.board.Abilities["build"], f.board.Revision, f.status = build, rev, status }) |
| + } |
| for name, act := range acts { |
| before, _ := base.counts() |
| + board(false, 200) |
| act() |
| - if n, _ := base.counts(); n != before { |
| + if n, _ := base.counts(); n != before || !canBuild() { |
| t.Errorf("%s fetched a fresh copy again: %d", name, n-before) |
| } |
| h.advance(61 * time.Second) |
| act() |
| - if n, _ := base.counts(); n != before+1 { |
| - t.Errorf("%s didn't fetch a stale copy first: %d", name, n-before) |
| + if n, _ := base.counts(); n != before+1 || canBuild() { |
| + t.Errorf("%s didn't act on the stale copy fetched first: %d fetches, building %v", name, n-before, canBuild()) |
| + } |
| + // A failed fetch leaves the copy it had. |
| + h.advance(61 * time.Second) |
| + board(true, 500) |
| + act() |
| + if canBuild() { |
| + t.Errorf("%s: a failed fetch changed the copy", name) |
| + } |
| + board(true, 200) |
| + act() |
| + if !canBuild() { |
| + t.Errorf("%s: building back on wasn't fetched", name) |
| } |
| } |
| } |
diff --git a/internal/thintest/ability_hold_contract_test.go b/internal/thintest/ability_hold_contract_test.go| index 46fbcd8b..2b1b0d6b 100644 |
| --- a/internal/thintest/ability_hold_contract_test.go |
| +++ b/internal/thintest/ability_hold_contract_test.go |
| @@ -149,34 +149,86 @@ func TestResumeBeforeRefusalReported(t *testing.T) { |
| } |
| } |
| -// A job held before it reached any work (its record_task refused, its |
| -// turn then ended) is started again by Carry on now: the request goes to |
| -// its thread once more, with its context, once however often it is |
| -// tapped (Astra phase 2 round 4, P2). |
| -func TestTasklessHoldResumes(t *testing.T) { |
| - o := newTeamRig(t) |
| +// tasklessHeld is a job held before it reached any work: its |
| +// record_task refused with building off, its turn then ended, building on |
| +// again. It returns the request, its first turn and its thread. |
| +func (o *teamRig) tasklessHeld(key, context string) (string, string, string) { |
| + o.t.Helper() |
| o.ask("Make me a website.") |
| - request, cmd := o.handoff("tl", "Make me a website.", "") |
| - lane := wire.JobLane(request) |
| + request, cmd := o.handoff(key, "Make me a website.", context) |
| o.setBoard(wire.AbilityBuild) |
| o.in(cmd.TurnID, func() { |
| - refusedOff(t, "record_task", o.call("tl-rt", wire.ToolRecordTask, map[string]any{"title": "Site", "brief": "Build it."})) |
| + refusedOff(o.t, "record_task", o.call(key+"-rt", wire.ToolRecordTask, map[string]any{"title": "Site", "brief": "Build it."})) |
| }) |
| o.reply(cmd.TurnID) |
| o.reply(o.turn) |
| o.setBoard() |
| + return request, cmd.TurnID, wire.JobLane(request) |
| +} |
| + |
| +// A job held before it reached any work is started again by Carry on now: |
| +// the person's request goes to its thread once more, with the hand-off's |
| +// context, once however often and however it is tapped; held again |
| +// later, it is started again once more (Astra phase 2 round 4, P2; round |
| +// 5, P2). |
| +func TestTasklessHoldResumes(t *testing.T) { |
| + o := newTeamRig(t) |
| + request, first, lane := o.tasklessHeld("tl", "They want a new site.") |
| card := o.heldCard(request, heldBack) |
| if _, err := o.a.CarryOn(o.ctx, card.ID, card.Revision, "tl-1"); err != nil { |
| t.Fatal(err) |
| } |
| again := o.message(lane) |
| - if again.TurnID == cmd.TurnID || !strings.Contains(again.Text, "Make me a website.") { |
| - t.Fatalf("the request wasn't started again: %+v", again) |
| + if again.TurnID == first || !strings.HasPrefix(again.Text, "Make me a website.\n\n[Reference from the Assistant, not the person's words: They want a new site.]\n") { |
| + t.Fatalf("the request wasn't started again with its context: %+v", again) |
| } |
| - if _, err := o.a.CarryOn(o.ctx, card.ID, card.Revision, "tl-1"); err != nil { |
| - t.Errorf("the same tap again: %v", err) |
| + for _, key := range []string{"tl-1", "tl-2"} { |
| + _, _ = o.a.CarryOn(o.ctx, card.ID, card.Revision, key) |
| + } |
| + if res := o.use("tl-nd", "team_nudge", map[string]any{"request": request, "words": "Make me a website."}); !res.IsError { |
| + t.Errorf("a nudge while it runs again: %+v", res) |
| } |
| if n := o.rows("SELECT count(*) FROM chat_turns WHERE lane = ?", lane); n != 2 { |
| t.Errorf("%d turns in the job's thread, want 2", n) |
| } |
| + // Held again: its turn's record_task refused again. |
| + o.setBoard(wire.AbilityBuild) |
| + o.in(again.TurnID, func() { |
| + refusedOff(t, "record_task", o.call("tl-rt2", wire.ToolRecordTask, map[string]any{"title": "Site", "brief": "Build it."})) |
| + }) |
| + o.reply(again.TurnID) |
| + o.setBoard() |
| + card = o.heldCard(request, heldBack) |
| + if _, err := o.a.CarryOn(o.ctx, card.ID, card.Revision, "tl-3"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if third := o.message(lane); third.TurnID == again.TurnID { |
| + t.Fatalf("held again, not started again: %+v", third) |
| + } |
| +} |
| + |
| +// A held job whose turn left a question open for the person isn't sent |
| +// its request again: it waits on their answer. |
| +func TestTasklessHoldWaitsOnQuestion(t *testing.T) { |
| + o := newTeamRig(t) |
| + o.ask("Make me a website.") |
| + request, cmd := o.handoff("tq", "Make me a website.", "") |
| + lane := wire.JobLane(request) |
| + o.setBoard(wire.AbilityBuild) |
| + o.in(cmd.TurnID, func() { |
| + refusedOff(t, "record_task", o.call("tq-rt", wire.ToolRecordTask, map[string]any{"title": "Site", "brief": "Build it."})) |
| + if res := o.call("tq-ask", wire.ToolAskPerson, map[string]any{"question": "Which website?", "options": []string{"A new one", "One I have"}}); res.Code != "asked" { |
| + t.Fatalf("ask %+v", res) |
| + } |
| + }) |
| + o.reply(cmd.TurnID) |
| + o.reply(o.turn) |
| + o.setBoard() |
| + card := o.heldCard(request, heldBack) |
| + if _, err := o.a.CarryOn(o.ctx, card.ID, card.Revision, "tq-1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := o.rows("SELECT count(*) FROM chat_turns WHERE lane = ?", lane); n != 1 { |
| + t.Errorf("%d turns in the job's thread, want 1", n) |
| + } |
| } |