equipo: Task 18 review 1, removed setter reads off, audit in the tx
chatMe now reports a roster denial as chat.ErrForbidden as well as the instance's ErrForbidden (database errors unchanged), so a setting a removed owner turned on reads off and other owners can still see and change it; regression through production wiring. A new test proves the audit runs on the roster check's transaction and rolls back with it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+150
−2
.rastrillo/budgets.txt+2 −2docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+20 −0internal/equipo/chat/hosted_setting_test.go+43 −0internal/equipo/chat_wiring.go+12 −0internal/equipo/hosted_settings_test.go+73 −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/hosted-runners-2: 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 2.6s
ci-box: codex: fetched and verified in 3.3s
ci-box: codex-code-mode-host: fetched and verified in 1.3s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.3s
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.4s
ci-box: opencode: installed and verified in 2.3s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.6s
ci-box: clone deepened in 5.2s
ci-box: file times set from content: 3888 files, 271 directories
ci-box: ready in 18.7s
=== 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:273: 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/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 832c42ac..427e2e8d 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -14,7 +14,7 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr |
| time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI. |
| time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage. |
| -size internal/equipo 24825 - Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, installer, abilities, lookups, Mac waits, slice F codes, D1, probe details, Design's copy, /api/team; measured 24735. Hosted slice 2 Task 15 review 1: work.reason.pack_incomplete (pending); 24736. Task 17: work.reason.deps_conflict, deps_new_module, deps_missing, deps_too_large and token_renewal_failed (pending); 24741. Task 18: the owner setting "Run checks in a hosted VM" (config flag, routes, section, handler, four pending keys); 24825. |
| +size internal/equipo 24837 - Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, installer, abilities, lookups, Mac waits, slice F codes, D1, probe details, Design's copy, /api/team; measured 24735. Hosted slice 2 Task 15 review 1: work.reason.pack_incomplete (pending); 24736. Task 17: work.reason.deps_conflict, deps_new_module, deps_missing, deps_too_large and token_renewal_failed (pending); 24741. Task 18: the owner setting "Run checks in a hosted VM" (config flag, routes, section, handler, four pending keys); 24825. Its review round 1: chatMe reports a roster denial as chat.ErrForbidden too (chatDenied); 24837. |
| size internal/wire 9884 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), abilities, 36 lookups, 37 Mac Engineering, 38 Design, unproven and probe detail codes, 39 hosted runners (hosted.go: placement, hosted_pack and deps transfer limits, enrolment types); measured 9848. Task 15 opened TransferHeader.Valid to hosted_pack (inbound, base then candidate) and added ReasonPackIncomplete; 9860. Its review round 1 registered it in StepReasons; 9862. Task 17: the hosted worker's reasons (deps_conflict, deps_new_module, deps_missing, deps_too_large, token_renewal_failed) registered in StepReasons, and TransferHeader.Valid opened to deps with the hosted_pack rules (the worker accepts the bundle; Task 23 sends it); 9884. |
| size internal/equipotest - 12693 GitHub connect value search, lifecycle and sweep-log contracts; Task 21 migration fixtures, Rastrillo asset contract, renderer archive link; measured 0/12693 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| @@ -59,7 +59,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 45208 19070 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. |
| +size internal/equipo/chat 45208 19113 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. |
| 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. |
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index 71cc34c8..4133bff9 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -1395,3 +1395,23 @@ Mutations (each an exact-string replace from a script under `$TMPDIR`, one at a |
| - **229** routes without the flag. In `internal/equipo/hosted_settings.go`, the `if !a.hostedRunners { return }` guard deleted. `CGO_ENABLED=0 go test ./internal/equipo -run TestHostedSettingHiddenWithoutFlag -count=1`: exit 1, `hosted_settings_test.go:57: routes without the flag: [GET /conversation/settings/hosted POST /settings/hosted]`. Restored (identical). |
| - **230** menu entry without the flag. In `settings_hub.go`, `return a.hostedSection(owner) == nil` became `return owner`. Same command: exit 1, `hosted_settings_test.go:61: listed without the flag (owner true)`. Restored (identical). |
| - **231** any value turns the flag on. In `config.go`, `getenv("EQUIPO_HOSTED_RUNNERS") == "1"` became `!= ""`. Same command: exit 1, `hosted_settings_test.go:43: EQUIPO_HOSTED_RUNNERS="0" read as true`. Restored (identical). |
| + |
| +### Task 18 review round 1 (t18-r1.md: two Important findings fixed) |
| + |
| +1. **A removed setter blocked the page.** Production `chatMe` returned this package's `ErrForbidden` for an inactive or missing member, so chat's `errors.Is(err, chat.ErrForbidden)` branch in `hostedChecksOf` did not see a denial. If owner A turned the setting on and was then removed, owner B's `HostedSettings` failed with 403. Fix, at the adapter (`internal/equipo/chat_wiring.go`): `chatMe` returns a roster denial as `chatDenied`, which unwraps to both `ErrForbidden` and `chat.ErrForbidden` and keeps the instance's words. Database errors pass through unwrapped. This is chat's one roster read, so the other "no longer an owner" paths (autonomy, Copy delegation, grants and others) now also read a removed member as a denial instead of a failure. The session check (`chatCurrentPerson`) is unchanged. |
| +2. **Audit atomicity is now proven.** `TestHostedSettingAuditAtomic` (chat) checks that the audit gets the roster check's own transaction connection (a `gorm.TxCommitter`, the same `ConnPool` `Me` read through). The audit then writes a row there, and a later failure in the same transaction (a trigger aborting the `chat_events` insert) rolls that row back together with the change. |
| + |
| +Red: |
| +- `CGO_ENABLED=0 go test ./internal/equipo -run TestHostedSettingRemovedOwnerProductionWiring -count=1`: `hosted_settings_test.go:179: owner B after A's removal: [] You do not have access to this page. Ask an owner for access.` This is production wiring: `NewStore`, `Bootstrap`, `SetMember` removing A, and person-API principals. |
| +- `TestHostedSettingAuditAtomic` passed on the existing code. It closes a gap in test strength, and mutation 234 is its failing evidence. |
| + |
| +Green: |
| +- `CGO_ENABLED=0 go test ./internal/equipo/... -run 'TestHostedSetting' -count=1`: ok (9 tests). |
| +- Because `chatMe` is shared, I also ran the whole of `./internal/equipo` (71.4 s) and `./internal/equipo/chat` (25.5 s) once: ok. `./internal/thintest -run 'Remov|Roster|Revok|Owner|Member|Autonomy|Copy|Settings'`: ok. |
| +- `make migration-check budget build vet`: exit 0, with two records raised and reasons given (internal/equipo 24837; chat 45208/19113). |
| +- gofmt and `git diff --check`: clean. |
| + |
| +Mutations (exact-string replace from a script under `$TMPDIR`, one at a time, restored and compared): |
| +- **232** no normalisation. In `chat_wiring.go`, `if errors.Is(err, ErrForbidden) {` (before `return wire.Me{}, chatDenied{err}`) became `if false && errors.Is(err, ErrForbidden) {`. `CGO_ENABLED=0 go test ./internal/equipo -run TestHostedSettingRemovedOwnerProductionWiring -count=1`: exit 1, `hosted_settings_test.go:180: owner B after A's removal: [] You do not have access to this page. Ask an owner for access.` Restored (identical). |
| +- **233** database errors read as denials. The same line became `if err != nil && errors.Is(err, err) {`. Same command: exit 1, `hosted_settings_test.go:206: a database error became a denial: The information is unavailable. Try again in a minute.: SQL logic error: no such table: members (1)`. Restored (`cmp` identical). A first form of this mutation left `errors` unused and did not compile, so it is not counted. |
| +- **234** audit through `s.db` instead of the transaction. In `chat/hosted_setting.go`, `s.authority.Audit(t.db, person, "project.hosted_checks"` became `s.authority.Audit(s.db.G, person, "project.hosted_checks"`. `CGO_ENABLED=0 go test ./internal/equipo/chat -run TestHostedSettingAuditAtomic -count=1`: exit 1, `hosted_setting_test.go:187: audited write: audit outside the roster check's transaction`. Restored (identical). |
diff --git a/internal/equipo/chat/hosted_setting_test.go b/internal/equipo/chat/hosted_setting_test.go| index cccee37a..da305bcc 100644 |
| --- a/internal/equipo/chat/hosted_setting_test.go |
| +++ b/internal/equipo/chat/hosted_setting_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "strings" |
| "testing" |
| + "amadan.net/oficina/equipo/internal/wire" |
| "gorm.io/gorm" |
| ) |
| @@ -157,3 +158,45 @@ func TestHostedSettingAudited(t *testing.T) { |
| t.Fatalf("unaudited change moved the revision to %d", rev) |
| } |
| } |
| + |
| +// TestHostedSettingAuditAtomic: the audit gets the very transaction the |
| +// roster check read through, and an audit row it wrote there rolls back |
| +// when a later write in the same transaction fails. |
| +func TestHostedSettingAuditAtomic(t *testing.T) { |
| + r, _ := rosterRig(t) |
| + r.task("tkhosted", "Hosted", hkOwner) |
| + r.exec("CREATE TABLE audit_probe (detail text)") |
| + me := r.s.authority.Me |
| + var roster gorm.ConnPool |
| + r.s.authority.Me = func(tx *gorm.DB, address string) (wire.Me, error) { |
| + roster = tx.Statement.ConnPool |
| + return me(tx, address) |
| + } |
| + r.s.authority.Audit = func(tx *gorm.DB, _, _, detail string) error { |
| + if _, inTx := tx.Statement.ConnPool.(gorm.TxCommitter); !inTx || tx.Statement.ConnPool != roster { |
| + return errors.New("audit outside the roster check's transaction") |
| + } |
| + return tx.Exec("INSERT INTO audit_probe(detail) VALUES (?)", detail).Error |
| + } |
| + audits := func() int { |
| + var n int |
| + r.must(r.s.db.G.Raw("SELECT count(*) FROM audit_probe").Scan(&n).Error) |
| + return n |
| + } |
| + if err := r.s.SetHostedChecks(r.ctx, hkOwner, "p1", true, 0); err != nil { |
| + t.Fatalf("audited write: %v", err) |
| + } |
| + if audits() != 1 { |
| + t.Fatal("the audit row was not kept") |
| + } |
| + r.exec("CREATE TRIGGER fail_events BEFORE INSERT ON chat_events BEGIN SELECT RAISE(ABORT, 'events unavailable'); END") |
| + if r.s.SetHostedChecks(r.ctx, hkOwner, "p1", false, 1) == nil { |
| + t.Fatal("a failed event write committed") |
| + } |
| + if n := audits(); n != 1 { |
| + t.Fatalf("%d audit rows: the failed change's audit was kept", n) |
| + } |
| + if on, _ := r.hostedRead("p1"); !on { |
| + t.Fatal("the failed change committed") |
| + } |
| +} |
diff --git a/internal/equipo/chat_wiring.go b/internal/equipo/chat_wiring.go| index b07fba15..1b2e9341 100644 |
| --- a/internal/equipo/chat_wiring.go |
| +++ b/internal/equipo/chat_wiring.go |
| @@ -2,6 +2,7 @@ package equipo |
| import ( |
| "context" |
| + "errors" |
| "fmt" |
| "log/slog" |
| "net/http" |
| @@ -138,8 +139,19 @@ func (s *Store) chatCurrentPerson(ctx context.Context, tx *gorm.DB) error { |
| return s.currentPersonAPI(tx, ctx) |
| } |
| +// chatDenied is a roster denial as the chat store reads it: still this |
| +// package's ErrForbidden (and its words) and also chat.ErrForbidden, so |
| +// chat's "no longer an owner" paths see a removed or missing member as |
| +// a denial, not a failure. Database errors are never wrapped. |
| +type chatDenied struct{ error } |
| + |
| +func (d chatDenied) Unwrap() []error { return []error{d.error, chat.ErrForbidden} } |
| + |
| func chatMe(tx *gorm.DB, address string) (wire.Me, error) { |
| m, err := currentRunnerMember(tx, address) |
| + if errors.Is(err, ErrForbidden) { |
| + return wire.Me{}, chatDenied{err} |
| + } |
| if err != nil { |
| return wire.Me{}, err |
| } |
diff --git a/internal/equipo/hosted_settings_test.go b/internal/equipo/hosted_settings_test.go| index 16a0afad..14ff4134 100644 |
| --- a/internal/equipo/hosted_settings_test.go |
| +++ b/internal/equipo/hosted_settings_test.go |
| @@ -3,13 +3,20 @@ package equipo |
| import ( |
| "bytes" |
| "context" |
| + "errors" |
| + "io" |
| + "log/slog" |
| "net/http" |
| "strings" |
| "testing" |
| "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "amadan.net/rastrillo/rastrillo/db" |
| + "amadan.net/rastrillo/rastrillo/dbtest" |
| "amadan.net/rastrillo/rastrillo/migrate" |
| "github.com/go-chi/chi/v5" |
| + "gorm.io/gorm" |
| ) |
| // hostedRoutesOf lists the hosted setting's routes a router serves. |
| @@ -133,3 +140,69 @@ func TestHostedSettingMigrationOff(t *testing.T) { |
| t.Fatalf("migration turned hosted checks on: %t %q %d %v", on, owner, revision, err) |
| } |
| } |
| + |
| +// TestHostedSettingRemovedOwnerProductionWiring runs the setting through |
| +// the instance's own chat authority (chatMe, the person API session |
| +// check, the audit table). Owner A turns it on and is removed: it reads |
| +// off, and owner B can still see the page and change it. A is refused, |
| +// and a database failure stays a database failure, not a denial. |
| +func TestHostedSettingRemovedOwnerProductionWiring(t *testing.T) { |
| + schema := dbtest.FromSet(BootSchema) |
| + t.Cleanup(schema.Remove) |
| + d, err := db.Open(schema.Path(t), slog.New(slog.NewTextHandler(io.Discard, nil))) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { d.Close() }) |
| + const a, b = "owner-a@example.com", "owner-b@example.com" |
| + s := NewStore(d) |
| + if err := s.Bootstrap(context.Background(), []string{a, b}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := d.Writer().Exec("INSERT INTO chat_projects(id,repo,title,state,revision) VALUES('p1','amadan.net/oficina/example','Example','active',1)"); err != nil { |
| + t.Fatal(err) |
| + } |
| + as := func(who string) context.Context { |
| + return personapi.WithVerifiedPrincipal(context.Background(), personapi.PersonPrincipal{Address: who}) |
| + } |
| + if err := s.Chat().SetHostedChecks(as(a), a, "p1", true, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + var revision int64 |
| + if err := d.Writer().QueryRow("SELECT revision FROM members WHERE address=?", a).Scan(&revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := s.SetMember(as(b), Actor{Address: b}, a, RoleOwner, false, revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + list, err := s.Chat().HostedSettings(as(b), b) |
| + if err != nil || len(list) != 1 || list[0].On || list[0].Revision != 1 { |
| + t.Fatalf("owner B after A's removal: %+v %v", list, err) |
| + } |
| + if err := s.Chat().SetHostedChecks(as(b), b, "p1", true, 1); err != nil { |
| + t.Fatalf("owner B could not change it: %v", err) |
| + } |
| + if list, err := s.Chat().HostedSettings(as(b), b); err != nil || len(list) != 1 || !list[0].On || list[0].Revision != 2 { |
| + t.Fatalf("owner B's setting: %+v %v", list, err) |
| + } |
| + if err := s.Chat().SetHostedChecks(as(a), a, "p1", false, 2); !errors.Is(err, ErrForbidden) { |
| + t.Fatalf("removed owner A: %v", err) |
| + } |
| + var denied error |
| + if err := s.db.G.Transaction(func(tx *gorm.DB) error { _, denied = chatMe(tx, a); return nil }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if !errors.Is(denied, ErrForbidden) || !errors.Is(denied, chat.ErrForbidden) || denied.Error() != ErrForbidden.Error() { |
| + t.Fatalf("a removed member's denial: %v", denied) |
| + } |
| + var audits int |
| + if err := d.Writer().QueryRow("SELECT count(*) FROM audit_events WHERE kind='project.hosted_checks'").Scan(&audits); err != nil || audits != 2 { |
| + t.Fatalf("audit rows %d %v", audits, err) |
| + } |
| + if _, err := d.Writer().Exec("DROP TABLE members"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := chatMe(s.db.G, b); err == nil || errors.Is(err, chat.ErrForbidden) || errors.Is(err, ErrForbidden) { |
| + t.Fatalf("a database error became a denial: %v", err) |
| + } |
| +} |