Repository navigation
Commit 35c6331
fix(seed): a deferred-key seed row a person deleted stays deleted (#35361)
Fixes #34856
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:种子行在落地时若其 externalId 中的引用尚为空(如被指派的人还没注册),现在会以其按"作者原写键"派生的落地 id
记入落地键账本;此后无论引用仍空还是已解析,删除都能被识别。
- 为什么改:之前这类行在账本里没有任何记录,用户删掉后下一次种子加载会把它重新插回来,删除不生效。
- 风险与回滚:仅影响 `landedKeys` 开启的 upsert/ignore
数据集里、键含延迟引用的行;键完整的行、从未落地的行、重新播种行为不变。回滚即 revert 本 PR。
-
先看:`packages/metadata-protocol/src/seed-loader.ts`(`deferredLandedKey`、`isWithdrawnRow`、撤回分支里丢弃本行
pass-2
延迟),`packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts`
末尾的 #34856 describe。
- 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run
src/seed-loader-deferred-key-reference.test.ts`,预期 17 个用例全绿(其中 8 个是
#34856 新增)。
- 需要你做的:无,席位落地。
## What changes
A seed row whose `externalId` includes a reference that is still empty
on the load that lands it (the #34800 shape: a person not signed up yet)
keyed `''` in the landed-key ledger, and the ledger records only
non-empty keys, so a person's delete of that row was undone by the next
load.
- `seed-loader.ts`: such a row is now recorded under
`deferredLandedKey`, an `id` key over `seedDeferredKeyRowId` of the
AUTHORED key (the id the row lands with, #34800 / PR #34854). It is read
off the record before any reference resolves, so the next load computes
the same key whether the reference is still empty or has resolved since.
- The honour check (`isWithdrawnRow`) consults that key after the
existing natural-key and found-by-id checks, both when the record keys
`''` and when it keys complete but that complete key was never recorded.
- A row withdrawn this way also drops the key-reference deferrals it
pushed on the way, so pass 2 does not report a drop for a row that was
never meant to land (caught by the `success` assertion before this line
existed).
Why the derived id and not "the key it will carry": the resolved key is
unknown while the reference stays empty, which is exactly the state the
first delete happens in. The derived id is the one identity computable
in both states. Its `id` spelling cannot collide with a reference-keyed
dataset's natural-key entries, because field names travel with the
values in a ledger key.
## Tests
A new top-level `describe` in
`packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts`,
the #34800 harness (real `SeedLoaderService`, that file's already-pinned
engine double, a fresh loader per load). It goes in that file rather
than a new one so the pinned double is reused instead of copied into the
engine-double ledger:
- `ignore` and `upsert`: deleted while the person is still missing, not
inserted again (success, skipped 1, inserted 0).
- `ignore` and `upsert`: deleted, then the person signs up, still not
inserted again.
- The ledger entry equals `[["id", ROW_ID]]` for the row's landed id.
- CONTROL: a complete-key row deleted stays deleted, as before.
- CONTROL: a deferred-key row the seed never landed here still lands,
beside the deleted one.
- A kept deferred-key row found again and filled once the person signs
up is the existing pin `with the landed-key record kept, the row is
found too…` in the same file, still green.
- CONTROL: a deliberate re-seed brings the deleted row back.
## Acceptance notes
- Real-engine pin (ObjectQL + SqlDriver) not added:
`@objectstack/metadata-protocol` has no objectql/driver dependency, and
the real-driver sibling lives in `packages/runtime`, outside this card's
file fence. Loader-level pins with the copied engine double cover the
behaviour.
- Edge, not changed: when a dataset authors `organization_id` as a
natural-key reference rather than taking the stamped tenant
organization, `seedDeferredKeyRowId` is computed over the pre-resolution
value at the honour check and the post-resolution value at landing
(pre-existing in #34800's `rowLandedWithEmptyKeyReference`).
`deferredLandedKey` is computed once, before resolution, so the ledger
stays self-consistent across loads either way.
## Verification
All readings on head `ca2df4fd`.
<details><summary>Red on main, then green</summary>
- Before the fix (pins run against the unchanged loader at 81c0947):
`Tests 7 failed | 2 passed (9)`. The four delete cases failed with
`expected [ { name: 'Onboard', … } ] to have a length of +0 but got 1`,
which reproduces the card.
- `pnpm --filter @objectstack/metadata-protocol typecheck` exit 0; full
package `vitest run`: `Test Files 359 passed | 9 skipped (368)`, `Tests
23227 passed | 45 skipped (23272)` (run on 3bd8c56; ca2df4f only moves
the pins into the harness file).
- On ca2df4f: `seed-loader-deferred-key-reference.test.ts` +
`seed-loader-landed-ids.test.ts`: `Tests 44 passed (44)`; typecheck exit
0.
</details>
<details><summary>Ablations (each restored, `git diff HEAD` empty and
HEAD blob hash matched after)</summary>
- Delete the ledger-record line (`else if (deferredKeyFields.size > 0 …)
landedKeyByRecordIndex.set(i, deferredLandedKey)`): 6 failed.
- Replace the honour branch with `return false`: 5 failed (on ca2df4f,
against the folded pins: `Tests 5 failed | 12 passed (17)`).
- Delete `deferredUpdates.length = deferredUpdatesBeforeRow`: 2 failed
(the `success` assertion on the still-missing cases).
- Mutations landed through `scripts/ablation-replace.mjs` (anchor 1 to
0, blob moved); no build involved, as the pins import `./seed-loader.js`
from source.
</details>
<details><summary>Gates</summary>
- `dispatch-gates.mjs --commands` derived 67 families for this diff; all
67 run on ca2df4f, all exit 0. `--ran` reconciliation: 67 derived, 67
run, 0 NOT-MEASURED, 0 UNRUN.
- `check-plugin-teardown-shape.mjs --self-test` first exited 3 on a
shallow clone (its pinned fixture commit was missing); after fetching
that one commit it passed, 48 cases.
- `check:engine-double-contract`: `OK — 1359 pinned`.
- `overlap-check.mjs --branch=HEAD`: `VERDICT clean exit 0`, 0 PR heads
share a file.
- `check-nul-bytes.mjs`: OK.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8b550f8 commit 35c6331
3 files changed
Lines changed: 160 additions & 2 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2297 | 2297 | | |
2298 | 2298 | | |
2299 | 2299 | | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
2300 | 2317 | | |
2301 | 2318 | | |
2302 | 2319 | | |
| |||
2461 | 2478 | | |
2462 | 2479 | | |
2463 | 2480 | | |
2464 | | - | |
| 2481 | + | |
2465 | 2482 | | |
2466 | 2483 | | |
2467 | | - | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
2468 | 2489 | | |
2469 | 2490 | | |
2470 | 2491 | | |
2471 | 2492 | | |
| 2493 | + | |
| 2494 | + | |
2472 | 2495 | | |
2473 | 2496 | | |
2474 | 2497 | | |
| |||
2749 | 2772 | | |
2750 | 2773 | | |
2751 | 2774 | | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
2752 | 2779 | | |
2753 | 2780 | | |
2754 | 2781 | | |
| |||
2908 | 2935 | | |
2909 | 2936 | | |
2910 | 2937 | | |
| 2938 | + | |
| 2939 | + | |
2911 | 2940 | | |
2912 | 2941 | | |
2913 | 2942 | | |
| |||
0 commit comments