Repository navigation
refactor(daemon): own the replay script source fixture where it is used #3704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/daemon/src/__tests__/support/replay-script-source-fixture.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import fs from 'node:fs'; | ||
| import type { ReplayScriptSourceBundle } from '@agent-device/contracts/replay'; | ||
| import type { DaemonWireRequest } from '@agent-device/contracts/command'; | ||
| import { resolveUserPath } from '@agent-device/host-kit/file'; | ||
| import { loadReplayScriptSourceBundle } from '@agent-device/replay-port/script-source-bundle'; | ||
| import { discoverReplaySourcePaths } from '@agent-device/replay-port/source-discovery'; | ||
|
|
||
| /** A native `.ad` script's one-entry source bundle for test requests. */ | ||
| export function replayScriptSourceBundleFor(filePath: string): ReplayScriptSourceBundle { | ||
| const entry = resolveUserPath(filePath, { cwd: process.cwd() }); | ||
| return { entry, files: { [entry]: fs.readFileSync(entry, 'utf8') } }; | ||
| } | ||
|
|
||
| /** A Maestro flow's bundle — async because the engine that walks its includes loads on demand. */ | ||
| export async function maestroScriptSourceBundleFor( | ||
| filePath: string, | ||
| ): Promise<ReplayScriptSourceBundle> { | ||
| return await loadReplayScriptSourceBundle({ | ||
| inputPath: filePath, | ||
| cwd: process.cwd(), | ||
| replayBackend: 'maestro', | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Attaches the script sources a real client would have collected for a `replay`/`test` request | ||
| * (#1802): the daemon opens no caller path, so every request that reaches one carries them. | ||
| * Test harnesses that stand in for "a request as it arrives at the daemon" call this so their | ||
| * cases keep expressing what they are about; a request that already carries its own sources (or | ||
| * deliberately carries none, to pin the daemon's refusal) is returned untouched. | ||
| * | ||
| * Collection that cannot succeed — a case driving `replay` at a path that deliberately does not | ||
| * exist — leaves the request alone rather than throwing: the real client raises that failure at | ||
| * the CLI boundary (pinned in `cli-client-commands.test.ts`), and a daemon-level harness must | ||
| * still deliver the request so the daemon's own response is what the case observes. | ||
| */ | ||
| export async function withClientReplayScriptSources( | ||
| req: DaemonWireRequest, | ||
| ): Promise<DaemonWireRequest> { | ||
| if (req.command !== 'replay' && req.command !== 'test') return req; | ||
| const inputs = req.positionals ?? []; | ||
| const entryPath = inputs[0]; | ||
| if (entryPath === undefined) return req; | ||
| const cwd = req.meta?.cwd ?? process.cwd(); | ||
| const replayBackend = req.flags?.replayBackend; | ||
| try { | ||
| if (req.command === 'replay') { | ||
| if (req.flags?.replayScriptSource) return req; | ||
| return withFlags(req, { | ||
| replayScriptSource: await loadReplayScriptSourceBundle({ | ||
| inputPath: entryPath, | ||
| cwd, | ||
| replayBackend, | ||
| }), | ||
| }); | ||
| } | ||
| if (req.flags?.replayScriptSources) return req; | ||
| return withFlags(req, { | ||
| replayScriptSources: await Promise.all( | ||
| discoverReplaySourcePaths({ inputs, cwd, replayBackend }).map( | ||
| async (inputPath) => | ||
| await loadReplayScriptSourceBundle({ inputPath, cwd, replayBackend }), | ||
| ), | ||
| ), | ||
| }); | ||
| } catch { | ||
| return req; | ||
| } | ||
| } | ||
|
|
||
| function withFlags( | ||
| req: DaemonWireRequest, | ||
| flags: Partial<NonNullable<DaemonWireRequest['flags']>>, | ||
| ): DaemonWireRequest { | ||
| return { ...req, flags: { ...(req.flags ?? {}), ...flags } }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.