Close open ships questions when main_ships is written
A merge_ships card is the merge policy's main_ships asked lazily, but a policy write (project page form, set_merge_policy, a policy card's Save) never closed it, so a stale question stayed on Needs you until tapped, then failed with a conflict. writePolicy now resolves every open ships card for the project in the same transaction once main_ships is yes or no, with the setting on record as the card's choice and a card event. answerShips marks its own card answered before writing the policy, so answering on the card is unchanged. The conversation shows the settled setting (new copy, pending review). Plan task T1 of needs-you-ux.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+218
−4
docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+2 −0internal/equipo/card_settled_test.go+27 −0internal/equipo/chat/mergeauth.go+37 −4internal/equipo/chat/ships_settle_test.go+145 −0internal/equipo/chat_page.go+3 −0internal/equipo/copy.go+4 −0
CI failed — run details
CI log
=== prepare ===
ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws
ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
ci-box: user namespaces allowed: 233151
ci-box: cgroup: cgroup2fs
ci-box: disk /home/ci/work/repos/oficina__equipo/wt/needs-you-ux: Type Size Avail | ext4 96G 84G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type Size Avail | ext4 96G 84G
ci-box: bwrap: fetched and verified in 0.4s
ci-box: claude: fetched and verified in 1.3s
ci-box: codex: fetched and verified in 5.1s
ci-box: codex-code-mode-host: fetched and verified in 1.6s
ci-box: libwrap: fetched and verified in 0.4s
ci-box: socat: fetched and verified in 0.4s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 9.8s
ci-box: pi: installed and verified in 7.3s
ci-box: opencode: installed and verified in 1.9s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 9.4s
ci-box: clone deepened in 4.6s
ci-box: file times set from content: 3772 files, 245 directories
ci-box: ready in 19.3s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
--- FAIL: TestReleaseCopyReviewed (0.09s)
task_pages_test.go:236: COPY REVIEW REQUIRED: copy-status.py verify found copy pending review or stale bookkeeping
FAIL
rastrillo-budget/v1 ran 85ms
FAIL amadan.net/oficina/equipo/internal/equipotest 0.233s
FAIL
make: *** [Makefile:260: copy-release-check] Error 1
amadan: step copy failed: exit status 2
amadan: job failed at step copy — its output is above, not at the tail of this log
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index fbd59ae2..900ffc18 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -7219,6 +7219,8 @@ records remain unchanged. |
| | `chat.card.build_note` | Which option should Equipo build? Say it in your own words. | Direction card (dynamic specialists slice 1, 2026-11-29) | COPY APPROVED (Paul, 2026-11-29, copy-review v4fsltihakfhehduzju7dgu47m, unchanged) | |
| | `api.direction_note` | Say which option to build. Open this card on the web to add your note. | Direction card (dynamic specialists slice 1, 2026-11-29) | COPY APPROVED (Paul, 2026-11-29, copy-review v4fsltihakfhehduzju7dgu47m, unchanged) | |
| | `work.explore.build_note` | %s said which option to build in their own words: %s | Build task brief (dynamic specialists slice 1, 2026-11-29) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-29) | |
| +| `chat.card.ships_settled_ships` | The merge settings now say merging to main ships to users. | Copy specialist | COPY REVIEW PENDING | |
| +| `chat.card.ships_settled_not_ships` | The merge settings now say main is not a release. | Copy specialist | COPY REVIEW PENDING | |
| ## Task 21 |
diff --git a/internal/equipo/card_settled_test.go b/internal/equipo/card_settled_test.go| new file mode 100644 |
| index 00000000..60a40752 |
| --- /dev/null |
| +++ b/internal/equipo/card_settled_test.go |
| @@ -0,0 +1,27 @@ |
| +package equipo |
| + |
| +import ( |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// A ships question settled by a policy write shows, in the conversation, |
| +// the setting now on record, never "the rules changed, nothing saved" |
| +// (needs-you-ux T1). |
| +func TestShipsSettledNote(t *testing.T) { |
| + for choice, key := range map[string]string{ |
| + wire.ChoiceShips: "chat.card.ships_settled_ships", |
| + wire.ChoiceNotShips: "chat.card.ships_settled_not_ships", |
| + } { |
| + v := cardView(wire.Card{Kind: wire.CardMergeShips, State: wire.CardResolved, Choice: choice, Options: []string{wire.ChoiceShips, wire.ChoiceNotShips}}, nil, nil) |
| + if want := copyText(key); want == "" || v.Note != want || v.Open { |
| + t.Errorf("%s: note %q open %v, want %q", choice, v.Note, v.Open, want) |
| + } |
| + } |
| + // A stale card (no choice on record) keeps the stale line. |
| + v := cardView(wire.Card{Kind: wire.CardMergeShips, State: wire.CardResolved}, nil, nil) |
| + if v.Note != copyText("chat.card.merge_policy_stale") { |
| + t.Errorf("stale note %q", v.Note) |
| + } |
| +} |
diff --git a/internal/equipo/chat/mergeauth.go b/internal/equipo/chat/mergeauth.go| index ff0d9325..f24b1680 100644 |
| --- a/internal/equipo/chat/mergeauth.go |
| +++ b/internal/equipo/chat/mergeauth.go |
| @@ -129,12 +129,43 @@ func (t *txn) writePolicy(r *mergePolicyRecord, by string, touch bool) error { |
| if err := t.db.Save(r).Error; err != nil { |
| return err |
| } |
| + if err := t.settleShipsCards(r); err != nil { |
| + return err |
| + } |
| if !touch { |
| return nil |
| } |
| return t.refreshMergeCards("project_id = ?", r.ProjectID) |
| } |
| +// settleShipsCards closes the project's open ships questions once the |
| +// policy has main_ships on record, whoever wrote it and however: the |
| +// question is that setting asked lazily. Each closes resolved, its |
| +// choice the setting now on record, never as the person's answer. |
| +func (t *txn) settleShipsCards(r *mergePolicyRecord) error { |
| + choice := "" |
| + switch r.MainShips { |
| + case mergegate.ShipsYes: |
| + choice = wire.ChoiceShips |
| + case mergegate.ShipsNo: |
| + choice = wire.ChoiceNotShips |
| + default: |
| + return nil |
| + } |
| + var open []cardRecord |
| + if err := t.db.Where("project_id = ? AND kind = ? AND state = ?", r.ProjectID, wire.CardMergeShips, wire.CardOpen).Find(&open).Error; err != nil { |
| + return err |
| + } |
| + for i := range open { |
| + c := &open[i] |
| + c.State, c.Choice = wire.CardResolved, choice |
| + if err := t.saveCard(c); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| +} |
| + |
| // refreshMergeCards decides again for each open merge card matching the |
| // condition (a policy change, a hold) and rewrites its words and options |
| // when it still asks, with a new revision either way: the person answers |
| @@ -778,14 +809,16 @@ func (t *txn) answerShips(person string, c cardRecord, in wire.AnswerCard) (wire |
| if in.Choice == wire.ChoiceShips { |
| pr.MainShips = mergegate.ShipsYes |
| } |
| - if err := t.savePolicy(&pr, person); err != nil { |
| + // The card is answered first: the policy write then settles only |
| + // other open ships questions, never this one. |
| + c.State, c.Choice = wire.CardAnswered, in.Choice |
| + if err := t.saveCard(&c); err != nil { |
| return wire.Card{}, wire.Card{}, err |
| } |
| - if err := t.auditRow(mergeAuditRecord{ProjectID: c.ProjectID, Kind: auditShips, At: "card", DecidedBy: decidedPerson + person, Inputs: fmt.Sprintf(`{"main_ships":%q}`, pr.MainShips)}); err != nil { |
| + if err := t.savePolicy(&pr, person); err != nil { |
| return wire.Card{}, wire.Card{}, err |
| } |
| - c.State, c.Choice = wire.CardAnswered, in.Choice |
| - if err := t.saveCard(&c); err != nil { |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: c.ProjectID, Kind: auditShips, At: "card", DecidedBy: decidedPerson + person, Inputs: fmt.Sprintf(`{"main_ships":%q}`, pr.MainShips)}); err != nil { |
| return wire.Card{}, wire.Card{}, err |
| } |
| out, err := t.cardView(c) |
diff --git a/internal/equipo/chat/ships_settle_test.go b/internal/equipo/chat/ships_settle_test.go| new file mode 100644 |
| index 00000000..be1306c4 |
| --- /dev/null |
| +++ b/internal/equipo/chat/ships_settle_test.go |
| @@ -0,0 +1,145 @@ |
| +package chat |
| + |
| +import ( |
| + "encoding/json" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// A ships question is the merge policy's main_ships asked lazily: when |
| +// any policy write puts main_ships on record, the open question for that |
| +// project closes in the same transaction, naming the setting now on |
| +// record, with a card event; another project's stays open, and a write |
| +// that leaves main_ships unknown closes nothing (needs-you-ux T1). |
| + |
| +// shipsRig is an hkRig with projects p1 and p2, each with an open ships |
| +// question for the owner. |
| +func shipsRig(t *testing.T) *hkRig { |
| + t.Helper() |
| + r := newHKRig(t) |
| + r.task("tkone", "Swipe back", hkOwner) |
| + r.must(r.tx(func(t *txn) error { |
| + if err := t.db.Create(&projectRecord{ID: "p2", Repo: "amadan.net/oficina/other", State: wire.ProjectActive, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now}).Error; err != nil { |
| + return err |
| + } |
| + for _, p := range []string{"p1", "p2"} { |
| + c := cardRecord{ID: "ships-" + p, Person: hkOwner, Kind: wire.CardMergeShips, State: wire.CardOpen, ProjectID: p, Name: p, Question: "Does merging ship?", Options: `["ships","not_ships"]`, Undo: `{"policy_revision":0}`, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now} |
| + if err := t.db.Create(&c).Error; err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| + })) |
| + return r |
| +} |
| + |
| +func (r *hkRig) card(id string) cardRecord { |
| + r.t.Helper() |
| + var c cardRecord |
| + r.must(r.tx(func(t *txn) error { return t.db.Where("id = ?", id).First(&c).Error })) |
| + return c |
| +} |
| + |
| +// cardEvents counts the card events written for id. |
| +func (r *hkRig) cardEvents(id string) int { |
| + r.t.Helper() |
| + var rows []eventRecord |
| + r.must(r.tx(func(t *txn) error { return t.db.Where("type = ?", wire.EventCard).Find(&rows).Error })) |
| + n := 0 |
| + for _, e := range rows { |
| + if strings.Contains(e.Body, `"id":"`+id+`"`) { |
| + n++ |
| + } |
| + } |
| + return n |
| +} |
| + |
| +func (r *hkRig) shipsSettled(id, choice string) { |
| + r.t.Helper() |
| + c := r.card(id) |
| + if c.State != wire.CardResolved || c.Choice != choice || c.Revision != 2 { |
| + r.t.Fatalf("ships card %s: state %q choice %q revision %d, want resolved %q at 2", id, c.State, c.Choice, c.Revision, choice) |
| + } |
| + if n := r.cardEvents(id); n != 1 { |
| + r.t.Fatalf("ships card %s: %d card events, want 1", id, n) |
| + } |
| +} |
| + |
| +func (r *hkRig) shipsOpen(id string) { |
| + r.t.Helper() |
| + if c := r.card(id); c.State != wire.CardOpen || c.Choice != "" || c.Revision != 1 { |
| + r.t.Fatalf("ships card %s changed: %+v", id, c) |
| + } |
| +} |
| + |
| +func TestShipsQuestionClosesOnPolicyForm(t *testing.T) { |
| + r := shipsRig(t) |
| + d := mergegate.DefaultPolicy() |
| + // A write that leaves main_ships unknown closes nothing. |
| + p, err := r.s.SetMergePolicy(r.ctx, hkOwner, "p1", wire.SetMergePolicy{Mode: mergegate.ModeAsk, MaxLines: d.MaxLines, MaxFiles: d.MaxFiles, MainShips: mergegate.ShipsUnknown, ExtraSensitive: []string{}, Revision: 0}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r.shipsOpen("ships-p1") |
| + if _, err := r.s.SetMergePolicy(r.ctx, hkOwner, "p1", wire.SetMergePolicy{Mode: p.Mode, MaxLines: p.MaxLines, MaxFiles: p.MaxFiles, MainShips: mergegate.ShipsNo, ExtraSensitive: []string{}, Revision: p.Revision}); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.shipsSettled("ships-p1", wire.ChoiceNotShips) |
| + r.shipsOpen("ships-p2") |
| +} |
| + |
| +func TestShipsQuestionClosesOnStricterTool(t *testing.T) { |
| + r := shipsRig(t) |
| + args, _ := json.Marshal(map[string]any{"project": "p1", "words": "main ships to users", "main_ships": mergegate.ShipsYes}) |
| + var res wire.ToolResult |
| + r.must(r.tx(func(t *txn) error { |
| + var err error |
| + res, err = t.setMergePolicy(turnRecord{ID: "turn1", Person: hkOwner}, args) |
| + return err |
| + })) |
| + if res.Code != "policy_set" { |
| + t.Fatalf("tool %+v, want policy_set (stricter applies at once)", res) |
| + } |
| + r.shipsSettled("ships-p1", wire.ChoiceShips) |
| + r.shipsOpen("ships-p2") |
| +} |
| + |
| +func TestShipsQuestionClosesOnPolicyCardSave(t *testing.T) { |
| + r := shipsRig(t) |
| + d := mergegate.DefaultPolicy() |
| + d.MainShips = mergegate.ShipsNo |
| + raw, _ := json.Marshal(map[string]any{"policy_revision": 0, "policy": d, "words": ""}) |
| + c := cardRecord{ID: "policy-p1", Person: hkOwner, Kind: wire.CardMergePolicy, State: wire.CardOpen, ProjectID: "p1", Name: "p1", Question: "Save?", Options: `["save","cancel"]`, Undo: string(raw), Revision: 1, CreatedAt: r.now, UpdatedAt: r.now} |
| + r.must(r.tx(func(t *txn) error { return t.db.Create(&c).Error })) |
| + r.must(r.tx(func(t *txn) error { |
| + _, _, err := t.answerPolicyCard(hkOwner, c, wire.AnswerCard{Choice: wire.ChoiceSave, Revision: 1}) |
| + return err |
| + })) |
| + if got := r.card("policy-p1"); got.State != wire.CardAnswered || got.Choice != wire.ChoiceSave { |
| + t.Fatalf("policy card %+v", got) |
| + } |
| + r.shipsSettled("ships-p1", wire.ChoiceNotShips) |
| + r.shipsOpen("ships-p2") |
| +} |
| + |
| +// Answering the ships card itself is unchanged: it is the person's |
| +// answer, not a settled card. |
| +func TestShipsQuestionAnsweredOnCard(t *testing.T) { |
| + r := shipsRig(t) |
| + c := r.card("ships-p1") |
| + r.must(r.tx(func(t *txn) error { |
| + _, _, err := t.answerShips(hkOwner, c, wire.AnswerCard{Choice: wire.ChoiceShips, Revision: 1}) |
| + return err |
| + })) |
| + if got := r.card("ships-p1"); got.State != wire.CardAnswered || got.Choice != wire.ChoiceShips || got.Revision != 2 { |
| + t.Fatalf("answered ships card %+v", got) |
| + } |
| + // One save, one event: the policy write does not settle it first. |
| + if n := r.cardEvents("ships-p1"); n != 1 { |
| + t.Fatalf("%d card events, want 1", n) |
| + } |
| + r.shipsOpen("ships-p2") |
| +} |
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go| index e79fe688..1fb057a4 100644 |
| --- a/internal/equipo/chat_page.go |
| +++ b/internal/equipo/chat_page.go |
| @@ -295,6 +295,9 @@ func cardView(c wire.Card, choices []string, tasks map[string]wire.Task) chatCar |
| v.Note = copyText("chat.card.ships_chose_" + c.Choice) |
| case c.State == wire.CardAnswered && c.Kind == wire.CardMergePolicy: |
| v.Note = copyText("chat.card.policy_chose_" + c.Choice) |
| + case c.State == wire.CardResolved && c.Kind == wire.CardMergeShips && c.Choice != "": |
| + // Settled by a policy write: the setting now on record. |
| + v.Note = copyText("chat.card.ships_settled_" + c.Choice) |
| case c.State == wire.CardResolved: |
| v.Note = copyText("chat.card.merge_policy_stale") |
| } |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 6c245035..6efed1cb 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -2447,6 +2447,10 @@ var pageCopy = map[string]string{ |
| "chat.card.cancel": "Cancel", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "chat.card.policy_chose_save": "Saved.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "chat.card.policy_chose_cancel": "Left as it was.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + // Needs you UX pass (needs-you-ux, 2026-11-30): settled questions. |
| + "chat.card.ships_settled_ships": "The merge settings now say merging to main ships to users.", // COPY REVIEW PENDING |
| + "chat.card.ships_settled_not_ships": "The merge settings now say main is not a release.", // COPY REVIEW PENDING |
| + |
| // The daily roll-up (2026-11-12): earlier days on the conversation page. |
| "chat.day.today": "Today", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
| "chat.day.still_open": "Still open from earlier days", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |