Repository navigation
fix(runtime)!: refuse a package uninstall while an active validation rule reads a field it adds - #31227
Conversation
…a field it adds DELETE /packages/:id withdraws the package's objectExtensions fields from the served object just as a disable withholds them, but it asked no dependent-rule scan, so another package's active validation rule that read one of those fields then refused every write to its object. The door now asks the disable door's verdict (readDisableDependentRules) before any state moves and answers its refusal: 409 PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE with the sentence disableDependentRulesMessage spells under an uninstall lead. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dtwL9RzJUEskoEex5
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dtwL9RzJUEskoEex5
📓 Docs Drift CheckThis PR changes 1 package(s): 30 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 8 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 28 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 9aecbf7e50bf70a3aeffac02e93510de6fd2bb40 && git checkout 9aecbf7e50bf70a3aeffac02e93510de6fd2bb40
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 065bba721e4ba180c6bdbbf2c5fb787d49bac596 ee03285db1abf7ad9ed6bfe924aeb933e2a44a47 && git checkout -B drift-repro 065bba721e4ba180c6bdbbf2c5fb787d49bac596 && git merge --no-ff ee03285db1abf7ad9ed6bfe924aeb933e2a44a47
node scripts/docs-audit/affected-docs.mjs --json 065bba721e4ba180c6bdbbf2c5fb787d49bac596
|
…efusal The uninstall door answered the disable door's sentence verbatim, so under its uninstall lead it said the fields were ones the disable would withhold and told the caller to keep the package enabled, which does not stop an uninstall. The sentence builder takes an optional operation; its uninstall form says the uninstall would withdraw the fields and to keep the package installed. The default form is byte-identical to the disable door's. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dtwL9RzJUEskoEex5
|
domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F 席位核对 — ACCEPT · domain:server#4 · Head-sha:
|
domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F
Requested by 田騏 · project thread
Fixes #30999
Clause-②: yes (narrowing)
Metadata-protocol: none
维护者速读
DELETE /api/v1/packages/:id)现在先问停用门已经在问的同一个检查:如果别的已启用包有生效中的校验规则在读这个包通过objectExtensions加的字段,就拒绝卸载,返回 409PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE,消息和停用门同一句话,只是开头换成「cannot be uninstalled」,并列出每条规则(包 · 对象 · 规则)。拒绝时什么都不动。VALIDATION_FAILED,而包已经没了,连重新启用这条退路都没有。停用门早就拦这种情况([Decision] A package can be disabled while an enabled package's validation rule reads one of its extension fields, and then every write to that object is refused #30379),卸载门是漏掉的那一个。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(无依赖的包照常卸载并清掉停用记录,把规则在租户覆盖层关掉后卸载照常通过)。ee03285db1ab),席位核对 ACCEPT 见 comment 6712026943;批准后由席位落地。deletePackage)同样缺这道拒绝,已另立 packages: the in-process uninstall verb (deletePackage) withdraws extension fields a dependent active validation rule reads, with no refusal — only the HTTP door asks #31232,不在本 PR。What changes
DELETE /api/v1/packages/:idwithdraws the package'sobjectExtensionsfields from the served objects, exactly asPATCH /packages/:id/disablewithholds them, but it never asked the dependent-rule scan the disable door asks. The door now asks that same verdict,readDisableDependentRules(exported asreadPackageDisableDependents), with no second copy, and refuses with the same wire pair and the same sentence:requireWritablePackage) and BEFOREresolveProtocol,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.409with{ error: { code: 'PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE', message } }, the message built bydisableDependentRulesMessage(exported asformatPackageDisableDependents) under the leadPackage 'ID' cannot be uninstalled. Noerror.details, as at the disable door.@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 underpackages/spec.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.DELETEof the read package answers409with the code, and the message equals the exported builder over the exported verdict under the uninstall lead. Nothing moved:deletePackagewas never called, the package and its field are still served, the state file is unchanged, and a write to the object still lands.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.200, its field leaves the served object, and a write to the object lands.Acceptance notes
DELETEanswered200, the field left the served object and the package left the registry, and the next write to the object answered400 VALIDATION_FAILED:Validation rule 'qx_tier_known' could not be evaluated (runtime: No such key: qx_tier) — write rejected.formatPackageDisableDependents,{ operation: 'disable' | 'uninstall' }, default'disable', whose sentence is byte-identical to before (seat rework 1).deletePackagein@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.message, so an admin sees the refusal sentence naming the rules.Verification
Ablation: the check removed, the refusal pin goes red
node scripts/ablation-replace.mjsreplaced the verdict read in the DELETE arm with an empty list (anchor1 -> 0, blob97f5c5fb5c8b -> 197d54665e7a), then restored it (blob equals HEAD,git diff HEADempty). The subject is imported fromsrcthrough a relative path, so nodist/leg applies.The two CONTROLs also went red, by cascade: the first case's uninstall had already removed the package they build on.
Local gates at head 0fc6353
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 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) andpnpm check:dual-build-cjs-loads(needed every package'sdist/; ran after a fullpnpm build).--ranreconciliation: 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 rootpnpm lintover the touched package): exit 0.Human Minimum
packages/specholds no runtime logic. (packages/specis not touched.)pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (Not touched.)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code
🤖 Generated with Claude Code