Repository navigation
feat: two companies isolated by scope and row policy, and the Central deletes a client (step 5) - #54
Conversation
… as a union (step 4.2, U1)
…ients through identity's ports (step 4.2, U3)
…rrection, behind the operator's menu link (step 4.2, U4)
…ration deletes the test companies (step 4.2, U5)
…' lines to the roadmap's ceiling
…of adding to it, so setup time never counts
…as the lock, not before
… journey runs in Chromium (step 4.2, U6)
…t, and native joins no longer protect a reachable path
…cope, CNPJ reuse, B6 and B8)
…perator policies need the administrator, closed scope switch, no session clearing, CNPJ as consequence)
…reads nothing, auth.user predicate on its own row, no session exception)
…t/conexus-e05-build
…at/conexus-e05-build
…s bound each scope's role (step 5, U3) The operator's policies and the invitation scope's read of members come in the next two commits, each provisional until the founder's word; the Central's and the link's tests turn green with them.
…through one SECURITY DEFINER helper (step 5, U3, provisional A) Firstmate's provisional choice A of 2026-10-17, waiting for the founder's word: the helper is owned by hub_administrators, a role that cannot log in and reads only administrators' rows, and only hub_operator executes it. Without it the operator's policies on auth.member and auth.user expand each other, which PostgreSQL refuses. Swapping it for option B replaces this commit.
…company (step 5, U3, provisional A) Firstmate's provisional choice A of 2026-10-17, waiting for the founder's word: Better Auth's accept counts the company's members for its limit and reads back the member it inserts, and step 4.1's link view reads whether the person joined and whether the company has a member yet. Swapping it for option B replaces this commit.
|
Reviewer: Claude Sonnet 5.5 (claude-sonnet-5-5) (delta 027a229..3d2d1cd) Conferência 2 de no máximo 3. Rules read: Ran
The first delta check's findings
Findings
Verdictapprove: the Bloqueia of delta 1 (J's marker) is fixed with a test that fails without the fix, the other four items are fixed or properly pointed, and the fixes created no Bloqueia. The founder keeps the merge and his words on #51, #53 and #55; CI at |
…ntence; the rename keeps its own company lock The registration opens the client with the bounced invitation's id, and the note shows only while that invitation is the client's live one, so a cancel or a new invitation removes it. Its words are 4.1's for a refused address. renameCompanyOn locks the company again, a no-op after the correction's lock that keeps the port safe alone; the removal row now checks the lock order by the renewal race.
…at/conexus-e05-build # Conflicts: # apps/server/src/hub/operations/clients.ts # apps/server/src/hub/operations/routes.ts # scripts/removals.json
…exus-e042-build) into feat/conexus-e05-build
…tep 5, U3) operator_all on auth.company splits: the Central still reads and creates any company, but UPDATE and DELETE hold only for the scope's company, as on members, invitations and clients. An unfiltered change in A's scope leaves B and an empty C.
…s company scope (step 5) accept-one-transaction and client-one-transaction name libraryCommandOn's line, which libraryInstallationOn now repeats. membership-page-anchor-scoped survived because the person scope's member policy holds the same rule; its row becomes person-member-policy, caught by isolation 'positivo'. New row operator-company-scope.
…is a new one (founder, 2026-10-17: B)
deleteCompanyOn's comment cites the plugin's closed endpoint (crud-org.mjs:255) and its membership refusal (:264-268), and no longer C50; boundaries.md says no check follows the deletion, as the code does. deleteClient's body takes the company name schema and a shared Revision, so an empty or over-long name is malformed. The delete dialog invalidates the list by a key derived from the operation (web W11).
# Conflicts: # docs/roadmap.md
A member's invitation, renewal and cancellation now go through the plugin's endpoints, still in the company's scope; the mail after them keeps the sender's scope and takes main's delivered or refused outcome; the owner's mail keeps the operator's scope. Both sides' removal rows stay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since step 4.2's closing a member renews through the plugin's endpoint with resend, whose expiry write uses ctx.context.adapter (crud-invites.mjs:135-143) instead of getCurrentAdapter, so it left the company scope's transaction for the Hub's login, and failed in phase 2. The adapter createAuth gives the library now reaches getCurrentAdapter on every call. New test: a refusal after the plugin's write takes the new expiry back; removal library-adapter-joins-transaction.
…conexus-e05-build Its tree is already main's; the merge makes the approved card commit 3fa4793 an ancestor for the approval check.
|
Reviewer: Claude Opus 5.5 (claude-opus-5-5) (delta 3d2d1cd..aac9842) Conferência 3 de no máximo 3. Rules read: RanMy own
Item 5,
|
Main's tree is the build branch's at ea81cc9, already merged here.
Etapa 5, "Duas empresas", from the card approved at f64ebb5 (
docs/steps/e05-duas-empresas.md).Aguarda a palavra do fundador
Two pieces were added by firstmate's provisional A, after the U1 census found two gaps in the card's matrix. Each is its own commit, so either can be swapped for B without unpicking the rest. PR #51 is the record for his word. Nothing here merges before it.
SECURITY DEFINERfunction,auth.is_installation_administrator(person). It is owned by the non-login rolehub_administrators, has a fixedsearch_path, and onlyhub_operatormay execute it. Every operator policy uses it. Why: when the operator's administrator check readsauth.userfromauth.member's policy, and the operator reads owners inauth.user, each policy expands the other, and PostgreSQL refuses ("infinite recursion detected in policy"). The card's point 4 says aSECURITY DEFINERgoes back to the card. Criterion 18 and its removal entryoperator-policy-admin-onlycover it.hub_invitationreads the members of that invitation's company only. Why: the card gave the invitation scope INSERT on members without SELECT. Better Auth's accept counts the members (crud-invites.mjs:276), and step 4.1's link view shows them, so both broke.The grant lists are in their own PRs: U2 and A1's role and grants in #53 (phase 1), and U7 in #55 (phase 2). Each waits for the founder's word (D11). This PR carries #53's commits, so #53 merges first, and #54 never merges alone.
Also waiting for the founder's word:
feat/conexus-e05-card-trim, ready to fast-forward PR 50. I did not push it to PR 50's branch, because that branch is checked out in another lane's worktree. The approval check now sees the card differ from f64ebb5 until he confirms the trim.Criteria and their proofs (L19)
catalog.test.ts(RLS on, no FORCE; snapshot);isolation.test.ts"sem contexto"isolation.test.ts"positivo";companies.test.tsisolation.test.ts"filtro esquecido"isolation.test.ts"escrita"isolation.test.ts"conexão reciclada"invitations.test.ts"ritmo entre empresas"database.check.ts, compiled byisolation.test.ts"o tipo"client-deletion.test.ts"apagar: fora";sign-up.test.ts"apagar só pela Central"client-deletion.test.ts"apagar"client-deletion.test.ts"apagar: recusas"client-deletion.test.ts"apagar: concorrência" (6 of 6 local runs green) and "apagar: concorrência com o link" (fails with 500 when the fix is taken out; removalinvitation-link-deleted)client-deletion.test.ts"log"delete-client-dialog.test.tsx; T23 in the pinned Chromium (below)register-client-form.test.tsx"recarregar durante um cadastro que não decidiu…": the app itself goes to the list and asksscripts/removals.json:invitation-link-deleted,rls-company-policy,scope-role-set,scope-in-signature,operator-policy-admin-only,client-delete-revision,client-delete-operator-only, each run with--onlyand caughttests/e2e/two-companies.test.ts, added tonpm run e2eisolation.test.ts"operador sem papel"T23, done locally on PostgreSQL 18 in Docker with Playwright's Chromium 153. The dialog was checked at 1366, 390 and 320 px in both themes, with a keyboard pass. There is no horizontal scroll at any width, and on phones the dialog sits 16 px from each edge. Focus starts in the field and stays inside the dialog. Enter does nothing until the name is typed. The console was clean, and a trace of the deletion was recorded.
Departures that follow from a card contract (L7)
FOR SHAREandFOR NO KEY UPDATEneed the UPDATE grant and policy, so each scope that locks a row holds UPDATE on it.libraryInstallation, with no scope, because nobody is signed in yet.invitation-acceptance.test.tsandpassword-write.test.tsnow revoke and grant onhub_invitationinstead ofhub_runtime, because that role writes now. Their assertions are unchanged.client-deletion.test.ts, becauseclients.test.tswould pass Biome's 300 lines. The native-route refusal sits insign-up.test.ts, next to its twin "empresa só pela Central", becausecompanies.test.tsis at 269 lines.deleteCompanytakes the company lock itself. Removalclient-delete-operator-onlytargetsdisableOrganizationDeletion, because row policy already hides the client from anyone who is not the operator.INVITATION_CLOSED. The link answers 404, as criterion 11 asks.AlertDialog, in the sheet's dress. It was not fetched from shadcn's registry, because no outside call was authorized.noticesearch parameter of the list route. That route file is outside U5's declared radius.button-dangerandbutton-danger-confirmare built as button variants and listed as built incomponents.md.mainin a PR of its own (docs: propose decision 0039, company scope and row policy (step 5, U1) #51) before the proof code. docs: propose decision 0039, company scope and row policy (step 5, U1) #51 is open, and its commit is merged here.database-grants.sqlare here as well as in feat(db): step 5 scope roles and their grants, phase 1 (step 5, U2) #53. The merge order is feat(db): step 5 scope roles and their grants, phase 1 (step 5, U2) #53, then feat: two companies isolated by scope and row policy, and the Central deletes a client (step 5) #54.correct()(departure 1). The card's F5 says the build stops if a fit fails. This is a fix to a real deadlock, not a new rule. The same defect is in feat: the Operations Central registers a client, and its administrator joins as first owner (step 4.2) #52; firstmate routes the fix there.created_atorupdated_at, which no command writes.isolation.test.ts"positivo" now writes the company's invitation instead of the company row, which a company's routes only lock.docs/roadmap.mdto 1,510 words. Prose was trimmed in sections 2 and 3, with no decision or approval line touched; it is now at 1,497.sessionStoragemark is set before a registration is sent. A reload that finds it goes to the current list with "O último cadastro ficou sem resposta. O cliente está nesta lista?". The list's notice then leaves the address, so a reload or a copied link does not repeat it.aria-hidden(FloatingFocusManager,markOthers). The dialog's test now checks that the page's buttons are hidden while it is open. The extra Tab stop that reachesbodycomes from Base UI's focus guards and is left as is.deleteCompanyOnhas no check afterwards. The adapter returns no row count, and a read through the same row policy as the DELETE could never fire (C50).installationRead. The status page reads its starts in a read-only, repeatable-read transaction again. Narrowing the unscoped doors by type, with a dependency-cruiser fence, is issue Step 5: type the unscoped database doors narrowly and fence their callers #59.Closing list
e05-proofof the Hub's project was created, with a new empty database. The owner's password was reset on that branch only. The run used the direct address, whichdocs/how-to/hub-server.mdnames as the Hub runtime's kind.isolation.test.tspassed 7 of 7, and the catalog's RLS checks passed, in phase 1 and in phase 2. Then the branch was deleted. The run read no company row, and no credential reached the repository. The 0039 Result, in the U7 PR, records it.docs/steps.second-card(L5), until the 4.2 card leavesdocs/steps. The roadmap is at 1,497 words and the card at 4,000 with the trim.e05-proofof the Hub's project, a new empty databasee05_proofowned byhub_owner, migrated from zero by the suites, at the direct address.feat/conexus-e042-build. This PR targetsfeat/conexus-e042-build, so the diff is step 5 alone.docs/roadmap.md.The review's push (006)
Head 027a229. Proof for this push:
boot.test.ts"mudada",main.test.ts"log por pedido"); phase 2, 269 of 270, one skipped by phase.correct-client-form"200" timing out under load and passing alone twice.second-card.The delta check's push (007)
hub_invitation's UPDATE onauth."user"is narrowed toname,email_verifiedandupdated_at, what the password command writes. A person's role cannot be written from the link scope. The invitation suites pass, 60 of 61 with one skipped by phase.asPerson. After a database error inside the work, the transaction is aborted and re-entering the company scope fails with 25P02. The work's failure is now the one that rises. New test: "asPerson: a falha da consulta é a que sobe…", which fails with the oldfinally. The function moved out ofopenDatabaseto stay under the 60-line limit.For the founder's review of the screen texts