Test the question close guards: placement and the roster
Astra round 1, P2: placement questions are question cards too, and no test held either close path to refusing one, so dropping the placement exclusion passed. Nor was dismissal's transaction-time roster check covered. Store-level tests: No longer needed and settle_question both refuse a placement question (not found, card untouched) while closing an ordinary one, and a person removed from the roster since their session began dismisses nothing, read through the transaction's handle.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+99
−0
internal/equipo/chat/question_close_guards_test.go+99 −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.3s
ci-box: claude: fetched and verified in 1.5s
ci-box: codex: fetched and verified in 3.4s
ci-box: codex-code-mode-host: fetched and verified in 1.4s
ci-box: libwrap: fetched and verified in 0.3s
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.9s
ci-box: pi: installed and verified in 7.5s
ci-box: opencode: installed and verified in 2.1s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.7s
ci-box: clone deepened in 4.7s
ci-box: file times set from content: 3782 files, 245 directories
ci-box: ready in 18.2s
=== 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 88ms
FAIL amadan.net/oficina/equipo/internal/equipotest 0.238s
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/internal/equipo/chat/question_close_guards_test.go b/internal/equipo/chat/question_close_guards_test.go| new file mode 100644 |
| index 00000000..6c54ed9e |
| --- /dev/null |
| +++ b/internal/equipo/chat/question_close_guards_test.go |
| @@ -0,0 +1,99 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| +) |
| + |
| +// The two ways a coordinator question closes unanswered (needs-you-ux |
| +// T2 and T3, Astra round 1): a placement question is a question card |
| +// too, but it has its own answer path, so neither No longer needed nor |
| +// settle_question closes one; and No longer needed checks the roster |
| +// inside its transaction, so a person removed since signing in closes |
| +// nothing. |
| + |
| +// questionCard records an open question card for hkOwner in the |
| +// person's own conversation; placement makes it a placement question. |
| +func (r *hkRig) questionCard(id string, placement bool) cardRecord { |
| + r.t.Helper() |
| + c := cardRecord{ID: id, Person: hkOwner, Kind: wire.CardQuestion, State: wire.CardOpen, TurnID: "t_1", Question: "Where does it live?", Options: "[]", Revision: 1, CreatedAt: r.now, UpdatedAt: r.now} |
| + if placement { |
| + c.Placement, c.Options = `{"requested_name":"patrix"}`, `["oficina/sample"]` |
| + } |
| + r.must(r.tx(func(t *txn) error { return t.db.Create(&c).Error })) |
| + return c |
| +} |
| + |
| +func TestPlacementQuestionNotDismissed(t *testing.T) { |
| + r := newHKRig(t) |
| + r.questionCard("c_place", true) |
| + if _, err := r.s.DismissQuestion(r.ctx, hkOwner, "c_place", 1); !errors.Is(err, ErrNotFound) { |
| + t.Fatalf("dismissed a placement question: %v", err) |
| + } |
| + if c := r.card("c_place"); c.State != wire.CardOpen || c.Revision != 1 { |
| + t.Fatalf("placement question %+v", c) |
| + } |
| + // An ordinary question beside it closes. |
| + r.questionCard("c_plain", false) |
| + if out, err := r.s.DismissQuestion(r.ctx, hkOwner, "c_plain", 1); err != nil || out.State != wire.CardResolved { |
| + t.Fatalf("plain question %+v %v", out, err) |
| + } |
| +} |
| + |
| +func TestPlacementQuestionNotSettled(t *testing.T) { |
| + r := newHKRig(t) |
| + r.questionCard("c_place", true) |
| + r.questionCard("c_plain", false) |
| + settle := func(id string) wire.ToolResult { |
| + args, _ := json.Marshal(map[string]string{"question": id, "why": wire.SettleAnswered}) |
| + var res wire.ToolResult |
| + r.must(r.tx(func(t *txn) error { |
| + var err error |
| + res, err = t.settleQuestionTool(turnRecord{ID: "t_2", Person: hkOwner}, &wire.ToolCall{Name: wire.ToolSettleQuestion, Args: args}) |
| + return err |
| + })) |
| + return res |
| + } |
| + if res := settle("c_place"); !res.IsError || res.Code != "not_found" { |
| + t.Fatalf("settled a placement question: %+v", res) |
| + } |
| + if c := r.card("c_place"); c.State != wire.CardOpen { |
| + t.Fatalf("placement question %+v", c) |
| + } |
| + if res := settle("c_plain"); res.IsError || res.Code != "settled" { |
| + t.Fatalf("plain question %+v", res) |
| + } |
| +} |
| + |
| +// The roster is read inside the dismissal's transaction, through its |
| +// handle: a person removed since their session began closes nothing. |
| +func TestDismissChecksRosterInTransaction(t *testing.T) { |
| + r := newHKRig(t) |
| + r.s.authority.CurrentPerson = func(_ context.Context, tx *gorm.DB) error { |
| + var active []bool |
| + if err := tx.Raw("SELECT active FROM members WHERE address = ?", hkOwner).Scan(&active).Error; err != nil { |
| + return err |
| + } |
| + if len(active) != 1 || !active[0] { |
| + return ErrForbidden |
| + } |
| + return nil |
| + } |
| + r.questionCard("c_q", false) |
| + r.must(r.tx(func(t *txn) error { return t.db.Exec("UPDATE members SET active = 0 WHERE address = ?", hkOwner).Error })) |
| + if _, err := r.s.DismissQuestion(r.ctx, hkOwner, "c_q", 1); !errors.Is(err, ErrForbidden) { |
| + t.Fatalf("a removed person dismissed: %v", err) |
| + } |
| + if c := r.card("c_q"); c.State != wire.CardOpen || c.Revision != 1 { |
| + t.Fatalf("card after a removed person's dismissal %+v", c) |
| + } |
| + r.must(r.tx(func(t *txn) error { return t.db.Exec("UPDATE members SET active = 1 WHERE address = ?", hkOwner).Error })) |
| + if _, err := r.s.DismissQuestion(r.ctx, hkOwner, "c_q", 1); err != nil { |
| + t.Fatalf("an active person: %v", err) |
| + } |
| +} |