Repository navigation
Commit 00110fd
feat(verify): run a flow locally and report its node trace before it is submitted (#35243)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8AJJJRiYjshMUNgyMZSqBsr)_
Fixes #34779
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:`os verify` 新增 `--flow NAME`(配 `--flow-record` /
`--flow-input`),在一次全新的内存启动里把一个流程真实跑一遍,逐节点报告状态、第一个失败(错误码与节点名)以及这次运行写了什么。
-
为什么改:作者在提交流程之前没有办法知道它在引擎里实际会怎么走;缺执行器的节点、绑不上的触发器、写到真实数据源的节点,过去都要到部署后才暴露。
- 风险与回滚:只新增选项与导出,不带 `--flow` 时 `os verify` 行为字节不变;回滚即 revert 本
PR。运行只写本次启动的内存库,写到其它数据源的对象在驱动被调用前就被拒;`http`、`connector_action`(含插件经它贡献的连接器)、`notify`、`script`
这四种外呼节点在本地不执行,运行停在第一个并点名它;插件自定义的其它外呼节点类型不在替身之列,仍会真实执行。被 try_catch
捕获的停止只列出,不会掩盖之后真实失败的节点。
- 先看:`packages/verify/src/flow-run.ts` 的 `standInOutbound`(外呼节点替身,只装在本次
verify 启动的引擎上)与 `confineToEphemeral`(隔离中间件);同文件 `runFlowProof` 第 6
步的启动分支(记录触发走真实写入,api 与 time_relative
按各自触发器的上下文启动);`packages/cli/src/commands/verify.ts` 中失败计数的接线。
- 两分钟验证:`pnpm --filter @objectstack/verify exec vitest run
--maxWorkers=2 src/flow-run.test.ts`,预期 13 个测试全绿。
- 需要你做的:无,席位落地。
## What changes
- **`@objectstack/verify`: `runFlowProof(stack, config, { flow, record?,
input? })`** runs one flow once on a booted verify stack and returns a
`FlowRunReport`. `formatFlowRunReport` prints it.
- The report carries each step's status as the engine's run log records
it (`listRuns`), any node whose type no installed plugin runs
(`getUnknownNodeTypeAudit`, mapped to node ids through
`collectFlowGraphs`, reached or not), the first failure with its kind,
code and node, and every write the run made.
- Engine members used: `getFlow`, `getFlowRuntimeStates`,
`getUnknownNodeTypeAudit`, `listRuns`, `execute`, and (for the outbound
stand-in) `getRegisteredNodeTypes`, `getActionDescriptor` and
`registerNodeExecutor`, called on the verify stack's own engine. Nothing
under `packages/services/service-automation` changed.
- **The run starts the way production starts it.**
- A record-change flow is fired by its own trigger. The run writes the
`--flow-record` row as the dev admin: an insert for a create or write
leg; seed, then an unchanged save, for an update leg; seed, then delete,
for a delete leg.
- An API-triggered flow is started with no caller and the context the
inbound hook builds: the body (`--flow-input`) as both `record` and
`params`, with `event: 'api'`
(`packages/triggers/trigger-api/src/api-trigger.ts`, the queue consumer
in `arm`).
- A time-relative flow is started with no caller and the context the
sweep builds for each row: the `--flow-record` row, seeded first so it
is in the table, as `record` and as `params`, with the watched `object`
and `event: 'time_relative'`
(`packages/triggers/trigger-schedule/src/time-relative-trigger.ts`, the
per-row context in the sweep). The acting organization a sweep can set
(`tenantId`) is not reproduced. A time-relative flow given no record is
`record_required`.
- A schedule, or another flow declared `runAs: 'system'`, starts with no
caller and `--flow-input` as its `params`. A real tick's own `jobId` /
`flowName` / `schedule` params and a binding's acting organization are
not reproduced.
- Any other flow goes through the trigger route as the dev admin, with
`--flow-input` as its params.
- **The trigger is checked before anything runs.** A flow whose trigger
never binds is reported with the trigger named and the engine's reason
(`unboundCause`), and nothing is run. The one exception is
`deployment_policy`, which `FLOW_UNBOUND_CAUSES` calls an operator
setting and not a defect: a schedule or time-relative trigger the
scheduled-work switch keeps unarmed (the default) is reported as not
armed, with the engine's sentence, and the flow still runs through the
no-caller start.
- **Confinement.** The run registers an ObjectQL middleware, once per
engine. It refuses insert, update, delete, purge and restore on any
object whose driver is not the ephemeral default driver the boot
created. The refusal is `PERMISSION_DENIED`/403 and fires before the
other datasource's driver is called. The node that made the write fails,
naming the object and the datasource, and the refused write is listed.
- **Four outbound node types are not executed.** Before the run starts,
each registered `http`, `connector_action`, `notify` and `script`
executor on the verify stack's engine is replaced, once per engine, by a
stand-in that executes nothing. Every connector a plugin contributes
runs behind `connector_action`, so it is covered. A plugin's own node
type that calls out under another name is not stood in, and runs for
real. The stand-in keeps the type's own descriptor and returns a
guard-class failure, so no `fault` edge on the node is followed.
Production paths are untouched, because the stand-in only exists on the
engine `os verify --flow` boots for this run.
- Each failing step is classified. A stop is the stopped node's own
step, or a step whose failure carries the stand-in's sentence: a
container around it, or a `subflow` / `map` node whose child run was
stopped.
- The first failure is the first failing step that is not a stop. Only
when the run failed and no other step failed is the stop why it ended:
then the verdict is `stopped` and the first failure is
`outbound_not_run`, naming the outbound node. For a child flow that is
the child's node, and a `fault` edge on the calling node is still
followed, because the subflow arm does not carry the guard class
(service-automation is not edited).
- A stop the run goes on past (a `try_catch` region's catch, a parallel
branch) is a note, and a later node that fails is still the first
failure and still fails `os verify`.
- Every stood-in node the run reached is listed in `outboundStops`. A
run that ends at a stop is reported and does not fail `os verify`.
- **`os verify --flow NAME [--flow-record JSON] [--flow-input JSON]`**
boots a fresh stack for the flow run and prints the report.
- These outcomes fail the command: a failed run, a missing executor, an
unbound trigger (other than by policy), a record-change or time-relative
flow given no record, and a write refused outside the stack.
- These are reported but do not fail it: a run its start condition
skipped, a run that paused at a screen, wait or approval, a run that
ended at an outbound stop, and a trigger left unarmed by the
deployment's switch.
- The `--flow` help text names the four stood-in types and says a
plugin's own outbound node type runs for real. `--json` carries the
report as `flowRun`.
- The JSON flag parser lives in
`packages/cli/src/utils/flow-json-flag.ts`.
- **Docs.** `content/docs/deployment/cli.mdx` documents the flag next to
the other `os verify` runtime checks, and adds `flowRun` to the JSON
section.
- **Ported from cloud** (read only, at `c21b372`). The semantics of the
studio flow tools were ported and adapted to the framework's shapes.
Cloud hand-builds a trigger context; here the real trigger fires, or the
trigger's own context is built from the trigger's source. Sources:
- `packages/service-ai-studio/src/tools/flow-tools.ts`: the shape of the
node trace and first failure.
- `packages/service-ai-studio/src/tools/flow-trigger-words.ts`: start
mode chosen per trigger type.
Nothing hosted, tenant-scoped or secret was moved.
## Tests
`packages/verify/src/flow-run.test.ts` holds thirteen pins against a
real `bootStack` with service-automation, service-datasource and the
triggers:
1. **CONTROL.** A healthy record-change flow, fired by a real insert,
reports each node as success and the one `fr_ledger` row it wrote. The
triggering write and the run-history rows are excluded.
2. **No executor.** A node of type `fr_missing_node` is reported with
node id `mystery` named, and the run fails with kind `no_executor`.
3. **Unbound trigger.** Kind `trigger_unbound`, with the trigger named
as `'record_change' on 'fr_watch'` and cause `missing_trigger`. No steps
run and nothing is written.
4. **Confinement.** A `create_record` into `fr_remote`, an object on
datasource `fr_remote_ds` backed by a recording driver double, fails
with kind `confined_write`. The node is named, the refused write is
listed, and the remote driver's call log is unchanged.
5. **Outbound not run.** An `http` node aimed at a local server the test
owns (loopback allowlisted for the egress guard) is stopped: the server
receives no request, the report says `stopped` and `outbound_not_run`
naming node `call` (`http`), the log shows only `start` and `call`, and
the Ledger write after it never ran.
6. **Caught stop, later failure.** A `try_catch` around an `http` node,
then a Ledger write with no name. The server receives nothing, the
verdict is `failed`, the first failure is `node_failed` at `boom`, the
stop is listed in `outboundStops`, and there is one hard failure.
7. **Parallel.** One branch calls out and the other branch's write
fails. The verdict is `failed`, the first failure names `fork_boom`, and
the stop is listed.
8. **Child flow.** A parent calls a child whose `http` node is stopped.
The verdict is `stopped`, the first failure is `outbound_not_run` naming
the child's node `child_call`, the Ledger write after the call never
ran, and there are no hard failures.
9. **Policy-unarmed schedule.** With the scheduled-work switch off, a
schedule flow reports cause `deployment_policy`, no failure, a no-caller
start, `completed`, and its Ledger row.
10. **API record.** An API-triggered flow whose node reads `record.name`
writes `hook for zeta` from `--flow-input {"name":"zeta"}`.
11. **Time-relative record.** A time-relative flow whose node reads
`record.name` and `record.id` writes a row naming the seeded contract's
id. The seed is not reported as the flow's write.
12. **Update leg.** The seed-then-save fires a `record-after-update`
flow.
13. **Delete leg.** The seed-then-delete fires a `record-after-delete`
flow, and the row is gone.
`packages/cli/src/utils/flow-json-flag.test.ts` has 7 tests: it parses
objects, and refuses arrays, scalars and bad JSON, naming the flag.
Each changed behaviour was ablated with `scripts/ablation-replace.mjs`
and turned red. Each restore was proven by the tool: blob equals HEAD
and `git diff HEAD` is empty. The verify sources are imported relatively
by the test, so no build sits between the mutation and the run. Pins 12
and 13 cover behaviour this PR already had and that this round did not
change, so they were not ablated.
<details><summary>Ablation readings</summary>
| Pin | Mutation | Result |
|---|---|---|
| no executor | `report.missingExecutors = [];` | `expected [] to deeply
equal [ { nodeId: 'mystery', ... } ]`, 1 failed / 3 passed |
| unbound trigger | `if (report.trigger && !report.trigger.bound)` → `if
(false)` | `expected { kind: 'not_started', ... } to match object {
kind: 'trigger_unbound', ... }`, 1 failed / 3 passed |
| CONTROL | trigger-write exclusion removed | `expected [ { object:
'fr_watch', ... } ] to deeply equal []`, 1 failed / 3 passed |
| confinement | `if (ql.getDriverForObject(op.object) === ephemeral)
return next();` → `return next();` | run `completed` and wrote `insert
fr_remote remote_1 (datasource fr_remote_ds)` into the remote driver;
expected `failed`, 1 failed / 3 passed |
| outbound | stand-in not installed (`report.confinement.outbound =
[];`) | run `COMPLETED`, 3 steps, and the local server received `/ping`:
`expected [ '/ping' ] to deeply equal []`, 1 failed / 9 passed |
| policy | `const policyUnarmed = false;` | the schedule pin got
`not_run` instead of `completed`, and the time-relative pin failed too
(its trigger is policy-unarmed as well), 2 failed / 8 passed |
| api record | `record` dropped from the API context | `expected
"completed", received "failed"`, 1 failed / 9 passed |
| time-relative record | `record` dropped from the sweep context |
`expected "completed", received "failed"`, 1 failed / 9 passed |
| caught stop (round 3) | a stop first in the log masks the rest (the
round-2 behaviour) | caught and parallel pins: `expected "failed",
received "stopped"`, 2 failed / 11 passed |
| child flow (round 3) | the stand-in's sentence no longer recognised |
child pin `expected "stopped", received "failed"`; the parallel pin also
went red, because its container step carries the sentence; 2 failed / 11
passed |
The first round's first CONTROL and confinement attempts were no-ops:
`ablation-replace` refused them because the replacement count did not
rise. Both were re-run with a marker comment in the replacement. The
first four rows were measured against 4 pins, the next four against 10,
and the last two against the current 13.
</details>
<details><summary>Suite and typecheck readings</summary>
| Run | Result |
|---|---|
| `flow-run.test.ts` at `17561e0f98` (the last commit that changes code;
`3d4db25136` changes only prose) | 13/13 passed |
| `@objectstack/verify` full suite at `3d4db25136` | 53 files, 458 tests
passed |
| `@objectstack/verify` typecheck | exit 0 (tsc plus
`check:test-typecheck`) |
| `@objectstack/cli` typecheck at `3d4db25136` | exit 0 |
| `flow-json-flag.test.ts` | 7/7 passed |
| `os verify --flow todo_task_reminder` on `examples/app-todo`, at
`3d4db25136` | exit 0. The schedule was not armed by policy and the run
completed. `send_reminder` (`notify`) was not executed: it was caught in
its `try_catch` and is listed with the went-on-past note. 0 hard
failures. |
Round 1 also ran the `@objectstack/cli` unit tier: 427 of 429 files
passed, and the two that failed passed with 29 tests once the CLI was
built (the published-subpath pins read `dist`). Rounds 2 and 3 changed
only help text in the cli, so the tier was not re-run. The cli
integration tier and `test:repo` are left to CI. The diff touches no
integration-tier file and no spawn entry point.
</details>
## Acceptance notes
- **Boundary.** The confinement covers row writes through ObjectQL, the
only write path the flow's data nodes use. Outbound calls are covered by
not executing the four named node types. A plugin's own node type that
calls out under a name other than `http`, `connector_action`, `notify`
or `script` is not stood in and runs for real. An object's declared
webhooks fire on record events, not through flow nodes, and are outside
the stand-in (not measured).
- **Not covered:** running outbound nodes locally (an opt-in would be a
separate Feature).
- **Scope.** `scripts/check-verify-stand-in-erasure.mjs` is outside the
claimed file surface. `check:verify-stand-in` requires every new
`@objectstack/verify` export to be classified, so `runFlowProof` and
`formatFlowRunReport` are recorded there as not stand-ins.
- **Smoke on `examples/app-todo`.** `os verify --flow
todo_task_reminder` in a default environment now reports the schedule as
not armed on this deployment, runs it with no caller, and stops the
`notify` node `send_reminder` inside its `try_catch`. The catch region
ran, the run completed, and `os verify` passed with 0 hard failures.
## Verification
<details><summary>Gates</summary>
- The derived list (`node scripts/pm/dispatch-gates.mjs --ran`, each
exit code recorded) gives 122 families: 121 run with exit 0, and 1 NOT
MEASURED. The NOT MEASURED family is `check:dual-build-cjs-loads`, which
needs a full `pnpm build`. CI's `Build Core` step runs it.
- The 103 families that read this round's files were run at head
`3d4db25136`, and all exited 0.
- The other families read only files this round did not change, so their
round-1 readings stand.
- `overlap-check`: `VERDICT clean exit 0`. The branch merges cleanly
with origin/main `b02484e13a`, with #35244 and with #34717 (both share
`cli.mdx`).
- The branch merged origin/main at `f2078e3674`. The commits on main
since then touch none of this PR's files, and nothing under
`packages/verify`, `packages/services/service-automation`,
`packages/objectql` or `packages/triggers`.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi)_
<!-- signed: repo:objectstack#1 · os-warren ·
session_01JQwxbYRqkDAGuse5Wqbohi -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b02484e commit 00110fd
9 files changed
Lines changed: 1758 additions & 6 deletions
File tree
- .changeset
- content/docs/deployment
- packages
- cli/src
- commands
- utils
- verify/src
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2943 | 2943 | | |
2944 | 2944 | | |
2945 | 2945 | | |
| 2946 | + | |
2946 | 2947 | | |
2947 | 2948 | | |
2948 | 2949 | | |
| |||
3092 | 3093 | | |
3093 | 3094 | | |
3094 | 3095 | | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
| 3101 | + | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
| 3111 | + | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
| 3139 | + | |
3095 | 3140 | | |
3096 | 3141 | | |
3097 | 3142 | | |
| |||
3128 | 3173 | | |
3129 | 3174 | | |
3130 | 3175 | | |
3131 | | - | |
3132 | | - | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
3133 | 3181 | | |
3134 | 3182 | | |
3135 | 3183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
| |||
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
141 | 153 | | |
142 | 154 | | |
143 | 155 | | |
144 | 156 | | |
145 | 157 | | |
146 | | - | |
| 158 | + | |
147 | 159 | | |
148 | 160 | | |
149 | 161 | | |
| |||
154 | 166 | | |
155 | 167 | | |
156 | 168 | | |
| 169 | + | |
| 170 | + | |
157 | 171 | | |
158 | 172 | | |
159 | 173 | | |
| |||
185 | 199 | | |
186 | 200 | | |
187 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
188 | 215 | | |
189 | 216 | | |
190 | 217 | | |
| |||
267 | 294 | | |
268 | 295 | | |
269 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
270 | 300 | | |
271 | 301 | | |
272 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
273 | 308 | | |
274 | 309 | | |
275 | 310 | | |
| |||
465 | 500 | | |
466 | 501 | | |
467 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
468 | 520 | | |
469 | 521 | | |
470 | 522 | | |
| |||
506 | 558 | | |
507 | 559 | | |
508 | 560 | | |
509 | | - | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
510 | 567 | | |
511 | 568 | | |
512 | 569 | | |
513 | 570 | | |
514 | 571 | | |
515 | | - | |
| 572 | + | |
516 | 573 | | |
517 | 574 | | |
518 | 575 | | |
| |||
522 | 579 | | |
523 | 580 | | |
524 | 581 | | |
| 582 | + | |
525 | 583 | | |
526 | 584 | | |
527 | 585 | | |
| |||
| 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 | + | |
| 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 | + | |
0 commit comments