Skip to content

feat: the Operations Central registers a client, and its administrator joins as first owner (step 4.2) - #52

Merged
leandrotcawork merged 20 commits into
mainfrom
feat/conexus-e042-build
Oct 17, 2026
Merged

leandrotcawork merged 20 commits into
mainfrom
feat/conexus-e042-build

Conversation

@leandrotcawork

@leandrotcawork leandrotcawork commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Step 4.2, "Cadastro de cliente", built from the card docs/steps/e042-cadastro-de-cliente.md, approved 2026-10-16 at 819b1157ca1edc62fb83a5f31d07faa391e32716 ("Aprovo"). U2's table and grants came first in #48; this branch carries U1 and U3 to U6 on top of them, and merges #48's branch for its two test-only fixes (session.test.ts, database.test.ts), so the diff shrinks to this step's own once #48 lands.

What the founder gets

The operator opens Central de Operação from the account menu and registers a client with CNPJ, razão social, display name and the administrator's e-mail. The company is born with no member, and the administrator receives "Conexus convidou você para ser o primeiro dono de X", creates a password and joins as owner. While the client awaits its administrator, the operator corrects its data and resends, cancels or reissues the owner invitation through step 4.1's routes. Once active, the Central shows the company's data and its owners only. Conexus never becomes a member, and nobody creates a company outside the Central.

Units

Unit Commit What
U2 545e27f (#48) operations.client; hub_runtime reads, inserts and updates it, never deletes
U1 97d9fce One table of actions for member and operator; the proof is a union of sealed classes
U3 c5b69d1 /api/clients: register, correct, list, read, through identity's ports; every invitation write goes through the plugin's adapter
U4 4e5376f The Central's screens behind the operator's menu link
U5 574e842 Company creation removed from contract, server and screens; the P6 B migration
U6 0b091f9, ef82a5d, 14d6a27, c131cd8 The first owner's invitation from Conexus, in the read and the mail; the Central's journey in Chromium

Review fixes, after the two whole-step reviews: 54f8db7 (correction's lock order), then the findings and main, up to f65ed8d.

Criteria and their proof (L19)

# Proof
A1 apps/server/src/hub/identity/admission.check.ts forges each proof variant; tsc refuses all three
A2 companies.test.ts "fora: o operador não lê empresa alguma…"
A3 operations/clients.test.ts "fora: o membro…"
A4 operations/clients.test.ts "sem membro…"; removal operator-not-member
A5 operations/clients.test.ts "a chave…"; removal client-attempt-replay
A6 operations/clients.test.ts "o CNPJ…"
A7 operations/clients.test.ts "recusas…"; removals client-owner-not-operator, client-one-transaction
A8 operations/client-reads.test.ts "corrigir: aguardando…"; "corrigir: contra o aceite que chega antes…" holds the company from a test connection, queues the acceptance then the correction: 409 CLIENT_ACTIVE, name unchanged; "corrigir: contra a renovação…": both 200, never 40P01 (removal client-correction-company-lock). The accept race is held twice, by the correction's lock and by renameCompanyOn's, so no single removal reaches the first race test
A9 operations/client-reads.test.ts "ler…"
A10 operations/owner-invitation.test.ts "o operador reenvia, cancela e convida de novo…"; removal owner-invitation-awaiting-only
A11 operations/clients.test.ts "log…"
A12 clients.test.tsx, register-client-form.test.tsx (including "o endereço do administrador recusado…"), correct-client-form.test.tsx; owner-invitation.test.ts "o endereço do administrador recusado pelo provedor…"; the sweep's six Central states
A13 account-menu.test.tsx, clients.test.tsx "sem o papel de operador…", the browser walk below
A14 companies.test.ts "criar: POST /api/companies não existe mais…", sign-up.test.ts "empresa só pela Central…" (removal company-creation-closed), people.test.tsx "/companies/new… não existe mais", route.test.tsx "sem empresas, também para o operador…"
A15 platform/migrate.test.ts "a exceção de P6…"
A16 operations/owner-invitation.test.ts "primeiro dono…" (mail, read with firstOwner), invitation.test.tsx "o primeiro dono de um cliente lê a frase de P5…", tests/e2e/client.test.ts (the page's sentence in Chromium); the founder's use

The rule the P6 B migration uses to choose what it deletes

apps/server/migrations/20261017014712_p6b_test_companies/migration.sql, in one transaction at migrate:

  1. DELETE FROM auth.invitation where the invitation's company has no row in operations.client.
  2. DELETE FROM auth.member where the member's company has no row in operations.client.
  3. UPDATE auth.session SET active_organization_id = NULL where that company has no row in operations.client.
  4. DELETE FROM auth.company where the company has no row in operations.client.

Every company that exists before this release was created by the old "Nova empresa" and has no client row, so all of them go, with their members and invitations. People, accounts and sessions stay. The founder confirms the exact list before the release, as the card says. A rollback does not bring them back (the declared exception to data D6).

Declared departures (L7)

  • Every invitation write goes through the plugin's adapter (getOrgAdapter), not the endpoints, which admit only a member. The Hub's admission stays the single gate (C26, S6). Recorded in docs/reference/boundaries.md, "A company with no member and every invitation, through the plugin's adapter".
  • CLIENT_OWNER_IS_OPERATOR also on createInvitation, so the operator cannot invite an operator as first owner through step 4.1's routes either.
  • pageOf, pageKey and after moved from identity/companies.ts to platform/pages.ts, now that two subjects page. Pager moved from hub/identity to ui.
  • dependency-cruiser: the "subject only through public" rule exempts server tests, which still follow the T5 rule, so operations tests can use identity's test Hub.
  • Test files split for the 300-line limit: client-reads.test.ts from clients.test.ts; A16's server test lives in owner-invitation.test.ts, not invitation-journey.test.ts.
  • The registration replay is read after admitOperator, so a non-operator learns nothing from a key.
  • mayCreate renamed mayOperate in U4 rather than U5, since the menu link needed it first.
  • The account menu reads the company list on every page (refetchOnMount: false) to know mayOperate; two keyboard harness tests now reload to read it.
  • A15 deletes P6's row from the migrations table instead of migrating "up to the previous migration": every test database is born migrated, so the test plants its rows and runs migrate again.
  • The test Hub's companies are planted as rows (plantCompany), and Ana owns them as a person, not the operator, since the operator is never a member.
  • U6 fixed two defects of earlier units that the Central's journey found: the menu's link item stayed open over the page it opened (Base UI's Menu.LinkItem defaults closeOnClick to false; the wrapper now closes like any item, components.md notes it), and the client list answered 500 once a first owner accepted (an accepted owner invitation was shaped as if still awaiting).
  • people.test.tsx "Convidar de novo" no longer asserts the order of two parallel reads, which nothing orders; it asserts each list is read once more.
  • database: { joins: true } removed with its removal row library-joins-native. Its test created a fourth company through the plugin's endpoint, which is closed; the only other caller, /organization/list, is not exposed. Without it the whole server suite passes and pg prints no concurrent-query warning. The row invitation-replay-resends-unmailed follows U6's new text.
  • Lock order of a correction. correct() now locks the company before the operator's row and the client, the order the owner's invitation, its renewal and its accept keep. The card's correction locked the operator's row first and deadlocked a renewal (40P01), found by step 5's build (feat: two companies isolated by scope and row policy, and the Central deletes a client (step 5) #54, departure 1); this is the same fix, through identity's lockCompany port. client-reads.test.ts "corrigir: contra a renovação do convite de dono…" queues a renewal and then a correction on a held company: 500 with 40P01 before, both 200 after.
  • A bounced administrator address at registration answers 201 with the registered client and mailBounced: true, instead of 422 MAIL_BOUNCED (removed from registerClient's failures). The form opens the client with "Cliente cadastrado. Esse endereço não recebe e-mails. Cancele o convite e use Convidar outro e-mail.", reusing 4.1's sentence for a refused address. The search carries the bounced invitation's id (convite=<invitationId>), and the note shows only while that invitation is the client's live one: a cancel or a new invitation removes it (register-client-form.test.tsx "o aviso do endereço recusado vale só para aquele convite…"), and the invitation is marked mailed, so a replay does not resend. The native, smallest shape: no column, the provider's answer travels with the one response that saw it. A provider that may not have sent still answers MAIL_UNAVAILABLE, and the same key resends (C37).
  • firstOwner on the received invitation (InvitationView, derived from "no member yet", no column), so the page says P5's sentence, "Conexus convidou você para ser o primeiro dono de X.", as the mail does.
  • renameCompanyOn keeps its own lock of the company, so the port is safe on its own; the correction takes the same lock first, for the lock order, and the second one on a held row changes nothing. invitationExpiry reads the plugin's invitationExpiresIn instead of a copy of the number.
  • Phones: the Central's rows put the date under the text below sm and wrap anywhere, so the CNPJ, the administrator's e-mail and a long name stay whole; the client's title and owners wrap instead of cutting. A page the guard hides names no place in the header (Central de Operação was shown on the 404).
  • tests/e2e/invitation-image.test.ts created its company with POST /api/companies, which U5 removed (404 in CI's image job). In the image the first person is the operator, so the test now registers a client and checks the owner's invitation mail, with the same checks on sender, link, fallback, expiry and no remote image. Passed locally against an image built from this branch.
  • tests/e2e/live-hub.ts holds what both journeys share (the live Hub, the mail provider's door, the browser's route), moved out of invitation.test.ts; knip's root project includes tests/e2e.

New dependency (L16)

@brazilian-utils/brazilian-utils 2.5.0, in packages/hub-api and apps/web: isValidCnpj(v, { version: 2 }), the founder's choice in the card. A small validator, cheap to undo, not on the list of expensive choices.

Change size

npm run change-budget -- --base origin/main: 2,553 changed lines without tests and generated files, under the card's 3,950. The per-unit split runs over in U1 (901 of 400), U5 (1,529 of 400) and U6 (901 of 300), because a commit's lines count against its unit: U5 carries the migration's generated snapshot and the removal of the old creation path, and U6 the shared e2e module and the two fixes above. U3 (1,380 of 1,650) and U4 (866 of 1,050) are under.

Checks run locally

npm run verify (lint, typecheck, deps, knip, docs, openapi, suppressions, every test, build): green. npm run migrations -- --base origin/main: ok. node scripts/removals.ts: every row caught. After the review fixes, the affected suites ran again: server 255, web 119 vitest (the known cache.test.tsx load timeout passed alone) and 182 node/browser, both e2e journeys, and the touched removal rows, all caught. npm run e2e: both journeys pass. npm run test:image against an image built from this branch: passes. All on PostgreSQL 18 in Docker, shaped like CI.

The browser walk (T23)

The repository's Playwright Chromium against a local Hub on PostgreSQL 18 in Docker, the mail provider faked at its door. The use script's 16 states (the operator's home, the menu, the empty Central, the registration with a wrong CNPJ, with the operator's own e-mail and with a CNPJ that exists, the client awaiting, the list, the owner's invitation before and after the password, the owner's company, the active client and list, the operator's home after), each at 1366, 390 and 320 px in light and dark: no horizontal scroll, no console error or CSP refusal, every Tab stop with a 2px outline, and the menu closes after its link. Traces of both browsers kept. The owner's mail rendered at 600 and 320 px, light and dark, says "Conexus convidou você para ser o primeiro dono de X." in subject and body.

Closing list (L19)

…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)
…t, and native joins no longer protect a reachable path
@leandrotcawork

Copy link
Copy Markdown
Collaborator Author

Reviewer: Claude Opus 5.5 (claude-opus-5-5)

Rules read: AGENTS.md, .agents/skills/conexus-review/SKILL.md, docs/reference/checklist.md, docs/steps/e042-cadastro-de-cliente.md, docs/guides/{code,security,data,web,design,testing,delivery}.md at main c9f22c5 (all read with git show origin/main:<path>). Reviewed: c131cd8 (fetched with git fetch origin pull/52/head; sha confirmed).

Ran

  • git diff origin/main...c131cd8 (108 files) read. I read the core in full: identity/{admission,clients,public,auth}.ts, operations/{clients,routes,public}.ts, the three migrations.
  • T23, the real browser. I used the repository's pinned Playwright Chromium against a local Hub on PostgreSQL 18 in Docker. The Hub was booted the way tests/e2e/live-hub.ts does it, and the mail provider was faked at its HTTP door. I walked use script steps 1–5 as a user, at 1366, 390 and 320 px, in light and dark:
    • Every step passed. A wrong CNPJ check digit gets "Confira o CNPJ…" and the operator's own e-mail gets "Este e-mail é de um operador da Conexus.". With right data, the client reads "Aguardando o administrador". Corrigir dados and Reenviar work (the deadline moved). The same CNPJ again gets "Já existe um cliente com este CNPJ.".
    • The second mailbox got "Conexus convidou você para ser o primeiro dono de Empresa Teste". The owner set a password, accepted, and the company opened for them.
    • The Central then shows "Ativo", "Ativo desde" and "Donos: name, e-mail", with no invitation actions and no Corrigir dados. The operator's home says "Você ainda não participa de nenhuma empresa.".
    • No page had horizontal scroll at any width. No CSP refusal and no page error; the only console errors were the expected 422 and 409. Every Tab stop on the registration form showed a 2 px outline.
    • 120 screenshots. The ones I looked at: 09-detail-awaiting-390-dark, 14-list-awaiting-390-light, 16-invite-accept-1366-light, 18-detail-active-320-dark, 19-list-active-320-light, 04-central-empty-1366-dark, 07-form-bad-cnpj-320-light, 22-after-cancel-390-light.
    • Not run in the browser: confirming a cancel and then Convidar outro e-mail; the 412, the 409 CLIENT_ACTIVE and OWNER_INVITATION_OPEN texts; loading and error states.
  • Mutation, A8 race. I deleted await lockCompany(tx, input.companyId) at apps/server/src/hub/identity/clients.ts:85 and ran client-reads.test.ts three times: pass (2.9 s), timeout, pass (1.4 s). Then I reverted it.
  • Mutation, T4. I added import … from '../identity/admission.ts' to operations/clients.ts and ran depcruise apps/server/src: error subject-only-through-public. Reverted.
  • Cnpj.safeParse on counterexamples:
    • accepted: 12ABC34501DE35, lower case, masked, spaced
    • refused: all zeros, AAAAAAAAAAAA00, 13 digits, wrong check digit
  • Read only, not run: the A15 migration test (my run hung on this machine's memory and was killed), node scripts/removals.ts, and the remaining server tests.
  • CI at this commit, when I looked: image fails in actions/setup-node. Its cache download stopped at 37% (job 117317886982), before any test ran, so this is the runner, not the code. web, check and scripts were still pending. CI needs a green rerun before the merge (L13). It is not a finding against the code.
  • pstack interrogate was not run as a skill. In its place, three independent subagents (Opus, Sonnet) reviewed T2/P3/P4, P6/T4/web/image, and T23, and I checked each of their claims against the code before I kept it.

Findings

  1. Bloqueia. The must test for A8's race against acceptance cannot fail.
    • Evidence: apps/server/src/hub/operations/client-reads.test.ts:73-89 runs correction and acceptance at once and accepts either outcome. On a 200 it only checks the new name.
    • It never checks the case the lock exists to prevent: a correction that answers 200 and renames a company that is already active.
    • With the lock at identity/clients.ts:85 removed, the test passed 2 of 3 runs. No row in scripts/removals.json covers that lock: invitation-company-lock covers invitations.ts only.
    • Breaks: card A8 ("contra o aceite, um vence") and testing T12; removing the lock is not caught.
    • Recommendation: force the interleaving instead of racing. Hold the company's lock from a test connection while acceptance commits, then assert the correction answers 409 CLIENT_ACTIVE with the name unchanged. Add a removal row, for example client-correction-company-lock, for identity/clients.ts:85.
    • Cost: Se for assim para produção, o fundador perde a garantia de que um cliente já ativo não tem os dados trocados pela Central quando uma mudança futura tirar ou mover esse lock, porque nenhum teste fica vermelho.
  2. Fechamento. Step 4.1's member invitation writes moved from auth.api to getOrgAdapter, beyond what the card names.
    • Evidence: invitations.ts and invitation-management.ts drop auth.api.createInvitation, cancelInvitation and resend. They now use organizationAdapter (invitations.ts:200,260, invitation-management.ts:85).
    • Renewal writes expiresAt itself (auth.ts:60, invitationExpiry), and the call needs @ts-expect-error (auth.ts:216).
    • The card's U3 names the adapter for registration. Its failure table keeps "compensação nativa" for step 4.1's path.
    • My judgment: one writer for both proofs is the sound design. An operator's owner invitation goes through step 4.1's routes, and the plugin's endpoint refuses a non-member, so two writers would be two owners of one rule. getOrgAdapter is a typed export (plugins/organization), the founder chose it in T2, and docs/reference/boundaries.md:101 declares it.
    • What remains: the card text says less than the build does. Nothing is lost today: no organizationHooks, no sendInvitationEmail, no cancelPendingInvitationsOnReInvite, and invitationLimit is ∞.
    • Recommendation: record "every invitation write through the adapter" as a card amendment at closing (L7). Add to boundaries that turning on a plugin invitation hook later would be bypassed.
  3. Fechamento. The closing list leaves out three items the card's "A dívida" orders (L19):
    • the D6 exception under "Roll back" (docs/architecture.md:155 still says every migration only adds);
    • the S6/S11 amendment (the operator acts as a fact of the person, not as a member);
    • the note in decision 0015 (a company with no member is awaiting its owner).
    • Evidence: the PR touches only boundaries.md and components.md under docs.
    • Recommendation: add the three to the closing list.
  4. Fechamento. At 390 and 320 px the client list cuts off the CNPJ and the invitation's e-mail, both of which the matrix requires.
    • Evidence: apps/web/src/hub/operations/clients.tsx:44-52. Three truncate lines share the row with a shrink-0 "Cadastrado em" column.
    • Screenshots: 14-list-awaiting-390-light shows "Empresa Teste Corrigida…" and "Aguardando o administra…". 19-list-active-320-light shows "Empresa T…" and "Empresa Tes…".
    • Nothing is lost, since the detail page shows everything, but on a phone two clients with similar names cannot be told apart.
    • Recommendation: below sm, put the date under the text column, or let the second line wrap.
  5. Fechamento. advanced.database.joins: true (auth.ts:278) stays, but its removal row library-joins-native is gone.
    • The adapter calls the Hub now makes (adapter.mjs:141,352,728,793) use no join.
    • Recommendation: delete the option, or tie a row to a path that still joins.
  6. Fechamento. The A15 test forces P6 to run again by deleting P6's row from the migrations table (a declared departure). If the migrator compares against the last migration applied, the test will break once the next migration lands.
    • Recommendation: add a comment there. The selection itself is exact (read).
    • Only auth.invitation and auth.member reference the company, both with ON DELETE RESTRICT. session.active_organization_id has no foreign key and is cleared.
    • None of the four statements can touch a company with a row in operations.client.
    • The test asserts that the client company, its member, its invitation and its session survive, and that the test company's session is nulled.
  7. Fechamento. Two small text points:
    • Replaying the original registration after a correction answers 409 IDEMPOTENCY_CONFLICT. Both comparisons read the current values (operations/clients.ts:70, identity/clients.ts:57). That fits C37, but no line says so; add a comment.
    • The awaiting detail repeats "Aguardando o administrador" in the header and in the invitation line (09-detail-awaiting-390-dark). Send this to the founder's text review.
  8. Issue futura.
    • Neither acceptance nor renewal checks isOperator, so a person promoted to operator after being invited could become a member. The card lists this risk; nothing promotes a person today.
    • Registration does not go through step 4.1's invitation pace (identity/clients.ts:64-75).
    • An active client left with no owner would answer 500 (owners.min(1)). Step 5 should consider it when it adds member removal.
    • Since c131cd8, the image no longer renders the member-invitation mail, only the owner's. It is still covered in unit tests.

Checked and sound, with the item from the brief:

  • (T2) There is no native path for a company with no member. auth.api.createOrganization always writes the creator as a member (crud-org.mjs:76-100). beforeAddMember cannot skip that, and isSystemAction needs a call with no session. The adapter writes inside the Hub's transaction (getCurrentAdapter; auth.ts:160-166), which the "recusas" triggers and client-one-transaction prove. The boundary is declared.
  • (T4) Operations' non-test code imports only identity/public.ts and platform/*. The depcruise mutation is caught. The test exemption lets a test reach only the test Hub, held by the T5 rule. The proofs are sealed in admission.ts.
  • (P3/T3) The CHECK, client_cnpj_key and the attempt key's UNIQUE match U2. A 23505 maps to CLIENT_EXISTS only by constraint name (C52). Two registrations of one CNPJ under two keys: the second blocks on the index and rolls back whole, adapter company included. The statuses match the card.
  • (P4) The correction locks the client row FOR UPDATE, answers 412 on an old revision, then takes the company lock that acceptance also takes. No lock-order inversion. OWNER_INVITATION_OPEN counts live pending invitations under the lock. The operator gets 404 on readInvitations and on a company that has members, and may invite only as owner.
  • (P5/P7) The subject and body match P5. The Central shows data and owners only.
  • (8) The image test still checks the sender, link, fallback, the UTC expiry text and no remote image, now through /api/clients.
  • The declared departures: reading the replay after admitOperator is safer than the card's order (S10). CLIENT_OWNER_IS_OPERATOR on createInvitation uses one predicate, so one owner. pageOf moving to platform follows from C4.

Verdict

request changes: A8's must test for the race against acceptance cannot fail, and no removal row guards the correction's company lock (T12). Everything else is Fechamento or Issue futura, and the use script passes in the browser at all three widths and both themes.

@leandrotcawork

Copy link
Copy Markdown
Collaborator Author

Reviewer: Sonnet 5.5 (claude-sonnet-5-5)

Rules read: AGENTS.md, .agents/skills/conexus-review/SKILL.md, docs/reference/checklist.md, the card docs/steps/e042-cadastro-de-cliente.md, and the docs/reference/boundaries.md diff, all at main c9f22c5f9f8028486fc54bb21a1c0ad2321d103d via git show origin/main:<path>. The guides web.md, design.md and testing.md (T23) were read by search for the rules a screen touches; code.md, security.md, data.md and delivery.md were not read in full, and the rubric is taken from the skill's step 7. Reviewed: c131cd86674e34a6c4e4d6ee8696afced8b07be5 (fetched with git fetch origin pull/52/head, sha confirmed). CI at read time: 4 of 12 checks passed, 8 pending (including image, server (1/3/4), web), none failed.

Ran

  • Whole diff read against main (108 files; server, contract, web, migrations, tests, boundaries). interrogate (multi-model) was not run, for time.
  • Visual QA (T23) on this machine: the repository's own live-hub helpers (real Hub on PostgreSQL 18 in Docker started by me, --rm, stopped at the end; mail provider faked at its HTTP door), Playwright Chromium 1.63, a walk as the operator and as the invited owner: home, menu, empty Central, form with a wrong CNPJ, with the operator's own e-mail, with a repeated CNPJ, client awaiting, correction, list, invitation page before and after the password, owner's company, active client and list, operator home after, and a non-operator opening /operations/clients and /companies/new. 17 states × 1366, 390 and 320 px × light and dark = 102 screenshots, looked at (a sample of 12 opened by eye, the rest checked by script). Script results: no horizontal scroll in any state, no CSP refusal or page error, the menu closes after its link, "Nova empresa" gone, Tab stops on the register form all with a 2px solid outline. A second walk with long names: cancel (with the e-mail confirmation), "Convidar outro e-mail", the operator's e-mail refused on that field (422), a new e-mail invited, second mail sent. A third walk with a provider that permanently bounces one address (finding 1).
  • Mutation check on a suspected uncaught removal: renameCompanyOn without lockCompany (apps/server/src/hub/identity/clients.ts:85) and client-reads.test.ts still 3/3 green (finding 2). Two further mutants (no row lock in correct, no operator check in checkOwnerInvitation) were inconclusive: the machine was at load average 66 and the runs timed out, so I make no claim from them.
  • Read, not run: the full suites, npm run removals, the P6 migration test, npm run test:image, the e2e journeys (CI runs them; the PR reports them green locally).

Findings

  1. Bloqueia. A registration whose administrator address is bounced by the provider leaves a committed client and a dead-end form. The route mails after the commit and answers MAIL_BOUNCED 422 (apps/server/src/hub/operations/routes.ts:28); the form maps it to the e-mail field (apps/web/src/hub/operations/client-fields.tsx:9) with "Esse endereço não recebe e-mails. Confira o e-mail e convide de novo." Retrying with a good address sends a new key and answers "Já existe um cliente com este CNPJ." on the CNPJ field. Run: provider bouncing bounce@…; DB afterwards clients=1, companies=1, invitation pending; the form stayed on /operations/clients/new both times. Nothing tells the operator the client exists or that the way out is the list, the client, Cancelar convite, Convidar outro e-mail (which does work, run). Breaks: A12 "cada recusa cai no seu lugar" and the matrix row "Cadastrar cliente"; code C37 (a settled refusal reuses the form as if nothing was written). Cost: Se for assim para produção, o operador da Conexus perde tempo e a confiança no cadastro quando o provedor recusar o e-mail do administrador: o cliente já foi criado, o formulário manda convidar de novo e a nova tentativa é recusada por CNPJ repetido. Recommend: on MAIL_BOUNCED at registration, tell the operator the client was registered and send them to it (the failure carries no id, so either the route answers 201 with the client and the invitation shown as not delivered, or the form names the list); add the test the card's A12 implies.
  2. Bloqueia. A8 "contra o aceite, um vence" is a "must" test that cannot fail (T12). client-reads.test.ts:73-92 accepts both outcomes and only checks that a 200 left the new name; a correction applied after the first membership also returns 200, so the test is green without lockCompany in renameCompanyOn (clients.ts:85). Run: lock line replaced by a comment, 3 of 3 pass. There is no removal row for it either (scripts/removals.json has none for the correction's lock). Breaks: T12, card A8. Cost: Se for assim para produção, a Conexus perde a garantia de que um cliente já ativo não é corrigido pela Central quando alguém remover ou reordenar esse lock numa mudança futura: o operador renomeia uma empresa que já tem dono e nenhum teste avisa. Recommend: a deterministic test that holds the company's lock in an open transaction and shows the correction waits, then answers 409 CLIENT_ACTIVE once a member row exists, plus a removal row client-correction-locks-company.
  3. Fechamento. The first owner's invitation page says "Conexus convidou você para Empresa Teste como Dono." (screenshot 12-invitation-before-password-390-light.png), not P5's sentence; "primeiro dono" appears only in the mail and the form hint (grep over apps/web/src). The test named "convite e e-mail dizem Conexus, Dono e "primeiro dono"" (owner-invitation.test.ts:125) asserts "primeiro dono" only on the mail and inviterName on the read, so its name promises more than it proves (checklist 4, C70). The card's U6 lists no web folder, so I read the page as outside its contract; the builder already put it on the founder's text review. If the founder reads A16 as covering the page, this becomes Bloqueia. Recommend: rename the test, and decide the page text at the founder's review.
  4. Fechamento. At 390 px the client list hides what the card says it shows: the row truncates the legal name and CNPJ and cuts "Aguardando o administra…", so the CNPJ and the administrator's e-mail are not readable in the list (11-list-awaiting-390-dark.png, b-long-list-390.png). A 100-character display name is cut with an ellipsis in the list and in the detail title at 320 and 390 px, and the detail's data rows (client.tsx:16-21) hold no display-name row, so the full name is readable nowhere on those screens (a-long-detail-320.png). Recommend: a "Nome de exibição" row in Data, and let the list row wrap (break-words) below 480 px instead of truncate (V13).
  5. Fechamento. A non-operator opening /operations/clients gets the 404 body but the header still says "Central de Operação" (route staticData.place, 17-owner-opens-central-390-light.png), naming the Central to someone who must not know it. Recommend: set the place from the guard's outcome, or give the 404 the neutral title.
  6. Fechamento. Moving every invitation write to the adapter dropped two native checks that the Hub now owns separately. Cancel and replace no longer pass the plugin's invitation: ["cancel"] permission (crud-invites.mjs:435-438); admitInviter checks invitation: ["create"] for all (admission.ts:9, :181-182). Renewal computes expiresAt with invitationExpiry() (auth.ts:60) where the plugin used getDate(invitationExpiresIn) (crud-invites.mjs:136). Same results today (the member role holds neither permission; one constant feeds both), but two owners of one rule if the role table changes. Recommend: an ACTIONS entry for cancel with its own statement, and derive invitationExpiry from ORGANIZATION.invitationExpiresIn.
  7. Fechamento. database: { joins: true } stays in auth.ts with a comment that it saves queries, but its removal row and its test were deleted and the PR says the whole suite passes without it. Remove it (subtract) or protect it with a row; as written it is a line that exists only because the old code had it (checklist 1).
  8. Fechamento. .dependency-cruiser.cjs (outside the card's folders, declared in the PR) exempts server tests from subject-only-through-public so operations tests can use identity's test Hub. It follows from T4, and the T5 rule still confines tests to main.ts, a public.ts or the test database, so the wall is intact; the guide text for C4 or T5 should say it.
  9. Fechamento. P6 has no gate and no preview: the migration runs at migrate on deploy and nothing but the card's process holds the release until the founder confirms the list. Recommend firstmate holds the release on that confirmation by name; an optional read-only count (select id, name from auth.company c where not exists (select 1 from operations.client where company_id = c.id)) would give the founder the exact list if the card's "no database query" allows it.
  10. Issue futura. Client.state ACTIVE requires one owner or more (operations.ts, owners.min(1)); a company with a member and no owner would make the list answer 500. Nothing can create one today. Trigger: the first step that removes members or changes roles.
  11. Issue futura. clientsOf drops a client row whose company is gone without a sign (flatMap to []), so a page can hold fewer than 50 rows with next: MORE, and getClient answers 404. Trigger: step 5's client deletion, which deletes across the two owners.
  12. Issue futura. The image test no longer renders the member-inviter branch of the mail in the final image (it now registers a client, so only the Conexus branch). Same template, so low risk; add a member invite there when step 4.3 or 5 touches the image test.

Judged, no finding:

  • (1) Departures: the adapter for every invitation write follows from E2 (the operator is admitted on invite, and the plugin's endpoints admit only a member) and is declared in boundaries.md with library lines; the rest are test, move or tooling consequences, declared. The two I query are in findings 6 and 8.
  • (2) T2: no native path exists. createOrganization always writes the caller as a member (crud-org.mjs:74-100, also with a server-side userId, which the organization skill describes), and the removal row operator-not-member swaps in exactly that call. getOrgAdapter is exported (organization/index.mjs:1-4, .d.mts) though the skill does not document it; the @ts-expect-error in auth.ts is justified in the line and in boundaries.md, with the four adapter lines to reread on upgrade. The boundary is declared.
  • (3) T4: operations/* imports identity only through ../identity/public.ts (types), identity imports nothing from operations; subject-only-through-public enforces it and scripts/rules.test.ts plants a violation per rule. Operations writes its own table in a transaction identity opens (libraryCommand as a port), as the card says.
  • (4) P6: four statements, each WHERE NOT EXISTS (… operations.client …), so a company with a client row is untouchable; only auth.member and auth.invitation reference auth.company, so the delete cannot fail on a foreign key; sessions are nulled first. migrate.test.ts A15 proves the selection with a kept and a deleted company. D6 exception declared in the SQL comment and the card. Review before release: see finding 9.
  • (5) P3/T3: the DB holds the full 14-character UNIQUE (client_cnpj_key) and a format CHECK; check-digit validity is in the contract (isValidCnpj(v, {version: 2}), 2.5.0 supports it, sideEffects: false), not in the DB, which is as the card says. Two registrations of one CNPJ end 201 + 409 CLIENT_EXISTS through the constraint name (test "o CNPJ", read; the browser run showed the 409 on the CNPJ field).
  • (6) P4: correction is gated by revision and the company lock (finding 2 is about its test, not its code); cancel then "Convidar outro e-mail" works in the browser, the operator's address is refused on the field, a new mail goes out; invite and cancel read the membership under the company lock, so acceptance and cancel cannot both win.
  • (7) P5/P7: the mail subject and body say "Conexus convidou você para ser o primeiro dono de X" (run); the active detail shows data and owners only, no actions (run); texts match the matrix and the failure table. Findings 3, 4, 5 are the screen faults.
  • (8) The image test fix: still proves what it is for (the final image's bundle renders and sends the mail over HTTP with no mail toolchain installed; the installed check is untouched). Registering the first person as operator is how the product now works. Finding 12 is the only loss. Read, not run.

Verdict

request changes: two Bloqueia (1: a bounced administrator address strands the registration form after the client is committed; 2: the A8 "must" test passes with the company lock removed), at head c131cd86674e34a6c4e4d6ee8696afced8b07be5.

…ner's invitation does, so a renewal never deadlocks it
…ow, a bounced administrator lands on the registered client, the first owner's page says P5, the list wraps on phones, a hidden Central names no place, native joins removed
@leandrotcawork

Copy link
Copy Markdown
Collaborator Author

Reviewer: Claude Opus 5.5 (delta c131cd8..f65ed8d)

Rules read: .agents/skills/conexus-review/SKILL.md, and from the card docs/steps/e042-cadastro-de-cliente.md rows A8, A12 and A16, the matrix and the failure table, plus the L12 classes in docs/guides/delivery.md, at main 7364445. Reviewed: f65ed8d (fetched pull/52/head, sha confirmed), as a delta check against c131cd8. This is conferência 1 de no máximo 3.

Ran

  • I read git diff c131cd8 f65ed8d (26 files) line by line. The merge 46194bd adds no content: its tree is identical to 54f8803's (git diff 54f8803 46194bd is empty), and main 7364445 is an ancestor of the head. So the step's own changes are 54f8db7, 54f8803 and f65ed8d.
  • Database: my own PostgreSQL 18 in Docker (--rm, now stopped), set up like CI with superuser postgres and non-superuser conexus_owner.
  • client-reads.test.ts at the head: 4 of 4 pass.
  • node scripts/removals.ts --only client-correction-company-lock gives caught.
  • Mutation, A8. I deleted await identity.lockCompany(...) in operations/clients.ts correct() and ran it 3 times. Red each time: actual [200, undefined], expected [409, 'CLIENT_ACTIVE']. The new test is deterministic.
  • Mutation, the old lock order. I took the lock out of correct() and put lockCompany back inside renameCompanyOn, after the operator's row and the client's row. I ran it 2 times. The renewal race test went red both times with [[200], [500 INTERNAL_UNEXPECTED]] and a logged 40P01 from lockCompany. The A8 test stayed green, as expected, because that order still locks the company. The lock-order fix is real and its test catches the regression. I reverted both mutations.
  • owner-invitation.test.ts and invitation-acceptance.test.ts: 14 of 14 pass. The web tests in src/hub/operations and invitation.test.tsx: 39 of 39 pass.
  • Mutation, the 404 place. I reverted the notFound check in routes/_app/route.tsx. The test "sem o papel de operador…" went red. Reverted.
  • drizzle-orm 1.0.0-rc.4: migrator.utils.js:14 picks the pending migrations by name (!dbNamesSet.has(lm.name)). So the new A15 comment is accurate.
  • T23, a real browser. The repository's Playwright Chromium (1.63) ran a scratch walk against a live Hub built with tests/e2e/live-hub.ts. A fake provider permanently bounced any address that starts with bounce. Each state was captured at 1366, 390 and 320 px, in light and dark.
    • The walk: register with a bounced address, open "Cancelar convite" and confirm, open "Convidar outro e-mail", invite davi@…, reload, register a client with a 100-character name and a 77-character e-mail, the list, and a non-operator opening /operations/clients.
    • What the script checked: horizontal overflow was 0 in every state, no text was clipped, and there was no page error and no CSP refusal.
    • Screenshots I opened: 01-bounced-client-*, 02b-after-new-invite-390-light, 03-long-client-320-dark, 04-list-320-light, 04-list-390-dark, 05-non-operator-404-390-light.

The fix list, item by item

Item State Evidence
1 A8 must test fixed client-reads.test.ts "contra o aceite que chega antes" holds the company from a test connection and queues the acceptance, then the correction. It asserts 409 CLIENT_ACTIVE and an unchanged name. The removal row client-correction-company-lock is caught, and my mutation went red 3 of 3.
Lock-order fix (step 5's 40P01) fixed correct() takes lockCompany first (operations/clients.ts:121-123), through a new identity port. The renewal race test goes red with 40P01 under the old order (run).
2 Bounced administrator wrongly fixed, in part The 201 with mailBounced lands the operator on the client (run), and the server test covers cancel and then invite another address. But the note stays on the page after the recovery. See finding 1.
3 P5's sentence on the page fixed invitation.tsx:205-207 uses firstOwner. The vitest checks the heading, and tests/e2e/client.test.ts:49 waits for it in Chromium.
4 List at 390/320 fixed In 04-list-320-light and 04-list-390-dark, the CNPJ, the administrator's e-mail and a 100-character name are whole. The date sits under the text. No overflow. The detail's title and owners wrap too.
5 Non-operator 404 title fixed The header shows only the logo and initials, and the page body has no "Central" (run). The test turns red without the change (run).
6 joins: true fixed Removed from auth.ts. Declared in the PR body.
7 Closing list fixed (listed) The PR's closing list now names the D6 exception, S6/S11, decision 0015, the card amendment about the adapter, and the guide text for the dependency-cruiser exemption. boundaries.md:113-116 gains the note about hooks being bypassed. The dropped cancel permission is declared, and invitationExpiry now reads ORGANIZATION.invitationExpiresIn (auth.ts:61).
8 Comments fixed The C37 replay comment is at operations/clients.ts:70-71, and the A15 comment is at migrate.test.ts:214-215. "Aguardando o administrador" is on the founder's text review.
Issues futuras fixed #60 and #61 cover Opus 8's first two items. #62 covers Opus 8 and Sonnet 10, #63 covers Opus 8 and Sonnet 12, and #64 covers Sonnet 11.
Opus 2, 3, 5, 6, 7 / Sonnet 3–8 closed These are the same as items 3–8 above.
Sonnet 9 (P6 gate) not a build item Firstmate holds the release on the founder's list.

Findings

  1. Bloqueia. The bounce note never goes away. It tells the operator to cancel the good invitation that replaced the bounced one.

    • Evidence: client.tsx:71-76 shows the note while convite === 'recusado' and the client awaits its owner. Nothing ties the note to the invitation that bounced, and cancelling or inviting another address keeps the search in the URL.
    • Run: I registered with bounce@…, cancelled, and invited davi@…, whose mail was delivered. The URL was still …?convite=recusado, and the page still said "Cliente cadastrado, mas o e-mail do administrador recusou o convite. Cancele o convite e use Convidar outro e-mail." Under it, the invitation section showed "[email protected] / Aguardando o administrador … Reenviar, Cancelar convite" (02b-after-new-invite-390-light). A reload keeps the note too.
    • Breaks: A12 ("cada recusa cai no seu lugar") and the matrix row "Detalhe, aguardando", because the page tells the operator something false about the invitation it shows.
    • Cost: Se for assim para produção, o operador da Conexus perde o convite certo quando, depois de convidar outro e-mail, segue o aviso que continua na tela e cancela o convite que chegou; o administrador fica com um link morto.
    • Recommendation: carry the id of the bounced invitation (convite=<invitationId>), and show the note only while that invitation is the client's live one. Add to register-client-form.test.tsx or client a test that the note is gone after a cancel or a new invitation.
  2. Fechamento. The note's wording, "o e-mail do administrador recusou o convite", reads as if the administrator declined. In fact the provider refused the address. Step 4.1 already has a phrase for this: "Esse endereço não recebe e-mails." Send the text to the founder's text review.

  3. Fechamento. renameCompanyOn now relies on its caller already holding the company's lock (identity/clients.ts:71-74). Only a comment says so. Today the removal row and the A8 test protect it.

    • Recommendation: keep lockCompany inside the port as well. A second FOR UPDATE on a row the transaction already holds is a no-op, so the lock order and the 40P01 fix stay as they are, and the port carries its rule (S8) by itself.
  4. Fechamento. Two changes to the card's contract are not in the closing list:

    • registerClient no longer lists MAIL_BOUNCED and answers 201 with mailBounced (packages/hub-api/src/operations.ts:101-108);
    • the client detail's invitation shows a bounced address as "Aguardando o administrador" once the note is gone, by design: no column.

    Both are declared in the PR body. Add the card amendment to the closing list (L7).

  5. Fechamento. CI at f65ed8d was all queued when I looked (12 checks). The merge needs it green on this commit (L13).

No new defect in the other changed lines. I checked invitation-reads.ts firstOwner and the contract, the firstOwner: false fixture updates, sweep-replies.ts, the route.tsx notFound selector, the validateSearch .catch({}), and the wrap-anywhere row.

Verdict

request changes: Bloqueia 2's fix leaves a note that outlives the bounced invitation and tells the operator to cancel the replacement. Every other Bloqueia and Fechamento of both reviews is closed, the A8 removal is caught, and the lock-order fix is proved by mutation.

…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.
@leandrotcawork

Copy link
Copy Markdown
Collaborator Author

Reviewer: Claude Opus 5.5 (delta f65ed8d..d38b41a)

Rules read: .agents/skills/conexus-review/SKILL.md (step 9, the delta check) and the L12 classes in docs/guides/delivery.md, at main 7364445. I also read the earlier delta report (conferência 1, at f65ed8d). Reviewed: d38b41a (fetched pull/52/head, sha confirmed). This is a delta check against f65ed8d, conferência 2 de no máximo 3.

Ran

  • I read git diff f65ed8d d38b41a line by line. It changes 6 files in one commit, d38b41a.
  • Web: vitest run src/hub/operations/register-client-form.test.tsx src/hub/operations/client. 2 files, 20 of 20 tests pass.
  • Mutation, the old note (the note shown whatever the invitation id). I made 3 mutations in client.tsx. After each one, the new test "o aviso do endereço recusado vale só para aquele convite…" went red with expected <p role="status"> to be null, and the other 10 tests stayed green. I reverted each mutation.
    • (a) ownerInvitation.id === convite → convite !== undefined.
    • (b) (a), and the state === 'PENDING' check dropped too. This is the old note's condition.
    • (c) Only the PENDING check dropped.
  • Server: I started my own PostgreSQL 18 container (--rm, CI's image digest, superuser postgres plus non-superuser conexus_owner, as test-database sets it up). I stopped it with docker stop.
    • I ran client-reads.test.ts 3 times, with lockCompany both in correct() and in renameCompanyOn. 4 of 4 passed each time, including the A8 test "contra o aceite que chega antes" and the renewal race test "contra a renovação do convite de dono… nunca 40P01".
  • node scripts/removals.ts --only client-correction-company-lock printed caught client-correction-company-lock.
  • Mutation, both locks removed (in correct() and in renameCompanyOn): the A8 test and the renewal race test both went red. The A8 "must" test can still fail (T12).
  • Mutation, only the lock in renameCompanyOn removed: every test stays green, as expected. correct() already holds the lock, so the second lock is redundant protection.
  • CI at d38b41a: 13 of 13 checks pass (gh-axi pr checks 52).
  • I did not do the T23 browser walk. Memory allowed it (3.1 GB available), but the 25-minute limit did not. The web test covers the same path through the real router and the real Client page with only the HTTP layer faked: register with a bounced address, cancel, invite another, check the note. Conferência 1 already took the layout screenshots for this page. This delta adds no layout: the note keeps the same <p role="status"> and only its text changes.

The findings of conferência 1, one by one

Finding State Evidence
1 Bloqueia: the bounce note outlives the bounced invitation fixed The search now carries the bounced invitation's id, through register-client-form.tsx:33-36 and $companyId.tsx:11 (InvitationId.optional(), still under .catch({})). client.tsx:71-73 shows the note only while the client awaits its owner, the live invitation is that id, and the invitation is PENDING. A cancel turns the invitation CANCELED, and a new invitation has a new id. The note goes away in both cases and does not come back on a reload. The new test asserts both, and mutations (a), (b) and (c) turn it red.
2 Fechamento: wording fixed The note now reads "Cliente cadastrado. Esse endereço não recebe e-mails. Cancele o convite e use Convidar outro e-mail.". That is 4.1's phrase, MAIL_BOUNCED.phrase (packages/hub-api/src/failures.ts:163). See new finding 1 on how the phrase is written in.
3 Fechamento: keep lockCompany inside renameCompanyOn fixed identity/clients.ts:89 locks again. The doc comment at :79-82 says why. correct() still locks first (operations/clients.ts:121-123), so the lock order of the 40P01 fix stays as it was, and the renewal race test is green 3 of 3. The lock is FOR NO KEY UPDATE on the company row (invitations.ts:66-71), so a second take in the same transaction is a no-op.
3, the removal row moved, still caught Because of the second lock, removing the lock from correct() no longer turns A8 red, since the rename still locks. The row client-correction-company-lock (scripts/removals.json:563-574) now names the renewal race test, which is what catches the wrong order. I ran it: caught. The A8 test itself still fails when both locks go (mutation above).
4 Fechamento: two card amendments in the closing list fixed The PR body's closing list now has "Card amendment: registerClient answers 201 with mailBounced…" and "Card amendment: once the bounce note is gone…".
5 Fechamento: CI green fixed 13 of 13 pass at d38b41a.

Findings

  1. Fechamento. client.tsx:75-76 copies the phrase "Esse endereço não recebe e-mails." as a literal, and the test does the same at register-client-form.test.tsx:52. The phrase's owner is the failures table, FAILURES.MAIL_BOUNCED.phrase (packages/hub-api/src/failures.ts:163), and the web already reads phrases from that table (ui/states.tsx:38, :68). If the founder's text review changes the phrase, the two copies drift apart. Recommendation: build the note from FAILURES.MAIL_BOUNCED.phrase. It is wording, and no one loses data, so it does not hold the merge.

I read every other changed line and found no new defect:

  • the InvitationId search schema, where a malformed id falls back to {} through .catch({});
  • the client.state.kind === 'AWAITING_OWNER' guard before reading ownerInvitation.id, which is always true right after a registration;
  • the invitationOf and owner test helpers;
  • the import split in identity/clients.ts.

Carrying the invitation id in the operator's own URL exposes nothing new. The operator already receives that id in the client's response, and the server answers with Referrer-Policy: no-referrer (platform/http.ts:51).

Verdict

approve: conferência 1's Bloqueia is closed and a mutation proves it, all 4 of its Fechamento findings are closed, the A8 removal is caught, the lock order holds, and CI is green at d38b41a. One new Fechamento (the phrase written in rather than read from FAILURES) goes to the closing list.

@leandrotcawork
leandrotcawork merged commit 8537530 into main Oct 17, 2026
13 checks passed
leandrotcawork pushed a commit that referenced this pull request Oct 17, 2026
…exus-e042-build) into feat/conexus-e05-build
leandrotcawork added a commit that referenced this pull request Oct 17, 2026
…AIL_BOUNCED's phrase (#65)

The Central's note and its test take 4.1's sentence from the shared failure table instead of a copy
of its words, so the two can never drift (second delta check of #52, closing item 1).

Co-authored-by: developmentconexus <[email protected]>
@leandrotcawork
leandrotcawork deleted the feat/conexus-e042-build branch November 12, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants