Commit 8f6d831
fix(plugin-security): the sys_permission_set duplicate-name refusal carries UNIQUE_VIOLATION, and the packaged-set lock answers first (#19437)
Fixes #19307
Clause-②: yes
The data door's duplicate-name refusal on `sys_permission_set` had two
halves, both reproduced on today's head (`c33707933`) before any edit
and re-measured after, on `examples/app-showcase` with a seeded admin
over a cookie session.
## The two halves
**1. No machine-readable `code`.** The insert leg threw a bare `Error`
carrying `.status = 409` and no `.code`. The flat `{ error, code }`
responder invents nothing for a producer that declared nothing, so the
caller got prose — against ADR-0112's 2026-08-17 amendment (#9232),
under which the flat door carries the closed member too.
**2. ⭐ It ran BEFORE `assertPermissionSetNotPackageDeclared`.** A
package-declared set has a projected row, so its name is duplicate AND
locked at once. The admin who opens the Clone dialog on a packaged set
and types the base set's own name — the single most likely thing to type
— got `already exists`, which names no remedy, and never reached
`NOT_OVERRIDABLE`, which names the clone path.
## Live readings — five legs, same script, before and after
Script: `POST /api/v1/data/sys_permission_set` as the seeded admin; full
text in the report comment on #19307.
| leg | BEFORE (`c33707933`) | AFTER (this branch, built) |
|:--|:--|:--|
| 1. duplicate name = **package-declared** `showcase_manager` | `409` ·
`{"error":"[Security] permission set 'showcase_manager' already
exists","object":"sys_permission_set"}` — **no `code` key** | `403` ·
`"code":"NOT_OVERRIDABLE"`, message: *"…Choose a different name for your
set, or clone 'showcase_manager' (the "Clone" action…)"* |
| 2. create a NON-packaged set | `201` | `201` (unchanged) |
| 3. ⚖️ negative control — duplicate of that NON-packaged set | `409` ·
no `code` | `409` · `"code":"UNIQUE_VIOLATION"`, message byte-identical
|
| 4. ⚖️ contrast control — unauthenticated `PATCH`, same resource |
`401` · `"code":"UNAUTHENTICATED"` | `401` · `"code":"UNAUTHENTICATED"`
(unchanged) |
| 5. ⚖️ contrast control — `PATCH` the packaged set (non-duplicate
route) | `403` · `"code":"NOT_OVERRIDABLE"` | unchanged |
Legs 4 and 5 are what make legs 1 and 3 readings rather than constants:
the flat door already varied its `code` by path, so the absence was this
producer's and never the door's.
## Why `UNIQUE_VIOLATION`, reused and not minted
`sys_permission_set` declares `{ fields: ['name'], unique:
'organization' }`, and the reading recorded on that index itself (#8554)
is `org_yi 409 UNIQUE_VIOLATION`. So the platform **already** answers
this exact collision with this exact envelope whenever the index catches
it instead of the projection's pre-check. A second spelling here would
make one condition answer two envelopes depending only on which layer
got there first — the drift `@objectstack/rest` and
`@objectstack/driver-memory` deliberately registered the SAME code to
avoid. `RESOURCE_CONFLICT` (the standard member 409 derives from) is
what the door supplies for a producer that named no condition; using it
would be that second spelling.
## The `packages/spec` touch is one provenance row
`check:error-code-provenance` recognises `objlit`, `assign` and `*_CODE`
`constdef` stamp sites and states in its own bounds line that it is
**blind to class fields**. Written as a class-field literal, this
package would have become an unlisted EMITTER of a registered code with
every gate in the repo green — the invisibility the ledger header names
("no admission rule checks WHO emits"), found by hand three times
already (#7504 / #13254 / #13353). So the code is stamped through an
exported `PERMISSION_SET_NAME_CONFLICT_CODE`, which puts the emitter
inside the gate's field of view, and the ledger gains the matching row
under `@objectstack/plugin-security`.
Measured red then green, in that order:
- class-field spelling, no ledger row: gate **exit 0** — it never saw
the stamp;
- `*_CODE` constant, no ledger row: gate **exit 1** —
*"@objectstack/plugin-security stamps 'UNIQUE_VIOLATION' (constdef) at
packages/plugins/plugin-security/src/errors.ts:372 — not listed under
its own owner key"*;
- `*_CODE` constant + the row: gate **exit 0**, 339 stamp sites, 322
listed.
**It is provenance, not identity, and that is measured rather than
asserted.** The deduped ledger union is **282 distinct codes before and
282 after, added [] / removed []** — `UNIQUE_VIOLATION` was already a
member under two other packages. `pnpm --filter @objectstack/spec
check:generated` reports all 15 generated artifacts up to date, which
supports ONE claim only — no regeneration is MISSING. ⛔ It does NOT show
the published TYPE is unchanged, and here it is not: `ERROR_CODE_LEDGER`
is exported `as const satisfies`, so this row moves `typeof
ERROR_CODE_LEDGER['@objectstack/plugin-security']` from a 3-tuple to a
4-tuple. `check:api-surface` stayed GREEN THROUGH that change, because
`api-surface/api.json` records the symbol name (`ERROR_CODE_LEDGER
(const)`) and no signature, `api-surface-signatures.json` covers 27
`define*` helpers and not this const, and `api-surface-declarations/`
was withdrawn by #19024 and does not exist on this base. That is why
this PR declares `Clause-②: yes` and grades `@objectstack/spec` `minor`.
1 parent 097d268 commit 8f6d831
6 files changed
Lines changed: 496 additions & 6 deletions
File tree
- .changeset
- packages
- plugins/plugin-security/src
- spec/src/api
- scripts
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
367 | 451 | | |
368 | 452 | | |
369 | 453 | | |
| |||
0 commit comments