From 6dc09a5e568a3eee0fc110a376b096576c6bbb2a Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:52:11 -0800 Subject: [PATCH 1/2] test(session-test-source-discovery-inspection): write remote test attempt artifacts from shipped script sources inspectReplayTestSource now returns the script it read as sourceText, and discoverReplayTestEntries copies that field onto a run entry when the source has it. runSingleReplayTestAttempt passes entry.sourceText into prepareReplayTestAttemptArtifacts. When the value is a string, including an empty string, copyReplaySourceFile writes it to replay.ad and to the original flow filename and leaves the caller path unopened; when sourceText is absent, it still copies the local file. Refs #4561 --- ...n-test-source-discovery-inspection.test.ts | 16 +++++++ .../session-test-source-discovery.ts | 2 +- packages/replay-test/src/index.ts | 7 +-- .../__tests__/session-test-artifacts.test.ts | 41 ++++++++++++++++- .../__tests__/session-test-attempt.test.ts | 46 +++++++++++++++++++ .../__tests__/session-test-discovery.test.ts | 22 +++++++++ .../src/internal/session-test-artifacts.ts | 25 ++++++++-- .../src/internal/session-test-attempt.ts | 2 +- .../src/internal/session-test-discovery.ts | 12 ++++- .../src/internal/session-test-types.ts | 6 +++ 10 files changed, 166 insertions(+), 13 deletions(-) diff --git a/packages/replay-port/src/daemon-port/__tests__/session-test-source-discovery-inspection.test.ts b/packages/replay-port/src/daemon-port/__tests__/session-test-source-discovery-inspection.test.ts index a0205f1dfe..68e0d540b3 100644 --- a/packages/replay-port/src/daemon-port/__tests__/session-test-source-discovery-inspection.test.ts +++ b/packages/replay-port/src/daemon-port/__tests__/session-test-source-discovery-inspection.test.ts @@ -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'); diff --git a/packages/replay-port/src/daemon-port/session-test-source-discovery.ts b/packages/replay-port/src/daemon-port/session-test-source-discovery.ts index 6ef93fe530..baf287fc93 100644 --- a/packages/replay-port/src/daemon-port/session-test-source-discovery.ts +++ b/packages/replay-port/src/daemon-port/session-test-source-discovery.ts @@ -79,5 +79,5 @@ function inspectReplayTestSource( } : {}), }; - return { path: filePath, manifest }; + return { path: filePath, manifest, sourceText: script }; } diff --git a/packages/replay-test/src/index.ts b/packages/replay-test/src/index.ts index c4f469f001..2fb7645fe8 100644 --- a/packages/replay-test/src/index.ts +++ b/packages/replay-test/src/index.ts @@ -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 diff --git a/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts b/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts index ef16fc0b92..e2a35f1185 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts @@ -1,4 +1,4 @@ -import { test } from 'vitest'; +import { test, vi } from 'vitest'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -80,6 +80,45 @@ test('prepareReplayTestAttemptArtifacts preserves original Maestro flow filename 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'); diff --git a/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts b/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts index e42b3788a5..699fb2a205 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts @@ -70,3 +70,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); +}); diff --git a/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts b/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts index 2f620df7d5..7a18a623c3 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts @@ -52,6 +52,28 @@ test('platform filter runs caller-bound sources, which take their platform from assert.equal(entries[0]?.kind, 'run'); }); +test('discovery copies shipped source text onto filtered run entries and leaves it absent when the source has none', () => { + const sourceText = 'appId: demo\n---\n- launchApp\n'; + const entries = discoverReplayTestEntries({ + platformFilter: 'ios', + discoverSources: sourcesOf( + { path: '01-flow.yaml', manifest: callerBound, sourceText }, + { path: '02-ios.ad', manifest: declared('ios') }, + ), + }); + + 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, sourceText); + } + assert.equal(native?.kind, 'run'); + if (native?.kind === 'run') { + assert.equal('sourceText' in native, false); + } +}); + test('platform filter drops declared sources that do not match, without a skip entry', () => { const entries = discoverReplayTestEntries({ platformFilter: 'android', diff --git a/packages/replay-test/src/internal/session-test-artifacts.ts b/packages/replay-test/src/internal/session-test-artifacts.ts index aa052def70..ddda04e425 100644 --- a/packages/replay-test/src/internal/session-test-artifacts.ts +++ b/packages/replay-test/src/internal/session-test-artifacts.ts @@ -44,9 +44,10 @@ export function buildReplayTestArtifactSlug(filePath: string, cwd?: string): str export function prepareReplayTestAttemptArtifacts( filePath: string, attemptArtifactsDir: string, + sourceText?: string, ): void { fs.mkdirSync(attemptArtifactsDir, { recursive: true }); - copyReplaySourceFile(filePath, attemptArtifactsDir); + copyReplaySourceFile(filePath, attemptArtifactsDir, sourceText); } export function materializeReplayTestAttemptArtifacts(params: { @@ -127,9 +128,20 @@ function copyReplayTestArtifacts( return copiedPaths; } -function copyReplaySourceFile(filePath: string, attemptArtifactsDir: string): void { +function copyReplaySourceFile( + filePath: string, + attemptArtifactsDir: string, + sourceText?: string, +): void { const genericReplayPath = path.join(attemptArtifactsDir, 'replay.ad'); - fs.copyFileSync(filePath, genericReplayPath); + // Shipped entry text is the source of truth. A remote daemon does not share the caller's + // disk, so a string — including "" — is written and the caller path is not opened. Omitted + // text keeps the local copy. + if (typeof sourceText === 'string') { + fs.writeFileSync(genericReplayPath, sourceText); + } else { + fs.copyFileSync(filePath, genericReplayPath); + } // Sources that are not native `.ad` keep their original filename alongside `replay.ad`, so // CI artifacts point back at the flow the author wrote. This is artifact naming, not format @@ -138,9 +150,12 @@ function copyReplaySourceFile(filePath: string, attemptArtifactsDir: string): vo // Keep replay.ad for existing artifact consumers, and preserve the original // Maestro filename so CI artifacts point back to the source flow. const originalReplayPath = path.join(attemptArtifactsDir, path.basename(filePath)); - if (path.resolve(originalReplayPath) !== path.resolve(genericReplayPath)) { - fs.copyFileSync(filePath, originalReplayPath); + if (path.resolve(originalReplayPath) === path.resolve(genericReplayPath)) return; + if (typeof sourceText === 'string') { + fs.writeFileSync(originalReplayPath, sourceText); + return; } + fs.copyFileSync(filePath, originalReplayPath); } function buildUniqueArtifactFileName( diff --git a/packages/replay-test/src/internal/session-test-attempt.ts b/packages/replay-test/src/internal/session-test-attempt.ts index 11101da418..c318582e24 100644 --- a/packages/replay-test/src/internal/session-test-attempt.ts +++ b/packages/replay-test/src/internal/session-test-attempt.ts @@ -142,7 +142,7 @@ async function runSingleReplayTestAttempt( attemptIndex, ); const attemptArtifactsDir = path.join(context.testArtifactsDir, `attempt-${attempt}`); - prepareReplayTestAttemptArtifacts(entry.path, attemptArtifactsDir); + prepareReplayTestAttemptArtifacts(entry.path, attemptArtifactsDir, entry.sourceText); const attemptRequestId = buildReplayTestAttemptRequestId({ requestId, suiteInvocationId, diff --git a/packages/replay-test/src/internal/session-test-discovery.ts b/packages/replay-test/src/internal/session-test-discovery.ts index 57e77bd7b5..10e0a768b1 100644 --- a/packages/replay-test/src/internal/session-test-discovery.ts +++ b/packages/replay-test/src/internal/session-test-discovery.ts @@ -16,6 +16,8 @@ export type ReplayTestDiscoveryEntry = path: string; title?: string; manifest: ReplayTestManifest; + /** Opaque entry text from the inspected source. Absent when that source has none. */ + sourceText?: string; } | { kind: 'skip'; @@ -45,8 +47,14 @@ export function discoverReplayTestEntries(params: { // no-match message never re-derives one from an entry shape it does not own. const filteredOut = { undeclared: 0, declaredOther: 0 }; for (const source of sources) { - const { path: filePath, manifest } = source; - const run = { kind: 'run', path: filePath, title: manifest.title, manifest } as const; + const { path: filePath, manifest, sourceText } = source; + const run = { + kind: 'run' as const, + path: filePath, + title: manifest.title, + manifest, + ...(sourceText !== undefined ? { sourceText } : {}), + }; if (!platformFilter) { entries.push(run); continue; diff --git a/packages/replay-test/src/internal/session-test-types.ts b/packages/replay-test/src/internal/session-test-types.ts index a7dfe1ca44..81950bda9c 100644 --- a/packages/replay-test/src/internal/session-test-types.ts +++ b/packages/replay-test/src/internal/session-test-types.ts @@ -97,6 +97,12 @@ export type ReplayTestManifest = Readonly<{ export type ReplayTestSource = Readonly<{ path: string; manifest: ReplayTestManifest; + /** + * Opaque entry text the host already read. A string, including `""`, is written into the + * attempt directory and `path` is not opened. Absent when the host did not supply text, which + * keeps the local file copy. + */ + sourceText?: string; }>; /** From 129752a3cc49ca750cbf485718de7ec8e3b8592c Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Tue, 17 Nov 2026 04:57:09 -0800 Subject: [PATCH 2/2] refactor(replay-test): require shipped source text on replay test sources ReplayTestSource.sourceText and the run discovery entry's sourceText are now required, and copyReplaySourceFile always writes that text into the attempt directory. The fs.copyFileSync fallback that read the entry path on the daemon host is gone, so a remote client can no longer make the daemon copy a daemon-host file into the downloadable artifacts. inspectReplayTestSource already sets the text on every source. Refs #4561 --- .../__tests__/session-test-artifacts.test.ts | 48 +++++++++++------ .../__tests__/session-test-attempt.test.ts | 4 +- .../__tests__/session-test-discovery.test.ts | 53 ++++++++++++++----- .../src/internal/session-test-artifacts.ts | 22 +++----- .../src/internal/session-test-discovery.ts | 6 +-- .../src/internal/session-test-types.ts | 7 ++- 6 files changed, 87 insertions(+), 53 deletions(-) diff --git a/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts b/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts index e2a35f1185..3d599f1bf5 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts @@ -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, @@ -72,9 +71,12 @@ 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); @@ -125,11 +127,14 @@ test('materializeReplayTestAttemptArtifacts writes failure manifest and copies l 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', @@ -178,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); @@ -187,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, @@ -209,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); @@ -219,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', @@ -259,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]; @@ -295,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: { @@ -328,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'); diff --git a/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts b/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts index 699fb2a205..a239fbbe7e 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts @@ -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, }; } diff --git a/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts b/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts index 7a18a623c3..9b3ad1a96e 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts @@ -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', + }, ), }); @@ -45,20 +49,25 @@ 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 and leaves it absent when the source has none', () => { - const sourceText = 'appId: demo\n---\n- launchApp\n'; +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 }, - { path: '02-ios.ad', manifest: declared('ios') }, + { path: '01-flow.yaml', manifest: callerBound, sourceText: flowText }, + { path: '02-ios.ad', manifest: declared('ios'), sourceText: nativeText }, ), }); @@ -66,11 +75,11 @@ test('discovery copies shipped source text onto filtered run entries and leaves const native = entries.find((entry) => entry.path === '02-ios.ad'); assert.equal(flow?.kind, 'run'); if (flow?.kind === 'run') { - assert.equal(flow.sourceText, sourceText); + assert.equal(flow.sourceText, flowText); } assert.equal(native?.kind, 'run'); if (native?.kind === 'run') { - assert.equal('sourceText' in native, false); + assert.equal(native.sourceText, nativeText); } }); @@ -78,8 +87,12 @@ test('platform filter drops declared sources that do not match, without a skip e 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', + }, ), }); @@ -94,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 && @@ -112,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 && @@ -130,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 && diff --git a/packages/replay-test/src/internal/session-test-artifacts.ts b/packages/replay-test/src/internal/session-test-artifacts.ts index ddda04e425..6df16f449c 100644 --- a/packages/replay-test/src/internal/session-test-artifacts.ts +++ b/packages/replay-test/src/internal/session-test-artifacts.ts @@ -44,7 +44,7 @@ export function buildReplayTestArtifactSlug(filePath: string, cwd?: string): str export function prepareReplayTestAttemptArtifacts( filePath: string, attemptArtifactsDir: string, - sourceText?: string, + sourceText: string, ): void { fs.mkdirSync(attemptArtifactsDir, { recursive: true }); copyReplaySourceFile(filePath, attemptArtifactsDir, sourceText); @@ -131,17 +131,13 @@ function copyReplayTestArtifacts( function copyReplaySourceFile( filePath: string, attemptArtifactsDir: string, - sourceText?: string, + sourceText: string, ): void { const genericReplayPath = path.join(attemptArtifactsDir, 'replay.ad'); - // Shipped entry text is the source of truth. A remote daemon does not share the caller's - // disk, so a string — including "" — is written and the caller path is not opened. Omitted - // text keeps the local copy. - if (typeof sourceText === 'string') { - fs.writeFileSync(genericReplayPath, sourceText); - } else { - fs.copyFileSync(filePath, genericReplayPath); - } + // The daemon writes the shipped text and never reads the entry path, because a remote daemon + // does not share the caller's disk and a daemon-side read would copy a daemon-host file into + // downloadable artifacts. + fs.writeFileSync(genericReplayPath, sourceText); // Sources that are not native `.ad` keep their original filename alongside `replay.ad`, so // CI artifacts point back at the flow the author wrote. This is artifact naming, not format @@ -151,11 +147,7 @@ function copyReplaySourceFile( // Maestro filename so CI artifacts point back to the source flow. const originalReplayPath = path.join(attemptArtifactsDir, path.basename(filePath)); if (path.resolve(originalReplayPath) === path.resolve(genericReplayPath)) return; - if (typeof sourceText === 'string') { - fs.writeFileSync(originalReplayPath, sourceText); - return; - } - fs.copyFileSync(filePath, originalReplayPath); + fs.writeFileSync(originalReplayPath, sourceText); } function buildUniqueArtifactFileName( diff --git a/packages/replay-test/src/internal/session-test-discovery.ts b/packages/replay-test/src/internal/session-test-discovery.ts index 10e0a768b1..8a7ed531eb 100644 --- a/packages/replay-test/src/internal/session-test-discovery.ts +++ b/packages/replay-test/src/internal/session-test-discovery.ts @@ -16,8 +16,8 @@ export type ReplayTestDiscoveryEntry = path: string; title?: string; manifest: ReplayTestManifest; - /** Opaque entry text from the inspected source. Absent when that source has none. */ - sourceText?: string; + /** Opaque entry text from the inspected source. */ + sourceText: string; } | { kind: 'skip'; @@ -53,7 +53,7 @@ export function discoverReplayTestEntries(params: { path: filePath, title: manifest.title, manifest, - ...(sourceText !== undefined ? { sourceText } : {}), + sourceText, }; if (!platformFilter) { entries.push(run); diff --git a/packages/replay-test/src/internal/session-test-types.ts b/packages/replay-test/src/internal/session-test-types.ts index 81950bda9c..ef133d6fe2 100644 --- a/packages/replay-test/src/internal/session-test-types.ts +++ b/packages/replay-test/src/internal/session-test-types.ts @@ -98,11 +98,10 @@ export type ReplayTestSource = Readonly<{ path: string; manifest: ReplayTestManifest; /** - * Opaque entry text the host already read. A string, including `""`, is written into the - * attempt directory and `path` is not opened. Absent when the host did not supply text, which - * keeps the local file copy. + * Opaque entry text the host already read, always written into the attempt directory; `path` is + * never opened. */ - sourceText?: string; + sourceText: string; }>; /**