Repository navigation
Commit 8925d5b
fix(metadata-protocol): a seed resolves a lookup another package adds through objectExtensions to the target's id (#36272)
Fixes #35254
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:应用作者在模块里给别的包的对象加的关联字段,演示数据现在能正确连上目标记录;以前在本地开发和正式部署启动时,这类字段里存的是目标的名称文字,记录页上显示“受限记录”。
- 为什么做:模块扩展对象是垂直模块的标准做法,两个下游应用的演示数据因此连错,其中一个连带算错了客户评级和订单利润判断。
-
出错会怎样:只影响种子数据读取对象定义的方式;万一有问题,表现为某个演示数据的关联没连上或启动日志报出无法解析的引用,撤回本次改动即恢复原样。以前已存成文字的记录不会被自动改写,重新跑一次种子数据即可修正。
- 要你做什么:无
## What changes
`SeedLoaderService.resolveObjectDefinition`
(`packages/metadata-protocol/src/seed-loader.ts`) is the one place the
seed loader reads an object definition. Every per-field decision of a
load goes through it: the reference graph, natural-key resolution,
required-on-insert, the tenant column, the roll-up strip, the replay
comparands and the undeclared-column warning.
- **Before:** it took the metadata service's copy whenever that copy had
`fields`, and fell back to the engine's schema only when the metadata
service had none. A boot that loads a compiled artifact (`os dev`, `os
serve`, the cloud runtime) gives the metadata service each object as its
own package wrote it. The fields another package adds through
`objectExtensions` (ADR-0130 D5) live only in the ObjectQL registry's
fold. So a lookup that an extension adds was never a reference. It had
no graph edge, and its natural key was written verbatim into the
foreign-key column.
- **After:** it reads the engine's registered schema first. That is the
object as served, with extensions folded in. It falls back to the
metadata service's copy only when the engine has no schema for the name,
or exposes no schema registry (`IDataEngine` does not require one). The
loader merges no extension itself: the registry's fold is the one
source. The marketplace case the old fallback existed for (an object
only the engine registry knows) is still served: it is now found on the
first read.
- The #35655 roll-up strip (PR #36118) used to take the union of the
resolved definition and `engineSchemaOf`. The resolved definition now IS
the engine's schema whenever the engine has one, so the union collapses
to `summaryFieldNames(objectDefinition)`. Its pins are unchanged and
green.
- Docblocks that named the old order are corrected:
`resolveObjectDefinition`, `seedReferenceGraphFields`,
`declaresNameColumn`, and the #35655 extension pin's header in
`seed-loader-summary-stale.test.ts`.
- `.changeset/35254-seed-extension-lookup.md`:
`@objectstack/metadata-protocol` patch.
The in-process boot (`@objectstack/verify` without an artifact) bridges
the metadata service from the folded registry, so the metadata copy and
the engine copy already agreed there. This change makes the artifact
boot read what that boot already read.
## Tests
New pins in
`packages/metadata-protocol/src/seed-loader-engine-schema-fallback.test.ts`,
as a top-level `describe('[#35254] …')` on that file's engine double,
which is already pinned. The metadata double serves the authored
`ext_order` without `quote_ref`. The engine double's `getSchema` serves
the folded object with `quote_ref → ext_quote`. Every case has a
CONTROL: `account_ref`, a lookup the owner authored on the same object.
- `upsert` and `ignore` (the inserting modes; `insert` itself is a
retired `SeedMode`): `quote_ref` stores the quote's id. `insertOrder`
puts `ext_quote` (and `ext_account`) before `ext_order`. The `ext_order`
node's `dependsOn` is `[ext_account, ext_quote]`, and its references
include `quote_ref->ext_quote` beside `account_ref->ext_account`.
- `update`: the existing order row gets the quote's id and the account's
id, and no second order is inserted.
- A cycle (`ext_quote.order_ref` back to the order): the cycle is
detected, one side waits for pass 2, and both links resolve. The pass-2
writes and the `insertOrder` are identical to the CONTROL, where
`quote_ref` is authored.
- An unknown natural key: both the extension lookup and the authored
lookup are refused the same way (one errored record, the same error with
the field and target names normalised, no raw key stored), and the
extension's error names `ext_order.quote_ref`.
- `falls back to the metadata service definition when the engine has no
schema for the object` (renamed from `prefers the metadata service
definition …`): the engine is asked first for every seeded object, and
the metadata service is read for each.
<details>
<summary>Premise on the real boot path: os dev on a two-package
artifact</summary>
A fixture of the card's shape, not committed: app package `qx_app` owns
`qx_account` and `qx_order` (with the authored `account_ref`). Module
`qx_mod` (built with `artifactObjects`) owns `qx_quote`, adds
`quote_ref` (→ `qx_quote`) to `qx_order`, seeds `O-1` in `update` mode
and inserts `O-2` in `upsert` mode, both with `quote_ref` by the quote's
name. The `os dev --fresh` boot came from this branch's CLI closure
build, and the rows were read with `GET /api/v1/data/qx_order` as the
seeded dev admin.
| leg | `O-1.quote_ref` (update) | `O-2.quote_ref` (upsert) |
`account_ref` (CONTROL) |
|:--|:--|:--|:--|
| origin/main resolver put back (blob 2713d6f4cb) | `"Acme Annual
Renewal Quote"` | `"Acme Annual Renewal Quote"` | the account's id |
| this branch (blob fdbca4a) | the quote's id | the quote's id | the
account's id |
`[SeedLoader] Dependency graph built` read `insertOrder: [qx_account,
qx_quote, qx_order]` on both legs. That reading does not tell the legs
apart on this fixture; the unit pins assert the edge itself.
</details>
<details>
<summary>Ablation of the resolver order</summary>
The fix was committed first. `node scripts/ablation-replace.mjs --hold`
replaced the three-line engine-first body with `origin/main`'s
metadata-first body: anchor x1 → x0, replacement x0 → x1, blob
fdbca4a → 2713d6f4cbe4. Then `pnpm --filter
@objectstack/metadata-protocol build` ran, and
`ablation-dist-preflight.mjs @objectstack/metadata-protocol
'fromMetadata?.fields'` read the marker present in `dist/`.
- Unit pins (source import): `Tests 7 failed | 15 passed (22)`. All five
#35254 pins were red (for example `expected 'Q-ACME' to be 'gen-1'`). So
were the renamed fallback pin (`expected [] to deeply equal [
'crm_account', … ]`, metadata read first) and the #35655 extension
roll-up pin (`expected [ 'name', 'total', 'ext_refunds' ] to not include
'ext_refunds'`, because the union is gone). The throwing-schema CONTROL
stayed green.
- `os dev` on that build: the raw names in the table above.
- Restore: `git checkout HEAD -- ABS_PATH` in a trap. Blob after restore
fdbca4a equals the HEAD blob, `git diff HEAD` is empty, and `git
status --porcelain -- packages/` is empty. After a rebuild, the
`--absent` dist reading passed. The tree reading reported only the
uncommitted `os dev` fixture (since deleted). Green again: `Tests 22
passed (22)`, and `os dev` stored the ids.
The pins were later moved from a new file into
`seed-loader-engine-schema-fallback.test.ts` unchanged (see Acceptance
notes). `seed-loader.ts` did not change after the ablation.
</details>
<details>
<summary>Suite and gate readings</summary>
- `pnpm --filter @objectstack/metadata-protocol test` at e3d3340:
`Test Files 363 passed | 9 skipped (372)`, `Tests 23325 passed | 45
skipped (23370)`. `typecheck`: VERDICT command-exit 0. At the head
(dd69776, a test-file move only), the two edited test files read
`Tests 22 passed (22)` and `typecheck` exits 0.
- `dispatch-gates.mjs --commands` derived 67 families, and the list is
identical at the head. All 67 ran locally, with each exit captured
before any pipe:
- 65 exited 0.
- `check:engine-double-contract` exited 1 at e3d3340 (RETAINED: the
new file's pinned double was not in the pinned ledger). The pins moved
onto the file's already-pinned double, and the gate exits 0 at
dd69776.
- `check:dual-build-cjs-loads` exited 3 (PREREQUISITE NOT MET: no local
`dist/` for packages outside this diff). NOT MEASURED locally; CI runs
it.
- `--ran` reconciliation: "67 derived, 67 run, 0 NOT-MEASURED, 0 UNRUN",
exit 0.
- `overlap-check` at dd69776: VERDICT clean, exit 0.
</details>
## Acceptance notes
- **The pins live in an existing file.** The dispatch asked for a new
file named after the card, unless `check:engine-double-contract` refused
a new engine double. The gate asked for its pinned ledger to be
regenerated (`--write`), and that ledger write was refused in this
session. So the pins were folded into
`seed-loader-engine-schema-fallback.test.ts`, whose engine double is
already pinned and is the same double the new file had copied.
- **The test harness boot does not reproduce the defect.** It was
measured: a dogfood test booting `bootStack` from `@objectstack/verify`
with `MetadataPlugin({ artifactSource })` over the same two-package
artifact read the extension field absent from
`metadata.getObject('qa_ext_order')` and present in `getSchema`. Yet it
stored the quote's id on BOTH legs of the ablation, so it could not pin
this defect, and it is not committed. Only the real `os dev` boot showed
the raw key. Why the harness's seed load sees a different definition was
not established. This is reported as a finding, not fixed here. Carried
by #36274.
- Rows an earlier load stored with the raw key are not rewritten.
Re-running the seed in `update` or `upsert` mode replaces the key with
the id (the replay compare sees a difference). The changeset says so.
- The basic-insert fallback seeder in
`packages/runtime/src/app-plugin.ts` (no metadata service, or the loader
threw) does not go through this resolver, as #36118's notes already
record.
## Verification
Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec
vitest run --maxWorkers=2
src/seed-loader-engine-schema-fallback.test.ts`. Expect `Tests 8
passed`, including five `[#35254]` cases.
Read first, by risk:
1. `packages/metadata-protocol/src/seed-loader.ts`, the
`resolveObjectDefinition` hunk: the order flip that every per-field read
inherits.
2. The same file, the `summaryFields` hunk in `loadDataset`: #36118's
union collapsed onto the single source.
3.
`packages/metadata-protocol/src/seed-loader-engine-schema-fallback.test.ts`:
the probe assertion of the renamed fallback pin, and the new `[#35254]`
block.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh)_
<!-- signed: repo:objectstack#4 · os-project-manager ·
session_01FEkQ5miLqNucRZevceHwNh -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4ab1218 commit 8925d5b
4 files changed
Lines changed: 274 additions & 48 deletions
File tree
- .changeset
- packages/metadata-protocol/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
465 | 464 | | |
466 | 465 | | |
467 | 466 | | |
| |||
0 commit comments