Repository navigation
Commit f7b2d02
feat(automation): IAutomationService.dryRun runs an unpublished flow once, unarmed, as a named user (#34477)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XTThuYNZSKyejbiF4WXQyHm)_
Fixes #33661
Clause-②: yes (widening) — `AutomationEngine.dryRun` admits a `runAs:
'system'` self-triggered draft for the named user (ruling B);
`@objectstack/core` exports the shared flow-start rules
(`aiAccountElevatedStartRefusal`, `requiredPermissionsStartRefusal`,
`requiredPermissionsRefusal`, `missingCapabilities`,
`isAiServiceAccount`, `AI_ACCOUNT_ELEVATED_START_REFUSAL`,
`FlowStartPermissionRefusal`); plugin-security's registered `security`
service serves `canWriteObject`
Metadata-protocol: none
## 维护者速读
-
**改了什么**:自动化服务新增「试跑」:把一份未发布的流程定义,以指定用户的身份、针对一条给定记录跑一次;写记录只模拟不落库,外发(HTTP、邮件等)只展示载荷不发送,遇到审批、等待、屏幕节点就停下并说明原因。
- **为什么改**:让作者在发布前看到流程每一步会做什么、会写哪些值、会不会被权限拒绝,而不必真的触发或改数据;同时落实维护者裁决 B(以
`runAs: 'system'` 声明的自触发草稿可以试跑,但只按试跑人的权限,绝不提权)。
- **风险与回滚**:风险集中在试跑把写操作拦在门外这一层,漏拦就会真写数据;测试逐类断言了「零写入」。准入规则从 runtime 下沉到
core 共用一份,按名启动的行为不变(runtime 609 个测试文件全绿)。回滚即 revert 本 PR,无数据迁移。
-
**先看**:`packages/services/service-automation/src/dry-run.ts`(写拦截的数据引擎代理
`dryRunDataEngine` 与 `dryRun`
准入顺序);`packages/core/src/security/flow-start-rules.ts`(两条共用准入规则);`packages/plugins/plugin-security/src/security-plugin-security-service.ts`(security
服务新暴露 `canWriteObject`)。
- **两分钟验证**:`pnpm --filter @objectstack/service-automation exec vitest
run src/dry-run.test.ts`,预期 30 个测试全过,其中包括「审批节点停下且从未被调用」和「零写入」的断言。
- **需要你做的**:批准本 PR
里的契约改动(`packages/spec/src/contracts/automation-service.ts` 中 dryRun
准入那一条,按裁决 B 改写)。裁决记录 6917953931 写明契约改动在实现落地前欠契约评审和你的批准;L1 与契约评审在同一 head
通过后,席位会请你批准,批准后由席位落地。
## What changes
**`AutomationEngine.dryRun(definition, options)`** implements the
`IAutomationService.dryRun` contract. The run is unarmed and
unregistered. It runs as the named user against the supplied record, and
it writes, sends and pauses nothing.
- **Admission, in the contract's order.**
1. A missing `userId` throws a `TypeError`.
2. The definition goes through `registerFlow`'s own checks, now one
private `judgeFlowRegistration` that both call, so a dry run throws
exactly what `registerFlow` throws.
3. Tenant membership comes from the grants resolver's
`accessible_org_ids`.
4. The by-name start rules: the AI service account rule, then the flow's
`requiredPermissions`.
5. The start condition: `condition_not_met`, or `failed` with the fault.
6. The input schema.
- **Ruling B (record 6917953931).** A self-triggered `runAs: 'system'`
draft is admitted for the named user, and its run context always
resolves as `runAs: 'user'`, so it is never elevated. The contract
bullet now says so, and its pin test holds the new sentences and the
absence of the old one.
- **One spelling of the shared rules.** The AI service account rule and
the `requiredPermissions` rule moved down to `@objectstack/core`
(`security/flow-start-rules.ts`), because service-automation does not
depend on runtime. `flowStartRefusal` in runtime and `dryRun` both call
`aiAccountElevatedStartRefusal` and `requiredPermissionsStartRefusal`.
Runtime re-exports every moved symbol under its old name
(`AI_ACCOUNT_ELEVATED_START_REFUSAL`, `isAiServiceAccount`,
`requiredPermissionsRefusal`, `FlowStartPermissionRefusal`,
`missingCapabilities`). The elevated self-triggered rule stays in
runtime, since only the by-name doors ask it.
- **Traversal** reuses the engine's own `executeNode` and `traverseNext`
bodies on a dry host, so routing and compute nodes run on the real
executors: assignment, decision, gateways, loop, parallel and try/catch.
Region bodies (loop, parallel, try/catch) are diverted into the dry run
through `activeDryRunExecuteNode()`, so a write inside a loop is
simulated too.
- **Writes.** The CRUD nodes' data engine is wrapped by
`dryRunDataEngine` while a dry run is active.
- Insert, update and delete are simulated. A new record gets a
`dry-run:UUID:N` placeholder id.
- An update or delete targets exactly the rows the engine's own dispatch
picks: the one id it names (from the filter, or an update's own `id`
value), the filter's rows under `multi`, or none when it refuses the
call (the engine's own error).
- A read by id sees the simulated row laid over the live one. A filtered
read answers the live rows only, as the contract says.
- An insert or update is judged by `canWriteObject` for the named user
(`allowed` or `refused`). A delete, or a kernel with no check installed,
answers `not_judged`.
- A check that throws is a denial (`refused`). An update or delete by
predicate without `multi` fails with the engine's own error and targets
no row.
- A refused write's step carries `PERMISSION_DENIED`. The run goes on
along a `fault` edge or out of a `try_catch` region that contains it,
and otherwise ends `failed` with that write as the last step.
- **Outbound nodes** never execute and bind no output. Their step
reports the payload, built from the spec's expression and text-slot
ledgers.
- **Stops.** A node whose descriptor `supportsPause` stops the run with
a class: `approval`, `wait`, `screen` (its ScreenSpec is built by the
real screen executor), `starts_flow` or `suspends`. A type no class
covers stops the run as `not_simulated`.
- **`security` service.** The registered service now serves
`canWriteObject`, so the dry run can judge a write without performing
it.
## Tests
- `packages/services/service-automation/src/dry-run.test.ts`, 30 tests:
- Each node class the in-app v2-narrow tier offers: `create_record`
(placeholder id, computed values, zero writes, a read by id sees the
simulated row), `update_record` (live target, overlay read, the write
check asked with the non-system named user), `assignment`, `decision`
(branch, expressions, `next`; also a gateway decision), and `approval`
(stops, and the executor is never called).
- Admission refusals: the `requiredPermissions` refusal equals
`requiredPermissionsRefusal` from core, the AI account refusal equals
`AI_ACCOUNT_ELEVATED_START_REFUSAL`, a non-member organization is
refused, ruling B admits without elevating, plus the TypeError, the
`registerFlow` throw, `condition_not_met` and a faulted condition.
- Also: a refused write, `not_simulated`, a write inside a loop, and an
outbound `http` payload with nothing sent.
- Review round: a `save_notice` payload and a refusing `end` node in
zh-CN through their translation keys; a refused write going on along its
`fault` edge; a write check that throws is refused; unread grants (a
failed read, an empty answer, no resolver) refuse a `runAs: 'system'`
draft; an update or delete by predicate without `multi` fails with the
engine's own message, with a `multi` control; an update whose fields
name the id, with no filter, targets that one row, with a `multi`
control targeting every readable row.
- The `automation-dry-run.pin.test.ts` contract pin was updated for
ruling B.
- `registered-security-service-members.pin.test.ts` ledgers
`canWriteObject` with its reason (see Acceptance notes).
## Acceptance notes
- **`canWriteObject` stays off `ISecurityService`: settled by the
published contract.** The dryRun contract of #33757
(`FlowDryRunWritePermission`, contract-reviewed) names it "a method of
`@objectstack/plugin-security`'s service, not of `ISecurityService`". On
`main` the registered service did not serve it; this PR serves it and
ledgers it in `SERVED_NOT_DECLARED`, citing that contract. That pin's
header now states the exception: a member a published contract places
off `ISecurityService` stays off it, and its entry cites that contract.
Declaring it on `ISecurityService` would be a separate contract change
and is not part of this PR.
- **Surface beyond the claim.** The claim named service-automation and
spec. This PR also touches:
- `@objectstack/core`: the shared rules.
- `@objectstack/runtime`: re-exports only.
- `@objectstack/plugin-security`: `canWriteObject` on the service.
- `scripts/engine-double-contract.pinned.json`: the gate's own `--write`
for the new pinned test double.
- **Text slots** in an outbound payload render as their live executor
renders them, in `options.locale`. `save_notice`'s message reads its
`flows.FLOW.notices.NODE.message` translation through that executor's
own renderer; a refusing `end` node's message reads its translation too.
`notify` and `http` render the authored text, as their live executors
do.
- **Known approximations, each inside the contract's words:**
- Approvers are omitted from an approval stop ("when the run can resolve
them").
- An unconditional fan-out still runs its branches concurrently. Its
steps are grouped per branch, depth-first.
- A grants resolver that throws, answers nothing, or is not wired fails
closed: refused for a tenant, for a declared `requiredPermissions`, and
for a `runAs: 'system'` definition, because the AI service account rule
cannot be asked without the grants. That last refusal carries the dry
run's own message.
- An update or delete by predicate with `multi` lists every row it
targets, uncapped, since `FlowDryRunWriteStep.recordIds` is defined as
the rows the write targets.
- Not touched: cloud's `test_flow`, every HTTP or MCP door, the #33935
retry clause, `docs/adr/**`, `skills/**`.
## Verification
Readings are on head `3392bc4f0` for service-automation and the dry-run
suite, and on `4889de397` for spec, plugin-security, core and runtime,
which the last round did not touch. The first ablation below was run on
`2e47ef291`.
- **Tests** (under `os-verify-lock`, VERDICT command-exit 0 for each):
- `@objectstack/service-automation`: 286/286 files, 4082/4082 tests
(`3392bc4f0`).
- `@objectstack/runtime`: 609/609 files, 11271 passed, 19 skipped.
- `@objectstack/core`: 149/149 files, 3595/3595 tests.
- `@objectstack/spec`: 845/845 files, 27059 passed, 1 todo.
- `@objectstack/plugin-security`: 273/273 files, 6824 passed, 45
skipped.
- `dry-run.test.ts` 30/30 (`3392bc4f0`); the member pin 4/4 and the spec
dry-run pin 5/5 (`4889de397`).
- **Typecheck:** `core`, `runtime`, `plugin-security` and
`service-automation` are green, `check:test-typecheck` included.
Runtime's first attempt was red only because `@objectstack/driver-turso`
had no dist. Building the dependency closure fixed it.
- **Ablations.** On `2e47ef291`, the dry run's admission call was
replaced with `null` through `scripts/ablation-replace.mjs`.
- Mutation landed: anchor count 1 to 0, blob `bd40dedf94bb` to
`ced6b2f7de22`.
- `dry-run.test.ts` went to 2 failed, 16 passed: the
`requiredPermissions` refusal and the AI account refusal.
- Restore proven: blob equals HEAD and `git diff HEAD` is empty. The
tests import the engine from source, so no dist was involved.
- On `4889de397`, one each for the translation read, the unread-grants
refusal and the throwing write check, through
`scripts/ablation-replace.mjs`: each turned exactly its own pin red (1
failed, 25 passed) and was restored to a blob equal to HEAD with an
empty `git diff HEAD`.
- On `3392bc4f0`, the by-id targeting branch disabled: exactly the
id-targeting pin went red (1 failed, 29 passed), restored to a blob
equal to HEAD.
- **Gates:** `node scripts/pm/dispatch-gates.mjs --commands` derived 108
for this diff.
- On `4889de397`: 108 derived, 108 ran, all exit 0, `check:i18n` and
`check:dual-build-cjs-loads` included. `--ran` reconciliation: 108
derived, 108 run, 0 NOT-MEASURED, 0 UNRUN. On `3392bc4f0`, for the two
files that round touched: 60 derived, 60 ran, all exit 0.
- `node scripts/check-platform-checklist.mjs --changed-from
origin/main`: OK, 29 anchors judged, 0 lost.
<details><summary>The ablation run</summary>
```text
ablation-replace: ok mutation landed: anchor 1 -> 0, blob bd40ded -> ced6b2f7de22
× refuses a named user missing a capability requiredPermissions names, with the by-name message, and runs nothing
× refuses an AI service account a runAs system definition with the account rule's message
Tests 2 failed | 16 passed (18)
ablation-replace: ok restored: blob == HEAD (bd40ded) and `git diff HEAD` is empty
```
</details>
<details><summary>Suite totals</summary>
```text
packages/services/service-automation test: Test Files 286 passed (286)
packages/services/service-automation test: Tests 4082 passed (4082)
packages/runtime test: Test Files 609 passed (609)
packages/runtime test: Tests 11271 passed | 19 skipped (11290)
packages/core test: Test Files 149 passed (149)
packages/core test: Tests 3595 passed (3595)
packages/spec test: Test Files 845 passed (845)
packages/spec test: Tests 27059 passed | 1 todo (27060)
```
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5kYk6G1CvandwWbbhe
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5kYk6G1CvandwWbbhe -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 96c800a commit f7b2d02
17 files changed
Lines changed: 1845 additions & 124 deletions
File tree
- .changeset
- packages
- core/src/security
- plugins/plugin-security/src
- runtime/src
- services/service-automation/src
- builtin
- spec/src/contracts
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
96 | 100 | | |
97 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
98 | 108 | | |
99 | 109 | | |
100 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
| |||
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
410 | 417 | | |
411 | 418 | | |
412 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2328 | 2328 | | |
2329 | 2329 | | |
2330 | 2330 | | |
2331 | | - | |
| 2331 | + | |
2332 | 2332 | | |
2333 | 2333 | | |
2334 | 2334 | | |
2335 | 2335 | | |
2336 | 2336 | | |
| 2337 | + | |
2337 | 2338 | | |
2338 | 2339 | | |
2339 | 2340 | | |
| |||
0 commit comments