Repository navigation
Commit a32d50b
test(runtime): the protocol uninstall door leaves no handler of the package it uninstalls bound (#33844)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbTGhxJSYAmQXU7efVdNqrpw)_
Fixes #33624
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:只加一个测试文件,钉住"协议卸载门 `DELETE /api/v1/packages/ID` 卸载后,该包的脚本动作和
body hook 不再在引擎上运行"。没有改任何运行时代码。
- **为什么改**:卡片怀疑这扇门不调用
`unbindAppArtifactHandlers`,处理器会挂到重启。实测证伪:这扇门能卸的包(经 `POST /packages`
创作的包)的处理器挂在 `metadata-service` 名下,卸载时由重载同步撤掉;由运行时绑定器以 `app:ID`
绑定的包(install-local 安装或代码包)会被这扇门以 422 只读拒绝,根本卸不掉。所以方案 A 不需要,卡片随本测试关闭。
- **风险与回滚**:零运行时风险,只新增测试;回滚即删除该测试文件。
-
**先看**:`packages/runtime/src/domains/packages-uninstall-handlers-withdrawn.test.ts`(两个用例:创作包卸载后动作
404、hook 不再触发、对照包仍运行;绑定器包被 422 拒绝、处理器随包保留)。
- **两分钟验证**:`pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2
src/domains/packages-uninstall-handlers-withdrawn.test.ts`,预期 2 passed。
- **需要你做的**:无,席位落地。
## What changes
One test file, no runtime code. It answers the card's Step 1 (measure)
on a real kernel, through the dispatcher's routes, and pins the answer:
**the premise does not reproduce**, so the card closes with this
measurement (the card's own rule: "If it does not reproduce, close this
card with the measurement"). Fix A (a `runtime.package-handlers`
uninstall cleanup) is not taken; no uninstall response's `cleanups` list
changes.
### The measurement (origin/main d7e1a5a, this branch adds only the
pin)
Composition: `ObjectKernel` + SQL driver (better-sqlite3 in memory) +
the real `ObjectQLPlugin` (engine, registry, protocol, authored resync)
+ the runtime `AppPlugin` (default action runner) +
`HttpDispatcher.dispatch` for every call.
1. **A package this door can uninstall** is a writable base: installed
with `POST /api/v1/packages`, its script action and body hook saved
under it with `PUT /api/v1/meta/action|hook/NAME?package=ID`. Their
handlers are bound under the environment's authored owner
`metadata-service`, never under `app:ID`. After `DELETE
/api/v1/packages/ID` answers `200` (`registryRemoved: true`, the action
and hook rows in `persisted.deleted`):
- the engine lists no holder of the action key (`[]`, was
`['metadata-service']`);
- `POST /api/v1/actions/OBJECT/NAME/RID` answers `404
RESOURCE_NOT_FOUND` and the body did not run;
- a `POST /api/v1/data/OBJECT` write carries only the CONTROL package's
stamp (`|q`, was `|p|q`);
- CONTROL: another authored package's action and hook still run.
2. **A package the runtime binder bound under `app:ID`**, registered
through the `manifest` service with `source: 'marketplace'` and bound by
`bindAppArtifactHandlers` with install-local's own options (what
`MarketplaceInstallLocalPlugin`'s install does): the door answers `422
WRITABLE_PACKAGE_REQUIRED` before anything moves (`isWritablePackage` is
false for any id in the engine's `manifests`; a code boot lands there
too). The package stays installed, so its handler and hook stay bound
and run, which is correct; its own door (`DELETE
/api/v1/marketplace/install-local/ID`) unbinds them. So the binder's
owners never reach this door.
### What withdraws the authored handlers (the area's question about the
`metadata:reloaded` announcement from #33546)
Two paths each withdraw them before the door answers; either one is
enough on its own:
- the announcement `DELETE` makes (`announcePackageReload(…,
'uninstalled')`, `packages.ts`), whose `metadata:reloaded` subscriber in
`ObjectQLPlugin` runs `resyncAuthoredHooks` + `resyncAuthoredActions` (a
full teardown and rebind of the `metadata-service` set from the stored
rows);
- the protocol's per-row delete events (`onMetadataMutation`, `state:
'deleted'`), which run the same resyncs, fire-and-forget.
The announcement is the one the door awaits, so it is what makes the
answer deterministic (see Acceptance notes).
### H2 (shared cleanup registry)
It exists and both doors walk it: `deletePackage` runs
`runUninstallCleanups` at
`packages/metadata-protocol/src/protocol-package-uninstall.ts:385`;
install-local's door runs it through `protocol.runUninstallCleanups`
(`packages/cloud-connection/src/marketplace-install-local-plugin.ts:3718`
→ `:4107`). The runtime registers `runtime.package-jobs`
(`app-artifact-handlers.ts:2453`), `runtime.package-state` and
`runtime.package-datasources` there. No `runtime.package-handlers`
exists, and with the measurement above none is needed.
## Tests
- New:
`packages/runtime/src/domains/packages-uninstall-handlers-withdrawn.test.ts`,
2 cases, green.
- CONTROL through the install-local door:
`packages/cloud-connection/src/marketplace-install-local-uninstall-handlers.test.ts`
(the real route handler on a real kernel) 6/6 green on this tree: its
uninstall leaves no handler under `app:ID`.
### Ablations (one-time, not kept)
Each leg mutated on disk through `scripts/ablation-replace.mjs`,
objectql legs rebuilt and proved in `dist/` with
`scripts/ablation-dist-preflight.mjs`, restored (`git status
--porcelain` empty, `--absent` on the rebuilt `dist/`):
| Leg | Mutation | Result |
|:--|:--|:--|
| 1 | no uninstall announcement (packages.ts) | green: the delete-event
resync still withdraws them |
| 2 | no resync on `state: 'deleted'` mutation events (objectql
plugin.ts) | green: the announcement alone withdraws them |
| 3 | legs 1 + 2 together | **red**: `no handler is left under the
uninstalled package's action: expected [ 'metadata-service' ] to deeply
equal []` |
| 4 | no read-only refusal on `DELETE` (packages.ts) | **red**:
`expected [ 200, undefined ] to deeply equal [ 422,
'WRITABLE_PACKAGE_REQUIRED' ]` |
## Acceptance notes
- With the announcement ablated the case stays green only because the
fire-and-forget delete-event resync finishes before the door answers on
this in-memory store; the announcement is the awaited, deterministic
path. Not a defect on main (both paths are present), noted for whoever
ever touches either.
- Leg 4 shows the one shape where fix A would matter: were the read-only
refusal ever lifted for a registered manifest, the door would answer
`200` for a package whose handlers the binder holds under `app:ID`.
Today that shape is unreachable (ADR-0070 refusal), so nothing is filed.
## Verification
Local readings: see the os-dev-report comment on #33624 for the gate
list with exit codes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 2dd0e06 commit a32d50b
1 file changed
Lines changed: 237 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 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
0 commit comments