Skip to content

Commit 4df62e6

Browse files
fix(scenarios): load the card seed through the platform's seed path (#34985)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBQ3DFv6XZAspQRYGQoEWhr8)_ Fixes #34897 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:场景卡运行器不再用数据 API 逐行写入种子数据,改为把卡片种子打成一个只含 `data[]` 的包,经托管安装门交给平台自己的种子加载器写入;恢复已删除种子行也走同一条路。 - 为什么改:构建按 skill 指引声明了 `initialStates: ['draft']` 的状态机,数据 API 属于用户写入,于是 travel_expense 卡 120 张报销单中 114 张(已付款/已提交等)被拒,其下 470 条明细与审批步骤连带被拒,584/757 行丢失,问数轮次在错误的数据上进行。 - 风险与回滚:种子行不再触发构建的记录触发流(平台种子语义如此);已普查 9 张卡,没有一张的答案依赖种子时触发流。拒收记录不再带错误码,只有加载器原文。回滚即 revert 本 PR。 - 先看:`packages/qa/scenarios/src/runner/orchestrate.ts` 的 `loadSeedRows` 与 `seedApp`(风险最高:错误清单到拒收记录的映射);同文件 `restoreSeededRows` 第 2 步;`packages/qa/scenarios/test/runner/orchestrate.test.ts` 新增的 `TravelRulesApp` 一组用例。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run --maxWorkers=2 test/runner/orchestrate.test.ts -t "past its entry state"`,预期 6 个用例全部通过。 - 需要你做的:无,席位落地。 ## What changes - `seedApp` builds one dataset per object in its existing load order (the card's own `id` on each row; persona user ids, `owner_id` and rewritten handles as before; deferred cycle lookups still left out) and hands them to a new module-private `loadSeedRows`. - `loadSeedRows` installs a data-only package (`data[]`, `externalId: 'id'`, `mode: 'insert'`, its own namespace per load) through the harness's existing `installManaged` door. The platform's seed loader writes package data under `SEED_WRITE_EXECUTION_CONTEXT`: the `state_machine` rule is skipped, every other rule and hook still runs, and record-change flows are suppressed. It maps the answer's `data.seeded.errorList` into the same `seed.refused` records: one per row the loader could not write, plus `fields` for a written row whose reference did not resolve. A refused package, a harness with no managed door, or a load that did not run inline refuses every row, with the reason. - The second pass (PATCH of the lookups that close a reference cycle) is unchanged. - `restoreSeededRows` step 2 re-inserts the round's missing seeded rows as one load through the same path. - No exported signature or type changes: the harness interface gains no member, and the new helpers are module-private. The `installManaged` doc comment and the door table in `app.ts` say the seed loads through it. - README: the Seed paragraph names the door and the posture. It states that seed rows fire no record-triggered flow and that no card relies on one. - Test doubles: both `FakeApp`s give the managed door the measured answer shape (`test/runner/seed-door.ts`). ### Route A, and one place the mechanism moved The seat ruled route A: load the rows as declared `data[]` under the seed posture, and keep the PATCH pass for runtime-id fields. I measured that assumption before building (condition 1, below). `data[]` carries runtime user ids as sent: `owner_id` and the `user` field landed, and the persona read its own 10 claims (M3). The seat then ruled on that deviation (A, 21:58Z): persona ids ride in the load, and the PATCH pass now sets only the deferred cycle lookups. Re-patching the persona ids would put a user-door update, with its update triggers and hooks, back on every persona-owned seed row, and the seed posture exists to avoid exactly that. The README's Seed paragraph says the same. ## Tests - New block `seedApp — a card row already past its entry state loads through the seed path…`, run on the travel_expense card with a double of the kept build's rules (`TravelRulesApp`): - the user door refuses a paid claim; - through `seedApp`, all 757 rows load: 114 non-draft claims, and `ln_001_hotel` / `as_001_1` hold `claim: 'c001'`; - control: a trip that breaks `end_after_start` is refused with the loader's message and no code, and its claim, two lines and two steps go with it (751 inserted); - `restoreSeededRows` puts a removed paid claim back; - a reference the loader drops from a row it wrote (an `errorList` entry whose `field` is the lookup): the row is refused with `fields: ['parent']`, `inserted` drops by one (755), and its deferred `manager` patch still runs (`secondPass` 3); a row with both a write entry and a reference entry counts once, without `fields`; and a restore counts the written row as reinserted. The double (`test/runner/seed-door.ts`) can now drop a reference from a row it writes, as the real loader reports one (`referencesDropped`). - a harness with no managed door refuses every row, saying so. - Updated: the partial-tally test (one load, which throws, counts nothing); two refusal expectations now read the loader's message and no code; the fresh-copy seed-difference regex; `UnmanagedOnly` now drops the managed door explicitly. ## Gates and test runs (head 1c5dbc3) - `pnpm --filter @objectstack/scenarios build && … test && … typecheck`, under the verify lock: `Test Files 39 passed (39)`, `Tests 1092 passed (1092)`, typecheck clean, `VERDICT command-exit 0`. - S1 round (1c5dbc3, two commits: a README sentence and the S1 test): the package run above is on this head. The README path derives 42 gate families and the two test paths add 7; all exit 0 except the two standing NOT MEASURED (`check-plugin-teardown-shape --self-test` and `check:dual-build-cjs-loads`, both exit 3). `overlap-check`: VERDICT clean exit 0. - Derived gate list: `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --commands` gives 67 families at 81b6323. That is the same list as on the earlier head. The reconciliation (`--ran` with each exit code captured before any pipe) reads `67 derived, 65 run, 2 NOT-MEASURED, 0 UNRUN`. - `pnpm check:dispatcher-error-vocabulary` was red on the first head. It flagged a refusal helper that took a `code` parameter it could not name as a literal. 81b6323 removes it: a refused seed package now puts the door's code in the message. The gate was re-run on that tree and exited 0. - NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs --self-test`. It exited 3 because the shallow clone lacks the commit it needs ("Deepen the clone"). The scan itself, `node scripts/check-plugin-teardown-shape.mjs`, exited 0. - NOT MEASURED: `pnpm check:dual-build-cjs-loads`. It exited 3 with `PREREQUISITE NOT MET`: other packages have no `dist/` in this worktree. CI builds them and runs it. - Not run locally: `test:repo` and the repo-wide scans. Both belong to CI. <details><summary>Derived families, exit codes</summary> ```text exit 0 · node scripts/check-adr-0087-registration.mjs --base origin/main exit 0 · node scripts/check-adr-0087-registration.mjs --self-test exit 0 · node scripts/check-changeset-no-major.mjs --base origin/main exit 0 · node scripts/check-closing-keyword-parity.mjs exit 0 · node scripts/check-closing-keyword-parity.mjs --self-test exit 0 · node scripts/check-comment-mask-adoption.mjs exit 0 · node scripts/check-comment-mask-adoption.mjs --self-test exit 0 · node scripts/check-comment-mask-corpus.mjs exit 0 · node scripts/check-dts-emitted.mjs --self-test exit 0 · node scripts/check-empty-changeset.mjs --base origin/main exit 0 · node scripts/check-empty-changeset.mjs --self-test exit 0 · node scripts/check-issue-citations.mjs exit 0 · node scripts/check-plugin-teardown-shape.mjs exit 3 · node scripts/check-plugin-teardown-shape.mjs --self-test exit 0 · node scripts/ci/assert-turbo-remote-cache.mjs --self-test exit 0 · node scripts/ci/plan-test-core-shards.mjs --self-test exit 0 · node scripts/ci/prune-turbo-cache.mjs --self-test exit 0 · node scripts/ci/snapshot-next.mjs --self-test exit 0 · node scripts/docs-audit/check-affected-docs.mjs exit 0 · node scripts/docs-audit/check-drift-comment.mjs exit 0 · node scripts/pm/check-governed-queue-guard.mjs --self-test exit 0 · node scripts/pm/release-rehearsal-clone.mjs --self-test exit 0 · node scripts/release-pending-publish.mjs --self-test exit 0 · pnpm --filter @objectstack/spec run check:duration-unit-keys exit 0 · pnpm --filter @objectstack/spec run check:error-code-provenance exit 0 · pnpm check:adr-anchors exit 0 · pnpm check:changeset-gate-self-tests exit 0 · pnpm check:ci-filter-parity exit 0 · pnpm check:cli-command-ids exit 0 · pnpm check:closed-ceremony-text exit 0 · pnpm check:cross-package-test-inputs exit 0 (re-run on 81b6323; 1 on the first head) · pnpm check:dispatcher-error-vocabulary exit 0 · pnpm check:doc-authoring exit 0 · pnpm check:driver-memory-census exit 0 · pnpm check:dts-closure exit 3 · pnpm check:dual-build-cjs-loads exit 0 · pnpm check:engine-double-contract exit 0 · pnpm check:error-status-conformance exit 0 · pnpm check:gitlink-declared exit 0 · pnpm check:issue-citations exit 0 · pnpm check:keyed-text-bounds exit 0 · pnpm check:lean-entry-closure exit 0 · pnpm check:logger-receiver-detach exit 0 · pnpm check:nul-bytes exit 0 · pnpm check:object-def-param-keys exit 0 · pnpm check:objectql-double-limit exit 0 · pnpm check:optional-error-sink exit 0 · pnpm check:org-identifier exit 0 · pnpm check:page-declaration-shape exit 0 · pnpm check:platform-object-tenancy-census exit 0 · pnpm check:published-files exit 0 · pnpm check:query-options-erasure exit 0 · pnpm check:refd-timer-probe exit 0 · pnpm check:registry-log-declared exit 0 · pnpm check:rest-log-spy-declared exit 0 · pnpm check:settings-bind-window exit 0 · pnpm check:slot-lookup exit 0 · pnpm check:sourcemap-no-sources-content exit 0 · pnpm check:system-context-census exit 0 · pnpm check:test-source-alias exit 0 · pnpm check:tier-file-adoption exit 0 · pnpm check:type-check-coverage exit 0 · pnpm check:type-check-debt exit 0 · pnpm check:undeclared-dep-imports exit 0 · pnpm check:vouch-for-reference-callers exit 0 · pnpm check:watch-hint-literal exit 0 · pnpm check:where-matcher ``` </details> <details><summary>Ablation: the seed path and the restore path, one leg each</summary> The scenarios tests import the runner from `src/` by relative path, so neither leg needs a dist rebuild. Each leg was written with `node scripts/ablation-replace.mjs` from the HEAD blob `a8c96bc92dd1` of `orchestrate.ts` and restored the same way. After each restore, the blob equalled HEAD and `git diff HEAD` was empty. - Leg 1: the seed loop goes back to one data-API insert per row (blob `a8c96bc92dd1 -> 1ff43a1b3708`, anchor 1 -> 0). 4 of the 5 new tests go red: all 757 load, the control, the restore (its seed already failed) and the missing-door case. The user-door test stays green, as it should. - Leg 2: only the restore re-insert goes back to the data API (blob `a8c96bc92dd1 -> 0aaa6d7a3034`). Only the restore test goes red: `failed: … demotravel_expense_claim: 1 missing (c001) (refused: insert demotravel_expense_claim c001: This status change is not allowed; a paid claim cannot be changed.)`. - Leg 3 (S1, head 1c5dbc3): the reference branch ignores entries (`unheld.set(key, held)` replaced by `void held`, blob `004bb0c7c0f6 -> 21619f29c539`, anchor 1 -> 0). Only the S1 test goes red (`expected { inserted: 756 } to deeply equal { inserted: 755 }`), 5 pass. Restored: blob == HEAD `004bb0c7c0f6`, `git diff HEAD` empty. </details> ## Acceptance notes - Seed refusals now carry the seed loader's sentence (`Failed to write OBJECT record #N (id=ID): …`) and no `code`, because the door's `errorList` names none. `seedDifference` and the scorecard read them unchanged. - In the re-run, the replayed ask turns score `Run-问数 3/13` and `Run-operations 2/6`. Those answers were recorded over the old 173-row seed and are now graded against the full truth. This is not a regression: the old round had 8 turns not measured, and those turns are now asked. - Not exercised live: the write-back restore (`restoreSeededRows`). Ask mode took the fresh-copy route, whose copy seeded alike. The write-back restore is covered by the unit test and its ablation. ## Verification Condition 1 asked whether `data[]` keeps the card's ids as lookup targets. I measured it before writing code, on a blank 18.5.0 host with the kept `template.json` installed, through `POST /api/v1/marketplace/install-local` (`installMode: 'managed'`): - M1, the template plus the card seed as `data[]` (`externalId: 'id'`, `mode: 'insert'`): `seeded.mode inline, inserted 757, errors 0`. The ids are kept: `c001` exists, `ln_001_hotel.claim = c001`, `dep_eng.manager = e05`. - M2, a separate data-only package with trip `t001` broken (end before start): `inserted 751, errors 11`. The trip is refused with the rule's message, and its claim, two lines and two steps go with it (two entries per dependent row: write plus lookup). - M3: `owner_id` and the `user` field carry persona user ids as sent, and the employee persona reads its own 10 claims. A second data-only package with its own namespace installs. The same namespace again is refused with 422. Condition 3 is the re-run on the round's kept build. That is `template.json`, sha256 `b7ab31a715d4e83c…`, in ask mode with the round's recorded ask turns (`--driver recorded:…/issue-34687/ask-round-2026-11-17/proof-managed/ask.rec.json`, `--create-version 18.5.0`). The record is on the project mount: `issue-34897/rerun-replay/` (`rerun.sh`, `run.log`, `started`, `exit`, `out/2026-11-17-scenario-travel_expense.json`). - It started at 2026-11-17T21:19:04Z on runner head 8308c29 and exited with `EXIT=0` at 21:22:39Z. - Template: `installMode managed`, after the unmanaged attempt was refused `422 UNMANAGED_INSTALL_UNCOPYABLE`. - Seed: `inserted 757, refused [], secondPass {demotravel_department.manager: 4}`. The scorecard reads `seed {inserted 757, total 757, refused 0}`. - Before: the same build seeded through the data API refused 114 claims at the root and 470 lines and steps in cascade, 584 of 757 rows. Now 0 of the 114 root rows are refused, and all 470 cascaded rows are inserted. - What changed after 8308c29 does not touch this path: the README, the changeset, and the message of a refused seed package, which this run never met. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 13fbf94 commit 4df62e6

7 files changed

Lines changed: 407 additions & 44 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
fix(scenarios): the runner loads a card's seed through the platform's seed path, so a build's status state machine no longer refuses rows the card states as already past their entry state
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The runner wrote every seed row through the data API as the admin. That is a user write, so a build's `state_machine` rule judged each one: a build that declared `initialStates: ['draft']` on a claim's status, as the data skill teaches, refused every claim the card states as `paid`, `submitted` or `rejected`, and every line and approval step under them failed for want of its claim. On `travel_expense` that was 114 root refusals and 470 cascaded ones, 584 of 757 rows.
11+
12+
The seed now goes in as one data-only package whose `data[]` holds the card's rows, installed through the managed install door. The platform's seed loader writes them as established facts: it skips the `state_machine` rule only, so every other validation rule and every hook still judges each row. Each row keeps the card's own `id`, a lookup value names the row seeded under it, and a user id in `owner_id` or a `user` field lands as sent. A refused row is still recorded with its object, id and the loader's message; the seed door names no error code. A restore puts a removed seeded row back the same way. The second pass, which sets the lookups that close a reference cycle, is unchanged.
13+
14+
Seed rows no longer fire a build's record-triggered flows, as the data API's insert did. No library card relies on that: every truth is computed from the seed's own values, and the cards that ask for such flows seed the values a flow would produce.

‎packages/qa/scenarios/README.md‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,25 @@ npx @objectstack/scenarios help # the comma
486486
measured: author turn failed: …**. Never a degraded score, and nothing runs on it: no score, seed, Run or iterate. The
487487
scorecard's author rows show every authoring turn's `resultSubtype`, the turns it took of its cap
488488
(`error_max_turns · 300/300 turns`) and its elapsed time.
489-
- **Seed** (`seed.ts`): rows go in as the admin, a lookup's target before its referrer. Where the card's declared
489+
- **Seed** (`seed.ts`, `loadSeedRows` in `orchestrate.ts`): rows go in as the admin through the platform's own seed
490+
path, never the data API: the runner installs one data-only package whose `data[]` holds the card's rows (keyed on
491+
the card's own `id`, so a lookup value names the row seeded under it), through the managed install door. The
492+
platform's seed loader writes them as established facts: a build's `state_machine` rule (its `initialStates` entry
493+
check) does not judge them, so a claim the card states as already `paid` loads as the card states it. Every other
494+
validation rule and every hook still judges each row, and a refused row is recorded with its object, id and the
495+
loader's message (`seed.refused`; the seed door names no error code). **Seed rows fire no record-triggered flow**,
496+
where the data API's insert used to fire a build's "on create" automation on each one. No card relies on that: every
497+
truth is computed from the seed's own values (`truth.ts` refuses one the seed does not determine), and the four cards
498+
that ask for record-triggered flows (`asset_lifecycle`, `requisition_to_receipt`, `service_desk`, `travel_expense`)
499+
seed the values such a flow produces (a ticket's group, SLA policy and breach flag, a line's over-standard flag, the
500+
statuses) explicitly. An operation's own write still goes through the agent's door and fires the build's automation.
501+
A restore puts a removed seeded row back the same way. A lookup's target loads before its referrer. Where the card's declared
490502
lookups lead back to where they start — `department.manager → employee` with `employee.department → department`, or a
491503
self-lookup naming a later row — the seed loads in two passes: every row first with each lookup naming a row not in
492-
yet left out, then one update per row sets those (`seed.secondPass` in the record). The side that waits is one the
504+
yet left out, then one update per row sets those (`seed.secondPass` in the record). That second pass sets only these
505+
deferred cycle lookups: `data[]` carries a persona's user id (`owner_id`, a `user` field) as sent, and patching it
506+
again would put a user-door update, with its update triggers and hooks, back on every seed row.
507+
The side that waits is one the
493508
build left optional; a build that makes every side of a cycle `required` cannot be seeded, which the data contract
494509
states and the scorecard reports as a Build finding naming the cycle (the seed is still sent, so the record holds
495510
the app's own refusals). A refused row takes out what it feeds (`seedDependence` in `orchestrate.ts`): with its

‎packages/qa/scenarios/src/runner/app.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616
* its access POST /api/v1/data/sys_user_permission_set { user_id,
1717
* permission_set, organization_id } — a user with no app permission
1818
* set reads `PERMISSION_DENIED` on every app object
19-
* a seed row POST /api/v1/data/:object with the card's own `id` (accepted
20-
* verbatim, so a lookup value in the seed names the real row)
19+
* the seed rows the managed install door below, with a data-only package whose
20+
* `data[]` holds them (`loadSeedRows` in `orchestrate.ts`): the
21+
* platform's seed loader writes them under its seed posture, which
22+
* skips the `state_machine` rule a user write meets. Measured on a
23+
* blank 18.5.0 host with the travel_expense build installed: every
24+
* row keeps the card's own `id`, a lookup value names the row
25+
* seeded under it, a user id in `owner_id` or a `user` field lands
26+
* as sent, and the answer's `data.seeded.errorList` names each row
27+
* refused (`sourceObject`, `recordIndex`, `message`; no code). A
28+
* second package claiming a namespace another holds is refused
29+
* (`PLUGIN_REGISTER_FAILED`), so each load takes its own
2130
* a waiting lookup PATCH /api/v1/data/:object/:id with the bare field patch (the
2231
* seed's second pass, `seedApp` in `orchestrate.ts`; read from the
2332
* route's source, `packages/rest/src/crud-routes.ts`, not yet
@@ -149,8 +158,10 @@ export interface AppHarness {
149158
* The same build installed managed (`installMode: 'managed'`): what ask mode
150159
* falls back to when the unmanaged door refuses the build
151160
* `UNMANAGED_INSTALL_UNCOPYABLE` (`withInstalledBuild` in `orchestrate.ts`).
161+
* It is also the door the seed loads through: a data-only package whose
162+
* `data[]` holds the rows (`loadSeedRows` in `orchestrate.ts`).
152163
* Optional, so a harness written before the fallback keeps compiling; without
153-
* it that refusal stays the mode's finding.
164+
* it that refusal stays the mode's finding, and every seed row is refused.
154165
*/
155166
installManaged?(manifest: Record<string, unknown>): Promise<HttpAnswer>;
156167
/** The environment's metadata of every collection the template carries, as an artifact. */

0 commit comments

Comments
 (0)