Repository navigation
Commit 9a3a500
fix(verify)!: run a managed mongodb datasource on verify's in-memory stand-in, refuse a managed plugin-driver datasource (#36171)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X1qGnTYLQs3EtmtCmjrcfCe)_
Fixes #35640
Ruling-ref: 7065449898
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill teaches which datasources `os
verify` stands in or refuses; the rule ships in the
`@objectstack/verify` README (updated here), which
`skills/objectstack-project` already points readers to
## 维护者速读
- 开发者或 AI
跑应用自检时:文档型数据库的数据源以前会连真实库,现在换成内存库照常验证;插件驱动的托管数据源以前会改写真实库,现在自检直接拒绝启动并点名该数据源;插件用同名注册自己的驱动顶替托管数据源时,自检同样拒绝启动。
- 属于"应用自检只碰自己建的库"这条规则的收尾,替声明了文档型数据库或插件驱动数据源的应用作者解决自检改写真实库、事后无法恢复的问题。
- 只有声明了插件驱动托管数据源的应用会碰到:自检从能跑变为拒绝启动;目前仓库内与姊妹仓都没有这样的应用;本改动可以直接撤回。
- 要你做什么:这次改动让一类原来能跑的自检改为拒绝启动(收紧),按规则需要你本人批准后才能合并。
## What changes
Ruled on the card (maintainer, 「C+A 能换内存库就换,否则拒绝」, decision record
7065449898): verify writes only to stores it creates, for every engine
the platform ships; a managed datasource on a plugin's driver id refuses
the boot; no switch.
- `packages/verify/src/managed-datasource-stand-in.ts`:
`managedStandInEngine` now answers for every driver id the platform
ships (`resolveDriverId` from `@objectstack/spec`, the same table the
default driver factory's `supports()` reads): `memory` gets a fresh
memory store, every other shipped engine, `mongodb` included, gets the
default store's engine. The "shipped engine with no faithful stand-in
keeps its real driver" branch is gone, and so is `hasManagedStandIn`.
New `unstandableManagedDatasources(config)` lists every declared managed
datasource (not `default`) on a driver id the platform does not ship,
judged on the same `isManagedDatasource` reader the factory and derive
use; `unstandableManagedDatasourceRefusal` is the sentence. The factory
itself refuses such a spec instead of handing it to the real factory
(unreachable from the connection service, whose `supports()` gate
already turns it away; defence for direct callers).
- `packages/verify/src/harness.ts`: `bootStack` refuses before it
composes anything (first statement of the boot, before any env change or
kernel) while such a datasource is declared, naming each datasource and
driver id and why. `os verify` already prints a boot error and exits 1
(`packages/cli/src/commands/verify.ts` run-level catch), so no CLI
change.
- `packages/verify/src/derive.ts`: the "managed, no stand-in, withheld"
branch and its report sentence are removed; objects on a managed
`mongodb` datasource enter every derived family.
- `packages/verify/src/managed-datasource-stand-in.ts` + `harness.ts`
(rework round 1, contract review 7067086844 S1): the connection service
keeps any driver already registered under a datasource's NAME, whatever
driver id it declares, so a plugin registering `driver.NAME` under a
managed datasource that declares a shipped id (`mongodb`, `postgres`, …)
bypassed both the stand-in and the refusal. New
`createManagedDatasourceDriverGuard(config)`: `bootClaimed` mounts it as
the FIRST plugin whenever a managed datasource other than `default` is
declared; its `start()` runs after every plugin's `init` (where plugin
drivers register) and before any plugin's `start` (where ObjectQL adopts
`driver.*`, syncs schemas, and the app connects and seeds), and refuses
the boot when a `driver.NAME` service or an engine driver is held under
a managed datasource's name, naming the datasource and its declared
driver id. Rework round 2 (contract review 7068014028, S2 + N4): the
guard now also matches each `driver.*` service by the driver instance's
own `name` (the key the engine registers it under), and after its
start-time check it wraps `registerDriver` on the engine instance, the
engine's only way to put a driver under a name, so a driver registered
later (ObjectQL's `driver.*` adoption, an `objectql:drivers-ready`
handler, a later plugin) under a managed datasource's name that verify's
factory did not build for it is refused before the engine holds it; the
identity check reads a per-name ledger the verify factory fills with the
exact instance it returns. `bootStack` rethrows the guard's own sentence
with the kernel error as cause (N4). Rework round 3 (contract review
7069009856, S3 + N6–N8): the wrap forwards to the engine's own
`registerDriver` when the engine already holds verify's stand-in under
that name (the engine keeps the stand-in and discards the newcomer
without calling it), so a late registration from an app plugin's
`start()` or the `runtime.onEnable` bridge boots on the stand-in instead
of being refused; a refusal a plugin catches still refuses the boot
after `bootstrap()` returns, and a boot that failed for another reason
keeps the kernel's own error (the guard's sentence only when the guard's
own refusal is in the cause chain). Not covered, stated in the jsdoc: a
plugin that replaces the `objectql` service, takes the guard's plugin
name, calls the prototype's `registerDriver`, deletes or overwrites the
own property, or a driver whose `name` answers differently on each read.
No key, flag, boot option or package export added. The driver-id refusal
now says the datasource names no driver id the platform ships ("a
plugin's driver, or a misspelling") and prints a missing driver as `(no
driver declared)` (N1).
- Text: the `harness.ts` and stand-in headers,
`packages/verify/README.md` (Posture), the `os verify` section of
`content/docs/deployment/cli.mdx`, and one changeset
`.changeset/35640-verify-memory-stand-in.md` (patch, `!`, BREAKING
section with FROM/TO/fix for both refusals, ADR-0087 disposition
`not-required (no-migration-prescription)`).
Read first (by risk):
1. `packages/verify/src/managed-datasource-stand-in.ts` — the
`managedStandInEngine` body and `unstandableManagedDatasources`: the
"shipped" set and the managed reader both refusal and factory decide on.
2. `packages/verify/src/harness.ts` — the two lines at the top of
`bootClaimed`: the refusal must precede every side effect; and the guard
mounted before `ObjectQLPlugin`.
`createManagedDatasourceDriverGuard` in the stand-in file: its `start()`
check sees every `init`-time registration, and its `registerDriver` wrap
with the factory ledger must catch every later one before the first
write (ObjectQL `start()`: adoption, `ql.init()`, `drivers-ready`, then
the first schema sync).
3. `packages/verify/src/verify.managed-datasource-stand-in.test.ts` —
the mongodb recording medium (a TCP listener counting connections) and
the refusal pin with its control.
Two-minute check: `pnpm --filter @objectstack/verify exec vitest run
--maxWorkers=2 src/verify.managed-datasource-stand-in.test.ts` → `Tests
32 passed (32)`, including `nothing reached the real mongodb address: no
connection was ever made to it` and `the boot is refused, naming the
datasource and the driver id, and the recording driver is never called`.
## Tests
The card's Done-when, pinned in
`verify.managed-datasource-stand-in.test.ts` (the component's shared
harness file, extended rather than a new file, one boot):
- Boot pin, `mongodb`: the fixture declares a managed secondary
`mongodb` datasource pointed at a local TCP listener that counts
connections (the recording medium), seeds two rows on its object, and
has an async `afterInsert` hook on another object writing into it. After
CRUD, reference shapes, delete behaviours, unique scopes and a REST
create: 0 connections to the listener; the object's CRUD case
`verified`; both seed rows and the hook rows present in the stand-in
(read back through REST); no hook error. CONTROL: the factory `os dev`
uses (`createDefaultDatasourceDriverFactory`) connects to that listener
for the same declaration.
- Refusal pin, plugin driver id: a fixture declaring a managed
datasource on a plugin's driver id, with a recording driver plugin and a
seed: `bootStack` rejects with a sentence naming `datasource
"vms_plug_ds" (driver "vms_plug_driver")`, and the recording driver's
plugin never initialised, so no call reached it. CONTROL: in the boot
above, the same recording plugin behind an EXTERNAL datasource (not
refused) initialises and takes the REST create.
- Refusal pin, name-keyed (round 1): a recording driver plugin registers
`driver.vmd_docs_ds` under a managed datasource declaring `mongodb`,
with a seed on its object: `bootStack` rejects naming `datasource
"vmd_docs_ds" (driver "mongodb")` and "registered a driver of its own";
the driver's recorded calls are exactly `[plugin.init]` (no connect, no
schema sync, no seed write). Unit pin: a missing driver reads
`datasource "a" (no driver declared)`.
- Refusal pins, round 2: a driver registered as `driver.vmk_elsewhere`
whose instance is named after the managed datasource, and a driver
registered on the engine from an `objectql:drivers-ready` handler for an
object-bound managed datasource. Both booted on a81e777 (recorded
calls ran through connect/syncSchema/seed `bulkCreate`/`updateMany`); at
26abb3e both are refused with the bare `verify: refusing to boot:`
sentence and the driver's calls are `[plugin.init]` / `[plugin.init,
drivers-ready]`. Ledger unit pin; the mongodb/SQL main boot is the
no-false-refusal control.
- Pins, round 3 (red on 26abb3e: `4 failed | 28 passed (32)`): a late
registration from an app plugin's `start()` and from the
`runtime.onEnable` bridge now BOOT on the stand-in (GET returns the
seed, a REST POST answers 201 and lands in the stand-in; the foreign
driver's calls are `[plugin.init, plugin.start]` / `[onEnable]`, no
connect, sync or write); a `drivers-ready` handler that catches the
refusal is still refused with the bare sentence; a caught refusal
followed by the plugin's own start failure reports that failure, not the
guard's sentence.
- Unit pins: the factory builds `mongodb`, `turso` and `pg` as the
default store's engine with nothing of the declared config, `mongodb` on
a `memory` default store as a fresh memory store, and refuses a plugin
driver id without asking the real factory; the refusal reader names
managed plugin-driver datasources with or without a declared
`schemaMode`, reads a name-keyed map, and (control) refuses no shipped
engine, no external or validate-only plugin datasource and not
`default`; `derive.test.ts` now pins that objects on managed `postgres`,
`mongodb` and plugin-driver datasources (and a required reference to the
mongodb one) are derived, not blocked.
Reverse verification (each mutation landed and restored by
`scripts/ablation-replace.mjs` or `git restore --source`, blob == HEAD
and `git diff HEAD` empty after each; the tests import the changed files
from `src/`, no `dist/` in the path):
<details><summary>Readings</summary>
- Base implementation (`3543b51d` versions of the three source files,
new tests): the boot reaches the real mongodb address and fails fast
(`datasource 'vms_docs_ds': connect failed — connection monitor to
127.0.0.1:32885 closed`); `Tests 8 failed | 7 passed | 8 skipped (23)`.
The decision thread's probe re-run on base `3543b51d`:
`connectionsToRealMongoAddress: 10`.
- `mongodb` mapped to no stand-in again: the refusal (same reader)
refuses the mongodb fixture; `Tests 3 failed | 12 passed | 8 skipped
(23)`, VERDICT command-exit 1.
- Refusal line deleted from `bootClaimed`: `× the boot is refused,
naming the datasource and the driver id, and the recording driver is
never called` — `expected undefined to be an instance of Error` (the
boot succeeded on the plugin's driver); `Tests 1 failed | 22 passed
(23)`.
- Name-keyed guard's throw deleted (round 1, head a81e777): `× the
boot is refused, naming the datasource and its declared driver id, and
the plugin driver receives no call` — `expected undefined to be an
instance of Error` (the boot ran on the plugin's driver); `Tests 1
failed | 24 passed (25)`; restored blob == HEAD.
- Round 2 (head 26abb3e): own-name leg dropped ⇒ `1 failed | 27
passed` (the other-key pin is still refused, by the wrap, but not by the
guard's start); `registerDriver` wrap removed ⇒ the drivers-ready pin
boots, `1 failed | 27 passed`; N4 rethrow deleted ⇒ `3 failed | 25
passed`. Each restored to the HEAD blob.
- Round 3 (head 205d953): S3 forward condition forced off ⇒ the two
late-registration pins red, `2 failed | 30 passed`; post-return refusal
disabled ⇒ the caught-refusal pin boots, `1 failed | 31 passed`;
identity check replaced by reading `refusal` alone ⇒ the own-failure pin
red, `1 failed | 31 passed`. Each restored to the HEAD blob.
- derive withholding mongodb objects again: `× exercises objects on
managed datasources of every shipped engine, mongodb included` —
`doc_task: expected 'withheld' to be falsy`; `Tests 1 failed | 32 passed
(33)`.
</details>
<details><summary>Package runs</summary>
- `pnpm --filter @objectstack/verify test`: `Test Files 55 passed (55)`,
`Tests 500 passed (500)` (head 205d953).
- `pnpm --filter @objectstack/verify typecheck`: `tsc --noEmit` clean;
`check:test-typecheck: OK — 0 file(s) / 0 error(s)`.
</details>
## Acceptance notes
- Premise P2 of the ruling, checked on `origin/main` 3543b51 before any
code: a plugin driver is constructed by its plugin and registered as a
`driver.NAME` service in the plugin's `init`
(`packages/drivers/driver-odata/src/plugin.ts:201`); `ObjectQLPlugin`
adopts every `driver.*` service
(`packages/objectql/src/plugin.ts:1524`); the connection service then
answers `already-registered` and never reaches the factory
(`packages/services/service-datasource/src/datasource-connection-service.ts:607-613`),
and for an unregistered plugin id its `factory.supports()` gate answers
`skipped-unsupported` (`:693`); `supports()` is `resolveDriverId(id) !==
undefined` (`default-datasource-driver-factory.ts:1131`). No single swap
point exists: the instance is the plugin's (the connection service
deliberately never evicts it).
- "Shipped" = `resolveDriverId` / `BUILTIN_DRIVER_IDS` in
`@objectstack/spec`
(`packages/spec/src/data/driver/config-registry.zod.ts`), which that
file states is exactly what the default factory builds. It includes the
federation-only `oracle` and `mssql`, which a managed datasource cannot
name at authoring; were one to reach verify anyway it would be stood in,
never connected.
- Two unreleased changesets on `main`
(`.changeset/verify-managed-datasource-stand-in.md`,
`.changeset/35640-verify-real-store-wording.md`) still describe
`mongodb` and plugin drivers keeping their real driver. They are outside
this claim's file surface, so they are not edited; the new changeset
says it supersedes them for this release.
- Not changed, as ruled: external datasources, a report line saying an
object ran on a stand-in, and the mongodb driver's own disagreements
with the stand-in.
## Verification
Local gates, the derived set (`dispatch-gates.mjs --commands`), run one
by one with each exit captured before any pipe; the readings are in the
reports on the card (round 3: #35640 comment 7069764734, 105 derived,
102 exit 0, 3 prerequisite-not-met left to CI). Full dogfood battery on
205d953: `Tests 4101 passed | 68 skipped (4169)`, no failures. CI owns
the full farm.
Session: session_01FEkQ5kt9AD1TPLy7Y9oa9D
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#4 · os-project-manager ·
session_01FEkQ5krBqrrgxCYgjXmfbv -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6c7c6db commit 9a3a500
8 files changed
Lines changed: 1088 additions & 117 deletions
File tree
- .changeset
- content/docs/deployment
- packages/verify
- src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3067 | 3067 | | |
3068 | 3068 | | |
3069 | 3069 | | |
3070 | | - | |
3071 | | - | |
3072 | | - | |
3073 | | - | |
3074 | | - | |
3075 | | - | |
3076 | | - | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
3077 | 3080 | | |
3078 | 3081 | | |
3079 | 3082 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
151 | 149 | | |
152 | 150 | | |
153 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | 213 | | |
217 | 214 | | |
218 | 215 | | |
| |||
272 | 269 | | |
273 | 270 | | |
274 | 271 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
289 | 277 | | |
290 | 278 | | |
291 | 279 | | |
| |||
0 commit comments