Skip to content

Commit 3c32e14

Browse files
committed
fix(replay): reject unrouted YAML before plugin admission
1 parent 6be2c0c commit 3c32e14

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

‎packages/daemon/src/server/__tests__/request-router-replay-plugin.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@ const source = {
4747
files: { '/caller/flow.ad': 'open com.example.app\nclose\n' },
4848
};
4949

50+
test.each(['yaml', 'yml'])(
51+
'bare %s replay reports explicit routing before plugin or device admission',
52+
async (extension) => {
53+
const f = await fixture();
54+
const entry = `/caller/flow.${extension}`;
55+
try {
56+
const result = await f.handler({
57+
token: 'token',
58+
command: 'replay',
59+
session: 'untouched',
60+
positionals: [entry],
61+
flags: { replayScriptSource: { entry, files: { [entry]: 'appId: com.example.app' } } },
62+
});
63+
expect(result).toMatchObject({
64+
ok: false,
65+
error: {
66+
code: 'INVALID_ARGS',
67+
message: `Maestro YAML requires explicit --maestro routing: replay ${entry} --maestro`,
68+
},
69+
});
70+
if (result.ok) throw new Error('Bare YAML replay succeeded');
71+
expect(result.error.details?.installCommand).toBeUndefined();
72+
expect(f.discover).not.toHaveBeenCalled();
73+
expect(f.store.get('untouched')).toBeUndefined();
74+
} finally {
75+
await f.registry.close();
76+
}
77+
},
78+
);
79+
5080
test.each(['replay', 'test'] as const)(
5181
'missing %s execution is classified before device selection',
5282
async (command) => {
@@ -78,6 +108,31 @@ test.each(['replay', 'test'] as const)(
78108
},
79109
);
80110

111+
test('explicit Maestro routing still admits only the Maestro plugin', async () => {
112+
const f = await fixture();
113+
const entry = '/caller/flow.yaml';
114+
try {
115+
const result = await f.handler({
116+
token: 'token',
117+
command: 'replay',
118+
session: 'untouched',
119+
positionals: [entry],
120+
flags: {
121+
replayBackend: 'maestro',
122+
replayScriptSource: { entry, files: { [entry]: 'appId: com.example.app' } },
123+
},
124+
});
125+
expect(result).toMatchObject({
126+
ok: false,
127+
error: { details: { reason: 'plugin-not-installed', package: '@agent-device/maestro' } },
128+
});
129+
expect(f.discover).not.toHaveBeenCalled();
130+
expect(f.store.get('untouched')).toBeUndefined();
131+
} finally {
132+
await f.registry.close();
133+
}
134+
});
135+
81136
test('a changed store needs a daemon restart and embedded runtimes never consult it', async () => {
82137
const home = mkdtempForTestSync('replay-plugin-store-');
83138
const env = { AGENT_DEVICE_HOME: home };

‎packages/replay-port/src/daemon-port/replay-plugin-admission.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import { getReplayBackend, getReplayExecution } from './replay-backend-registry.
44

55
/** Rejects unavailable execution before request binding can select or act on a device. */
66
export async function requireReplayPlugins(request: DaemonWireRequest): Promise<void> {
7-
const { isReplayBackendId, unsupportedReplayBackendMessage, resolveReplayFormat } =
8-
await import('@agent-device/ad-script');
7+
const {
8+
isReplayBackendId,
9+
unsupportedReplayBackendMessage,
10+
resolveReplayFormat,
11+
isMaestroYamlPath,
12+
maestroBackendRequiredMessage,
13+
} = await import('@agent-device/ad-script');
914
const backend = request.flags?.replayBackend;
1015
if (backend !== undefined && !isReplayBackendId(backend))
1116
throw new AppError('INVALID_ARGS', unsupportedReplayBackendMessage(backend));
@@ -19,6 +24,8 @@ export async function requireReplayPlugins(request: DaemonWireRequest): Promise<
1924
await getReplayBackend('maestro');
2025
} else if (request.command === 'replay') {
2126
const entry = request.flags?.replayScriptSource?.entry ?? request.positionals?.[0] ?? '';
27+
if (isMaestroYamlPath(entry) && backend !== 'maestro')
28+
throw new AppError('INVALID_ARGS', maestroBackendRequiredMessage('replay', entry));
2229
if (resolveReplayFormat(entry, request.flags?.replayBackend) === 'maestro')
2330
await getReplayBackend('maestro');
2431
else await getReplayExecution();

0 commit comments

Comments
 (0)