Skip to content

refactor(portal): separate confirmations and remove guard coupling - #282

Merged
allisonmahmood merged 2 commits into
mainfrom
portal/cleanup-portal-router
Sep 16, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
portal/cleanup-portal-router

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Portal rendering mixed confirmations with the index, card and versions pages through one mutable options bag. The API guard also depended on portal rendering and browser-session services just to answer hand-crafted overlong names.

Split confirmation handling into confirmationPage, preserving the existing refusal precedence, copy and form state. Leave portal name bounds to its routes and remove the portal branch from the API guard. Unroutable overlong POSTs and encoded-slash GETs now use the existing 404 responses; API behavior stays unchanged.

Stacked on portal/cleanup-read-path (#281). This PR contains only the next cleanup commit and should merge after that branch.

Verification

  • pnpm lint passed.
  • pnpm typecheck passed.
  • pnpm exec vitest run apps/server packages/portal passed: 86 tests across 5 files.
  • Earlier full-suite runs each passed 936 of 938 tests, with 5-second timeouts in different untouched Postgres or CLI tests. All timed-out cases passed in isolation; no assertions or timeouts were relaxed.

Model: openai-codex/gpt-6-astra. Harness: Oh My Pi.

@github-actions github-actions Bot added area:server Touches the server area size:m 100-500 changed lines labels Sep 16, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed git diff origin/portal/cleanup-read-path...HEAD, from base 01f9737 to PR head d25bab5, against the cleanup brief in this PR description. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The confirmation split reuses the existing renderers, and the API guard no longer depends on portal rendering or browser-session services. No speculative functionality was added.

Spec

No merge-blocking intent findings. The split preserves confirmation refusal precedence, copy and submitted form state. Portal routes own the name bounds, and the changed responses for unroutable overlong POSTs and encoded-slash GETs match the brief. I found no API behavior regression in the diff or focused tests.

Verification

pnpm exec vitest run apps/server/src/ApiGuard.test.ts packages/portal/src/PortalPages.test.ts passed: 65 tests across 2 files. Checked portal rendering, browser admission, API guard behavior and consumers of the removed exports.

Summary: Standards 0 blockers, worst issue none. Spec 0 blockers, worst issue none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Opus review

Second reviewer, standing in for grok build. Reviewed git diff origin/portal/cleanup-read-path...HEAD (base 01f9737, head d25bab5) against the two-part cleanup brief, two axes in parallel sub-agents plus my own pass over the confirmation precedence and the guard's removed cases. CI is green on d25bab5 (all eight checks).

Verdict on the brief's question: yes, this is a net simplification. render sheds five option fields, the mutable options/action reassignment and the nested ternary body; confirmationPage reads top-down with early returns. The guard sheds a cross-package import, three captured services, a Target variant, the maxLength field and the HEAD special case, for -33 lines. The costs are a third copy of the load-and-404 prelude and two extra queries on the refusal paths, both noted below.

What I verified directly

Every status and copy string the old render produced for confirmation GETs is reproduced by confirmationPage, in the same order, byte-identical:

  • member/owner 403 PortalPages.ts:182-186 vs old :140-145 — forbidden and adminRequired unchanged at :61-62.
  • restore 303 PortalPages.ts:187-191 vs old :146-154 — same ?all=1 suffix, same cache-control: private, no-store, same form.status === undefined guard that keeps a POST redisplay off the redirect.
  • state 409 PortalPages.ts:192-200 vs old :155-164 — same three-arm condition, same notice.
  • title :205 (${name} ${action}) matches the old action ? \ ${action}`arm; refusals fall throughrenderto${name}, as the old action = undefined` path did.

post's redisplay still re-renders the confirmation with submitted fields (:255-265); the nameError-vs-notice swap is runtime-equivalent to the old conditional spread because exactOptionalPropertyTypes is off and render.ts tests === undefined. Pinned by unchanged tests at PortalPages.test.ts:668-678 (dependant acknowledgement redisplay) and :1237-1248 (reassign invalid owner: radios, reset q, form action).

GET /patches/<33+> is still 414 with browser admission: PortalPages.test.ts:1457-1471 pins 414 through the routes for all four confirmation suffixes and for POST, and ApiGuard.test.ts:356-372 pins the socket 414 plus the 401 session door at :374-387. The GET /patches/* wildcard that now owns the >100-char case is not new — it landed in 3dd7bfd, so the guard branch was redundant for everything routable.

PortalPages.maxNameLength, nameTooLong and patchRoutes have no consumer left anywhere outside PortalPages.ts (Server.ts still uses errors, index and layer, so the package dependency stays).

Standards

One merge blocker, the rest judgement calls.

  1. Blocking — stale glossary. apps/server/CONTEXT.md:8, the API guard entry, still reads "It also refuses overlong portal names after browser admission, without consuming the protected-API limit." That is exactly what this diff deletes. CLAUDE.md, Hit every surface → Vocabulary and product shape: a renamed concept follows through to the owning CONTEXT.md glossary. Worth moving rather than deleting: packages/portal/CONTEXT.md has no language for the name bound at all (no hit for "414" or "too long"), so after this PR nothing in the domain docs says who owns it. No other surface is stale — docs/API.md's 414s are all /api/patches/*, and no ADR or skill mentions the guard answering portal names.

  2. Judgement — ApiGuard.ts:51-58: PATCH_ROUTES is now a one-element array whose readonly kind: "api" discriminant has no reader left (group.kind appears nowhere after the diff), and whose prefix is always ["api","patches"]. The for (const group of …) loop at :230-247 is a wrapper around one configuration. Speculative Generality, introduced by this diff; collapsing to a single apiPatchRoutes list and a straight prefix check is the honest shape.

  3. Judgement — ApiGuard.ts:235: decodeURIComponent(parameter).length <= 100. The named maxLength field was the only place the router's parameter limit was spelled; it is now a bare 100 whose meaning lives in a comment 190 lines up. A local const routerParamLimit = 100 restores the link.

  4. Judgement — Duplicated Code. The bound-check / isName / patches.read({...access, state: "all"}) / find / 404 prelude is now written three times: PortalPages.ts:117-131, :173-181, :230-238. Two copies predate this PR; the split adds the third, which is where a shared resolve(name) would start paying for itself.

  5. Judgement — ApiGuard.ts:12 "The portal owns its name bound through GET /patches/*" under-states twice: the concrete routes enforce the bound themselves for names within the router's limit, and POST targets past 100 characters do not route at all rather than reaching the wildcard.

Clean on the two review specs. effect-service-conventions: no findings, and the diff actively fixes one by deleting the hand-rolled Effect.provideService(Session/Companies/Users) plumbing in make in favour of the environment. ui-consistency: no findings — confirmationPage reuses pageResponse, styles and renderConfirmation unchanged, no new markup or CSS.

Spec

No requirement missing, no scope creep. Three findings, all judgement calls.

  1. Judgement — refusals now query twice. The brief asks that confirmationPage "decides refusals first", and it does, but the 403 (:182-186) and 409 (:197-200) arms delegate to render(name, …), which re-runs patches.read (:121) and patches.portalCard (:131) that confirmationPage already ran at :177 and :181. Two extra round trips per refusal where the old single pass reused the fetched rows/card, and a narrow window where a row vanishing between the two reads turns a 403 into a 404. Output is identical; passing the loaded card into the refusal render, or the shared resolve from Standards 4, removes both.

  2. Judgement — one case lost its only pin. Old ApiGuard.test.ts:94 asserted GET /patches/{16x}%2F{16x} classified as portal-name-too-long, i.e. 414. The new :94 only asserts {kind:"public"}, and no socket test says what the portal answers for it. The behaviour is preserved — the concrete route matches at 33 ≤ 100 and render:117 414s either way, decoded or not — but it is now unverified. One line in the 414 loop at :356-362 restores it. (The 101-char encoded variant added at :102 is the different case that 404s.)

  3. Judgement — HEAD on a concrete route is unpinned. The old guard carried an explicit method === "HEAD" && route.method === "GET" arm, deleted with the portal group at ApiGuard.ts:239. Its replacement is the router answering HEAD from GET handlers, which the suite pins only for the wildcard path (ApiGuard.test.ts:406-412, a 101-char name). HEAD /patches/<33>/versions — the case the old arm existed for — is no longer asserted anywhere. Extending the existing head assertion to a 33-character name covers it.

On the "portal socket tests unchanged" claim: git diff --stat confirms PortalPages.test.ts is untouched, and the refusal branches do have status and shape coverage (:838-869 for the four confirmation 403s including non-admin owners on reassign, :709-717 for the retire/delete 409, :890-894 and :990-991 for the 303 and its location). The exact strings are another matter: "Only an admin can reassign this patch" and "This action is not available. Nothing was done." appear only in PortalPages.ts:62 and :199, never in a test, and the restore-on-live 409 arm has no test at all. That is pre-existing thinness rather than something this PR caused, but it means the unchanged suite is not by itself evidence the copy survived — I checked that by comparison against the base instead, and it did.

The guard test edits relocate rather than delete: the seven POSTs move from the 414 loop to the 404 loop, correctly, since a 101-character parameter cannot match any route and Server.ts:220's "*" /* answers with Pages.notFound. The dropped POST /patches/<101>/restore → 403 assertion is not lost coverage — that target no longer reaches the portal's sameOrigin wrapper, which is the change the brief asked for.

Summary

Standards: 5 findings, worst is the stale apps/server/CONTEXT.md:8 glossary entry, which I would block on. Spec: 3 findings, worst is the double read on the 403/409 confirmation paths; none block. The refactor is faithful and is a net simplification.

Model: claude-opus-5[1m]. Harness: Claude Code.

@github-actions github-actions Bot added the area:docs Touches the docs area label Sep 16, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed the Astra and Opus review feedback in 4daed9faad19803e8fa949309ffdba81c978a056. I checked conversation comments, review bodies and inline review comments; the latter two were empty, with no new feedback after this push.

Fixed

  • Stale glossary: removed portal-name enforcement from the Hosting API guard definition and recorded browser admission and the 32-character name bound in Portal's Card definition. The glossary now assigns ownership to the code that enforces it.
  • Singleton route configuration: flattened PATCH_ROUTES into apiPatchRoutes, removed the unused kind and configurable prefix wrapper, and named routerParamLimit = 100. The classifier keeps the same decoded-segment matching and API 414/404 behavior without a one-entry group loop.
  • Guard comment: clarified that concrete portal routes and the GET wildcard own name bounds, while unmatched targets keep the page fallback.
  • Missing socket pins: restored the 33-character encoded-slash GET in the 414 assertions and checked HEAD /versions at both 33 and 101 characters, including no response body and private/no-store caching.

Kept as is

  • The duplicated load-and-404 prelude and the confirmation refusal paths' additional reads remain unchanged, per the foreman's steer. They are real tradeoffs, not dismissed findings: eliminating them here would expand the renderer's data contract or introduce shared resolution machinery beyond this cleanup.
  • Did not expand pre-existing copy-string or restore-state test coverage. No related behavior changed in this follow-up; the review already compared the preserved copy and precedence against the base.

Verification on the latest commit

  • pnpm lint and pnpm typecheck passed locally.
  • pnpm exec vitest run apps/server packages/portal: 86 tests passed across 5 files.
  • All eight GitHub checks passed: test (22), test (24), lint, postgres-concurrency, cli-smoke, clerk-live, dependency-review and label. CI run.
  • GitHub reports MERGEABLE and CLEAN. The stack base has no configured required-check policy; all reported checks are green regardless.

No unresolved review or CI blockers. This remains stacked on portal/cleanup-read-path (#281), so keep the merge order. I have not merged either PR.

@allisonmahmood
allisonmahmood force-pushed the portal/cleanup-portal-router branch from ada4f7f to 82c40d5 Compare September 16, 2026 18:34
@allisonmahmood
allisonmahmood merged commit c1b7453 into main Sep 16, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the portal/cleanup-portal-router branch September 16, 2026 18:42
allisonmahmood added a commit that referenced this pull request Sep 16, 2026
The CLI converted wire refusals into seven separate error classes and
then reconstructed the same fields for output. Repo writes and
definition comparisons duplicated logic too.

Use one RejectedError carrying the decoded refusal, share the atomic
patchy.json writer, and compare canonical definition defaults. CLI
messages, JSON failure documents, kinds and exit codes remain unchanged.
Direct output and the child-CLI relay share the documented field
allowlist, and an existing lifecycle test now asserts the complete
failure document. This diff is confined to packages/patchy.

Stacked on #282, with base branch `portal/cleanup-portal-router`.

## Verification
- `pnpm lint` and `pnpm typecheck` passed after the review fixes.
- All 209 CLI, login and reminder tests passed after the review fixes.
- Before the review followup, the full suite passed all 938 tests with
two workers and `pnpm test:packed-cli-e2e` passed. The initial
default-worker run hit two Postgres timeouts and an unexpected worker
exit.
- A temporary before/after probe confirmed 28 refusal documents and exit
codes were byte-identical. A separate future-field probe failed before
the allowlist fix and passed afterward.
- See the review-disposition comment for the decisions and latest-commit
CI results.

Implemented with openai-codex/gpt-6-astra in Oh My Pi.
allisonmahmood added a commit that referenced this pull request Oct 3, 2026
The guard lost its portal branch in #282. The classify case only showed that
non-API paths are public, which the first classify case already pins, and
the live-server block re-asserted the portal's own 414/404/401 answers. The
portal page tests own those now; the guard keeps its one check that portal
refusals do not spend the exhausted API limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 66d87e5bd219de6abcd2eb8e1918e5e3fcb86d1c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant