app-region-set: Astra round 3 (READY AFTER FIXES) P2 fixed
The browser replacement test waits for the server's first read of the form body before replacing the app, instead of sleeping. Round 3 findings committed; the review stops here (no P1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+75
−7
docs/superpowers/specs/CODEX-FINDINGS-APP-REGION-SET-R3.md+37 −0internal/console/appregionset_test.go+38 −7
CI passed — run details
diff --git a/docs/superpowers/specs/CODEX-FINDINGS-APP-REGION-SET-R3.md b/docs/superpowers/specs/CODEX-FINDINGS-APP-REGION-SET-R3.md| new file mode 100644 |
| index 000000000..3eff79cb3 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/CODEX-FINDINGS-APP-REGION-SET-R3.md |
| @@ -0,0 +1,37 @@ |
| +- **Round 2 P1, browser write identity — resolved.** [appregionset.go:415](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset.go:415) captures the incarnation before form parsing; both mutation checks preserve it. |
| +- **Round 2 P1, account collision — resolved.** [appregionset.go:128](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset.go:128) requires `?exact=sqid` for the operator’s global lookup; other references use membership-based resolution. |
| +- **Round 2 P2, concurrent placement — resolved.** [store.go:1721](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/store.go:1721) atomically requires `placement = ''`. |
| + |
| +Reviewed `551018757b6377b7ce3547befc23ccf550a8d396` against `origin/main` at `b1d00ca7d84dd2c158151469f9fd40283707e33b`. No files changed. |
| + |
| +1. **P2 — Tests: synchronize the browser replacement test with the handler.** |
| + |
| + [appregionset_test.go:561](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset_test.go:561) writes into the client-side pipe, then sleeps 200 milliseconds before replacing the app. That confirms the HTTP transport consumed bytes; it does not establish that the server captured the incarnation. |
| + |
| + **Failure scenario:** a slow handler reaches account/app resolution after the replacement. It correctly resolves and changes the replacement, but the test fails at [appregionset_test.go:587](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset_test.go:587). The intended interleaving therefore depends on scheduling. |
| + |
| + **Fix:** wrap the server-side request body with a notification on its first `Read`. Wait for that notification, replace the app, then release the remaining body. Include bounded waits and cleanup. |
| + |
| + **Fault family:** a concurrency regression test must establish the ordering it claims to exercise. This is a test defect; no production write-identity P1 remains. |
| + |
| +No P1 or P3 findings. Fix the P2 without another review round. |
| + |
| +The authorization paths preserve the person-only gate, owner/operator authority and non-member 404s. The readers do not relocate existing instances. Deploy compares the current stored region; canary checks its existing instance’s region. GET and the added Settings control introduce no bucket reads or polling. |
| + |
| +Targeted Go tests could not start because the read-only sandbox blocked Go’s work directory. Independent in-memory SQLite checks passed for the update predicates, timestamp preservation through the legacy rebuild, and compatibility with main’s app-schema reads and inserts. Changed Go files are formatted; `git diff --check` is clean. |
| + |
| +Census verdicts for this tip: |
| + |
| +| Unit or envelope | Verdict and evidence | |
| +|---|---| |
| +| `NewServer` | **Approve.** [server.go:1738](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/server.go:1738): route registration; existing read basis unchanged. | |
| +| `Store.NonHomeAppRegions` | **Approve.** [store.go:1739](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/store.go:1739): same console-owned query, with the later discrepancy cutoff. | |
| +| `Store.migrate` | **Approve.** [store.go:574](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/store.go:574): additive column through existing execution sites. | |
| +| `Store.migrateAppsKey` | **Approve.** [store.go:715](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/store.go:715), [store.go:734](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/store.go:734): preserves the column through the existing transactional rebuild. | |
| +| Template `external` unit | **Approve.** [app_settings.html:25](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/templates/app_settings.html:25): embedded form; no new read authority. | |
| +| `.` envelope | **Approve.** [apps.go:159](/home/paulca/amadan.net/carlos/platform-app-region/apps.go:159), [apps_region_cmd.go:55](/home/paulca/amadan.net/carlos/platform-app-region/apps_region_cmd.go:55): dispatch, authenticated API calls and formatting; no new root execution or filesystem authority. | |
| +| `internal/console` envelope | **Approve, including the Round 3 changes.** [appregionset.go:122](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset.go:122), [appregionset.go:261](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset.go:261), [appregionset.go:453](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/appregionset.go:453), [store.go:1711](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/store.go:1711): configured stores and console-owned SQLite; host-claim writes remain refused. `url.ParseQuery` parses the URL and adds no database read. No recorded root-read basis is weakened. | |
| +| `internal/console/templates` envelope | **Approve.** [app_settings.html:25](/home/paulca/amadan.net/carlos/platform-app-region/internal/console/templates/app_settings.html:25): unchanged embedded-template boundary. | |
| +| `internal/regionlabel` envelope | **Approve.** [regionlabel.go:81](/home/paulca/amadan.net/carlos/platform-app-region/internal/regionlabel/regionlabel.go:81): sorts existing in-memory keys; no I/O. | |
| + |
| +**READY AFTER FIXES** |
| \ No newline at end of file |
diff --git a/internal/console/appregionset_test.go b/internal/console/appregionset_test.go| index 7b609a722..9cb5f56dc 100644 |
| --- a/internal/console/appregionset_test.go |
| +++ b/internal/console/appregionset_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "net/http" |
| "net/url" |
| "strings" |
| + "sync" |
| "testing" |
| "time" |
| @@ -37,7 +38,13 @@ const ( |
| func newAppRegionFx(t *testing.T) *appRegionFx { |
| t.Helper() |
| - fx := newConsoleFixture(t) |
| + return newAppRegionFxWith(t, nil) |
| +} |
| + |
| +// newAppRegionFxWith is newAppRegionFx with the console's handler wrapped. |
| +func newAppRegionFxWith(t *testing.T, wrap func(http.Handler) http.Handler) *appRegionFx { |
| + t.Helper() |
| + fx := newConsoleFixtureWith(t, consoleFixtureOptions{WithKey: true, Wrap: wrap}) |
| fx.srv.cfg.HomeRegion = "ie" |
| pub, _, _ := sealedFor(t, "irrelevant") |
| fx.srv.cfg.SecretsPub = pub |
| @@ -540,7 +547,19 @@ func TestAppRegionSetNeedsANamedHome(t *testing.T) { |
| // body: a rename-and-replace while the body is still arriving changes |
| // nothing, and the replacement keeps its region. |
| func TestAppRegionBrowserRefusesAnAppReplacedMidRequest(t *testing.T) { |
| - fx := newAppRegionFx(t) |
| + // The server side of the form post signals its first body read: by |
| + // then the handler has resolved the app (accountAppIncarnation runs |
| + // before the CSRF check reads the form). |
| + reading := make(chan struct{}) |
| + var once sync.Once |
| + fx := newAppRegionFxWith(t, func(h http.Handler) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/apps/shop/region") { |
| + r.Body = &firstReadSignal{ReadCloser: r.Body, fire: func() { once.Do(func() { close(reading) }) }} |
| + } |
| + h.ServeHTTP(w, r) |
| + }) |
| + }) |
| c, csrf := signInAs(t, fx.consoleFixture, arOwner, "code-ar-owner-web") |
| pr, pw := io.Pipe() |
| req, err := http.NewRequest(http.MethodPost, fx.ts.URL+"/a/"+arSqid+"/apps/shop/region", pr) |
| @@ -556,12 +575,13 @@ func TestAppRegionBrowserRefusesAnAppReplacedMidRequest(t *testing.T) { |
| } |
| done <- res |
| }() |
| - // The handler has resolved shop once it waits on the body; give it the |
| - // first byte so the request is in flight, then replace the app. |
| - if _, err := pw.Write([]byte("csrf=")); err != nil { |
| - t.Fatal(err) |
| + go pw.Write([]byte("csrf=")) |
| + select { |
| + case <-reading: |
| + case <-time.After(10 * time.Second): |
| + pw.CloseWithError(fmt.Errorf("timed out")) |
| + t.Fatal("the handler never read the form body") |
| } |
| - time.Sleep(200 * time.Millisecond) |
| now := time.Now() |
| if err := fx.st.TrashAppRow(42, "shop", now); err != nil { |
| t.Fatal(err) |
| @@ -643,3 +663,14 @@ func TestAppRegionSetRefusesAPlacementMadeMeanwhile(t *testing.T) { |
| t.Fatalf("stored %q", r) |
| } |
| } |
| + |
| +// firstReadSignal calls fire on the first Read of the body it wraps. |
| +type firstReadSignal struct { |
| + io.ReadCloser |
| + fire func() |
| +} |
| + |
| +func (f *firstReadSignal) Read(p []byte) (int, error) { |
| + f.fire() |
| + return f.ReadCloser.Read(p) |
| +} |