Repository navigation
Commit 57675a2
fix(runtime)!: refuse a package uninstall while an active validation rule reads a field it adds (#31227)
domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F
<!-- claude-projects-attribution: {"github_login":"marchtian"} -->
_Requested by **田騏** · [project
thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSiGQNmXXF32wmaXpQFjc6kB9)_
Fixes #30999
Clause-②: yes (narrowing)
Metadata-protocol: none
## 维护者速读
- **改了什么**:卸载包(`DELETE
/api/v1/packages/:id`)现在先问停用门已经在问的同一个检查:如果别的已启用包有生效中的校验规则在读这个包通过
`objectExtensions` 加的字段,就拒绝卸载,返回 409
`PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE`,消息和停用门同一句话,只是开头换成「cannot
be uninstalled」,并列出每条规则(包 · 对象 · 规则)。拒绝时什么都不动。
- **为什么改**:以前卸载会直接撤掉这些字段,读它们的规则随即失效,该对象的每一次写入都报 400
`VALIDATION_FAILED`,而包已经没了,连重新启用这条退路都没有。停用门早就拦这种情况(#30379),卸载门是漏掉的那一个。
- **风险与回滚**:这是一次收窄(BREAKING):以前能卸载成功的请求,现在在有依赖规则时会被 409
拒绝。没有依赖规则的卸载、已停用包的卸载行为不变。没有改错误码台账、spec 或存储形状。回滚就是 revert 这个 PR。
- **先看**:`packages/runtime/src/domains/packages.ts` 的 DELETE 分支新增的那段检查(在
`requireWritablePackage` 之后、`resolveProtocol`
之前);`packages/runtime/src/domains/packages-disable-module-extension-fields.test.ts`
末尾的 `[#30999]`
describe;`.changeset/30999-uninstall-dependent-rule-refusal.md`。
- **两分钟验证**:`pnpm --filter @objectstack/runtime exec vitest run
src/domains/packages-disable-module-extension-fields.test.ts -t
30999`,预期 4 条全绿:卸载被 409 拒绝且什么都没动、拒绝文案的卸载版只改“撤掉/保留安装”两处,以及两条
CONTROL(无依赖的包照常卸载并清掉停用记录,把规则在租户覆盖层关掉后卸载照常通过)。
- **需要你做的**:维护者在 PR 上确认这次收窄(卸载门在有依赖规则时改为拒绝)。席位合同复审 PASS 见 comment
6712022339(Head-sha `ee03285db1ab`),席位核对 ACCEPT 见 comment
6712026943;批准后由席位落地。
-
**席位意见**:可合。拒绝在任何状态变动之前,复用停用门同一个判定和错误码,两门不会漂移;文案已改为“卸载会撤掉…或保留安装”。进程内卸载(`deletePackage`)同样缺这道拒绝,已另立
#31232,不在本 PR。
## What changes
`DELETE /api/v1/packages/:id` withdraws the package's `objectExtensions`
fields from the served objects, exactly as `PATCH /packages/:id/disable`
withholds them, but it never asked the dependent-rule scan the disable
door asks. The door now asks that same verdict,
`readDisableDependentRules` (exported as
`readPackageDisableDependents`), with no second copy, and refuses with
the same wire pair and the same sentence:
- **Where.** Right after the read-only check (`requireWritablePackage`)
and BEFORE `resolveProtocol`, `deletePackage`, the running-registry
withdrawal and the disable-record clear. A refused uninstall moves
nothing: stored rows, registry entry, served fields and the
environment's disable record stay as they were.
- **What it answers.** `409` with `{ error: { code:
'PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE', message } }`, the
message built by `disableDependentRulesMessage` (exported as
`formatPackageDisableDependents`) under the lead `Package 'ID' cannot be
uninstalled`. No `error.details`, as at the disable door.
- **The code stays.** It is ledgered once under `@objectstack/runtime`
(`ERROR_CODE_LEDGER`), and the refused state is the same one the disable
door refuses: a rule left reading a field the fold no longer serves.
Reusing it touches nothing under `packages/spec`.
- **What does not change.** An uninstall no active rule depends on
proceeds exactly as before: the verb is still handed the session user
(#31023) and the disable record is still cleared. A package that is
already disabled withholds its fields already, so its verdict is empty
and its uninstall proceeds.
## Why
The disable door has refused this since #30379: once a field is
withheld, a rule that reads it cannot be evaluated and fails closed, so
every write to its object is refused. The uninstall door withdraws the
same fields and skipped the scan, and after an uninstall there is no
package left to re-enable. Both doors now answer the one verdict.
## Tests
One new top-level describe in the shared dependent-rule harness,
`packages-disable-module-extension-fields.test.ts`, on a real kernel
(ObjectQL on SQLite, MetadataPlugin, the real uninstall verb spied on
and passed through). Two writable packages (installed as authored, so
the door may delete them) each extend the app's object with one field; a
third package's active rule reads the first one's field.
- **Refusal.** `DELETE` of the read package answers `409` with the code,
and the message equals the exported builder over the exported verdict
under the uninstall lead. Nothing moved: `deletePackage` was never
called, the package and its field are still served, the state file is
unchanged, and a write to the object still lands.
- **CONTROL: no dependent.** The second package (its field read by no
rule, while the reader's rule stays active on the same object), disabled
first, uninstalls with `200`; the verb received `{ packageId, actor:
'u_admin' }`, the package left the registry, its field left the served
object, and its disable record was cleared.
- **CONTROL: rule switched off through the tenant overlay.** With the
reader's rule switched off in the app's overlay, the first package
uninstalls with `200`, its field leaves the served object, and a write
to the object lands.
## Acceptance notes
- **Re-measure at branch start (premise holds).** On this rig with the
check removed, `DELETE` answered `200`, the field left the served object
and the package left the registry, and the next write to the object
answered `400 VALIDATION_FAILED`: `Validation rule 'qx_tier_known' could
not be evaluated (runtime: No such key: qx_tier) — write rejected.`
- **Wording.** The uninstall refusal says what the uninstall would do:
"which the uninstall would withdraw" and "or keep the package
installed.", through a new optional third argument of
`formatPackageDisableDependents`, `{ operation: 'disable' | 'uninstall'
}`, default `'disable'`, whose sentence is byte-identical to before
(seat rework 1).
- **Only the HTTP door refuses.** The in-process uninstall verb
(`deletePackage` in `@objectstack/metadata-protocol`) does not ask the
verdict, so an in-process caller can still withdraw a read field. The
claim scoped this card to the door; that question is raised in the
report for the seat.
- **Studio.** The Studio delete dialog shows the thrown `message`, so an
admin sees the refusal sentence naming the rules.
## Verification
<details><summary>Ablation: the check removed, the refusal pin goes
red</summary>
`node scripts/ablation-replace.mjs` replaced the verdict read in the
DELETE arm with an empty list (anchor `1 -> 0`, blob `97f5c5fb5c8b ->
197d54665e7a`), then restored it (blob equals HEAD, `git diff HEAD`
empty). The subject is imported from `src` through a relative path, so
no `dist/` leg applies.
```
× answers 409 with the disable door's code and sentence under an uninstall lead, and nothing moves
AssertionError: expected { status: 200, code: undefined } to deeply equal { status: 409, …(1) }
```
The two CONTROLs also went red, by cascade: the first case's uninstall
had already removed the package they build on.
</details>
<details><summary>Local gates at head 0fc6353</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 62 commands; all 62 exit 0. Two
first exited 3 on prerequisites and were rerun once the prerequisite was
met: `node scripts/check-plugin-teardown-shape.mjs --self-test` (its
pinned fixture commit was outside the shallow clone; fetched that one
commit) and `pnpm check:dual-build-cjs-loads` (needed every package's
`dist/`; ran after a full `pnpm build`).
- `--ran` reconciliation: 62 derived, 62 run, 0 NOT-MEASURED, 0 UNRUN.
- `pnpm --filter @objectstack/runtime test`: 554 files, 8930 passed, 19
skipped.
- `pnpm --filter @objectstack/runtime typecheck`: exit 0.
- `eslint packages/runtime --no-inline-config` (the root `pnpm lint`
over the touched package): exit 0.
- Dogfood battery: see the os-dev-report on #30999.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` is not touched.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (Not touched.)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_017ihL2dtwL9RzJUEskoEex5)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a5e280f commit 57675a2
3 files changed
Lines changed: 201 additions & 5 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 | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
1194 | 1194 | | |
1195 | 1195 | | |
1196 | 1196 | | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
1197 | 1209 | | |
1198 | 1210 | | |
1199 | 1211 | | |
| |||
1232 | 1244 | | |
1233 | 1245 | | |
1234 | 1246 | | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
898 | 898 | | |
899 | 899 | | |
900 | 900 | | |
901 | | - | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
902 | 904 | | |
903 | 905 | | |
904 | 906 | | |
| |||
1193 | 1195 | | |
1194 | 1196 | | |
1195 | 1197 | | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
1196 | 1204 | | |
1197 | | - | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1198 | 1210 | | |
1199 | 1211 | | |
1200 | 1212 | | |
1201 | 1213 | | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
1202 | 1217 | | |
1203 | 1218 | | |
1204 | 1219 | | |
1205 | | - | |
1206 | | - | |
| 1220 | + | |
| 1221 | + | |
1207 | 1222 | | |
1208 | 1223 | | |
1209 | 1224 | | |
| |||
3757 | 3772 | | |
3758 | 3773 | | |
3759 | 3774 | | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
| 3795 | + | |
| 3796 | + | |
| 3797 | + | |
| 3798 | + | |
| 3799 | + | |
| 3800 | + | |
3760 | 3801 | | |
3761 | 3802 | | |
3762 | 3803 | | |
| |||
0 commit comments