Skip to content

Commit e5c2d76

Browse files
feat(spec): IAutomationService.dryRun contract, a dry run of an unpublished flow definition (#33799)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XGs79gt89M449LFtvtMBbiv)_ domain:spec#1 · os-project-manager · session_01FEkQ5nK9bbdtG9bJTBujTZ Fixes #33757 Clause-②: yes (widening) Metadata-protocol: none Refs #33661 (the implementation in `@objectstack/service-automation` and `@objectstack/runtime`, which waits on this contract). objectstack-ai/cloud#3309 item 5, option A, ruled by the account owner. ## 维护者速读 - 改了什么:自动化服务的接口定义 `IAutomationService` 新增可选方法 `dryRun(definition, { userId, record, … })`,以及它的入参、结果和步骤类型;方法注释写明试跑规则。只改接口与说明,不改任何运行时行为。第二至五轮按契约复审补上:开始条件不成立或求值出错时的结果(判定顺序与已发布流程的运行一致;流程声明重试策略时,求值出错的答复是试跑自己的,引擎侧见 #33935)、写入权限的三态答复(允许 / 拒绝 / 未判定)、并行分支的步骤顺序。 - 为什么改:应用内 AI 写的流程要在发布前先给用户看效果(cloud#3309 第 5 项,方案 A)。平台现在只能运行已发布的流程,#33661 要实现试跑,先要有这份契约。 - 风险与回滚:纯新增的可选成员和新类型,已有成员、类型和错误码都没动,不实现它的服务仍满足接口。回滚即还原本 PR。 - 先看:`packages/spec/src/contracts/automation-service.ts` 的 `dryRun?(` 注释块(L1787–L1952,试跑规则,L1797 起是判定顺序);同文件 L1440–L1709 的新类型(L1594 写入权限三态,L1701 `startCondition`);`automation-dry-run.pin.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/spec exec vitest run src/contracts/automation-dry-run.pin.test.ts`,预期 5 条全绿。 - 需要你做的:无,席位落地。 ## What changes `packages/spec/src/contracts/automation-service.ts`: - **`IAutomationService.dryRun?(definition: unknown, options: FlowDryRunOptions): Promise<FlowDryRunResult>`** (L1953), **optional**. Measured: every `IAutomationService` member past `execute` and `listFlows` is optional, and `canonicalizeStoredFlow?` is optional for the same reason this is ("only the implementation that registers flows can offer this"). A caller that finds it absent says a dry run is not available. - **`FlowDryRunOptions`** (L1450): a required `userId`; `record`, `previous`, `object`, `event`, `params` and `locale` picked from `AutomationContext` (the keys `execute` reads); and `tenantId`, which must be an organization the named user is a member of. No grants slot: positions, permission sets, posture and email are resolved by the engine for the named user. - **`FlowDryRunStatus`** (L1504): `'completed' | 'condition_not_met' | 'stopped' | 'failed' | 'refused'`, each defined in its doc. - **`FlowDryRunResult`** (L1672): `status`, one ordered `steps` list, `refusal` (`{ code, message }`, set exactly on `'refused'`), `startCondition` (`{ expression, result: false }` on `'condition_not_met'`, or `{ expression, fault }` on a `'failed'` whose start condition threw; never both), `error` (set exactly on `'failed'`). No `runId`. - **`FlowDryRunRefusalCode`** (L1513): `Extract` of two existing `AutomationResult.code` members (`PERMISSION_DENIED`, `FLOW_INPUT_SCHEMA_INVALID`). No code minted. - **`FlowDryRunWritePermission`** (L1594): `'allowed' | 'refused' | 'not_judged'`: an insert or update is `'allowed'` or `'refused'` from the object-level check, a delete is `'not_judged'`, and every write is `'not_judged'` when no object-level check is installed. - **`FlowDryRunStep`** (L1662): a union discriminated on `kind`, over `route` (`start`, `end`, `loop`, `parallel`, `try_catch`; an `end` with `outcome: 'refused'` carries `refusalMessage`), `assignment` (values set), `decision` (`branch`, `expressions`, `next`: which branch, and every expression that held), `read` (`object`, `recordIds`), `write` (`operation`, `object`, `recordIds`, `values`, `permission`), `outbound` (`payload`) and `stop` (`reason`: `'approval' | 'wait' | 'screen' | 'starts_flow' | 'suspends' | 'not_simulated'`, with `approvers` / `wait` / `screen` / `flowName`). Every step carries `nodeId`, `nodeType`, and `refusal` (`FlowInnerRefusal`) or `error` when the node met one. - **The method's doc block** (L1787–L1952) states the semantics, one checkable sentence per point: - **Order of answers:** a missing `userId` throws `TypeError`; a definition `registerFlow` would refuse under its own `name` throws what `registerFlow` throws; then a non-member `tenantId` and admission (`status: 'refused'`, `PERMISSION_DENIED`); then a start condition that does not hold (`status: 'condition_not_met'`, mirroring `execute`'s skip exit) or whose evaluation throws (`status: 'failed'`, no steps, the fault in `startCondition` and `error`, mirroring `execute`'s catch on the default error strategy; under `errorHandling.strategy: 'retry'` the dry run's own answer, #33935); `execute`'s re-entrancy guard cannot fire for a dry run; then the node input-schema check (`status: 'refused'`, `FLOW_INPUT_SCHEMA_INVALID`), the order `execute` evaluates the last two in; no steps on any of these; then the nodes. - **The name:** the definition's own `name` is the one registration judges and nodes read their `flows.<flow>.…` keys under; a registered flow of that name is neither read nor touched. - **Unarmed and unregistered:** never registered (absent from `listFlows` / `getFlow`), trigger never armed, one pass with no retry, no run persisted. - **Identity:** acts as `userId` with that user's own resolved grants, never elevated (a `runAs: 'system'` definition included); a door serving a person passes that person's id. - **Admission:** `flowStartRefusal`'s three rules judged on the supplied definition against the named user, no system-principal bypass, each refusal `PERMISSION_DENIED` with the by-name start's message. - **Writes:** simulated, never made; a create binds an opaque placeholder id and the row holds only the fields the flow set (engine-set fields absent); an updated row reads as the live row with the simulated fields laid over it; a filtered read does not see simulated writes; no hook, trigger, other flow or audit row runs; validation, uniqueness and required fields are not judged; each write carries the three-way `permission` (`'not_judged'` never means allowed), and a `'refused'` write's step carries `refusal` (`PERMISSION_DENIED`). - **A node that meets a refusal or fails** is reported, never skipped; the run goes on along a `fault` edge or out of a `try_catch`, or ends `'failed'`, the dry run's own answer in both directions. - **Outbound** (`notify`, `http`, `connector_action`, `script`, `save_notice`): never sent, payload reported, no output bound. - **Stops:** the first node whose descriptor declares `supportsPause: true` stops the run and is reported by what it would do; no approval request, no resume, no child run. Any node type outside the named classes stops as `not_simulated`. - **Step order:** side-by-side branches are listed branch by branch in declaration order, each branch's steps together; for unconditional fan-out that is the dry run's own order and can differ from the live step log. Generated: `packages/spec/api-surface/contracts.json` and `packages/spec/export-origins/contracts.json` (the 14 new exported types), regenerated on the tree merged with `main` at `1e65a389`. Changeset: `.changeset/33757-flow-dry-run-contract.md`, `@objectstack/spec` patch (`Metadata-protocol: none`; AGENTS.md §3, every entry `patch`). ## Round 2 Answers contract review 6893425750 (FAIL at `0695d5ce`) under the seat's ruling 6893433747. Head `f635d5af`; `main` merged first (`bd969ec5`, no text conflict, the two generated files regenerated after). - **F1 (start condition).** New status `'condition_not_met'` and `FlowDryRunResult.startCondition: { expression; result: false }`. Its place in the answer order was wrong at `f635d5af` (after the input-schema refusal) and is corrected in round 3 (S10, below): after admission and before the input-schema check, as `execute` evaluates them (`engine.ts` L7711–L7731 on the merged tree: the start node's `condition`, a plain string routed through CEL, evaluated before the re-entrancy guard; the skip answers `output: { skipped: true, reason: 'condition_not_met' }`). - **F2 (permission).** `FlowDryRunWritePermission` and a required `permission` on every write step: `'allowed'` / `'refused'` from `canWriteObject` (insert / update) as the named user, `'allowed'` never meaning the write would succeed; `'not_judged'` for every delete and for everything `canWriteObject`'s own doc disclaims (row-level and post-image rules, controlled-by-parent, the tenant post-image, provenance gates, the `owner_id` forge). The doc says once that `'not_judged'` never means allowed. The round-1 sentence that promised a `refusal` for any permission refusal is gone; `FlowDryRunStepBase.refusal`'s example is now a read refused in the user's scope. - **F3 (routing nodes, order).** `parallel_gateway` / `join_gateway` (no executor on the tree) replaced by the shipped `parallel` (`builtin/parallel-node.ts`). Measured order: a `parallel` node's run record lists each branch's steps together in `config.branches` order (`branchSteps.flat()` over `Promise.all`, which keeps input order); an inclusive decision takes its branches one at a time, depth-first, in out-edge order (`dag-traversal.ts` L726–L752, "never `Promise.all`"); several unconditional out-edges run under `Promise.all` and the live log interleaves them (L786–L793). The contract lists every side-by-side case branch by branch in declaration order, each branch's steps together, so the dry run's list is deterministic; for unconditional fan-out that is the dry run's own order, not the live log's. - **F4.** `FLOW_NO_START_NODE` removed from `FlowDryRunRefusalCode` (registration refuses that definition, so the throw answers first), with a one-line note in the type's doc and an `@ts-expect-error` pin. - **F5.** `'failed'` now reads "the dry run could not continue past a step", the equivalence claim is gone, and both directions are named: unset outbound output, a never-elevated `runAs: 'system'` draft and a filtered read missing a simulated write (fails where the live run would not); validation, uniqueness, required fields and unjudged refusals (passes where the live run would fail). - **F6.** An updated row reads as the live row with the simulated fields laid over it; a created row holds only the fields the flow set, and the engine-set fields (defaults, autonumbers, formulas, the owner, timestamps) are absent. - **N7.** The definition's own `name` stands where `registerFlow` takes one: the name registration judges and the per-flow key nodes read; no registered flow is read or touched. - **N8.** Measured: no run setup refuses a `tenantId` today. `resolveUserAuthzGrants` applies positions and permission sets only in their own organization, so a non-member resolves none of them there, but it still lists that organization's members in `org_user_ids` (`resolve-authz-context.ts` L2494–L2504). The contract therefore makes the membership refusal the dry run's own: `status: 'refused'`, `PERMISSION_DENIED`, before admission. - **N9.** Stop reasons are what the node would do (`'approval'`, `'wait'`, `'screen'`, `'starts_flow'`, `'suspends'`, `'not_simulated'`); `FlowDryRunDecisionStep.expressions` is a list of every expression that held, in declaration order (empty on the default branch). - **Pin test** moved sentence by sentence (the five statuses, the two codes, the three permissions, the six stop reasons, `startCondition`, `expressions`, and the new doc sentences); both ablations re-run on the new head. ## Round 3 Answers delta review 6894214508 (FAIL at `f635d5af` on S10; F1–F6 and N7–N9 closed) under the seat's ruling 6894244795. Head `5753362e`. `main` has moved since `1e65a389` but touches none of the PR's files, so no merge this round. - **S10 (answer order).** "In what order it answers" now follows `execute`: a non-member `tenantId` and admission (`PERMISSION_DENIED`), then the start condition (`'condition_not_met'`), then the node input-schema check (`FLOW_INPUT_SCHEMA_INVALID`). The start-condition bullet names that order ("`execute` evaluates the start condition before its node input-schema check, so a condition that does not hold answers first"; `engine.ts` L7724, then `validateNodeInputSchemas` ~L7787, as the review measured). The pin gains one assertion on the three bullets' order, and the round-2 F1 line above is corrected. - **N11.** The `failedOnPermission` fixture's `'refused'` write step carries `refusal: { code: 'PERMISSION_DENIED', … }`, and the method doc now says so: a `'refused'` write's step carries `refusal` (`code: 'PERMISSION_DENIED'`). - **N12.** Method doc and type doc agree: an insert or update answers `'allowed'` or `'refused'`, a delete answers `'not_judged'`, and the refusals the check does not judge are never reported for any operation. Measured for "no object-level check installed": `canWriteObject` is a method of `@objectstack/plugin-security`'s service (`security-plugin.ts` L3747) and is not on `ISecurityService` (`contracts/security-service.ts` declares only `canReadObject?`); no other package calls it. So a kernel without that plugin has no such check, and both docs say every write step then answers `'not_judged'`. - **N13.** The step-order text (method doc and `FlowDryRunResult.steps`) says that for a node's unconditional out-edges the list is the dry run's own order: the live run runs them under `Promise.all`, and its step log can interleave them. ## Round 4 Answers delta review 6895013488 (FAIL at `5753362e` on S14; S10 and N11–N13 closed) under the seat's ruling 6895023324. Head `58c56c95`. No type is added or renamed, so both generated baselines are unchanged (regenerated, no diff). - **S14 (a start condition that throws).** Measured: `evaluateCondition` throws when the CEL result is not ok, and on a structural or `template` / `flow` dialect refusal (`dag-traversal.ts` L1118–L1188: L1129, L1142, L1173, L1184). In `execute` that throw happens at the start-condition gate (`engine.ts` L7724), before the re-entrancy guard (L7762) and `validateNodeInputSchemas` (L7787); the catch sets `errorMessage = err.message` (L8020) and, not being an `InputSchemaViolationError`, answers `success: false`, `status: 'failed'`, `error: errorMessage` with no node executed (or hands it to the retry strategy, which a dry run never uses: "one pass with no retry"). The contract now says the same in three places: - the answer-order list (L1806): a `condition` whose evaluation throws answers `status: 'failed'` and no steps, the condition and the thrown message in `startCondition` (`fault`) and the same message in `error`, before the input-schema check; - the `'failed'` status doc (L1481–L1495): "could not continue past a step, or could not evaluate the start condition", with its own sentence for the condition case (no steps; this one follows the live run); - `FlowDryRunResult` (L1667–L1701): `steps` is empty on that `'failed'`; `startCondition` is `{ expression; result: false; fault?: never } | { expression; fault: string; result?: never }`, set exactly when the run ended on the condition, `fault` being the text `execute` answers as `error`. - **N15.** One bullet in the order list (L1812): `execute`'s re-entrancy guard (`reentrancy_loop_guard`), which sits between the two checks, cannot fire for a dry run, since a dry run holds no active-run key and writes nothing. - **Changeset** (review ②): the writes bullet now reads as the contract does: an insert or update answers `allowed` or `refused` from the object-level write check, a delete answers `not_judged`, every write answers `not_judged` when no object-level check is installed, `not_judged` never means allowed, and row-level refusals are never reported. The start-condition bullet gains the faulting case. - **Pin:** `StartConditionShape` pins the two-arm shape; `bothResultAndFault` (`@ts-expect-error`) refuses `result` and `fault` together; a `conditionFaulted` fixture (`'failed'`, no steps, `startCondition.fault`, `error`); three new pinned sentences (the faulting-condition sentence, its `startCondition` (`fault`) clause, the re-entrancy clause); the order assertion now also requires the faulting-condition sentence between "Then the start condition." and "Then the node input-schema check". ## Round 5 Answers delta review 6896167662 (FAIL at `58c56c95` on S16; S14 and N15 closed) under the seat's ruling 6896183344. Head `2baaacd9`. No type or export changes, so both generated baselines are unchanged (regenerated, no diff). - **S16 (the faulting condition under the retry strategy).** Measured: in `execute`'s catch the strategy branch (`engine.ts` L8166) comes before the `'failed'` return, and `retryExecution`'s attempts go through `executeWithoutRetry` (`dag-traversal.ts` L1232), which finds the start node, runs `validateNodeInputSchemas` and then `executeNode` with no start-condition evaluation. So the round-4 "follows the live run" holds on the default error strategy only. The dry run's answer is unchanged (`'failed'`, no steps, `startCondition.fault`, the same text in `error`; "runs once per call, with no retry"), and each of the three sentences now carries the qualifier. On the default strategy it is the live run's answer. Under `errorHandling.strategy: 'retry'` it is the dry run's own, because the live run hands the throw to `retryExecution`, whose attempts skip the start condition and run the nodes. Each names #33935, the engine card, so the clause can go when it lands: - the order list (L1814–L1825); - the `'failed'` status doc (L1490–L1498), which now says "it is the dry run's own answer, not a prediction" for that case; - the `startCondition` doc (L1694–L1699). - **Changeset:** the start-condition bullet carries the same clause and names #33935. - **N17.** The `'failed'` status doc's first paragraph is rewrapped to the block's 80 columns (L1481–L1489). No pinned string crossed it. - **Pin:** two pinned sentences in the method doc follow the qualifier ("On the default error strategy that is the live run's answer", "Under `errorHandling.strategy: 'retry'` the answer is the dry run's own"). A new test requires "On the default error strategy", "`errorHandling.strategy: 'retry'`" and "#33935" in each of the three docs. It also requires the `'failed'` doc's "it is the dry run's own answer, not a prediction", and the round-4 unqualified sentence ("This one follows the live run, whose") is gone from the file. ## Tests `packages/spec/src/contracts/automation-dry-run.pin.test.ts` (the `automation-toggle-flow-caller` pin's form, compiled by `check:test-typecheck`): - **Signature and optionality** at the type level (`Eq`), plus a service class without `dryRun` that still implements `Pick<IAutomationService, 'execute' | 'listFlows' | 'dryRun'>`. - **Options:** `userId` required; no grants and no run-as channel (`@ts-expect-error` on `positions`, `permissions`, `posture`, `email`, `runAs`). - **Closed unions:** the five statuses, the two refusal codes (each an existing `AutomationResult.code` member; `FLOW_NO_START_NODE` refused by `@ts-expect-error`), the seven step kinds, the write operations, the three write permissions (required on every write step), the six stop reasons, `expressions: string[]`, the `startCondition` shape (two arms since round 4, never both); no `runId` on the result. - **Doc block:** the `dryRun` doc block must hold each ruled heading (including **The name.** and **Step order.**) and the key sentences (`'condition_not_met'`, `'not_judged'` never means allowed, the no-check-installed sentence, the refused-write `refusal` sentence, the overlay and created-row sentences, the step-order sentences, "could not continue past this"). - **Answer order (rounds 3 and 4):** one assertion that the admission bullet, the start-condition bullet, the faulting-condition sentence and the input-schema bullet appear in that order. - **Faulting start condition (rounds 4 and 5):** the `conditionFaulted` fixture, the doc sentences named above, and one test that the three docs qualify the live-run claim by the error strategy and name #33935. <details><summary>Ablations (each red, then restored with <code>git diff HEAD</code> empty)</summary> All through `node scripts/ablation-replace.mjs` (anchor hit 1 → 0; restore blob == HEAD each time). No `dist/` is involved: the pin imports `./automation-service` by relative path. Round 2, on `f635d5af` (restore blob `d6385572f811`): 1. Deleted "`'not_judged'` never means allowed." from the method doc → `AssertionError: \`'not_judged'\` never means allowed.: expected '/**\n * Dry-run a flow definition…' to contain …`, `Tests 1 failed | 2 passed (3)`. 2. Put `'FLOW_NO_START_NODE'` back into `FlowDryRunRefusalCode` → `tsc -p tsconfig.test.json`: `automation-dry-run.pin.test.ts(97,50): error TS2344: Type 'false' does not satisfy the constraint 'true'.` and `(98,1): error TS2578: Unused '@ts-expect-error' directive.` Round 3, on `5753362e` (restore blob `347e545f59f7`): 3. Swapped the start-condition and input-schema bullets back to the round-2 order → `× answers in the live run's order: admission, then the start condition, then the input-schema check`, `AssertionError: answer order at 991, 1274, 1096: expected false to be true`, `Tests 1 failed | 3 passed (4)`. Round 4, on `58c56c95` (restore blob `223d130181b1`): 4. Deleted the faulting-condition sentence from the order list → `× the method's doc block states each ruled point` (`AssertionError: A \`condition\` whose evaluation throws: expected '/**\n * Dry-run a flow definition…' to contain …`) and `× answers in the live run's order …` (`answer order at 991, 1096, -1, 1901`), `Tests 2 failed | 2 passed (4)`. 5. Narrowed `startCondition` back to `{ expression: string; result: false }` → `tsc -p tsconfig.test.json`: `automation-dry-run.pin.test.ts(100,43): error TS2344: Type 'false' does not satisfy the constraint 'true'.` and `(167,9): error TS2353: Object literal may only specify known properties, and 'fault' does not exist in type '{ expression: string; result: false; }'.` Round 5, on `2baaacd9` (restore blob `da99c730352e`): 6. Put the round-4 unqualified sentence back into the `'failed'` doc → `× a faulting start condition follows the live run only on the default error strategy (#33935)`, `AssertionError: the 'failed' status doc: expected '/**\n * The overall answer of {@link …' to contain 'On the default error strategy'`, `Tests 1 failed | 4 passed (5)`. 7. Deleted the retry clause from the order list → `× the method's doc block states each ruled point` and the strategy test (`the dryRun doc block: … to contain '\`errorHandling.strategy: \'retry\'\`'`), `Tests 2 failed | 3 passed (5)`. </details> ## Acceptance notes - **Readings beyond the order, accepted by the seat's ruling 6893433747:** `script` as outbound; `subflow` / `map` stop (via `supportsPause: true`, now reason `'starts_flow'`); the `not_simulated` stop; the `'failed'` status (reworded per F5); simulated writes not judged by validation. - **The `runAs: 'system'` question** (review ③): unchanged here, per the ruling. Rule 1 still refuses a `runAs: 'system'` definition of type `autolaunched`, `record_change` or `schedule` for every named user; the seat takes it to the maintainer on #33661. Admitting it later, still never elevated, would be a widening of this contract. - **What #33661 inherits.** `flowStartRefusal` lives in `@objectstack/runtime` and reads the caller's `ExecutionContext`; `@objectstack/service-automation` does not depend on runtime. The named user's `systemPermissions` and `principalKind: 'agent'` are both resolvable from a user id through `resolveUserAuthzGrants`, so the rules can be judged in the service without a second copy of the predicate, provided #33661 moves it where both packages reach it. The permission answer needs `canWriteObject` (plugin-security, not on `ISecurityService`) reachable from the run, with `'not_judged'` where it is not; the tenant membership read is new. - Not filed: nothing out of scope was found. ## Verification All on head `2baaacd9` (the round-2 merge with `main` at `1e65a389` plus the round-3, round-4 and round-5 commits; later `main` commits touch none of this PR's files). - `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2` (whole spec suite, under the verify lock): `Test Files 934 passed (934)`, `Tests 28511 passed | 1 todo (28512)`, `VERDICT command-exit 0`. - `pnpm --filter @objectstack/spec typecheck` (`tsc --noEmit`, `check:scripts-typecheck`, `check:test-typecheck` under `tsconfig.test.json`, 8 GB heap): `VERDICT command-exit 0`. The pin file adds no diagnostic and no debt-ledger entry. - Derived gates: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `2baaacd9` → the same 88 families, each run with its exit code captured before any pipe, after building `@objectstack/lint...`, `@objectstack/objectql...` and `@objectstack/spec` (each exit 0). `check:generated` and `check:api-surface` among them, exit 0 (rounds 4 and 5 change no exported name, so both baselines regenerate with no diff). `--ran`: `88 derived famil(ies) accounted for — 87 run, 1 NOT-MEASURED`. - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: exit 3, PREREQUISITE NOT MET (it reads every package's `dist/`). CI runs it. - Not run locally, CI's: repo-wide `pnpm lint`, `test:repo`, the dogfood battery (no `!` in the title and no `(narrowing)` arm). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (Interface and types only; the contract members are TypeScript interfaces like the rest of the file.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (Repo-wide lint is CI's run.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5nK9bbdtG9bJTBujTZ)_ <!-- signed: domain:spec#1 · os-project-manager · session_01FEkQ5nK9bbdtG9bJTBujTZ --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 0ff3b14 commit e5c2d76

5 files changed

Lines changed: 755 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
feat(spec): `IAutomationService.dryRun`, a dry run of a flow definition that need not be published: once, unarmed, as a named user, against a supplied start, without changing live data (#33757)
6+
7+
Clause-②: yes (widening) — a new optional member on `IAutomationService` and new exported types. No existing member, type or code changes, and an implementation without the member still satisfies the contract.
8+
Metadata-protocol: none
9+
10+
The contract half of #33661 (objectstack-ai/cloud#3309 item 5, option A, ruled by the account owner); #33661 implements it in `@objectstack/service-automation` and `@objectstack/runtime`. The method's doc block states the semantics the implementation owes:
11+
12+
- **Writes are simulated, never made.** `create_record`, `update_record` and `delete_record` report the write they would make (object, operation, target rows, values as computed) and a three-way `permission`: an insert or update answers `allowed` or `refused` from the object-level write check, a delete answers `not_judged`, and every write answers `not_judged` when no object-level check is installed; `not_judged` never means allowed, and row-level refusals are never reported. A create binds an opaque placeholder id that later reads by id see, holding only the fields the flow set; an updated row reads as the live row with the simulated fields laid over it. No hook, trigger, other flow or audit row runs, since nothing is written.
13+
- **Identity is the named user**, whose own grants the engine resolves, and the run is never elevated, a `runAs: 'system'` definition included. A `tenantId` must be an organization the user is a member of. Admission is the by-name start rule (`flowStartRefusal`), judged on the supplied definition against the named user; a refusal answers `status: 'refused'` with `PERMISSION_DENIED`, before any node runs.
14+
- **A start condition that does not hold** answers `status: 'condition_not_met'` with the condition, mirroring the live run's skip exit. One whose evaluation throws answers `status: 'failed'` with no steps, the condition and the thrown message in `startCondition`, as the live run's catch does on the default error strategy; under `errorHandling.strategy: 'retry'` the live run's retry attempts do not evaluate the start condition (#33935), so there the dry run's answer is its own. Both answer before the node input-schema check.
15+
- **Approval nodes and waits stop the run** (every node type whose descriptor declares `supportsPause: true`), reported with who would be asked, what would resume it, the screen, or the flow it would start. Nothing is created or scheduled.
16+
- **Side effects outside the data** (`notify`, `http`, `connector_action`, `script`, `save_notice`) are never sent, only reported with their computed payload.
17+
- **Unarmed and unregistered**: never registered or listed, the trigger never armed, no run persisted, one pass with no retry. An invalid definition throws what `registerFlow` throws.
18+
19+
**In-process APIs.** `@objectstack/spec/contracts` exports `FlowDryRunOptions`, `FlowDryRunResult`, `FlowDryRunStatus`, `FlowDryRunRefusalCode`, `FlowDryRunWritePermission`, `FlowDryRunStep` and the step types it unions over (`FlowDryRunStepBase`, `FlowDryRunRouteStep`, `FlowDryRunAssignmentStep`, `FlowDryRunDecisionStep`, `FlowDryRunReadStep`, `FlowDryRunWriteStep`, `FlowDryRunOutboundStep`, `FlowDryRunStopStep`). All additive.

‎packages/spec/api-surface/contracts.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@
130130
"FieldFileDescription (interface)",
131131
"FieldFileSlot (interface)",
132132
"FinishReason (type)",
133+
"FlowDryRunAssignmentStep (interface)",
134+
"FlowDryRunDecisionStep (interface)",
135+
"FlowDryRunOptions (interface)",
136+
"FlowDryRunOutboundStep (interface)",
137+
"FlowDryRunReadStep (interface)",
138+
"FlowDryRunRefusalCode (type)",
139+
"FlowDryRunResult (interface)",
140+
"FlowDryRunRouteStep (interface)",
141+
"FlowDryRunStatus (type)",
142+
"FlowDryRunStep (type)",
143+
"FlowDryRunStepBase (interface)",
144+
"FlowDryRunStopStep (interface)",
145+
"FlowDryRunWritePermission (type)",
146+
"FlowDryRunWriteStep (interface)",
133147
"FlowRuntimeState (interface)",
134148
"FlowUnboundCause (type)",
135149
"GenerateDraftOpts (interface)",

‎packages/spec/export-origins/contracts.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@
130130
"FieldFileDescription": "src/contracts/storage-service.ts#FieldFileDescription (interface)",
131131
"FieldFileSlot": "src/contracts/storage-service.ts#FieldFileSlot (interface)",
132132
"FinishReason": "node_modules/ai/dist/index.d.ts#FinishReason (type)",
133+
"FlowDryRunAssignmentStep": "src/contracts/automation-service.ts#FlowDryRunAssignmentStep (interface)",
134+
"FlowDryRunDecisionStep": "src/contracts/automation-service.ts#FlowDryRunDecisionStep (interface)",
135+
"FlowDryRunOptions": "src/contracts/automation-service.ts#FlowDryRunOptions (interface)",
136+
"FlowDryRunOutboundStep": "src/contracts/automation-service.ts#FlowDryRunOutboundStep (interface)",
137+
"FlowDryRunReadStep": "src/contracts/automation-service.ts#FlowDryRunReadStep (interface)",
138+
"FlowDryRunRefusalCode": "src/contracts/automation-service.ts#FlowDryRunRefusalCode (type)",
139+
"FlowDryRunResult": "src/contracts/automation-service.ts#FlowDryRunResult (interface)",
140+
"FlowDryRunRouteStep": "src/contracts/automation-service.ts#FlowDryRunRouteStep (interface)",
141+
"FlowDryRunStatus": "src/contracts/automation-service.ts#FlowDryRunStatus (type)",
142+
"FlowDryRunStep": "src/contracts/automation-service.ts#FlowDryRunStep (type)",
143+
"FlowDryRunStepBase": "src/contracts/automation-service.ts#FlowDryRunStepBase (interface)",
144+
"FlowDryRunStopStep": "src/contracts/automation-service.ts#FlowDryRunStopStep (interface)",
145+
"FlowDryRunWritePermission": "src/contracts/automation-service.ts#FlowDryRunWritePermission (type)",
146+
"FlowDryRunWriteStep": "src/contracts/automation-service.ts#FlowDryRunWriteStep (interface)",
133147
"FlowRuntimeState": "src/contracts/automation-service.ts#FlowRuntimeState (interface)",
134148
"FlowUnboundCause": "src/contracts/automation-service.ts#FlowUnboundCause (type)",
135149
"GenerateDraftOpts": "src/contracts/external-datasource-service.ts#GenerateDraftOpts (interface)",

0 commit comments

Comments
 (0)