Repository navigation
Phase 4: Account kinds: person, service, test - #1290
Merged
neuromechanist merged 19 commits intoSep 8, 2026
Merged
neuromechanist merged 19 commits into
neuromechanist merged 19 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1290Version: 🤖 Updated on each push. |
POST /admin/users/:username/kind now answers { error, message } for all
four refusals (same_kind, orcid_linked, own_account,
kind_changed_concurrently) instead of an ad hoc code, so a caller reads
one shape everywhere. orcid_linked's message names `nemar auth profile
orcid unlink` directly. client.ts's prefersMessage learns the new codes
so the CLI surfaces the server's sentence, not a generic fallback.
KIND_CHANGE_GUARDED_UPDATE_SQL moves to module scope so its guarded
UPDATE can be exercised directly at the SQL level (the real-engine
substitute for a concurrent race bun:sqlite's single-writer harness
cannot reliably produce -- documented in this file's header after a
20x Promise.all experiment came back 200/200 every time).
Epic #1272 phase 4, #1284 review; ADR 0048.
- nemar admin users --kind now re-filters the listing client-side, so a backend that still ignores ?kind= cannot mislabel it (mirrors the --awaiting-approval / --no-upload-access pattern). - nemar admin doctor kinds: a new, read-only check that every operational account (OPERATIONAL_ACCOUNT_KINDS, exported from shared/contract/user.ts so the migration test, the seed script's test, and this check stop drifting independently) still carries its expected kind; migration 0082's header now notes that the SQL copy of this list is separate from the one TypeScript source. - nemar admin keys create appends a retry-safety hint on a network failure (statusCode === 0): the key may have minted before the connection dropped. - --kind example added to `admin users --help`. - test/api-export-surface.unit.test.ts: pin the new getAdminUserByUsername export. Epic #1272 phase 4, #1284 review; ADR 0048.
webSessionMiddleware's catch block now tells a schema-shaped failure (no such column/table -- a migration that has not landed on this environment yet) apart from a plain transient lookup failure, each with its own console.error prefix ([web-session-mw] SCHEMA vs [web-session-mw]), so the two stop being indistinguishable in logs. Epic #1272 phase 4, #1284 review; ADR 0048.
- DeviceAuthAccountRow.account_kind (and AdminKeyTargetRow through it), realDatasetCreateGate's input, and upload.ts's inline SELECT row all narrow from a bare string to the closed AccountKind type. identity_conflict narrows from number | boolean to number: every construction of DeviceAuthAccountRow is a raw D1 read, which is always a number. - ProfileGapAccount.account_kind drops its | string escape hatch for the same reason; the one test that deliberately fed a bogus "member" value now casts it explicitly, with a comment explaining the cast defeats the type on purpose to prove the exemption still fails closed. - applyServerUser's account_kind param and Config.accountKind both reuse AccountKind (via ContractUser / accountKindSchema) instead of a bare string. - livenessStatusRefusal factors the pending/inactive-status prologue accountRefusal and accountLivenessRefusal both start with into one helper, so their shared ordering is structural rather than two functions kept in step by hand. The null/deleted check stays duplicated in each caller: it is what lets TypeScript narrow the row to non-null before the shared helper runs. Epic #1272 phase 4, #1284 review; ADR 0048.
Two factual corrections from #1284 review: - ADR 0048 and backend/test/upload-gate.unit.test.ts both claimed a service account "cannot reach [the dataset-create] route at all", on the theory that the device/key gates stop it. False: those gates only stop a service/test account from SELF-serving a key (self-minting, or the device flow's own sign-in). A key an owner minted for it through POST /admin/users/:username/keys authenticates through authMiddleware exactly like any other -- it never reads account_kind -- and reaches the dataset-create route, and every other authenticated route, normally. The ADR now explains that a service account is unrestricted at realDatasetCreateGate on purpose: that is what an operational/automation account is for. - The claim that yahya/arnodelorme "already hold verified iDs, so nothing regresses" is qualified as "at the time of writing" and noted as an observation about the current catalog, not something the migration or the kind exemption depends on. ADR 0048.
- The too_many_keys test name hardcoded "25"; it now interpolates MAX_LIVE_API_KEYS so the name cannot drift from the real cap. - DELETE /admin/users/:username/keys/:id had a person-kind case only in the GET describe block -- every DELETE case seeded a service target, despite the file's own docstring promising DELETE works for any kind. Added the missing person-kind revoke case. #1284 review; ADR 0048.
Two tests that could not previously fail for the reason they claimed
to test:
- "a tombstoned row is untouched" seeded a username the migration's IN
(...) list never named ("nemarAdmin-deleted"), so the deleted_at
gate it claimed to cover was never exercised. Now seeds the row
under the EXACT username the migration lists ("nemarAdmin") with
deleted_at stamped, in its own fresh database (migration 0080's
case-insensitive unique index on username would otherwise collide
with the shared fixture's live row of the same name).
- "case-insensitively" never actually seeded an inverted-case
username. Now seeds "NEMARADMIN" in its own fresh database and
proves the COLLATE NOCASE match.
Usernames are now derived from OPERATIONAL_ACCOUNT_KINDS (shared/
contract/user.ts) instead of a hand-copied list, so this file and the
migration's own username list can no longer drift from each other
independently of the SQL.
#1284 review; ADR 0048.
scripts/seed-dev-db.sql's account_kind UPDATEs had no test: nothing proved the SQL text itself, as opposed to a hand-retyped copy of it, assigns the right kind to the right usernames. ACCOUNT-KIND-SEED marker comments let the new test slice the real statements out of the file with readFileSync and execute them verbatim against a real bun:sqlite database, rather than retyping them. #1284 review; ADR 0048.
profile-gaps-matrix.test.ts and profile-gaps-route.test.ts proved the kind exemption on GET /users/me, GET /auth/me, and the upload-access refusal, but two other readers of the same account_kind column -- POST /auth/code/verify (builds its row inline) and PATCH /auth/profile via fetchPublicUserById -- had no coverage at all. Both name account_kind in their own hand-written SELECT, so nothing forced them to agree with the SELECT the already-tested routes use. #1284 review; ADR 0048.
The kind-change-between-confirm-and-collect diagnosis test only exercised a change to 'service'. ADR 0048 has accountRefusal answer the same service_account code for either non-person kind; this adds the 'test' variant as proof the diagnosis path was not accidentally written to special-case only 'service'. #1284 review; ADR 0048.
neuromechanist
merged commit Sep 8, 2026
48c5764
into
feature/issue-1272-epic-orcid-cli-signin
12 checks passed
This was referenced Sep 8, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Explicit account kinds (epic #1272, phase 4; ADR 0048).
users.account_kindispersonby default,servicefor automation, andtestfor a human's secondary persona. Kinds are set only by an owner, never inferred. Both non-person kinds are exempt from the ORCID gap (the interim admin-or-owner role exemption from ADR 0045 is gone; a person who is an admin is no longer exempt, and the operational admin accounts becomeservicein the migration), refused by the device flow and by self-service key minting with the one typed reasonservice_account, and keyed only by an owner throughnemar admin keys. Atestaccount on production may create onlyxxsandbox datasets, enforced first in the real-dataset create gate.Migration 0082 adds the column with a CHECK and sets the operational accounts by username (never by id):
nemarOwner,nemarAdmin,test-admin,test-ownerbecomeservice;cool-vibers,test-user,test-pending,test-verified,test-revokedbecometest;test-webstays a person because it is the shared web-QA account that must reach the authorize page and the Settings key form. The dev seed sets the same kinds.New routes (owner only):
POST /admin/users/:username/kind, andGET,POST,DELETEunder/admin/users/:username/keys(mint refuses a person target).GET /admin/users?kind=. CLI:nemar admin kind <username> <kind>,nemar admin keys create|list|revoke,nemar admin users --kind, aKind:line in listings and innemar auth statuswhen the kind is not person. The device flow reads one account row for lookup, confirm, and the token diagnosis.Closes #1284
Part of epic #1272
Test plan
backend/test/account-kind-migration.test.ts: CHECK, default, the username-keyed data half against seeded rows, idempotent on re-runtest/profile-gaps-matrix.test.ts,backend/test/profile-gaps-route.test.ts: exemption by kind on all readers; a person admin is not exempt; an unrecognised role no longer mattersbackend/test/device-auth-routes.test.ts,backend/test/api-keys-routes.test.ts: lookup, confirm, and collect-time refusals for both kinds; deny still allowed; self-mint refusedbackend/test/admin-keys-routes.test.ts,backend/test/admin-kind-route.test.ts: owner only; person target refused; cap; list and revoke; audit rows; self, same-kind and verified-ORCID refusals on the kind route; thekindlist filterbackend/test/dataset-create-test-kind.test.ts,backend/test/upload-gate.unit.test.ts: production real-dataset create refused for a test persona, sandbox allowed, non-production unrestrictedtest/admin-keys-cli.test.ts,test/admin-kind-cli.test.ts, the admin users and auth status CLI tests; route inventory and export-surface pinsbun run lint,bun run typecheck,bun run migrations:d1-check(84 migrations replayed on real local D1); fullbun testat the known baselinetest/admin-owner-key-mint-flow.test.ts(live tier) probe-skips until the epic reachesdev; the owner path needs an optionalTEST_OWNER_API_KEY