Repository navigation
Commit a835858
test(runtime): pin the /data door's 409 RESOURCE_CONFLICT for a sharing_rule row created or renamed under a declared rule's name (#25289)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuACdPWFJTLDcTrByFCHLzqb)_
Fixes #25253
Clause-②: no
Metadata-protocol: none
## What
Adds one end-to-end suite,
`packages/runtime/src/sharing-rule-declared-name.data-door.pin.test.ts`.
It boots the composition `bootStack` mirrors (ObjectQL, sqlite-wasm in
memory, Hono, the app, platform objects, auth, security, sharing, REST,
dispatcher). The application declares two sharing rules through its own
`sharingRules`. A signed-in administrator then drives the generic
`/data` door over HTTP:
- `POST /api/v1/data/sys_sharing_rule` under a declared rule's name
answers `409` with `code: RESOURCE_CONFLICT`, and no row lands.
- `PATCH /api/v1/data/sys_sharing_rule/:id` renaming an authored row
onto a declared rule's name answers `409` with `code:
RESOURCE_CONFLICT`, and the row keeps its name.
- **Control:** the same `POST` under a name no declaration holds answers
2xx and the row lands. So the 409 comes from the guard and not from the
rig.
- **Precondition:** the sharing-rule service the guard asks
(`declaredRuleNamed`) reads both declared rules, and neither has a row.
This is test-only. No production file changed and there is no behaviour
change. Today the door does answer 409 `RESOURCE_CONFLICT` on both
paths, so `content/docs/permissions/sharing-rules.mdx` (regime C) is
accurate.
**Wire shape, measured rather than assumed.** The `/data` door answers
its flat envelope: `{ error: "SENTENCE", code: "RESOURCE_CONFLICT",
object: "sys_sharing_rule" }`. `code` sits at the top level
(`mapDataError`, `@objectstack/types`), and the pin reads it there. It
does not use a fallback that would also accept a nested `error.code`.
The first run asserted the nested spelling and went red on exactly that.
**Why each refusal has its own declared rule.** `sys_sharing_rule`'s
unique constraint on the name also answers `409`, as `UNIQUE_VIOLATION`.
My first draft used one declared name for both cases. Under ablation the
create landed, and the rename then answered `409 UNIQUE_VIOLATION`, so a
status-only pin would have read that 409 as the guard's. Now each case
targets its own declared rule and stays independent under ablation.
`code` is asserted beside `status`.
## Lane: runtime, not plugin-sharing (deviation from the claim's file
surface)
The claim's file surface was `packages/plugins/plugin-sharing/src/**`
test files, based on the assumption that
`business-unit-parent-delete-restrict.test.ts` is an HTTP rig. I
measured it, and it is not. It drives `engine.delete` on a real ObjectQL
+ SqlDriver, and `/api/v1/data/...` appears only in a comment.
plugin-sharing has no `@objectstack/rest`,
`@objectstack/plugin-hono-server` or `@objectstack/runtime` dependency.
`@objectstack/runtime` depends on plugin-sharing, so adding runtime as a
dev dependency would create a workspace cycle. An HTTP pin in
plugin-sharing would therefore need new dependencies and a hand-built
door. The card names "plugin-sharing or runtime" as the lane, and
runtime already carries every piece: its full-composition pins
(`unresolved-object-name.actions-door.pin.test.ts`,
`hook-handler-package-scope.pin.test.ts`) use the same boot. So the
suite lives there. It adds no new testkit or helper file.
## Evidence (head a949814)
- `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2
src/sharing-rule-declared-name.data-door.pin.test.ts` gave Test Files 1
passed (1), Tests 4 passed (4).
- `pnpm --filter @objectstack/runtime exec vitest run --project local
--maxWorkers=2` gave Test Files 436 passed (436), Tests 6889 passed | 19
skipped. The lock reported VERDICT command-exit 0.
- `pnpm --filter @objectstack/runtime typecheck` exited 0. The pin is in
the `tsconfig.test.json` program (`--listFilesOnly` count 1) and carries
no ledger entry, so it compiles with zero errors.
- **Ablation, one round, guard disabled.** The runtime suite resolves
`@objectstack/plugin-sharing` through `dist/`, so each leg rebuilt it.
- `node scripts/ablation-replace.mjs` replaced the
`bindDeclaredRuleNameGuard` throw (`if (declared) throw new
DeclaredSharingRuleNameConflictError(...)`) with a marker assignment. On
disk: anchor x1 to x0, blob 26f18e1 to d5199123b3f6.
- `pnpm --filter @objectstack/plugin-sharing build` ran, then
`ablation-dist-preflight.mjs @objectstack/plugin-sharing
__ABLATION_25253` reported the marker present in 2 built files.
- The pin then went **2 failed | 2 passed**. The create case read
`expected 201 to be 409` and the rename case read `expected 200 to be
409`. The precondition and the control stayed green, as predicted.
- Restore: blob back to the HEAD blob 26f18e1, and `git diff HEAD`
was empty. I rebuilt, and `--absent` reported the marker absent from all
6 built files, with the tree clean against HEAD. The pin went back to 4
passed (4).
## Changeset
None. This PR carries `skip-changeset` because it publishes nothing.
`packages/runtime`'s `files[]` is `dist`, `README.md` and
`CHANGELOG.md`. After a runtime build, the pin's own fixture name
`pin_amber_projects_declared` has 0 hits there, and the positive control
`createDispatcherPlugin` has 4 hits in `dist/`.
## Gates
`node scripts/pm/dispatch-gates.mjs --commands` derived 53 families for
this diff. I ran each one under the verify lock and recorded its exit
code. `--ran` reports: 53 accounted for, 52 run (all exit 0), 1 NOT
MEASURED. The NOT MEASURED one is `pnpm check:dual-build-cjs-loads`,
which exited 3 (PREREQUISITE NOT MET) because it reads every package's
`dist/` and this checkout built only runtime's closure. This diff
changes no built output. CI runs it.
## Acceptance notes
- **File wall.** One run of this file reads `Duration 15.6–16.8 s`, of
which `import` is about 14 s and `tests` about 2 s. That is over the 10
s file line, and the cost is the full-composition boot, the same one the
sibling runtime pins pay. I declared no budget line: none of the three
ruled classes fits. This note is for the shard-timings refresh, which
reports and never reds.
- **Envelope dialects.** The sharing-rule route (`POST /sharing/rules`)
answers this refusal in the nested envelope (`error.code`), while the
`/data` door answers it flat (`code`). This is not a defect for this
card. It is the known two-dialect split, recorded here so nobody asserts
the wrong spelling on the wrong door.
---
_Generated by [Claude
Code](https://claude.ai/code/session_016g7nYP9wdNx1GDa5XDr7Uy)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016g7nYP9wdNx1GDa5XDr7Uy
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 49185cd commit a835858
1 file changed
Lines changed: 221 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 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
0 commit comments