Repository navigation
Commit 62f959d
fix(runtime)!: POST /packages refuses an overwrite over a read-only package with 422 WRITABLE_PACKAGE_REQUIRED (#24055)
Fixes #24030
Clause-②: no (narrowing)
## What changed
`POST /api/v1/packages` now asks `requireWritablePackage` (that is,
`isWritablePackage`, the ADR-0070 D2 read-only rule) for the manifest's
id. It asks after the `409 … already exists` check and before either
install limb writes. An overwrite over a package the deployment ships is
refused `422 WRITABLE_PACKAGE_REQUIRED`: booted by code, installed from
the marketplace, or a stored row whose manifest `scope` is `system` /
`cloud`. Disable, publish, revert and delete already give that answer.
The rule is not re-derived at this door.
- `packages/runtime/src/domains/packages.ts`: the guard, one call plus
its comment, on the `POST /packages` install path only.
-
`packages/runtime/src/domains/packages-install-overwrite-readonly.test.ts`:
the pins, 16 cases over both limbs (the `protocol` service's
`installPackage`, and the no-protocol fallback).
- `.changeset/24030-install-overwrite-readonly-package.md`:
`@objectstack/runtime` `minor` under the launch-window convention for a
breaking narrowing, with FROM / TO for an integrator, the `Clause-②`
line, and the ADR-0087 disposition `not-required
(no-migration-prescription)`.
A `CONTRACT_REVIEW_TIER` review is owed before the queue (narrowing);
the seat runs it.
## Answers, path by path
| Request | Before | After |
|---|---|---|
| Overwrite over a read-only id (`overwrite: true` in the body, or
`?overwrite=true`) | `201`, registry row replaced (and `sys_packages`
written on the protocol limb) | `422 WRITABLE_PACKAGE_REQUIRED`, nothing
written |
| Install over an existing id without `overwrite` (read-only or not) |
`409` | `409`, unchanged: the guard sits after it |
| Install of a new id, with or without `overwrite` | `201` | `201` |
| Overwrite of an authored package | `201` | `201` |
## Measured
**Reproduction at base `b74434c58`.** A throwaway probe on the
dispatcher harness (real `ObjectQL` with `registerApp`, real
`ObjectStackProtocolImplementation`), deleted afterwards:
```text
PROBE protocol code: status=201 rowReplaced=true version=2.0.0 source=authored manifests.has=true sys_packages.publish=1
PROBE protocol marketplace: status=201 rowReplaced=true version=2.0.0 source=authored manifests.has=true sys_packages.publish=1
PROBE fallback code: status=201 rowReplaced=true version=2.0.0 source=authored manifests.has=true sys_packages.publish=0
PROBE fallback marketplace: status=201 rowReplaced=true version=2.0.0 source=authored manifests.has=true sys_packages.publish=0
```
The new pin file at base: `8 failed | 8 passed`. Every refusal row is
red with `expected 201 to be 422`; every CONTROL row and the 409 row are
green.
**At head `8dd02793f`:** `16 passed (16)`.
**Ablation**, on the committed fix. `scripts/ablation-replace.mjs`
replaced the guard call with `null`: anchor 1 to 0, marker 0 to 1, blob
`b0bb67c44296` to `4e5996f62b61`. The test reaches `packages.ts` by
relative import, so no rebuild was needed. Result: `8 failed | 8
passed`. The 8 refusal rows went red; the 6 CONTROL rows and the two 409
rows stayed green. Restore: blob equals HEAD `b0bb67c44296`, and `git
diff HEAD` is empty.
## The dispatch's mechanism assumptions
1. **Reproduction:** reproduced on both limbs (above). The protocol limb
also wrote the `sys_packages` row: the `package` service's `publish` was
called once.
2. **Unknown id:** `isWritablePackage` answers writable for an id
nothing installed. An install of a new id with `overwrite: true` answers
`201`, pinned on both limbs. So the guard runs on every path that
reaches a write without refusing a fresh install.
3. **409 ordering:** the guard sits after the 409. A non-overwrite
install over a read-only id keeps its `409` (pinned on both limbs); an
overwrite gets the `422`.
4. **Who sends `overwrite`:** no first-party caller does.
- `packages/client` exposes `packages.install(m, { overwrite })`; only
its own tests send it.
- The CLI has no caller of this door.
- objectui at the `.objectui-sha` pin `f8267df93` sends no `overwrite`:
`git grep` for `overwrite: true` / `overwrite=true` finds 0 hits. Its
package create posts `{ manifest }` and expects the 409 on a duplicate.
- No legitimate use was found that this narrowing breaks.
## Tests and gates (local, at `8dd02793f`)
- `turbo run build --filter='@objectstack/runtime...' --concurrency=2`:
31 of 31 tasks successful, verify-lock `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/runtime typecheck`: exit 0, with
`check:test-typecheck: OK`. The new test file is in the
`tsconfig.test.json` program (`--listFiles` count 1) and has no tsc
error.
- `pnpm --filter @objectstack/runtime exec vitest run --project local
--maxWorkers=2`: `405 passed (405)` files, `6157 passed | 19 skipped`
tests, exit 0.
- `pnpm exec eslint --no-inline-config` on the two changed `.ts` files:
exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands` (64 families, from
merge base `b74434c58`): 62 exit 0. The other 2 are NOT MEASURED, each
exit 3 (`PREREQUISITE NOT MET`):
- `check:dual-build-cjs-loads` needs every package's `dist/`, and only
the runtime closure was built locally.
- `check:type-check-debt`: its closure build never acquired the shared
verify lock (queue-timeout).
- `--ran` reconciliation: 64 accounted, 0 UNRUN.
- `Lint & Repo Gates` (the repo-wide eslint run), `TypeScript Type
Check`, `Test Core` and `Build Core`: CI on this PR. `test:repo` was not
run locally; CI owns it.
## Acceptance notes
- **Finding, class (a):** an authored package can declare a
deployment-shipped scope and so lock itself.
- `POST /api/v1/packages` with `manifest.scope: 'cloud'` (or `'system'`)
answers `201` and stores an `authored` row. `isWritablePackage` judges
that row read-only, so `DELETE` and `PATCH …/disable` then answer `422
WRITABLE_PACKAGE_REQUIRED`.
- Before this PR, an overwrite with `scope: 'project'` was the one API
exit. After it, that overwrite is refused too, as the card's Done-when
requires for the scope arm.
- Measured at head with a throwaway probe, since deleted: `create=201
source=authored storedScope=cloud delete=422 disable=422
overwriteToProject=422`.
- Handed to the seat for filing and not fixed here. This door does not
refuse a key that the declaration (`ManifestSchema.scope`) admits, so
the remedy is a contract decision.
- The spec's `overwrite` description ("Overwrite an already-installed
package id instead of answering 409 Conflict") does not mention the
read-only refusal. This is a note on the doc surface only.
- `origin/main` was not merged before opening. Main has gained two
commits since the base (`c4111c676`, `d731b89a6`); they touch no file in
`packages/runtime`, `packages/metadata-protocol` or `packages/objectql`.
CI runs on the merge ref.
---
_Generated by [Claude
Code](https://claude.ai/code/session_018t6a5rvqPRvEDMCVVW9kYT)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent a33f3d5 commit 62f959d
3 files changed
Lines changed: 296 additions & 0 deletions
File tree
- .changeset
- packages/runtime/src/domains
| 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 | + | |
| 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 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1381 | 1381 | | |
1382 | 1382 | | |
1383 | 1383 | | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
1384 | 1401 | | |
1385 | 1402 | | |
1386 | 1403 | | |
| |||
0 commit comments