Skip to content

Commit 3fb7025

Browse files
fix(scenarios): template mode's iterate Run half runs an operation after a write on a fresh copy of the served app (#35291)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg1XdbbGasMNVx41tq3hZKV4)_ Fixes #34497 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:场景评测的 template 模式,在迭代后的 Run 半程里,某个操作若会碰到前一步写入留下的改动,现在改在一份新起的副本上跑。副本是一台空白宿主,装入迭代后应用实际对外提供的元数据(去掉读时装饰键)。不再通过应用自己的接口把数据写回。 - 为什么改:写回会被应用自己的单向状态规则拒绝(例如 asset_lifecycle 的报废申请批准后不能退回 submitted),后续操作全部记为 NOT MEASURED,评分卡上就没有对 agent 的结论。 - 风险与回滚:只影响评测工具(已发布的评测包的运行器),不影响产品和用户。每份副本多一次启动和一次种子加载。回滚就是 revert 本 PR,template 模式回到写回。 - 先看:`packages/qa/scenarios/src/runner/orchestrate.ts` 中的 `iteratedManifest` 和 `withInstalledBuild` 的 `copyOf`;再看 `test/runner/orchestrate.test.ts` 里 #34448 describe 的 template 用例。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run test/runner/orchestrate.test.ts -t 34497`,预期 1 passed。 - 需要你做的:无,席位落地。 ## What changes - `templateMode` now gives its iterate Run half a `FreshCopy` (`orchestrate.ts`). The copy is the same blank host, booted again, with the iterated app installed unmanaged the way the run's own install landed. Before, template mode wrote moved rows back through the app's doors (`restoreSeededRows`), and an app's one-way state rule refused that write-back. - `iteratedManifest` (module-private) builds what the copy installs: the manifest the run's install sent, with each served collection replaced by the items the host serves after the iterate. Each item goes through `stripReadDecorations` (`@objectstack/spec/kernel`) first. The spec says a served body is no valid input to its own schema until its read decorations are removed, and the unmanaged install door refuses a served flow carrying `_diagnostics` (measured below). - `withInstalledBuild` now hands `use` both `copyOf(manifest)` and `manifest`. `fresh` is `copyOf(landed.manifest)`, as before. Ask mode is unchanged. - README bullet "Each operation starts from the seeded rows": scratch, template and ask modes run the operation on a fresh copy, and door mode (or any half given no copy) writes back. Changeset: `@objectstack/scenarios` patch. ## Premise measurement (the card's gate, run before any change) This was a live measurement on blank hosts scaffolded with `create-objectstack@18.6.0`. No model ran. Host A installed `docs/qa/scenarios/builds/travel_expense.json` unmanaged and then took an iterate through `PUT /api/v1/meta/object/NAME`: a new object `demotravel_travel_advance` with a `state_machine` validation, plus a new lookup field `advance` on `demotravel_expense_claim`. Host B was a fresh boot of the same project with A's served metadata installed unmanaged. Both then got the card's personas and seed. <details><summary>Readings</summary> - Raw served items, as `metadataAsArtifact` returns them: B's install answered `422 INVALID_METADATA`, refusing 3 flows for `unrecognized_keys: _diagnostics`. - With `stripReadDecorations` applied: B's install answered 200 (`copiedCount` 31). All 11 collections had the same names on A and B (objects 8/8 including the iterate's new object, apps 1, views 6, dashboards 1, reports 1, datasets 3, actions 4, flows 3, permissions 3, skills 1, hooks 1). The per-item deep diff (fields, validations, actions) found 0 differences. The only difference is `objects/demotravel_travel_advance._packageId`, which reads `sys_metadata` on A and `com.example.demotravel-copy` on B. That is the protection envelope, not the item. - Seed: A 757 inserted / 0 refused, B 757 / 0. Personas employee, dept_manager and finance_officer were assigned on both. `seedDifference` empty. </details> ## Tests - `#34448` describe: the case "without a fresh copy the same rule refuses the write-back" is now "template mode: the iterate Run half measures all six operations…". It runs `runCard` with `modes: ['template']` on `asset_lifecycle`. All six operations are asked and measured. `dispose_scrapped_asset` carries `restored: { freshCopy: ['demoasset_disposal_request/dr06'] }`. No rule refusal happens, and the iterated host took only its seed's writes. Every copy installed the same objects as the iterated host, including the scripted iterate's object. Every boot stopped. - The one-way double (`OneWayApp`) now serves `_diagnostics` on metadata reads, and its unmanaged install door refuses an item carrying it, as the real door does. - The `#34294` case "with no fresh copy (template mode)" is retitled "(a Run half given none)". It still pins the write-back path, which door mode uses. <details><summary>Ablations (scripts/ablation-replace.mjs; tests import src, no build leg)</summary> - Template mode given no copy (`…opts.promptChoice, fresh);` changed to `…opts.promptChoice);` in `templateMode`, blob b3da89c to ac741fb0). The first attempt was refused with ANCHOR AMBIGUOUS (x2) and wrote nothing. Rerun with a longer anchor: `-t 34497` gave 1 failed, with 3 operations NOT MEASURED: `restore: the rows could not be restored to the seeded state: demoasset_disposal_request: 1 changed (dr06: status, decided_on) (refused: update … 400 VALIDATION_FAILED …)`. Restored blob equals HEAD, and `git diff HEAD` is empty. - No read-decoration strip (`items.map(stripReadDecorations)` changed to `items`, blob to fad3c78b): 1 failed, with 5 operations NOT MEASURED: `restore: no fresh copy of the app could be seeded for it (unmanaged install refused: 422 INVALID_METADATA …)`. Restored blob equals HEAD, and `git diff HEAD` is empty. </details> ## Verification <details><summary>At head 89ea8b1 (after merging origin/main 0c047d0)</summary> - `pnpm --filter '@objectstack/scenarios...' build`, then `pnpm --filter @objectstack/scenarios test`: Test Files 40/40, Tests 1182/1182. `typecheck` (`tsc --noEmit`) exit 0. Lock VERDICT command-exit 0. - `dispatch-gates --commands --repo objectstack-ai/objectstack` derived 63 families. 61 exited 0 and 2 exited 3. `check-plugin-teardown-shape --self-test` needed a shallow fixture; after `git fetch --depth=1` of 621a487 the rerun exited 0 with 48 cases. `check:dual-build-cjs-loads` needs every package's dist, and CI runs it. `--ran` reconciliation: 63 derived, 61 run, 2 NOT-MEASURED, 0 UNRUN. - `overlap-check --branch=HEAD --pr=35267`: clean. `check-nul-bytes` exit 0. </details> ## Acceptance notes - The copy installs the collections the template carries, the same set the iterate is scored on (`collections`). An iterate that adds an item of a metadata type the template had none of is neither scored nor copied. That gap already existed and is unchanged. - Rows the agent inserted during the iterate turn, as opposed to metadata, are not carried to a copy. The copy holds the card's seed only, the same as the scratch and ask copies. - Template-mode copies boot from the host project and install the iterated app. A copy whose install is refused is NOT MEASURED, with the door's answer. - The dispatch named ADR-0148 D1/D2 as the scenario runner's shape. Read at this head, ADR-0148 is the recycle-bin record, and its D1/D2 (snapshot store, restore under original ids) govern record restore in the engine, not this runner. They do not bear on this change, so there is no tension to resolve. The change stays inside the runner's Run half and adds no mode, door or record field. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CazXu8zyYD5PC6J2u7 <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CazXu8zyYD5PC6J2u7 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1950f07 commit 3fb7025

4 files changed

Lines changed: 116 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): template mode's iterate Run half runs an operation an earlier write would meet on a fresh copy of the iterated app, so a one-way state rule no longer leaves the operations after a transition unmeasured
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Scratch and ask modes already ran such an operation on a fresh seeded copy of the app. Template mode still wrote the moved rows back through the app's own doors, because its app holds the agent's iterate, made live through those doors, which a host booted again from the project would not hold. On a card with a state machine the write-back met the app's rule: in `asset_lifecycle`, approving scrap request DR-0006 (`submitted` → `approved`) was followed by a write-back to `submitted`, refused with 400 `VALIDATION_FAILED`, and every later operation of the half read `restore: … not measured`.
11+
12+
Now template mode's copy is a blank host booted from the same project with the iterated app installed unmanaged, the same way the run's own install landed: the manifest that install sent, with each collection the app serves replaced by the items it serves after the iterate. Each served item comes off its read decorations first (`stripReadDecorations` from `@objectstack/spec/kernel`), because a served body is no valid input to its own schema until they are removed. The unmanaged install door refuses a served flow that still carries `_diagnostics` (422 `INVALID_METADATA`, measured on a blank 18.6.0 host). Measured on that host with the `travel_expense` verified build and an iterate made through `PUT /api/v1/meta/object/…` (one new object with a state-machine rule, one new lookup field): the copy serves the same objects, fields, validation rules and actions as the iterated host. The only difference is the new object's `_packageId` (`sys_metadata` on the host, the install's copy package on the copy). The card's seed loads alike there (757/757 rows, no refusal, every persona's permission set assigned).
13+
14+
The result carries `restored: { freshCopy }` as in the other modes. A copy whose install is refused, that does not boot, or whose seed does not load as the run's did makes the operation NOT MEASURED with that reason. Door mode still writes the rows back.

‎packages/qa/scenarios/README.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,20 @@ npx @objectstack/scenarios help # the comma
551551
(`rowDrift`: every column but `created_at`, `updated_at`, `updated_by` and the fields the build computes — formula,
552552
summary, autonumber). When an earlier turn moved them (the agent's write, a probe's, a confirmed one, or a question
553553
turn that wrote), the operation starts from the seeded rows all the same, in one of two ways:
554-
- **Scratch and ask modes run it on a fresh copy** (`FreshCopy`, `runHalf`'s `fresh`): the runner boots the same
555-
app again (scratch: the same project; ask: the same blank host with the same build installed the same way), signs
556-
the personas in, loads the seed and reads the seeded state there, and that operation and every later turn of the
557-
half run on the copy; the copy it replaces is stopped. Nothing is written to undo the move, so no validation rule,
558-
hook or flow of the app judges a restore or runs on one: a one-way state rule (a request approved never goes back
559-
to submitted) cannot refuse it. The result carries `restored: { freshCopy }` (the rows that had moved, each
560-
`object/id`). A copy that does not boot, or whose seed does not load as the run's did (other rows loaded or
554+
- **Scratch, template and ask modes run it on a fresh copy** (`FreshCopy`, `runHalf`'s `fresh`): the runner boots
555+
the same app again (scratch: the same project; ask: the same blank host with the same build installed the same way;
556+
template: the same blank host with what the iterated app serves installed unmanaged, `iteratedManifest`: the run's
557+
install manifest with each served collection replaced by the items served after the iterate, their read
558+
decorations such as `_diagnostics` stripped, so the copy holds the agent's iterate made live through the app's
559+
doors), signs the personas in, loads the seed and reads the seeded state there, and that operation and every later
560+
turn of the half run on the copy; the copy it replaces is stopped. Nothing is written to undo the move, so no
561+
validation rule, hook or flow of the app judges a restore or runs on one: a one-way state rule (a request approved
562+
never goes back to submitted) cannot refuse it. The result carries `restored: { freshCopy }` (the rows that had moved, each
563+
`object/id`). A copy that does not boot or install, or whose seed does not load as the run's did (other rows loaded or
561564
refused, a permission set not assigned alike), makes the operation NOT MEASURED (`restore: no fresh copy of the
562565
app could be seeded for it (…)`, naming what had moved). Each copy costs one boot, the sign-ins and a seed load.
563-
- **Template mode writes the rows back** (`restoreSeededRows`), because its app holds the agent's iterate, made live,
564-
which a host booted again would not: a row a turn added is deleted, a seeded row a turn removed is inserted again
566+
- **Door mode writes the rows back** (`restoreSeededRows`), as does any Run half given no fresh copy: a row a turn
567+
added is deleted, a seeded row a turn removed is inserted again
565568
with the body the seed sent, and a changed column is set back to the value the seed left, in up to three rounds so
566569
a cascade settles, all through the app's own doors, which its rules judge. The result carries `restored`
567570
(`deleted`, `reinserted`, `setBack`). Rows that still differ after the rounds make the operation NOT MEASURED

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

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { tmpdir } from 'node:os';
6363
import { join } from 'node:path';
6464

6565
import { resolveStackCollection } from '@objectstack/core';
66+
import { stripReadDecorations } from '@objectstack/spec/kernel';
6667
import { SECURITY_ROLLUP_SOURCE_UNREADABLE, validateRollupSourceVisibility, type RollupSourceVisibilityFinding } from '@objectstack/lint';
6768

6869
import { applyExpectDelta, readableNumbers, truthsOver, type LoadedScenario } from '../loader.js';
@@ -150,10 +151,11 @@ export interface ProjectOps {
150151

151152
/**
152153
* Another copy of the app a Run half runs on: booted anew from the same
153-
* project, with the same build installed the same way, holding no rows of
154-
* the card's yet ({@link runHalf} seeds it). `release` stops it. A half that
155-
* has one starts an operation an earlier turn's write would otherwise meet on
156-
* a copy of its own instead of writing the rows back
154+
* project, with the same build installed the same way (template mode: the
155+
* metadata its app serves after the iterate, {@link iteratedManifest}),
156+
* holding no rows of the card's yet ({@link runHalf} seeds it). `release`
157+
* stops it. A half that has one starts an operation an earlier turn's write
158+
* would otherwise meet on a copy of its own instead of writing the rows back
157159
* ({@link restoreSeededRows}).
158160
*/
159161
export type FreshCopy = () => Promise<{ app: AppHarness; release(): Promise<void> }>;
@@ -697,6 +699,28 @@ export function withoutItems(artifact: Record<string, unknown[]>, baseline: Reco
697699
);
698700
}
699701

702+
/**
703+
* Template mode's iterated app as a manifest the install door takes: the
704+
* manifest the run's own install sent, with every collection the app serves
705+
* (`served`, the environment's items less what it served before the install)
706+
* replaced by the items served now, so a fresh host installed with it holds
707+
* the agent's iterate, made live through the app's doors, which a host booted
708+
* again from the project would not. A collection served empty is left out, as
709+
* {@link installableManifest} leaves one out. Each item comes off its read
710+
* decorations first (`stripReadDecorations`, `@objectstack/spec/kernel`): a
711+
* served body is no valid input to the schema that produced it until they are
712+
* removed, and the unmanaged install door refuses a flow that carries one
713+
* (`unrecognized_keys: _diagnostics`, measured on a blank 18.6.0 host).
714+
*/
715+
function iteratedManifest(installed: Record<string, unknown>, served: Record<string, unknown[]>): Record<string, unknown> {
716+
const out: Record<string, unknown> = { ...installed };
717+
for (const [key, items] of Object.entries(served)) {
718+
if (items.length) out[key] = items.map(stripReadDecorations);
719+
else delete out[key];
720+
}
721+
return out;
722+
}
723+
700724
/** Seed objects in lookup order: a row's lookup target is inserted before it, wherever a reference cycle allows ({@link seedPlan}). */
701725
export function seedOrder(scenario: LoadedScenario, required?: ReadonlySet<string>): string[] {
702726
return seedPlan(scenario.card, required).order;
@@ -2046,14 +2070,19 @@ interface VerifiedBuild {
20462070
* unmanaged install makes the environment's own. `fresh` boots another blank
20472071
* host from the same directory and installs the same build into it, the same
20482072
* way — in the mode the run's own install landed in ({@link FreshCopy}); a
2049-
* refused install there is that copy's failure.
2073+
* refused install there is that copy's failure. `copyOf` is the same with
2074+
* another manifest installed in its place (template mode's iterated app,
2075+
* {@link iteratedManifest}); `manifest` is the one the run's install sent.
20502076
*/
20512077
async function withInstalledBuild(
20522078
original: LoadedScenario,
20532079
ops: ProjectOps,
20542080
mode: ModeRun,
20552081
verified: VerifiedBuild | undefined,
2056-
use: (app: AppHarness, installed: { dir: string; url: string; collections: string[]; baseline: Record<string, unknown[]>; fresh: FreshCopy }) => Promise<void>,
2082+
use: (
2083+
app: AppHarness,
2084+
installed: { dir: string; url: string; collections: string[]; baseline: Record<string, unknown[]>; manifest: Record<string, unknown>; fresh: FreshCopy; copyOf: (manifest: Record<string, unknown>) => FreshCopy },
2085+
) => Promise<void>,
20572086
options: { managedFallback?: boolean } = {},
20582087
): Promise<void> {
20592088
// The installed copy keeps the TEMPLATE's namespace, which must be the card's own.
@@ -2112,19 +2141,21 @@ async function withInstalledBuild(
21122141
mode.findings.push(`unmanaged install refused ${install.code} (${install.status}): installed the same build managed instead`);
21132142
landed = { manifest: managed.manifest, install: (a, m) => a.installManaged!(m), mode: 'managed' };
21142143
}
2115-
const fresh: FreshCopy = async () => {
2116-
const copy = await freshBoot(ops, dir)();
2117-
try {
2118-
await copy.app.signInAdmin();
2119-
const again = await landed.install(copy.app, landed.manifest);
2120-
if (!again.ok) throw new Error(`${landed.mode} install refused: ${again.status} ${again.code ?? ''} ${again.message ?? ''}`.trim());
2121-
return copy;
2122-
} catch (e) {
2123-
await copy.release();
2124-
throw e;
2125-
}
2126-
};
2127-
await use(app, { dir, url: booted.url, collections, baseline, fresh });
2144+
const copyOf =
2145+
(installs: Record<string, unknown>): FreshCopy =>
2146+
async () => {
2147+
const copy = await freshBoot(ops, dir)();
2148+
try {
2149+
await copy.app.signInAdmin();
2150+
const again = await landed.install(copy.app, installs);
2151+
if (!again.ok) throw new Error(`${landed.mode} install refused: ${again.status} ${again.code ?? ''} ${again.message ?? ''}`.trim());
2152+
return copy;
2153+
} catch (e) {
2154+
await copy.release();
2155+
throw e;
2156+
}
2157+
};
2158+
await use(app, { dir, url: booted.url, collections, baseline, manifest: landed.manifest, fresh: copyOf(landed.manifest), copyOf });
21282159
});
21292160
}
21302161

@@ -2134,7 +2165,7 @@ async function templateMode(original: LoadedScenario, driver: AgentDriver, ops:
21342165
const card = scenario.card;
21352166
const mode: ModeRun = { mode: 'template', findings: [] };
21362167
const iterated = iteratedScenario(scenario);
2137-
await withInstalledBuild(original, ops, mode, verified, async (app, { dir, url, collections, baseline }) => {
2168+
await withInstalledBuild(original, ops, mode, verified, async (app, { dir, url, collections, baseline, manifest, copyOf }) => {
21382169
const before = await app.metadataAsArtifact(collections);
21392170
const build: BuildHalf = { commands: [], score: null };
21402171
await authorInto(build, async () => (await driver.author({ card: card.id, mode: 'template', phase: 'iterate', step: 'author', cwd: dir, prompt: templateIteratePrompt(card, { baseUrl: url, adminEmail: opts.admin.email, adminPassword: opts.admin.password }, opts.promptChoice), tier: card.tier })).turn);
@@ -2146,9 +2177,10 @@ async function templateMode(original: LoadedScenario, driver: AgentDriver, ops:
21462177
const served = withoutItems(after, baseline);
21472178
scoreInto(build, scenario, iterated, served);
21482179
mode.iterate = { build, changeSize: changeSize(before, after) };
2149-
// No fresh copy here: the app holds the agent's iterate, made live through its doors, which a host booted
2150-
// again would not hold; an earlier write is undone through those doors instead (`restoreSeededRows`).
2151-
mode.iterate.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'template', phase: 'iterate-run' }, labels, served, opts.askRepeats, opts.promptChoice);
2180+
// The app holds the agent's iterate, made live through its doors, which a host booted again would not hold:
2181+
// a fresh copy is a blank host with what the app serves now installed the same way (`iteratedManifest`).
2182+
const fresh = copyOf(iteratedManifest(manifest, served));
2183+
mode.iterate.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'template', phase: 'iterate-run' }, labels, served, opts.askRepeats, opts.promptChoice, fresh);
21522184
});
21532185
return mode;
21542186
}

‎packages/qa/scenarios/test/runner/orchestrate.test.ts‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,13 +3598,13 @@ describe('runHalf — each operation starts from the seeded rows: an earlier tur
35983598
expect(renderScorecard(cardScorecard(run))).toContain('| Run-operations | 2/2 |');
35993599
});
36003600

3601-
it('⛔ with no fresh copy (template mode), a restore that cannot be done makes the operation NOT MEASURED with the reason, not asked, never a pass or a fail', async () => {
3601+
it('⛔ with no fresh copy (a Run half given none), a restore that cannot be done makes the operation NOT MEASURED with the reason, not asked, never a pass or a fail', async () => {
36023602
class NoDeleteApp extends FakeApp {
36033603
override async deleteRow(): Promise<HttpAnswer> {
36043604
return { ok: false, status: 403, body: {}, code: 'PERMISSION_DENIED', message: 'refused by the double' };
36053605
}
36063606
}
3607-
/** The Run half on the booted app alone, as template mode runs it: no fresh copy, so the rows are written back through its doors. */
3607+
/** The Run half on the booted app alone, given no fresh copy, so the rows are written back through its doors. */
36083608
const halfOn = async (app: () => FakeApp) => {
36093609
const { scenario, ops, driver, apps } = setup({ app });
36103610
await ops.boot('host');
@@ -3653,10 +3653,23 @@ describe('runHalf — an operation an earlier write would meet runs on a fresh s
36533653
const ASSET_FILE = resolve(HERE, '../../../../../docs/qa/scenarios/asset_lifecycle.json');
36543654
const REFUSAL = 'That status change is not allowed: a request is approved or rejected once, and only an approved one is disposed of.';
36553655

3656-
/** The asset card's app as a well-built one is: a decided scrap request never goes back to submitted (400 VALIDATION_FAILED). Counts the writes its doors take. */
3656+
/**
3657+
* The asset card's app as a well-built one is: a decided scrap request never goes back to submitted (400 VALIDATION_FAILED).
3658+
* Counts the writes its doors take. Its metadata reads carry the platform's read decoration (`_diagnostics`), and its
3659+
* unmanaged install door refuses an item that still carries one, as a blank 18.6.0 host refuses a served flow.
3660+
*/
36573661
class OneWayApp extends FakeApp {
36583662
writes = { insert: 0, update: 0, delete: 0 };
36593663
refusedTransitions = 0;
3664+
override async metadataAsArtifact(collections: readonly string[]) {
3665+
const served = await super.metadataAsArtifact(collections);
3666+
return Object.fromEntries(Object.entries(served).map(([k, items]) => [k, items.map((i) => (typeof i === 'object' && i !== null ? { ...i, _diagnostics: { valid: true } } : i))]));
3667+
}
3668+
override async installUnmanaged(manifest: Record<string, unknown>): Promise<HttpAnswer> {
3669+
const decorated = Object.values(manifest).some((v) => Array.isArray(v) && v.some((i) => typeof i === 'object' && i !== null && '_diagnostics' in i));
3670+
if (decorated) return { ok: false, status: 422, body: {}, code: 'INVALID_METADATA', message: 'Unrecognized key(s): `_diagnostics`' };
3671+
return super.installUnmanaged(manifest);
3672+
}
36603673
override async insertRow(object: string, row: Record<string, unknown>) {
36613674
this.writes.insert++;
36623675
return super.insertRow(object, row);
@@ -3710,15 +3723,25 @@ describe('runHalf — an operation an earlier write would meet runs on a fresh s
37103723
expect([life.boots, life.stops]).toEqual([apps.length, apps.length]);
37113724
});
37123725

3713-
it('⛔ without a fresh copy the same rule refuses the write-back, and the disposal stays NOT MEASURED with the refusal named', async () => {
3714-
const { scenario, ops, driver, apps } = assetRun(() => new OneWayApp());
3715-
await ops.boot('host');
3716-
const half = await runHalf(namespacedScenario(scenario), apps[0]!, driver, { card: scenario.card.id, mode: 'template', phase: 'iterate-run' });
3717-
const dispose = half.operations.find((o) => o.operation === 'dispose_scrapped_asset')!;
3718-
expect(dispose.notMeasured).toMatch(/^restore: the rows could not be restored to the seeded state: demoasset_disposal_request: 1 changed \(dr06: status, decided_on\)/);
3719-
expect(dispose.notMeasured).toContain(`update demoasset_disposal_request dr06: 400 VALIDATION_FAILED ${REFUSAL.slice(0, 60)}`);
3720-
expect([dispose.turn, dispose.grade]).toEqual([undefined, undefined]);
3721-
expect(apps[0]!.refusedTransitions).toBeGreaterThan(0);
3726+
it('template mode: the iterate Run half measures all six operations, each one an earlier write would meet on a copy installed with what the app serves after the iterate (#34497)', async () => {
3727+
const { scenario, ops, driver, apps, life } = assetRun(() => new OneWayApp());
3728+
const run = await runCard(scenario, driver, ops, { modes: ['template'], admin: ADMIN, templateArtifact: artifact({ ns: 'demoasset' }) });
3729+
const half = run.modes[0]!.iterate!.run!;
3730+
expect(half.operations.map((o) => o.operation)).toEqual(['receive_and_issue_from_text', 'extend_overdue_loaner', 'manager_approves_scrap', 'dispose_scrapped_asset', 'employee_approves_own_scrap', 'check_out_asset_in_repair']);
3731+
// Six of six measured and asked: the approval moved DR-0006 one way, and the disposal after it ran all the same.
3732+
expect(half.operations.filter((o) => o.notMeasured !== undefined)).toEqual([]);
3733+
for (const o of half.operations) expect([o.operation, o.turn !== undefined, o.error]).toEqual([o.operation, true, undefined]);
3734+
expect(half.operations.find((o) => o.operation === 'dispose_scrapped_asset')!.restored).toEqual({ freshCopy: ['demoasset_disposal_request/dr06'] });
3735+
// The one-way rule judged no restore, and the host the agent iterated took no write after its seed.
3736+
expect(apps.map((a) => a.refusedTransitions)).toEqual(apps.map(() => 0));
3737+
const secondPass = Object.values(half.seed.secondPass ?? {}).reduce((a, b) => a + b, 0);
3738+
expect([apps[0]!.writes.update, apps[0]!.writes.delete, apps[0]!.writes.insert]).toEqual([secondPass, 0, half.seed.inserted]);
3739+
// Every copy holds the agent's iterate: installed with the items the iterated host serves, read decorations off.
3740+
const names = (a: OneWayApp) => ((a.installed!.objects ?? []) as Array<{ name: string }>).map((o) => o.name);
3741+
expect(names(apps[0]!)).toContain('democrm_opportunity'); // the scripted iterate's object, made live on the host only
3742+
expect(apps.length).toBeGreaterThan(1);
3743+
for (const copy of apps.slice(1)) expect(names(copy)).toEqual(names(apps[0]!));
3744+
expect([life.boots, life.stops]).toEqual([apps.length, apps.length]);
37223745
});
37233746

37243747
it('⛔ a copy whose seed does not load as the run\'s did, or that does not boot, leaves the operation NOT MEASURED with the reason, never graded on other rows', async () => {

0 commit comments

Comments
 (0)