-
Notifications
You must be signed in to change notification settings - Fork 139
fix(runner): resolve #playwright alias in runtime isolates #1386
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
Michael Price (michael-pr)
merged 4 commits into
main
from
fix-hash-dependency-resolution-runtime-isolate
Jul 1, 2026
+177
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4757e6b
fix(runner): resolve #playwright alias in runtime isolates
michael-pr 40ab104
fix(runner): distinguish ENOENT from other read errors in execSubpath…
michael-pr 2e75b05
refactor(runner): use zod schema for package.json validation
michael-pr 5852b47
test(runner): make non-ENOENT error propagation test deterministic
michael-pr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { afterEach, describe, expect, it } from "bun:test"; | ||
| import { realpathSync } from "node:fs"; | ||
| import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
|
|
||
| import { type Fs, makeDefaultFs } from "~/shell/fs.js"; | ||
|
|
||
| import { writeExecSubpathImports } from "./execSubpathImports.js"; | ||
|
|
||
| const tmpDirs: string[] = []; | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all( | ||
| tmpDirs.map((d) => rm(d, { recursive: true, force: true })), | ||
| ); | ||
| tmpDirs.length = 0; | ||
| }); | ||
|
|
||
| async function makeExecDir(): Promise<string> { | ||
| const d = realpathSync( | ||
| await mkdtemp(join(tmpdir(), "qawolf-subpath-imports-test-")), | ||
| ); | ||
| tmpDirs.push(d); | ||
| return d; | ||
| } | ||
|
|
||
| type PackageJson = { | ||
| name?: string; | ||
| type?: string; | ||
| dependencies?: Record<string, string>; | ||
| imports?: Record<string, unknown>; | ||
| }; | ||
|
|
||
| async function readPackageJson(execDir: string): Promise<PackageJson> { | ||
| const content = await readFile(join(execDir, "package.json"), "utf-8"); | ||
| return JSON.parse(content) as PackageJson; | ||
| } | ||
|
|
||
| describe("writeExecSubpathImports", () => { | ||
| it("adds the #playwright alias while preserving existing fields", async () => { | ||
| const execDir = await makeExecDir(); | ||
| await writeFile( | ||
| join(execDir, "package.json"), | ||
| JSON.stringify({ | ||
| name: "@qawolf/demo", | ||
| type: "module", | ||
| dependencies: { dotenv: "^16.4.5" }, | ||
| }), | ||
| ); | ||
|
|
||
| await writeExecSubpathImports({ execDir, fs: makeDefaultFs() }); | ||
|
|
||
| const pkg = await readPackageJson(execDir); | ||
| expect(pkg.imports).toEqual({ "#playwright": "playwright" }); | ||
| expect(pkg.name).toBe("@qawolf/demo"); | ||
| expect(pkg.type).toBe("module"); | ||
| expect(pkg.dependencies).toEqual({ dotenv: "^16.4.5" }); | ||
| }); | ||
|
|
||
| it("overrides a conflicting #playwright entry but keeps other imports", async () => { | ||
| const execDir = await makeExecDir(); | ||
| await writeFile( | ||
| join(execDir, "package.json"), | ||
| JSON.stringify({ | ||
| imports: { "#playwright": "patchright", "#utils": "./src/utils.js" }, | ||
| }), | ||
| ); | ||
|
|
||
| await writeExecSubpathImports({ execDir, fs: makeDefaultFs() }); | ||
|
|
||
| const pkg = await readPackageJson(execDir); | ||
| expect(pkg.imports).toEqual({ | ||
| "#utils": "./src/utils.js", | ||
| "#playwright": "playwright", | ||
| }); | ||
| }); | ||
|
|
||
| it("creates package.json with imports when none exists", async () => { | ||
| const execDir = await makeExecDir(); | ||
|
|
||
| await writeExecSubpathImports({ execDir, fs: makeDefaultFs() }); | ||
|
|
||
| const pkg = await readPackageJson(execDir); | ||
| expect(pkg.imports).toEqual({ "#playwright": "playwright" }); | ||
| }); | ||
|
|
||
| it("recovers from an invalid package.json by writing a fresh imports map", async () => { | ||
| const execDir = await makeExecDir(); | ||
| await writeFile(join(execDir, "package.json"), "{ not valid json"); | ||
|
|
||
| await writeExecSubpathImports({ execDir, fs: makeDefaultFs() }); | ||
|
|
||
| const pkg = await readPackageJson(execDir); | ||
| expect(pkg.imports).toEqual({ "#playwright": "playwright" }); | ||
| }); | ||
|
|
||
| it("propagates a non-ENOENT read error instead of clobbering package.json", async () => { | ||
| const execDir = await makeExecDir(); | ||
| const ioError = Object.assign(Error("EACCES: permission denied"), { | ||
| code: "EACCES", | ||
| }); | ||
| const fs: Fs = { | ||
| ...makeDefaultFs(), | ||
| readFile: () => Promise.reject(ioError), | ||
| }; | ||
|
|
||
| let caught: unknown; | ||
| try { | ||
| await writeExecSubpathImports({ execDir, fs }); | ||
| } catch (e) { | ||
| caught = e; | ||
| } | ||
| expect(caught).toBeInstanceOf(Error); | ||
| expect((caught as Error).message).toContain("permission denied"); | ||
| }); | ||
|
michael-pr marked this conversation as resolved.
|
||
| }); | ||
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,53 @@ | ||
| import { join } from "node:path"; | ||
|
|
||
| import { z } from "zod"; | ||
|
|
||
| import { isNoEntError } from "~/core/errors.js"; | ||
| import { type Fs } from "~/shell/fs.js"; | ||
|
|
||
| /** | ||
| * qawolf's `#playwright` driver alias, which the platform omits from bundle | ||
| * package.json — pointed at the pinned playwright the inner hop symlinks in. | ||
| */ | ||
| const flowSubpathImports = { "#playwright": "playwright" } as const; | ||
|
|
||
| // looseObject keeps all fields; imports is coerced to a record ({} if missing or malformed). | ||
| const packageJsonSchema = z | ||
| .looseObject({ imports: z.record(z.string(), z.unknown()).catch({}) }) | ||
| .catch({ imports: {} }); | ||
|
|
||
| export type WriteExecSubpathImportsArgs = { | ||
| execDir: string; | ||
| fs: Fs; | ||
| }; | ||
|
|
||
| /** Adds the flow subpath-import aliases to exec/package.json's imports map. */ | ||
| export async function writeExecSubpathImports( | ||
| args: WriteExecSubpathImportsArgs, | ||
| ): Promise<void> { | ||
| const { execDir, fs } = args; | ||
| const pkgPath = join(execDir, "package.json"); | ||
| const pkg = packageJsonSchema.parse(await readPackageJson(pkgPath, fs)); | ||
|
|
||
| const merged = { ...pkg, imports: { ...pkg.imports, ...flowSubpathImports } }; | ||
| await fs.writeFile(pkgPath, JSON.stringify(merged, undefined, 2)); | ||
| } | ||
|
|
||
| /** | ||
| * Reads and parses pkgPath. A missing file or malformed JSON yields {}; other | ||
| * read errors propagate so a transient failure never clobbers a staged file. | ||
| */ | ||
| async function readPackageJson(pkgPath: string, fs: Fs): Promise<unknown> { | ||
| let content: string; | ||
| try { | ||
| content = await fs.readFile(pkgPath); | ||
| } catch (err) { | ||
| if (isNoEntError(err)) return {}; | ||
| throw err; | ||
| } | ||
| try { | ||
| return JSON.parse(content); | ||
| } catch { | ||
| return {}; | ||
| } | ||
| } |
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
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.