Skip to content

Commit 129c387

Browse files
committed
fix: restore replay loader promise boundary
1 parent caaf758 commit 129c387

2 files changed

Lines changed: 19 additions & 31 deletions

File tree

‎src/__tests__/test-utils/replay-script-source.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1+
import fs from 'node:fs';
12
import type { ReplayScriptSourceBundle } from '@agent-device/contracts/replay';
23
import type { MaestroSourceReader } from '@agent-device/maestro';
4+
import { resolveUserPath } from '@agent-device/host-kit/file';
35
import type { DaemonRequest } from '../../daemon/types.ts';
46
import { loadReplayScriptSourceBundle } from '../../commands/replay/script-source-bundle.ts';
57
import { discoverReplaySourcePaths } from '../../commands/replay/source-discovery.ts';
68

7-
/**
8-
* A native `.ad` script's bundle, built from a file on disk through the client's own reader
9-
* (#1802) so a test never hand-rolls a shape the CLI would not actually send. Native loading is
10-
* synchronous because an `.ad` script has no include grammar and needs no engine; use
11-
* `maestroScriptSourceBundleFor` for a flow.
12-
*/
9+
/** A native `.ad` script's one-entry source bundle for test requests. */
1310
export function replayScriptSourceBundleFor(filePath: string): ReplayScriptSourceBundle {
14-
const bundle = loadReplayScriptSourceBundle({ inputPath: filePath, cwd: process.cwd() });
15-
if (bundle instanceof Promise) {
16-
throw new Error('native replay source bundle unexpectedly loaded asynchronously');
17-
}
18-
return bundle;
11+
const entry = resolveUserPath(filePath, { cwd: process.cwd() });
12+
return { entry, files: { [entry]: fs.readFileSync(entry, 'utf8') } };
1913
}
2014

2115
/** A Maestro flow's bundle — async because the engine that walks its includes loads on demand. */

‎src/commands/replay/script-source-bundle.ts‎

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,22 @@ export type ReplayScriptSourceRequest = {
1313
env?: Readonly<Record<string, string>>;
1414
};
1515

16-
export function loadReplayScriptSourceBundle(
16+
export async function loadReplayScriptSourceBundle(
1717
params: ReplayScriptSourceRequest,
18-
): ReplayScriptSourceBundle | Promise<ReplayScriptSourceBundle> {
19-
try {
20-
const entry = resolveUserPath(params.inputPath, { cwd: params.cwd });
21-
const entrySource = readReplayEntryScript(entry, params.inputPath);
22-
if (resolveReplayFormat(entry, params.replayBackend) !== 'maestro') {
23-
return finishBundle(entry, { [entry]: entrySource }, params.inputPath);
24-
}
25-
return (async () => {
26-
const { collectMaestroFlowSources } = await import('@agent-device/maestro');
27-
const files = collectMaestroFlowSources({
28-
entryPath: entry,
29-
entrySource,
30-
env: params.env,
31-
readSource: tryReadScriptFile,
32-
});
33-
return finishBundle(entry, files, params.inputPath);
34-
})();
35-
} catch (error) {
36-
return Promise.reject(error);
18+
): Promise<ReplayScriptSourceBundle> {
19+
const entry = resolveUserPath(params.inputPath, { cwd: params.cwd });
20+
const entrySource = readReplayEntryScript(entry, params.inputPath);
21+
if (resolveReplayFormat(entry, params.replayBackend) !== 'maestro') {
22+
return finishBundle(entry, { [entry]: entrySource }, params.inputPath);
3723
}
24+
const { collectMaestroFlowSources } = await import('@agent-device/maestro');
25+
const files = collectMaestroFlowSources({
26+
entryPath: entry,
27+
entrySource,
28+
env: params.env,
29+
readSource: tryReadScriptFile,
30+
});
31+
return finishBundle(entry, files, params.inputPath);
3832
}
3933

4034
function finishBundle(

0 commit comments

Comments
 (0)