Skip to content

Commit be07f5b

Browse files
committed
fix(maestro): assert the suggestion source, first trace write, and pinned help URLs
1 parent c428f29 commit be07f5b

5 files changed

Lines changed: 39 additions & 21 deletions

File tree

‎packages/contracts/src/replay-backend.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,12 @@ export type ReplayBackendHost = Readonly<{
237237
/** Reads one file out of the request's script source bundle; throws when it was not sent. */
238238
readScriptSourceFile(bundle: ReplayScriptSourceBundle, resolvedPath: string): string;
239239
scriptSourceRequiredMessage: string;
240-
/** Selects the device a run binds when no session or explicit platform already names one. */
240+
/**
241+
* Selects the device a run binds when no session or explicit platform already names one. It
242+
* applies the Maestro device-binding rule (the flow's app target steers selection on iOS only),
243+
* the same rule `packages/daemon/src/server/replay-device-selection.ts` applies when it
244+
* pre-binds a device for the request.
245+
*/
241246
resolveTargetDevice(
242247
flags: CommandFlags,
243248
binding: ReplayBackendDeviceBinding,

‎packages/maestro/src/replay-backend/__tests__/session-replay-maestro-failure.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
ReplaySessionStore,
66
} from '@agent-device/contracts/replay-backend';
77
import {
8+
collectMaestroFailureSuggestions,
89
executeMaestroFlow,
910
inspectMaestroFlow,
1011
type MaestroFailedAction,
@@ -96,8 +97,15 @@ test('the failure response hands the host the step, its warnings, and its sugges
9697
},
9798
);
9899

100+
const [handed] = buildActionFailureResponse.mock.calls[0] ?? [];
101+
const node = { index: 0, type: 'Button', label: 'save', identifier: 'save', hittable: true };
102+
expect(handed?.suggestNodes({ createdAt: 0, nodes: [node] })).toEqual(
103+
collectMaestroFailureSuggestions(failure, { createdAt: 0, nodes: [node] }),
104+
);
105+
expect(handed?.suggestNodes({ createdAt: 0, nodes: [node] })).not.toEqual([]);
99106
expect(buildActionFailureResponse).toHaveBeenCalledWith(
100107
expect.objectContaining({
108+
source: failure.source,
101109
stepIndex: failure.stepIndex,
102110
action: 'tapOn',
103111
actionLabel: 'tapOn "save"',

‎packages/maestro/src/replay-backend/__tests__/session-replay-maestro-observer.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ test('forwards command labels to progress and replay trace projection', () => {
4141
command: 'tapOn',
4242
value: 'save action',
4343
});
44-
expect(appendTraceEvent).toHaveBeenCalledWith(
44+
expect(appendTraceEvent).toHaveBeenNthCalledWith(
45+
1,
4546
tracePath,
4647
expect.objectContaining({
4748
type: 'replay_action_start',

‎src/__tests__/cli-startup-import-closure.test.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,24 @@ import { eagerClosureOf, eagerlyEvaluatedModules } from './eager-import-closure.
2121

2222
const srcRoot = path.resolve(import.meta.dirname, '..');
2323
const LAZY_HTTP_MODULES = new Set(['node:http', 'node:https']);
24-
/** Engines heavy enough that evaluating them on startup is a measurable regression. */
25-
const LAZY_ENGINE_MODULES = new Set(['@agent-device/maestro']);
24+
/**
25+
* Engines heavy enough that evaluating them on startup is a measurable regression: the engine
26+
* package and every subpath of it except the replay backend's engine-free declaration.
27+
*/
28+
function isLazyEngineModule(specifier: string): boolean {
29+
return (
30+
specifier === '@agent-device/maestro' ||
31+
(specifier.startsWith('@agent-device/maestro/') &&
32+
specifier !== '@agent-device/maestro/replay-backend-declaration')
33+
);
34+
}
35+
36+
test('the lazy engine set covers the plugin subpath but not its engine-free declaration', () => {
37+
expect(isLazyEngineModule('@agent-device/maestro')).toBe(true);
38+
expect(isLazyEngineModule('@agent-device/maestro/replay-backend')).toBe(true);
39+
expect(isLazyEngineModule('@agent-device/maestro/replay-backend-declaration')).toBe(false);
40+
expect(isLazyEngineModule('@agent-device/maestroish')).toBe(false);
41+
});
2642

2743
test.for([
2844
// --- static forms ---
@@ -104,7 +120,7 @@ test('the CLI startup import closure never evaluates the Maestro engine', () =>
104120
const offenders: string[] = [];
105121
for (const file of eagerClosureOf(path.join(srcRoot, 'cli.ts'))) {
106122
for (const specifier of eagerlyEvaluatedModules(file, fs.readFileSync(file, 'utf8'))) {
107-
if (LAZY_ENGINE_MODULES.has(specifier)) {
123+
if (isLazyEngineModule(specifier)) {
108124
offenders.push(`${path.relative(srcRoot, file)} -> ${specifier}`);
109125
}
110126
}
@@ -126,9 +142,7 @@ test('the replay command source closure keeps Maestro behind flow selection', ()
126142

127143
expect(replayClosure).toContain(sourceBundle);
128144
for (const file of replayClosure) {
129-
if (
130-
eagerlyEvaluatedModules(file, fs.readFileSync(file, 'utf8')).includes('@agent-device/maestro')
131-
) {
145+
if (eagerlyEvaluatedModules(file, fs.readFileSync(file, 'utf8')).some(isLazyEngineModule)) {
132146
offenders.push(path.relative(srcRoot, file));
133147
}
134148
}

‎src/cli/parser/__tests__/maestro-support-matrix.test.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@ import {
66
MAESTRO_COMPAT_LIMITATIONS,
77
MAESTRO_COMPAT_SUPPORTED_CAPABILITIES,
88
} from '@agent-device/maestro';
9-
import { maestroReplayBackendDeclaration } from '@agent-device/maestro/replay-backend-declaration';
109

11-
const MAESTRO_COMPATIBILITY_ADR_URL = declaredUrl('declared conformance divergences: ');
12-
const MAESTRO_COMPATIBILITY_ISSUE_URL = declaredUrl('Focused compatibility request: ');
13-
14-
function declaredUrl(prefix: string): string {
15-
const line = maestroReplayBackendDeclaration.help.body
16-
.split('\n')
17-
.find((candidate) => candidate.includes(prefix));
18-
const url = line?.slice(line.indexOf(prefix) + prefix.length).trim();
19-
if (!url?.startsWith('https://'))
20-
throw new Error(`declaration help has no URL after "${prefix}"`);
21-
return url;
22-
}
10+
const MAESTRO_COMPATIBILITY_ADR_URL =
11+
'https://github.com/callstack/agent-device/blob/main/docs/adr/0015-direct-maestro-engine.md';
12+
const MAESTRO_COMPATIBILITY_ISSUE_URL = 'https://github.com/callstack/agent-device/issues/new';
2313

2414
test('Maestro flag routes to the versioned compatibility help topic', () => {
2515
const flag = getFlagDefinitions().find((definition) => definition.key === 'replayMaestro');

0 commit comments

Comments
 (0)