Skip to content

Commit bcfc8e4

Browse files
fix(service-automation): a node with no installed executor follows its fault edge (#34984)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBQ3DFv6XZAspQRYGQoEWhr8)_ repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH Fixes #34959 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么:** 流程节点的类型没有任何已安装插件提供时(例如没装审批插件时的 `approval` 节点),这个节点的失败现在和其他节点失败一样处理。节点声明了 `fault` 连线就走这条线,处理节点读到的 `$error.code` 是 `NO_EXECUTOR`,文字和原来一样。 - **为什么改:** 以前这类失败在错误路由之前就直接抛出,作者声明的兜底路径(通知、回退、把记录改回去)永远不会执行,提交的记录一直停在原状态。hotcrm 实测有 4 个审批流程是这样。 - **风险与回滚:** 没有 `fault` 连线时行为不变:同一个失败步骤,同一句报错,运行失败。新增的可见变化只有一处:`try_catch` 捕获这类失败时,绑定的错误多了 `code: NO_EXECUTOR`。回滚就是还原这一个提交。 - **先看:** ① `dag-traversal.ts` 缺执行器的分支(新发布 `$error`,再调用 `followFaultEdge`);② 同文件新抽出的 `followFaultEdge`,另外两个失败分支改成调用它,判断条件没变;③ `fault-edge-guard-containment.test.ts` 末尾新增的 describe。 - **两分钟验证:** `pnpm --filter @objectstack/service-automation exec vitest run --maxWorkers=2 src/fault-edge-guard-containment.test.ts src/throw-arm-error-refresh.test.ts`,预期 2 个文件、16/16 通过。 - **需要你做的:** 无,席位落地。 ## What changes **`packages/services/service-automation/src/dag-traversal.ts`** - The missing-executor arm of `executeNode` (any node type except `start`) now grades the failure the way the two other failure arms already do: 1. It records the same failure step as before: `status: 'failure'`, `error: { code: 'NO_EXECUTOR', message: "No executor registered for node type 'T'" }`. 2. It publishes the failure: `$error = { nodeId, message, code: 'NO_EXECUTOR' }`, plus the node-scoped `NODE_ID.error` through `setNodeError`. This is the same shape as the returned-failure arm, where `code` is the classified code a handler branches on. 3. It follows a declared `fault` edge. With no `fault` edge it throws the same `Error` with the same text as before, so the run fails exactly as it did. - `followFaultEdge` (new, module-private) is now the only copy of the fault-edge routing. The thrown-failure arm and the returned-failure arm call it too. The decision whether a failure may route stays at each call site and is unchanged: `isGuardRefusal(execErr)` on the throw arm, and `errorClass === 'guard'` on the returned arm (#3863). - `start` keeps its no-executor success path, untouched. **Why this shape, and not a coded error thrown inside the `try`.** The catch block would: - grade the error through `gradeAfterTenantCurrencyReadFault`, which does nothing to it; - record the step as `EXECUTION_ERROR`, which loses `NO_EXECUTOR`; - publish `$error` without a `code`; - try the `readPartialSteps` fold, which has nothing to fold. Each of those would need a special case for a node that never ran. Calling the shared routing helper from the arm itself keeps the step code and the thrown text identical, and leaves one routing implementation. **What a NO_EXECUTOR failure does not pick up.** - `executeNode` has no node-level retry. Flow-level `errorHandling.strategy: 'retry'` and a `try_catch` retry ladder see exactly what they saw before when no `fault` edge routes. - A routed failure does not consume a flow retry. This is the existing #3863 pin, and it holds by construction. - The failure is classed `runtime` (routable), not `guard`. The metadata is valid, and a deployment that installs the plugin runs it. This is also why the boot audit only warns (ADR-0018 §M1). **Other executor lookups in service-automation, checked:** - Resume, region bodies (`runRegion`: `loop`, `parallel`, `try_catch`), and subflow children all re-enter through this same `executeNode`, so they are fixed by this change. - `dry-run.ts` runs the live `executeNode` body over a dry executor view. Its missing-type branch notes the failure, then the shared arm runs, so a dry run follows the `fault` edge as the live run does. That follows from the shared code; this PR does not pin it separately. - The ADR-0018 alias executor (`plugin-extension-api.ts`) returns `{ success: false }` when its canonical executor is missing. That already goes through the returned-failure arm, which routes. It is not the same bug, so it is left as is. - `releaseSuspension` (`dispatch-claims.ts`) is a teardown hook (no executor means nothing to release), and `unregisterNodeExecutor` is a registry removal. Neither is a failure path. **Boot warnings left unchanged.** `plugin.ts` ~3032 and the engine's per-flow `warnUnknownNodeTypes` both still say something true: the node fails with `NO_EXECUTOR`, and installing the plugin fixes it. A declared `fault` edge now routes that failure. **Route 2 (refusing at install or registration) is not taken.** It would refuse packages whose flows reach the node type only on a path a deployment never takes, and the boot warning already names them. No spec node type, edge type or schema changes. `flow.zod.ts` already declares `fault` as the error path. ## Tests New top-level describe in `src/fault-edge-guard-containment.test.ts` ("a node with no installed executor is graded like any other node failure"). The node is an `approval` node with no approvals plugin registered. - **routes:** with a declared `fault` edge, the run succeeds, the handler runs once, and the handler reads `$error` equal to `{ nodeId: 'signoff', message: "No executor registered for node type 'approval'", code: 'NO_EXECUTOR' }` and `signoff.error` equal to the message. - **step record:** the run log keeps exactly one `signoff` step, `failure` with `{ code: 'NO_EXECUTOR', message }`, and the step order is start success, then signoff failure, then handler success. - **CONTROL, no fault edge:** `success: false`, `status: 'failed'`, `error` equal to today's text byte for byte, handler not run, steps start success then signoff failure with `NO_EXECUTOR`. - **CONTROL, `start` with no executor:** a success step with no error, the run proceeds, and `$error` is untouched. - **CONTROL, a registered executor that throws:** the fault edge still routes. `$error` is `{ nodeId, message }` with no code, and the step code is `EXECUTION_ERROR`, as before. New top-level describe in `src/throw-arm-error-refresh.test.ts` (the #14955 `$error` freshness harness): a missing-executor node inside a `try_catch` try region (a made-up type, because a pausing `approval` may not sit in a region) publishes `$error` with `NO_EXECUTOR`, and `try_catch` binds `code: 'NO_EXECUTOR'` onto its caught error. Red first, on origin/main 0465f4a with only the tests added: routes ✗, step record ✗, and all three controls ✓. Ablation (one-off, no permanent file): with `HEAD` at bdee8dc, `dag-traversal.ts` was set back to its base blob (0465f4a) and hash-verified on disk. The 3 new routing and publishing tests went red, and the other 13 tests in the two files, including all 4 controls, stayed green. The file was then restored from `HEAD`, hash-verified, and `git diff HEAD` was empty. ## Acceptance notes - Pre-existing and unchanged: with no `fault` edge, a `try_catch` retry ladder (`maxRetries`) re-runs a node that cannot run, and flow-level `errorHandling.strategy: 'retry'` re-runs the whole flow on `NO_EXECUTOR`. Both are bounded. This PR leaves both alone and does not file them. - `engine.ts` ~5645 has a comment saying "executeNode() throws NO_EXECUTOR at run time". It is now more exactly "fails the node". It is a comment only and outside this claim's file surface, so it is left. - `content/docs/automation/flows.mdx` says "executing one fails with `NO_EXECUTOR`". That is still true, so it is left. - The platform-checklist item for an unknown node type (`docs/qa/platform-checklist/areas/automation.json`) tests the shape with no fault edge (`status: 'failed'` and a `NO_EXECUTOR` step). It still holds; the no-fault control pins it. ## Verification All readings are at head bdee8dc, in worktree `objectstack-issue-34959`. <details><summary>Package tests and typecheck: @objectstack/service-automation</summary> - `pnpm --filter @objectstack/service-automation exec vitest run --maxWorkers=2` (whole package), under the verify lock: `VERDICT command-exit 0`, Test Files 287 passed (287), Tests 4145 passed (4145). - `pnpm --filter @objectstack/service-automation run typecheck`: `tsc --noEmit` passed, and `check:test-typecheck: OK — ... 0 file(s) / 0 error(s)`. - `pnpm --filter @objectstack/service-automation run build`: `check-dts-emitted: 2/2 declared declaration file(s) present`. - Dependency closure built first: `pnpm --filter '@objectstack/service-automation^...' build`, `VERDICT command-exit 0`. </details> <details><summary>Derived gate families (dispatch-gates --commands, 70)</summary> - 68 exit 0. - 2 are NOT MEASURED (exit 3, PREREQUISITE NOT MET): - `node scripts/check-plugin-teardown-shape.mjs --self-test`: its pinned positive-control commit is not reachable from this shallow clone. This is checker health only, and the scan itself (`check:plugin-teardown-shape`) passed. - `pnpm check:dual-build-cjs-loads`: it reads a whole-workspace build that was not produced locally. CI's Lint & Repo Gates runs it. - `dispatch-gates --ran` with exit codes: "70 derived famil(ies) accounted for — 68 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - Everything outside the derived list is CI's: Test Core, Build Core, type-check lanes, and the dogfood shards in the merge queue. </details> <details><summary>overlap-check</summary> `node scripts/pm/overlap-check.mjs --branch=claude/issue-34959-missing-executor-fault-edge`: "✓ origin/main: merges cleanly", `VERDICT clean exit 0` (0 PR heads overlapping). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent a841e26 commit bcfc8e4

4 files changed

Lines changed: 270 additions & 22 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/service-automation': patch
3+
---
4+
5+
fix(service-automation): a flow node whose type no installed plugin provides now follows its `fault` edge
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A flow can name a node type that no installed plugin provides, for example an `approval` node on a deployment without `@objectstack/plugin-approvals`. Running that node fails with `NO_EXECUTOR` ("No executor registered for node type 'approval'"). Until now that failure skipped the node's `fault` edge: the run just failed, nobody was told, and the record that started it stayed where it was. An author could not declare a graceful path for it.
11+
12+
That failure is now handled like any other node failure:
13+
14+
- When the node declares a `fault` edge, the run follows it. The handler reads `{$error.code}` as `NO_EXECUTOR`, with the same message, and `{<nodeId>.error}` holds the message. The run log keeps the node's failed step with code `NO_EXECUTOR`, followed by the handler's steps.
15+
- Inside a `try_catch` region, the catch region's bound error now carries `code: 'NO_EXECUTOR'`.
16+
- With no `fault` edge, nothing changes: the same failed step, the same error text, and the run fails.
17+
18+
The boot warning that names flows referencing node types no installed plugin provides is unchanged. Installing the plugin is still the fix; the `fault` edge is the author's fallback until then.

‎packages/services/service-automation/src/dag-traversal.ts‎

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ export interface DagTraversalHost {
188188
readonly cancelRun: AutomationEngine['cancelRun'];
189189
}
190190

191+
/**
192+
* Route a failed node down its declared `fault` edge: run the edge's target and
193+
* answer `true`, or answer `false` when the node declares no `fault` edge (or the
194+
* edge names no node), leaving the caller to fail the run. The ONE copy of the
195+
* routing every failure arm of {@link executeNode} uses — the missing executor,
196+
* the thrown failure and the returned failure. Whether a failure MAY route (a
197+
* guard refusal never does, #3863) is the caller's decision, made before this
198+
* is called; `$error` is published by the caller before it, too (#14955).
199+
*/
200+
async function followFaultEdge(
201+
host: Pick<DagTraversalHost, 'executeNode'>,
202+
node: FlowNodeParsed,
203+
flow: FlowParsed,
204+
variables: Map<string, unknown>,
205+
context: AutomationContext,
206+
steps: StepLogEntry[],
207+
): Promise<boolean> {
208+
const faultEdge = flow.edges.find(e => e.source === node.id && e.type === 'fault');
209+
if (!faultEdge) return false;
210+
const faultTarget = flow.nodes.find(n => n.id === faultEdge.target);
211+
if (!faultTarget) return false;
212+
await host.executeNode(faultTarget, flow, variables, context, steps);
213+
return true;
214+
}
215+
191216
/** The body of {@link AutomationEngine.executeNode}, moved unedited; that method's docblock is its contract. */
192217
export async function executeNode(
193218
this: Pick<DagTraversalHost, 'renderRefusalMessage' | 'nodeExecutors' | 'executeWithTimeout' | 'setNodeError' | 'executeNode' | 'refuseUndeclaredSuspension' | 'traverseNext'>,
@@ -266,16 +291,38 @@ export async function executeNode(
266291
if (!executor) {
267292
// start node without executor is fine — just skip
268293
if (node.type !== 'start') {
294+
// A node whose type no installed plugin provides (an `approval`
295+
// node on a deployment without the approvals plugin) is a node
296+
// failure like any other, graded by the same three moves as the
297+
// two failure arms below: record the step, publish `$error`, then
298+
// follow a declared `fault` edge. Before this the throw came first
299+
// and the routing was never reached, so an author's graceful path
300+
// could not run and the record that started the run waited forever.
301+
//
302+
// It is a `runtime` failure, never a guard refusal: the metadata is
303+
// valid and a deployment that installs the plugin runs it, which is
304+
// also why the boot audit only warns about it (ADR-0018 §M1).
305+
//
306+
// `code` rides on `$error` as the returned-failure arm's classified
307+
// code does, so a handler can branch on `{$error.code}`.
308+
//
309+
// With no `fault` edge the run fails exactly as it always has: the
310+
// same step, the same thrown text. The node never ran, so nothing
311+
// it wrote can be carried and no node-level retry applies here.
312+
const message = `No executor registered for node type '${node.type}'`;
269313
steps.push({
270314
nodeId: node.id,
271315
nodeType: node.type,
272316
status: 'failure',
273317
startedAt: stepStartedAt,
274318
completedAt: new Date().toISOString(),
275319
durationMs: Date.now() - stepStart,
276-
error: { code: 'NO_EXECUTOR', message: `No executor registered for node type '${node.type}'` },
320+
error: { code: 'NO_EXECUTOR', message },
277321
});
278-
throw new Error(`No executor registered for node type '${node.type}'`);
322+
variables.set('$error', { nodeId: node.id, message, code: 'NO_EXECUTOR' });
323+
this.setNodeError(variables, node.id, message);
324+
if (await followFaultEdge(this, node, flow, variables, context, steps)) return;
325+
throw new Error(message);
279326
}
280327
// Log start node step
281328
steps.push({
@@ -409,16 +456,7 @@ export async function executeNode(
409456
// returns: `UnscopedRunDataAccessError` (ADR-0049/#1888) reports
410457
// that the metadata would run unscoped, and rerouting it would
411458
// let a `fault` edge disable the elevation check.
412-
const faultEdge = isGuardRefusal(execErr)
413-
? undefined
414-
: flow.edges.find(e => e.source === node.id && e.type === 'fault');
415-
if (faultEdge) {
416-
const faultTarget = flow.nodes.find(n => n.id === faultEdge.target);
417-
if (faultTarget) {
418-
await this.executeNode(faultTarget, flow, variables, context, steps);
419-
return;
420-
}
421-
}
459+
if (!isGuardRefusal(execErr) && await followFaultEdge(this, node, flow, variables, context, steps)) return;
422460
throw execErr;
423461
}
424462

@@ -504,16 +542,7 @@ export async function executeNode(
504542
// condition, a data node names no object); rerouting it would
505543
// make a single `fault` edge a switch that turns the guard off
506544
// while the run still reports success.
507-
const faultEdge = result.errorClass === 'guard'
508-
? undefined
509-
: flow.edges.find(e => e.source === node.id && e.type === 'fault');
510-
if (faultEdge) {
511-
const faultTarget = flow.nodes.find(n => n.id === faultEdge.target);
512-
if (faultTarget) {
513-
await this.executeNode(faultTarget, flow, variables, context, steps);
514-
return;
515-
}
516-
}
545+
if (result.errorClass !== 'guard' && await followFaultEdge(this, node, flow, variables, context, steps)) return;
517546
// [#24914, ruling B′] The text is unchanged — it is the run's
518547
// diagnostic, read by the run log, `failAncestors`, approvals
519548
// and every door's `message`. What the node's data call met is

‎packages/services/service-automation/src/fault-edge-guard-containment.test.ts‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,148 @@ describe('#3863 — a handled failure does not trigger flow-level retry', () =>
352352
expect(upstreamRuns).toBe(1);
353353
});
354354
});
355+
356+
/**
357+
* A node whose type no installed plugin provides — an `approval` node on a
358+
* deployment without the approvals plugin — fails with `NO_EXECUTOR`. That is
359+
* a node failure like any other, so a declared `fault` edge routes it: the
360+
* author's graceful path (notify, fall back, set the record back) runs instead
361+
* of the run failing with nobody told. With no `fault` edge the run fails
362+
* exactly as it always has, and `start`'s no-executor path is untouched.
363+
*/
364+
describe('a node with no installed executor is graded like any other node failure', () => {
365+
const NO_EXECUTOR_MESSAGE = "No executor registered for node type 'approval'";
366+
367+
function approvalFlow(name: string, withFault: boolean) {
368+
return {
369+
name,
370+
label: name,
371+
type: 'autolaunched' as const,
372+
nodes: [
373+
{ id: 'start', type: 'start' as const, label: 'Start' },
374+
{ id: 'signoff', type: 'approval' as any, label: 'Sign-off', config: { approvers: [{ type: 'user', value: 'u1' }] } },
375+
{ id: 'handler', type: 'script' as any, label: 'Handler', config: { function: 'noop' } },
376+
{ id: 'end', type: 'end' as const, label: 'End' },
377+
],
378+
edges: [
379+
{ id: 'e1', source: 'start', target: 'signoff' },
380+
{ id: 'e2', source: 'signoff', target: 'end' },
381+
...(withFault ? [{ id: 'e_fault', source: 'signoff', target: 'handler', type: 'fault' as const }] : []),
382+
{ id: 'e3', source: 'handler', target: 'end' },
383+
],
384+
};
385+
}
386+
387+
function engineWithHandler() {
388+
const engine = new AutomationEngine(createTestLogger());
389+
const seen: { handlerRuns: number; error?: unknown; nodeScoped?: unknown } = { handlerRuns: 0 };
390+
engine.registerNodeExecutor({
391+
type: 'script',
392+
async execute(_node, variables) {
393+
seen.handlerRuns++;
394+
seen.error = variables.get('$error');
395+
seen.nodeScoped = variables.get('signoff');
396+
return { success: true };
397+
},
398+
});
399+
return { engine, seen };
400+
}
401+
402+
it('routes a declared fault edge, and the handler reads $error.code NO_EXECUTOR', async () => {
403+
const { engine, seen } = engineWithHandler();
404+
engine.registerFlow('approval_with_fault', approvalFlow('approval_with_fault', true));
405+
406+
const result = await engine.execute('approval_with_fault');
407+
408+
expect(result.success).toBe(true);
409+
expect(seen.handlerRuns).toBe(1);
410+
expect(seen.error).toEqual({ nodeId: 'signoff', message: NO_EXECUTOR_MESSAGE, code: 'NO_EXECUTOR' });
411+
expect((seen.nodeScoped as { error?: unknown } | undefined)?.error).toBe(NO_EXECUTOR_MESSAGE);
412+
});
413+
414+
it('keeps the NO_EXECUTOR failure step in the run record when the fault branch completes', async () => {
415+
const { engine } = engineWithHandler();
416+
engine.registerFlow('approval_traced', approvalFlow('approval_traced', true));
417+
418+
await engine.execute('approval_traced');
419+
420+
const runs = await engine.listRuns('approval_traced');
421+
const steps = runs[0]?.steps ?? [];
422+
const signoff = steps.filter((s: any) => s.nodeId === 'signoff');
423+
expect(signoff).toHaveLength(1);
424+
expect(signoff[0]?.status).toBe('failure');
425+
expect(signoff[0]?.error).toEqual({ code: 'NO_EXECUTOR', message: NO_EXECUTOR_MESSAGE });
426+
expect(steps.map((s: any) => [s.nodeId, s.status])).toEqual([
427+
['start', 'success'],
428+
['signoff', 'failure'],
429+
['handler', 'success'],
430+
]);
431+
});
432+
433+
it('CONTROL — with no fault edge the run fails exactly as before', async () => {
434+
const { engine, seen } = engineWithHandler();
435+
engine.registerFlow('approval_no_fault', approvalFlow('approval_no_fault', false));
436+
437+
const result = await engine.execute('approval_no_fault');
438+
439+
expect(result.success).toBe(false);
440+
expect(result.status).toBe('failed');
441+
expect(result.error).toBe(NO_EXECUTOR_MESSAGE);
442+
expect(seen.handlerRuns).toBe(0);
443+
const runs = await engine.listRuns('approval_no_fault');
444+
const steps = runs[0]?.steps ?? [];
445+
expect(steps.map((s: any) => [s.nodeId, s.status, s.error?.code])).toEqual([
446+
['start', 'success', undefined],
447+
['signoff', 'failure', 'NO_EXECUTOR'],
448+
]);
449+
expect(steps[1]?.error?.message).toBe(NO_EXECUTOR_MESSAGE);
450+
});
451+
452+
it('CONTROL — a start node with no executor still records success and the run proceeds', async () => {
453+
const { engine, seen } = engineWithHandler();
454+
engine.registerFlow('start_only', {
455+
name: 'start_only',
456+
label: 'start_only',
457+
type: 'autolaunched',
458+
nodes: [
459+
{ id: 'start', type: 'start', label: 'Start' },
460+
{ id: 'handler', type: 'script' as any, label: 'Handler', config: { function: 'noop' } },
461+
{ id: 'end', type: 'end', label: 'End' },
462+
],
463+
edges: [
464+
{ id: 'e1', source: 'start', target: 'handler' },
465+
{ id: 'e2', source: 'handler', target: 'end' },
466+
],
467+
});
468+
469+
const result = await engine.execute('start_only');
470+
471+
expect(result.success).toBe(true);
472+
expect(seen.handlerRuns).toBe(1);
473+
expect(seen.error).toBeUndefined();
474+
const runs = await engine.listRuns('start_only');
475+
const startStep = runs[0]?.steps?.find((s: any) => s.nodeId === 'start');
476+
expect(startStep?.status).toBe('success');
477+
expect(startStep?.error).toBeUndefined();
478+
});
479+
480+
it('CONTROL — a registered executor that throws still routes its fault edge with the thrown message', async () => {
481+
const { engine, seen } = engineWithHandler();
482+
engine.registerNodeExecutor({
483+
type: 'approval',
484+
async execute() {
485+
throw new Error('approval store unreachable');
486+
},
487+
});
488+
engine.registerFlow('approval_throws', approvalFlow('approval_throws', true));
489+
490+
const result = await engine.execute('approval_throws');
491+
492+
expect(result.success).toBe(true);
493+
expect(seen.handlerRuns).toBe(1);
494+
expect(seen.error).toEqual({ nodeId: 'signoff', message: 'approval store unreachable' });
495+
const runs = await engine.listRuns('approval_throws');
496+
const signoff = runs[0]?.steps?.find((s: any) => s.nodeId === 'signoff');
497+
expect(signoff?.error).toEqual({ code: 'EXECUTION_ERROR', message: 'approval store unreachable' });
498+
});
499+
});

‎packages/services/service-automation/src/throw-arm-error-refresh.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,59 @@ describe('#14955 — the throw arm refreshes `$error` like the returned-failure
246246
expect(seen.deleted).toBe(false);
247247
});
248248
});
249+
250+
describe('the missing-executor arm publishes `$error` like the two failure arms', () => {
251+
it('a node with no installed executor inside a try region names itself, with code NO_EXECUTOR', async () => {
252+
// The node never ran, so nothing else can describe the failure: the
253+
// missing-executor arm publishes `$error` before deciding whether it
254+
// routes, and `try_catch` binds that fresh value's `code` onto its own
255+
// caught error, so a catch region can tell "the plugin is not installed"
256+
// from any other failure.
257+
const engine = new AutomationEngine(makeLogger());
258+
let seenCaught: any;
259+
let seenError: any;
260+
registerTryCatchNode(engine, ctxWith({}));
261+
engine.registerNodeExecutor({
262+
type: 'probe',
263+
async execute(_node, variables) {
264+
seenCaught = variables.get('caught');
265+
seenError = variables.get('$error');
266+
return { success: true };
267+
},
268+
} as NodeExecutor);
269+
engine.registerFlow('missing_in_try', {
270+
name: 'missing_in_try', label: 'Missing in try', type: 'autolaunched',
271+
nodes: [
272+
{ id: 'start', type: 'start', label: 'Start' },
273+
{
274+
id: 'tc', type: 'try_catch', label: 'Guarded',
275+
config: {
276+
errorVariable: 'caught',
277+
try: {
278+
// Not `approval`: a pausing type may not sit in a region at all.
279+
nodes: [{ id: 'signoff', type: 'uninstalled_step', label: 'Sign-off' }],
280+
edges: [],
281+
},
282+
catch: { nodes: [{ id: 'look', type: 'probe', label: 'Look' }], edges: [] },
283+
},
284+
},
285+
{ id: 'end', type: 'end', label: 'End' },
286+
],
287+
edges: [
288+
{ id: 'e1', source: 'start', target: 'tc' },
289+
{ id: 'e2', source: 'tc', target: 'end' },
290+
],
291+
} as any);
292+
293+
const result = await engine.execute('missing_in_try', { userId: 'u1' } as any);
294+
295+
expect(result.success).toBe(true);
296+
expect(seenError).toEqual({
297+
nodeId: 'signoff',
298+
message: "No executor registered for node type 'uninstalled_step'",
299+
code: 'NO_EXECUTOR',
300+
});
301+
expect(seenCaught?.code).toBe('NO_EXECUTOR');
302+
expect(seenCaught?.message).toBe("No executor registered for node type 'uninstalled_step'");
303+
});
304+
});

0 commit comments

Comments
 (0)