Skip to content
Closed
Changes from all 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
51 changes: 49 additions & 2 deletions sdk/tests/live-kernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ steps:
const directory = temporaryDirectory('flows-live-agent-worker-');
const dataDir = join(directory, 'data');
const cli = join(directory, 'agent-cli');
writeFileSync(cli, '#!/bin/sh\nprintf \'handled: %s\' "$1"\n');
const marker = join(directory, 'agent-ran');
writeFileSync(cli, `#!/bin/sh\nprintf '%s' "$1" > ${JSON.stringify(marker)}\n`);
chmodSync(cli, 0o755);
await startDaemon(dataDir);

Expand Down Expand Up @@ -235,9 +236,51 @@ steps:
type: 'agent',
state: 'done',
});
expect(readFileSync(marker, 'utf8')).toBe('Perform the declared work.');
worker.close();
});

it('reports a nonzero agent CLI exit through the kernel failure path', async () => {
const directory = temporaryDirectory('flows-live-agent-failure-');
const dataDir = join(directory, 'data');
const cli = join(directory, 'agent-cli');
writeFileSync(cli, '#!/bin/sh\nprintf failed >&2\nexit 7\n');
chmodSync(cli, 0o755);
await startDaemon(dataDir);

const client = await connectClient(dataDir);
await client.hello('live-sdk-agent-failure-worker');
const worker = new AgentWorker(client, {
workerId: 'live-sdk-agent-failure-worker',
pins: {
workspace: [{ surface: 'repo', revision_id: 'rev-a' }],
streams: [],
},
});
await worker.attach();

const completed = await client.runStart(toKernelSpec(compileYaml(`
version: '0.1.0'
steps:
- id: execute
type: agent
cli: ${JSON.stringify(cli)}
instruction: Fail as declared.
maxIterations: 1
`)));

expect(completed.status).toBe('parked');
expect(await waitForStep(client, completed.run_id, 'execute', 'done')).toMatchObject({
type: 'agent',
state: 'done',
});
expect(completionReasons(
(await client.journalRead(completed.run_id, 1)).entries,
'execute',
)).toEqual(['worker_error']);
worker.close();
}, 10_000);

it('can always get a parked run to a late-attaching worker', async () => {
// The contract that cost the most time to establish, so it is pinned here.
//
Expand Down Expand Up @@ -642,12 +685,16 @@ async function waitForStep(
state: string,
): Promise<unknown> {
const deadline = Date.now() + 5_000;
let observed: unknown;
while (Date.now() < deadline) {
const step = (await client.runGet(runId)).steps[stepId];
observed = step;
if (step?.state === state) return step;
await delay(20);
}
throw new Error(`step ${stepId} did not reach ${state} within 5000ms`);
throw new Error(
`step ${stepId} did not reach ${state} within 5000ms; last observed ${JSON.stringify(observed)}`,
);
}

function runArtifacts(dataDir: string): string[] {
Expand Down