Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/core/src/agents/runtime/workflow-orchestrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,54 @@ describe('WorkflowOrchestrator', () => {
expect(outcome.result).toBe('world');
});

// P4: outcome.meta surfaces the extracted `export const meta = {...}`
// declaration. Null when the script omits it.
it('outcome.meta is null when the script has no meta declaration', async () => {
const orchestrator = new WorkflowOrchestrator(async () => 'unused');
const outcome = await orchestrator.run({
script: `return 1`,
args: undefined,
});
expect(outcome.meta).toBeNull();
});

it('outcome.meta is the parsed meta when the script declares one', async () => {
const orchestrator = new WorkflowOrchestrator(async () => 'unused');
const outcome = await orchestrator.run({
script: `export const meta = { name: 'demo', description: 'demo workflow', phases: [{ title: 'plan' }] }
return 1`,
args: undefined,
});
expect(outcome.meta).toEqual({
name: 'demo',
description: 'demo workflow',
phases: [{ title: 'plan' }],
});
expect(outcome.result).toBe(1);
});

// P4: a script body that throws still surfaces the meta on the wrapped
// WorkflowExecutionError so the user-facing display can identify which
// workflow ran before the body failed.
it('WorkflowExecutionError carries meta when the body throws AFTER meta parsed', async () => {
const orchestrator = new WorkflowOrchestrator(async () => 'unused');
let caught: unknown;
try {
await orchestrator.run({
script: `export const meta = { name: 'fails', description: 'will throw' }
throw new Error("body boom")`,
args: undefined,
});
} catch (e) {
caught = e;
}
expect(caught).toBeInstanceOf(WorkflowExecutionError);
expect((caught as WorkflowExecutionError).meta).toEqual({
name: 'fails',
description: 'will throw',
});
});

it('surfaces a thrown error from the script', async () => {
const orchestrator = new WorkflowOrchestrator(async () => 'unused');
await expect(
Expand Down
20 changes: 19 additions & 1 deletion packages/core/src/agents/runtime/workflow-orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createWorkflowSandbox, debugLogger } from './workflow-sandbox.js';
import type {
WorkflowAgentOpts,
WorkflowAgentResult,
WorkflowMeta,
} from './workflow-sandbox.js';
import {
WORKFLOW_SUBAGENT_SYSTEM_PROMPT,
Expand Down Expand Up @@ -164,6 +165,13 @@ export class WorkflowExecutionError extends Error {
message: string,
readonly phases: string[],
readonly logs: string[],
/**
* The extracted meta if it was parsed before the script body threw —
* null otherwise (no declaration in the source, or malformed meta
Comment thread
LaZzyMan marked this conversation as resolved.
Resolved
* which itself was the failure). Surfaced so the tool's failure
* display can still show the workflow's name / description / phases.
*/
readonly meta: WorkflowMeta | null = null,
) {
super(message);
}
Expand All @@ -172,7 +180,7 @@ export class WorkflowExecutionError extends Error {
// FIX-E (Round 4 ARCH-I1): single source of truth for the dispatch return
// type is `workflow-sandbox.ts`. Re-exported here so external consumers
// (WorkflowTool) can import the alias from the orchestrator module.
export type { WorkflowAgentResult };
export type { WorkflowAgentResult, WorkflowMeta };

export interface WorkflowRunRequest {
script: string;
Expand All @@ -199,6 +207,14 @@ export interface WorkflowRunOutcome {
result: unknown;
phases: string[];
logs: string[];
/**
* The script's `export const meta = {...}` declaration (P4). `null` when
* the script omits the declaration. Surfaced verbatim from the sandbox's
* `getMeta()` so callers (`/workflows` listing, phase-tree UI) can read
* the workflow's name / description / phases / whenToUse without
* re-parsing the script source.
*/
meta: WorkflowMeta | null;
}

export type WorkflowAgentDispatch = (
Expand Down Expand Up @@ -1091,6 +1107,7 @@ export class WorkflowOrchestrator {
result,
phases: sandbox.getPhases(),
logs: sandbox.getLogs(),
meta: sandbox.getMeta(),
};
} catch (err) {
// T19 (PR #4732 R1): preserve phases and logs accumulated before the
Expand All @@ -1105,6 +1122,7 @@ export class WorkflowOrchestrator {
extractErrorMessage(err),
sandbox.getPhases(),
sandbox.getLogs(),
sandbox.getMeta(),
);
}
}
Expand Down
Loading
Loading