Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ test('replay-test source inspection reads declared platform, target and attempt
assert.deepEqual(entry?.manifest.attemptDefaults, { timeoutMs: 4000, retries: 2 });
});

test('replay-test source inspection returns shipped yaml when the entry path is not on disk', async () => {
const flowPath = '/client-only/missing/01-flow.yaml';
const yaml = 'appId: demo\nname: Remote Flow\n---\n- launchApp\n';

const [entry] = (
await buildReplayTestSourceDiscovery(
[{ entry: flowPath, files: { [flowPath]: yaml } }],
'maestro',
)
)();

assert.equal(entry?.path, flowPath);
assert.equal(entry?.sourceText, yaml);
assert.equal(entry?.manifest.title, 'Remote Flow');
});

test('replay-test source inspection keeps the order the caller discovered', async () => {
const root = mkdtempForTestSync('agent-device-test-inspect-order-');
const second = path.join(root, '02-second.ad');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ function inspectReplayTestSource(
}
: {}),
};
return { path: filePath, manifest };
return { path: filePath, manifest, sourceText: script };
}
7 changes: 4 additions & 3 deletions packages/replay-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* result aggregation — is private to `internal/`.
*
* The scheduler is format-agnostic: it imports neither engine, and a source reaches it only as
* a `ReplayTestManifest`. Host authority arrives as narrow capabilities on the runtime-dependency
* half of `runReplayTestSuite`'s parameter; none of them hands over a daemon request, a session
* store, mutable session state, or an engine.
* a `ReplayTestManifest` plus the opaque entry text the host already read. Host authority
* arrives as narrow capabilities on the runtime-dependency half of `runReplayTestSuite`'s
* parameter; none of them hands over a daemon request, a session store, mutable session state,
* or an engine.
*
* The parameter and result types themselves are not named here. The single caller builds the
* bag inline and TypeScript infers both, so re-exporting the names would add surface no consumer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from 'vitest';
import { test, vi } from 'vitest';
import assert from 'node:assert/strict';
import fs from 'node:fs';

Expand Down Expand Up @@ -44,10 +44,9 @@ test('materializeReplayTestAttemptArtifacts writes replay and result manifests f
const replayPath = path.join(root, 'flow.ad');
const screenshotPath = path.join(root, 'capture.png');
const attemptDir = path.join(root, 'attempt-1');
fs.writeFileSync(replayPath, 'context platform=ios\nopen "Demo"\n');
fs.writeFileSync(screenshotPath, 'png');

prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(replayPath, attemptDir, 'context platform=ios\nopen "Demo"\n');
materializeReplayTestAttemptArtifacts({
outcome: passedOutcome({ replayed: 4, healed: 1, artifactPaths: [screenshotPath] }),
filePath: replayPath,
Expand All @@ -72,25 +71,70 @@ test('prepareReplayTestAttemptArtifacts preserves original Maestro flow filename
const root = mkdtempForTestSync('agent-device-test-artifacts-maestro-');
const replayPath = path.join(root, 'auth-flow.yml');
const attemptDir = path.join(root, 'attempt-1');
fs.writeFileSync(replayPath, 'appId: demo.app\n---\n- assertVisible: Welcome\n');

prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(
replayPath,
attemptDir,
'appId: demo.app\n---\n- assertVisible: Welcome\n',
);

assert.equal(fs.existsSync(path.join(attemptDir, 'replay.ad')), true);
assert.equal(fs.existsSync(path.join(attemptDir, 'auth-flow.yml')), true);
});

test('prepareReplayTestAttemptArtifacts writes shipped flow text without opening a missing path', () => {
const root = mkdtempForTestSync('agent-device-test-artifacts-remote-source-');
const replayPath = path.join(root, 'missing-client', 'auth-flow.yaml');
const attemptDir = path.join(root, 'slug', 'attempt-1');
const source = 'appId: demo.app\n---\n- launchApp\n';
const copyFileSync = vi.spyOn(fs, 'copyFileSync');
const statSync = vi.spyOn(fs, 'statSync');

try {
prepareReplayTestAttemptArtifacts(replayPath, attemptDir, source);
assert.equal(
copyFileSync.mock.calls.some((call) => call[0] === replayPath),
false,
);
assert.equal(
statSync.mock.calls.some((call) => call[0] === replayPath),
false,
);
} finally {
copyFileSync.mockRestore();
statSync.mockRestore();
}

assert.equal(fs.readFileSync(path.join(attemptDir, 'replay.ad'), 'utf8'), source);
assert.equal(fs.readFileSync(path.join(attemptDir, 'auth-flow.yaml'), 'utf8'), source);
});

test('prepareReplayTestAttemptArtifacts writes only replay.ad when shipped text is a .ad entry', () => {
const root = mkdtempForTestSync('agent-device-test-artifacts-shipped-ad-');
const replayPath = path.join(root, 'missing-client', 'flow.ad');
const attemptDir = path.join(root, 'attempt-1');
const source = 'context platform=ios\nopen "Demo"\n';

prepareReplayTestAttemptArtifacts(replayPath, attemptDir, source);

assert.equal(fs.readFileSync(path.join(attemptDir, 'replay.ad'), 'utf8'), source);
assert.deepEqual(fs.readdirSync(attemptDir), ['replay.ad']);
});

test('materializeReplayTestAttemptArtifacts writes failure manifest and copies log artifacts', () => {
const root = mkdtempForTestSync('agent-device-test-artifacts-fail-');
const replayPath = path.join(root, 'flow.ad');
const screenshotPath = path.join(root, 'capture.png');
const logPath = path.join(root, 'daemon.log');
const attemptDir = path.join(root, 'attempt-2');
fs.writeFileSync(replayPath, 'context platform=android\nopen "Demo"\n');
fs.writeFileSync(screenshotPath, 'png');
fs.writeFileSync(logPath, 'log');

prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(
replayPath,
attemptDir,
'context platform=android\nopen "Demo"\n',
);
materializeReplayTestAttemptArtifacts({
outcome: {
status: 'failed',
Expand Down Expand Up @@ -139,7 +183,6 @@ test.each([
const root = mkdtempForTestSync('agent-device-artifact-collisions-');
const replayPath = path.join(root, 'flow.ad');
const attemptDir = path.join(root, 'attempt-1');
fs.writeFileSync(replayPath, 'context platform=android\nopen demo.app\n');
const artifactPaths = names.map((name, index) => {
const dir = path.join(root, String(index));
fs.mkdirSync(dir);
Expand All @@ -148,7 +191,11 @@ test.each([
return artifactPath;
});

prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(
replayPath,
attemptDir,
'context platform=android\nopen demo.app\n',
);
materializeReplayTestAttemptArtifacts({
outcome: passedOutcome({ artifactPaths }),
filePath: replayPath,
Expand All @@ -170,7 +217,6 @@ test('materialization preserves replay sources and diagnostics named after attem
const replayPath = path.join(root, 'flow.yml');
const attemptDir = path.join(root, 'attempt-1');
const source = 'appId: demo.app\n---\n- assertVisible: Welcome\n';
fs.writeFileSync(replayPath, source);
const names = ['replay.ad', 'flow.yml', 'result.txt', 'failure.txt'];
const artifactPaths = names.map((name) => {
const dir = path.join(root, 'diagnostics', name);
Expand All @@ -180,7 +226,7 @@ test('materialization preserves replay sources and diagnostics named after attem
return artifactPath;
});

prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(replayPath, attemptDir, source);
materializeReplayTestAttemptArtifacts({
outcome: {
status: 'failed',
Expand Down Expand Up @@ -220,9 +266,12 @@ test.each([false, true])(
const attemptDir = path.join(root, 'attempt-1');
const externalTrace = path.join(root, 'replay-timing.ndjson');
const localTrace = path.join(attemptDir, 'replay-timing.ndjson');
fs.writeFileSync(replayPath, 'context platform=android\nopen demo.app\n');
fs.writeFileSync(externalTrace, 'external trace');
prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(
replayPath,
attemptDir,
'context platform=android\nopen demo.app\n',
);
fs.writeFileSync(localTrace, 'attempt trace');
const artifactPaths = localFirst ? [localTrace, externalTrace] : [externalTrace, localTrace];

Expand Down Expand Up @@ -256,9 +305,12 @@ test('materialization copies a log listed in both the outcome and error only onc
const replayPath = path.join(root, 'flow.ad');
const logPath = path.join(root, 'daemon.log');
const attemptDir = path.join(root, 'attempt-1');
fs.writeFileSync(replayPath, 'context platform=android\nopen demo.app\n');
fs.writeFileSync(logPath, 'diagnostic log');
prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(
replayPath,
attemptDir,
'context platform=android\nopen demo.app\n',
);

materializeReplayTestAttemptArtifacts({
outcome: {
Expand Down Expand Up @@ -289,8 +341,11 @@ test.each(['result.txt', 'failure.txt', 'RESULT.TXT'])(
const root = mkdtempForTestSync('agent-device-artifact-in-place-manifest-');
const replayPath = path.join(root, 'flow.ad');
const attemptDir = path.join(root, 'attempt-1');
fs.writeFileSync(replayPath, 'context platform=android\nopen demo.app\n');
prepareReplayTestAttemptArtifacts(replayPath, attemptDir);
prepareReplayTestAttemptArtifacts(
replayPath,
attemptDir,
'context platform=android\nopen demo.app\n',
);
const diagnosticPath = path.join(attemptDir, name);
fs.writeFileSync(diagnosticPath, 'diagnostic contents');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ const FAILED_WITHOUT_WARNINGS: ReplayTestAttemptOutcome = {
function makeEntry(): ReplayTestRunEntry {
const root = mkdtempForTestSync('agent-device-test-attempt-');
const filePath = path.join(root, '01-flow.ad');
fs.writeFileSync(filePath, 'context platform=ios\nopen "Demo"\n');
const sourceText = 'context platform=ios\nopen "Demo"\n';
fs.writeFileSync(filePath, sourceText);
return {
kind: 'run',
path: filePath,
title: 'flow',
manifest: { device: { platform: { kind: 'declared', value: 'ios' } } },
sourceText,
};
}

Expand Down Expand Up @@ -70,3 +72,49 @@ test('a failed test result omits warnings when the attempt had none', async () =
const result = await runFailedCase(FAILED_WITHOUT_WARNINGS);
expect('warnings' in result).toBe(false);
});

test('a missing entry path runs from shipped source text', async () => {
const suiteArtifactsDir = mkdtempForTestSync('agent-device-test-attempt-remote-');
const filePath = path.join(suiteArtifactsDir, 'client-only', 'auth-flow.yaml');
const source = 'appId: demo.app\n---\n- launchApp\n';
let ran = false;

await runReplayTestCase({
entry: {
kind: 'run',
path: filePath,
manifest: { device: { platform: { kind: 'caller-bound' } } },
sourceText: source,
},
sessionName: 'default',
suiteInvocationId: 'suite-remote',
caseIndex: 0,
retries: 0,
suiteArtifactsDir,
suiteIndex: 1,
suiteTotal: 1,
runReplay: async () => {
ran = true;
return {
status: 'passed',
replayed: 1,
healed: 0,
warnings: [],
artifactPaths: [],
};
},
cleanupSession: async () => {},
emitProgress: () => {},
isCanceled: () => false,
emitDiagnostic: () => {},
bindAttemptCancellation: () => ({ cancel: () => {}, release: () => {} }),
});

expect(ran).toBe(true);
expect(
fs.readFileSync(
path.join(suiteArtifactsDir, 'auth-flow.yaml', 'attempt-1', 'replay.ad'),
'utf8',
),
).toBe(source);
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ test('platform filter skips sources that declared no platform', () => {
const entries = discoverReplayTestEntries({
platformFilter: 'android',
discoverSources: sourcesOf(
{ path: '01-untyped.ad', manifest: unspecified },
{ path: '02-android.ad', manifest: declared('android') },
{ path: '01-untyped.ad', manifest: unspecified, sourceText: 'open "Demo"\n' },
{
path: '02-android.ad',
manifest: declared('android'),
sourceText: 'context platform=android\n',
},
),
});

Expand All @@ -45,19 +49,50 @@ test('platform filter skips sources that declared no platform', () => {
test('platform filter runs caller-bound sources, which take their platform from the invocation', () => {
const entries = discoverReplayTestEntries({
platformFilter: 'android',
discoverSources: sourcesOf({ path: '01-flow.yaml', manifest: callerBound }),
discoverSources: sourcesOf({
path: '01-flow.yaml',
manifest: callerBound,
sourceText: 'appId: demo\n---\n- launchApp\n',
}),
});

assert.equal(entries.length, 1);
assert.equal(entries[0]?.kind, 'run');
});

test('discovery copies shipped source text onto filtered run entries', () => {
const flowText = 'appId: demo\n---\n- launchApp\n';
const nativeText = 'context platform=ios\nopen "Demo"\n';
const entries = discoverReplayTestEntries({
platformFilter: 'ios',
discoverSources: sourcesOf(
{ path: '01-flow.yaml', manifest: callerBound, sourceText: flowText },
{ path: '02-ios.ad', manifest: declared('ios'), sourceText: nativeText },
),
});

const flow = entries.find((entry) => entry.path === '01-flow.yaml');
const native = entries.find((entry) => entry.path === '02-ios.ad');
assert.equal(flow?.kind, 'run');
if (flow?.kind === 'run') {
assert.equal(flow.sourceText, flowText);
}
assert.equal(native?.kind, 'run');
if (native?.kind === 'run') {
assert.equal(native.sourceText, nativeText);
}
});

test('platform filter drops declared sources that do not match, without a skip entry', () => {
const entries = discoverReplayTestEntries({
platformFilter: 'android',
discoverSources: sourcesOf(
{ path: '01-ios.ad', manifest: declared('ios') },
{ path: '02-android.ad', manifest: declared('android') },
{ path: '01-ios.ad', manifest: declared('ios'), sourceText: 'context platform=ios\n' },
{
path: '02-android.ad',
manifest: declared('android'),
sourceText: 'context platform=android\n',
},
),
});

Expand All @@ -72,7 +107,11 @@ test('a suite that matched nothing after filtering is rejected', () => {
() =>
discoverReplayTestEntries({
platformFilter: 'android',
discoverSources: sourcesOf({ path: '01-ios.ad', manifest: declared('ios') }),
discoverSources: sourcesOf({
path: '01-ios.ad',
manifest: declared('ios'),
sourceText: 'context platform=ios\n',
}),
}),
(error: unknown) =>
error instanceof AppError &&
Expand All @@ -90,7 +129,11 @@ test('a suite whose only source declares no platform is told how to declare one'
() =>
discoverReplayTestEntries({
platformFilter: 'android',
discoverSources: sourcesOf({ path: '01-untyped.ad', manifest: unspecified }),
discoverSources: sourcesOf({
path: '01-untyped.ad',
manifest: unspecified,
sourceText: 'open "Demo"\n',
}),
}),
(error: unknown) =>
error instanceof AppError &&
Expand All @@ -108,7 +151,11 @@ test('a filter value no script can declare is not answered with declaration advi
() =>
discoverReplayTestEntries({
platformFilter: 'web',
discoverSources: sourcesOf({ path: '01-untyped.ad', manifest: unspecified }),
discoverSources: sourcesOf({
path: '01-untyped.ad',
manifest: unspecified,
sourceText: 'open "Demo"\n',
}),
}),
(error: unknown) =>
error instanceof AppError &&
Expand Down
Loading
Loading