Skip to content

Commit 00110fd

Browse files
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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/verify': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
feat(verify): run a flow locally and report its node trace before it is submitted
7+
8+
Clause-②: yes (widening: a new `os verify --flow` option, and new `@objectstack/verify` exports)
9+
Metadata-protocol: none
10+
11+
`os verify --flow <name>` runs one flow once on a fresh in-memory boot of the app and reports what the engine did: each node's status as the run's log records it, the first failure with its code and the node named, and every write the run made.
12+
13+
- The run starts the way production starts it. A record-change flow is fired by its own trigger: the run writes the record `--flow-record '{"field":"value"}'` names as the dev admin (inserted for a create or write leg; seeded and saved unchanged for an update leg; seeded and deleted for a delete leg). A flow its own trigger starts is started with no caller, with the context that trigger builds: an API-triggered flow gets `--flow-input '{...}'` as its record and its params (the request body); a time-relative flow gets the `--flow-record` row, seeded first, as its record (the acting organization a sweep can set is not reproduced); a schedule or another `runAs: 'system'` flow gets `--flow-input` as its params. Any other flow goes through the trigger route as the dev admin, with `--flow-input` as its params.
14+
- A node whose type no installed plugin runs is named, whether the run reached it or not. A flow whose trigger never binds is reported with the trigger and the engine's reason, and is not run. A schedule or time-relative trigger left unarmed by the deployment's scheduled-work switch (the default) is not a defect: it is reported as not armed and the flow is still run.
15+
- The run writes to the in-memory database the boot creates and nowhere else: a write to an object bound to any other datasource is refused before that datasource's driver is called, and the node that made it fails naming the object and the datasource. Four outbound node types are not executed: `http`, `connector_action` (with every connector a plugin contributes behind it), `notify` and `script`; a plugin's own node type that calls out under another name is not stood in and runs for real. A run that ends at one of them stops there and the report names it (`outbound_not_run`), in a child flow too; every node before it ran for real. A stop a `try_catch` catches is listed in `outboundStops`, and a later node that fails is still the first failure.
16+
- A failed run, a missing executor, an unbound trigger, a record-change or time-relative flow given no record, and a write refused outside the ephemeral stack each fail `os verify`. A run its start condition skipped, one that paused at a screen, wait or approval, and one stopped at an outbound node are reported and do not.
17+
- `--json` carries the report as `flowRun`.
18+
19+
New exports from `@objectstack/verify`: `runFlowProof`, `formatFlowRunReport`, and the `FlowRunRequest`, `FlowRunVerdict`, `FlowRunStart`, `FlowRunStep`, `FlowRunWrite`, `FlowRunFailureKind`, `FlowRunFailure`, `FlowRunTrigger` and `FlowRunReport` types. Nothing that ran before changes.

‎content/docs/deployment/cli.mdx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,7 @@ os verify --delete-behaviors # Also prove each declared delete
29432943
os verify --unique-scopes --multi-tenant # Also prove each declared unique collides where its scope says
29442944
os verify --parent-write-reach # Also prove each controlled_by_parent detail write follows its master
29452945
os verify --dashboard-windows # Also prove each dashboard date picker counts the rows its window selects
2946+
os verify --flow notify_on_new_case --flow-record '{"subject":"Printer jam"}' # Also run one flow and report its node trace
29462947
```
29472948
29482949
1. **Author-time rules.** The rule registry `os validate` runs, over the stack
@@ -3092,6 +3093,50 @@ os verify --dashboard-windows # Also prove each dashboard date
30923093
ground truth cannot model (`$or`, a range, a
30933094
relationship path, a condition on the window's own field), are reported
30943095
`excluded`.
3096+
With `--flow <name>`, another fresh boot runs that one flow once and reports
3097+
what the engine did: each node's status as the run's log records it, the
3098+
first failure with its code and the node named, and every write the run
3099+
made. The run starts the way production starts it. A record-change flow is
3100+
started by its own trigger: the run writes the record `--flow-record`
3101+
names (its fields as a JSON object) as the dev admin, inserting it for a
3102+
create or write leg, seeding it and saving it unchanged for an update leg
3103+
(so a condition comparing old and new values sees no change), and seeding
3104+
it and deleting it for a delete leg. A flow its own trigger starts is
3105+
started with no caller, with the context that trigger builds: an
3106+
API-triggered flow is handed `--flow-input` (a JSON object) as its record
3107+
and its params, as the inbound hook hands it the request body; a
3108+
time-relative flow is handed the `--flow-record` row as its record, seeded
3109+
first so it is in the table, as a swept row is (the acting organization a
3110+
sweep can set, `tenantId`, is not reproduced); a schedule, or another
3111+
flow declared `runAs: 'system'`, is handed `--flow-input` as its params
3112+
(a real tick's own `jobId`, `flowName` and `schedule` params and a
3113+
binding's acting organization are not reproduced). Any other flow goes
3114+
through the trigger route as the dev admin, with `--flow-input` as its
3115+
params. Before the run starts, every node whose type no installed plugin
3116+
runs is named, reached or not, and a flow whose trigger never binds is
3117+
reported with the trigger and the engine's reason, and is not run. A
3118+
schedule or time-relative trigger the deployment's scheduled-work switch
3119+
keeps unarmed (the default) is not a defect: it is reported as not armed
3120+
and the flow is still run. A run that fails, a node with no executor, a
3121+
trigger that never binds, a record-change or time-relative flow given no
3122+
record, and a write refused because its object lives outside the
3123+
ephemeral stack each fail `os verify`; a run the start condition skipped,
3124+
one that paused at a screen, wait or approval, and one stopped at an
3125+
outbound node are reported and do not. The run writes to the in-memory
3126+
database this boot creates and nowhere else: a write to an object bound to
3127+
any other datasource is refused before that datasource's driver is called,
3128+
and the node that made it fails naming the object and the datasource.
3129+
Four outbound node types are not executed: `http`, `connector_action`
3130+
(which also runs every connector a plugin contributes), `notify` and
3131+
`script`. A plugin's own node type that calls out under another name is
3132+
not stood in, and runs for real. A run that ends at one of the four stops
3133+
there, and the report names it (`outbound_not_run`); every node before it
3134+
ran for real. A stop inside a child flow is named at the child's node, and
3135+
a `fault` edge on the calling `subflow` or `map` node is still followed.
3136+
Inside a `try_catch` region the catch region handles the stop as it would
3137+
a failed call, and the run goes on: the stop is listed
3138+
(`outboundStops`), and a later node that fails is still the first failure
3139+
and still fails `os verify`.
30953140
`--multi-tenant` boots org-scoped so tenant-isolation RLS policies
30963141
apply; a walled tenancy posture (`OS_TENANCY_POSTURE` set to `isolated` or
30973142
`group`) asks for the same boot.
@@ -3128,8 +3173,11 @@ document carries depends on where the run ended:
31283173
`parentWriteReach` (with `--parent-write-reach`; its `personas` name who
31293174
wrote and who could not be provisioned), `dashboardWindows` (with
31303175
`--dashboard-windows`; its `presets` name what each preset handed the door
3131-
and how it resolved) and `hardFailures`, the count the exit status is read
3132-
from.
3176+
and how it resolved), `flowRun` (with `--flow`: the `verdict`, how the run
3177+
started, the `trigger` and whether it is bound, the `steps`, the
3178+
`missingExecutors`, the `firstFailure`, the `outboundStops`, the `writes`
3179+
and the `confinement`)
3180+
and `hardFailures`, the count the exit status is read from.
31333181
- **Could not run:** `{ "error": "<sentence>" }`, plus `code` and `httpStatus`
31343182
when the failure carries them.
31353183

‎packages/cli/src/commands/verify.ts‎

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
formatDashboardWindowReport,
2929
readSeedOutcome,
3030
formatSeedReport,
31+
runFlowProof,
32+
formatFlowRunReport,
3133
type VerifyReport,
3234
type SeedReport,
3335
type RlsReport,
@@ -36,6 +38,7 @@ import {
3638
type UniqueScopeReport,
3739
type ParentWriteReachReport,
3840
type DashboardWindowReport,
41+
type FlowRunReport,
3942
type RlsProbeDescriptor,
4043
type RlsPositionPersonaInput,
4144
} from '@objectstack/verify';
@@ -59,6 +62,7 @@ import {
5962
isReportedError,
6063
} from '../utils/format.js';
6164
import { reserveStdoutForJson } from '../utils/json-stdout.js';
65+
import { parseFlowJsonFlag } from '../utils/flow-json-flag.js';
6266

6367
/**
6468
* Should this `os verify` run boot an org-scoped (multi-tenant) stack?
@@ -138,12 +142,20 @@ export interface VerifyCapabilityAdvisory {
138142
* dashboard's `dateRange` binds counts, under each preset of the
139143
* picker, the fixture rows that window selects, asked of the dataset
140144
* door as the signed-in principal
145+
* - a flow run (--flow NAME): the named flow, run once the way
146+
* production starts it (a record-change flow by a real write of the
147+
* record --flow-record names), reported node by node with the first
148+
* failure and what it wrote; every write outside the ephemeral
149+
* stack is refused before its datasource is called, and the four
150+
* outbound node types (http, connector_action, notify, script)
151+
* are not executed: the run stops there (a plugin's own outbound
152+
* node type is not stood in)
141153
*
142154
* Exits non-zero on either stage's failures so it drops straight into CI.
143155
*/
144156
export default class Verify extends Command {
145157
static override description =
146-
'Run the author-time rules os validate runs, then boot the app in-process and verify it through the real HTTP stack (CRUD round-trip fidelity, plus the cross-owner RLS invariant, the reference-value shape proofs, the declared delete-behaviour proofs, the declared unique-scope proofs, the parent-derived write reach proofs and the dashboard date-window proofs on request)';
158+
'Run the author-time rules os validate runs, then boot the app in-process and verify it through the real HTTP stack (CRUD round-trip fidelity, plus the cross-owner RLS invariant, the reference-value shape proofs, the declared delete-behaviour proofs, the declared unique-scope proofs, the parent-derived write reach proofs, the dashboard date-window proofs and one flow run on request)';
147159

148160
static override examples = [
149161
'<%= config.bin %> verify',
@@ -154,6 +166,8 @@ export default class Verify extends Command {
154166
'<%= config.bin %> verify --unique-scopes --multi-tenant',
155167
'<%= config.bin %> verify --parent-write-reach',
156168
'<%= config.bin %> verify --dashboard-windows',
169+
`<%= config.bin %> verify --flow notify_on_new_case --flow-record '{"subject":"Printer jam"}'`,
170+
'<%= config.bin %> verify --flow nightly_cleanup --json',
157171
];
158172

159173
static override flags = {
@@ -185,6 +199,19 @@ export default class Verify extends Command {
185199
description: "Also prove, for every controlled_by_parent object, that a persona's edit, delete or create of a detail is admitted exactly when it holds that verb on the detail's object and can edit the master, written through the engine as verifier personas and one persona per declared position (ADR-0055 master-detail write reach)",
186200
default: false,
187201
}),
202+
flow: Flags.string({
203+
description:
204+
"Also run this flow once on a fresh boot and report each node's status, the first failure with its code and the node named, and what the run wrote. It starts the way production starts it: a record-change flow by a real write of the record --flow-record names, a flow its own trigger starts with no caller (an API-triggered flow with --flow-input as its record and params, a time-relative flow with --flow-record seeded and handed in as its record (no acting organization), a schedule or runAs: 'system' flow with --flow-input as its params), any other flow through the trigger route as the dev admin. A schedule the deployment's scheduled-work switch keeps unarmed is reported as not armed and still run. Every write outside the in-memory database this run boots is refused before its datasource is called. Four outbound node types (http, connector_action, notify, script) are not executed: a run that reaches one stops there and names it. A plugin's own node type that calls out under another name is not stood in, and runs for real",
205+
}),
206+
'flow-record': Flags.string({
207+
description:
208+
'With --flow on a record-change or time-relative flow: the record\'s fields as a JSON object. A create or write leg inserts it; an update leg seeds it and saves it unchanged; a delete leg seeds it and deletes it; a time-relative flow is handed the seeded row as the swept record',
209+
dependsOn: ['flow'],
210+
}),
211+
'flow-input': Flags.string({
212+
description: 'With --flow on a flow started directly: its input as a JSON object, handed to the start as its params (and, for an API-triggered flow, as its record, the request body)',
213+
dependsOn: ['flow'],
214+
}),
188215
'multi-tenant': Flags.boolean({
189216
description: 'Boot org-scoped (register the @objectstack/organizations plugin) so tenant-isolation RLS policies apply (also honors a walled $OS_TENANCY_POSTURE, and the legacy $OS_MULTI_ORG_ENABLED it falls back to)',
190217
default: false,
@@ -267,9 +294,17 @@ export default class Verify extends Command {
267294
'unique-scopes': boolean;
268295
'parent-write-reach': boolean;
269296
'dashboard-windows': boolean;
297+
flow?: string;
298+
'flow-record'?: string;
299+
'flow-input'?: string;
270300
'multi-tenant': boolean;
271301
json: boolean;
272302
}): Promise<void> {
303+
// The flow run's JSON arguments, judged before anything loads or boots:
304+
// a malformed one is the caller's to fix, and no stage should run first.
305+
const flowRecord = parseFlowJsonFlag('--flow-record', flags['flow-record']);
306+
const flowInput = parseFlowJsonFlag('--flow-input', flags['flow-input']);
307+
273308
// [#32141] The project's `.env*` files, loaded before anything reads the
274309
// environment — the config module, the tenancy posture below, and every
275310
// service the boot composes (the settings service reads its `OS_*`
@@ -465,6 +500,23 @@ export default class Verify extends Command {
465500
}
466501
}
467502

503+
// The flow run boots a fresh stack of its own as well: the run writes its
504+
// triggering record and whatever its nodes write, and the confinement
505+
// middleware it registers stays on that engine for the stack's life.
506+
let flowRun: FlowRunReport | undefined;
507+
if (flags.flow) {
508+
const flowStack = await bootStack(config, { multiTenant, hostRoot });
509+
try {
510+
flowRun = await runFlowProof(flowStack, config, {
511+
flow: flags.flow,
512+
...(flowRecord ? { record: flowRecord } : {}),
513+
...(flowInput ? { input: flowInput } : {}),
514+
});
515+
} finally {
516+
await flowStack.stop();
517+
}
518+
}
519+
468520
// Failure contract: a "real" runtime break the app's author must see.
469521
// A degraded RLS probe counts: the run reported verdicts it could not have
470522
// established, which is worse than no verifier at all.
@@ -506,13 +558,18 @@ export default class Verify extends Command {
506558
// A bound widget that went blank or counted other rows than its window
507559
// selects, or a windowed query the door refused or faulted. Inconclusive,
508560
// unbound and excluded widgets are reported, not counted.
509-
(dashboardWindows?.summary.hardFailures ?? 0);
561+
(dashboardWindows?.summary.hardFailures ?? 0) +
562+
// The flow did not run, failed at a node, has a node no executor runs,
563+
// or had a write outside the ephemeral stack refused. A skipped or
564+
// paused run, a run stopped at an outbound node, and a schedule left
565+
// unarmed by the deployment's switch are reported, not counted.
566+
(flowRun?.summary.hardFailures ?? 0);
510567

511568
if (flags.json) {
512569
// `emitJson`, not `this.log`: stdout is reserved (see `run()`), so the
513570
// report has to leave through the real stream — and awaiting the write
514571
// drains a report larger than one pipe buffer before `this.exit` below.
515-
await emitJson({ app: crud.app, config: absolutePath, multiTenant, capabilities, seed, crud, rls, referenceShapes, deleteBehaviors, uniqueScopes, parentWriteReach, dashboardWindows, hardFailures });
572+
await emitJson({ app: crud.app, config: absolutePath, multiTenant, capabilities, seed, crud, rls, referenceShapes, deleteBehaviors, uniqueScopes, parentWriteReach, dashboardWindows, flowRun, hardFailures });
516573
} else {
517574
this.log(formatReport(crud));
518575
this.log(formatSeedReport(seed));
@@ -522,6 +579,7 @@ export default class Verify extends Command {
522579
if (uniqueScopes) this.log(formatUniqueScopeReport(uniqueScopes));
523580
if (parentWriteReach) this.log(formatParentWriteReachReport(parentWriteReach));
524581
if (dashboardWindows) this.log(formatDashboardWindowReport(dashboardWindows));
582+
if (flowRun) this.log(formatFlowRunReport(flowRun));
525583
this.log('');
526584
this.log(
527585
hardFailures > 0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// `os verify --flow` takes the triggering record (`--flow-record`) and the
4+
// start's input (`--flow-input`) as JSON objects, judged before anything loads
5+
// or boots. This pins the decision, `parseFlowJsonFlag`, on its own: the
6+
// command body hands each flag to it once, before the author-time stage.
7+
8+
import { describe, it, expect } from 'vitest';
9+
import { parseFlowJsonFlag } from '../utils/flow-json-flag.js';
10+
11+
describe('parseFlowJsonFlag', () => {
12+
it('an absent flag is no value', () => {
13+
expect(parseFlowJsonFlag('--flow-record', undefined)).toBeUndefined();
14+
});
15+
16+
it('a JSON object is handed on as given', () => {
17+
expect(parseFlowJsonFlag('--flow-record', '{"subject":"Printer jam","priority":2}')).toEqual({
18+
subject: 'Printer jam',
19+
priority: 2,
20+
});
21+
});
22+
23+
it('text that does not parse is refused, naming the flag', () => {
24+
expect(() => parseFlowJsonFlag('--flow-input', '{subject: x}')).toThrow(/--flow-input/);
25+
});
26+
27+
it.each([['[1,2]'], ['"text"'], ['null'], ['3']])('JSON that is not an object (%s) is refused, naming the flag', (raw) => {
28+
expect(() => parseFlowJsonFlag('--flow-record', raw)).toThrow(/--flow-record/);
29+
});
30+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Read one of `--flow-record` / `--flow-input`: a JSON object, or a refusal
5+
* naming the flag. `undefined` when the flag was not given.
6+
*/
7+
export function parseFlowJsonFlag(flag: string, raw: string | undefined): Record<string, unknown> | undefined {
8+
if (raw === undefined) return undefined;
9+
let value: unknown;
10+
try {
11+
value = JSON.parse(raw);
12+
} catch (e) {
13+
throw new Error(`${flag} takes a JSON object; it did not parse (${(e as Error).message})`);
14+
}
15+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
16+
throw new Error(`${flag} takes a JSON object, such as '{"name":"Acme"}'`);
17+
}
18+
return value as Record<string, unknown>;
19+
}

0 commit comments

Comments
 (0)