Skip to content

fix(runner): resolve #playwright alias in runtime isolates#1386

Merged
Michael Price (michael-pr) merged 4 commits into
mainfrom
fix-hash-dependency-resolution-runtime-isolate
Jul 1, 2026
Merged

fix(runner): resolve #playwright alias in runtime isolates#1386
Michael Price (michael-pr) merged 4 commits into
mainfrom
fix-hash-dependency-resolution-runtime-isolate

Conversation

@michael-pr

@michael-pr Michael Price (michael-pr) commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description drafted with AI, edited and reviewed by me.

Overview of Changes

Flows in the isolated managed runtime crashed with ERR_PACKAGE_IMPORT_NOT_DEFINED because the platform's pulled flow bundle strips the imports field from package.json, so the staged exec/package.json had no #playwright alias to resolve. A new writeExecSubpathImports helper merges the alias back in after staging, resolving it through the existing inner-hop node_modules symlink to the pinned playwright package — fixing resolution for both the Node import path and the compiled-binary Bun.build path.

Before this fix, running a flow that imports from #playwright failed at module resolution:

• Sign Out /Users/michael/Library/Application Support/qawolf-nodejs/runtime-runs/5b2e6a877faea7fa-55999/exec/src/flows/authentication/sign-out.flow.ts
    FlowRunError: Flow "sign-out.flow" failed on attempt 1
    Caused by: TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#playwright" is not defined in package /Users/michael/Library/Application Support/qawolf-nodejs/runtime-runs/5b2e6a877faea7fa-55999/exec/package.json imported from /Users/michael/Library/Application Support/qawolf-nodejs/runtime-runs/5b2e6a877faea7fa-55999/exec/src/lib/entry-point-page-object.ts
        at importNotDefined (node:internal/modules/esm/resolve:297:10)
        at packageImportsResolve (node:internal/modules/esm/resolve:747:9)
        at moduleResolve (node:internal/modules/esm/resolve:844:16)
        at defaultResolve (node:internal/modules/esm/resolve:988:11)
        at #cachedDefaultResolve (node:internal/modules/esm/loader:697:20)
        at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:714:38)
        at nextStep (node:internal/modules/customization_hooks:189:26)
        at nextStep (node:internal/modules/customization_hooks:189:26)
        at resolveWithHooks (node:internal/modules/customization_hooks:417:10)

  ✗ passed (0.26s)

Testing

bun run typecheck
bun run lint
bun run format:check
bun run knip
bun run test
bun run build
  1. Pull a flow bundle that imports from #playwright and run it via the CLI's managed runtime (projectDir set).
  2. Verify exec/package.json in the staged run dir contains "imports": { "#playwright": "playwright" } alongside the bundle's original fields.
  3. Confirm the flow executes without ERR_PACKAGE_IMPORT_NOT_DEFINED, in both the Node dev path and a compiled binary build.

Checklist

  • Changes follow the code style of this project
  • Self-review completed
  • Tests added/updated (or not applicable)
  • No breaking changes (or described below)

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a1bfc15d-aed0-4f07-a38d-4fba174d7687

📥 Commits

Reviewing files that changed from the base of the PR and between 2e75b05 and 5852b47.

📒 Files selected for processing (1)
  • src/domains/runtimeEnv/execSubpathImports.test.ts

Walkthrough

This PR adds writeExecSubpathImports to ensure execDir/package.json contains the #playwright import alias, merging it with existing imports data and handling missing or invalid JSON. prepareRunDir now calls it when projectDir is present. A Bun test suite covers preservation, conflict resolution, file creation, invalid JSON recovery, and non-ENOENT read failures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: chajac

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits and accurately summarizes the runtime alias fix in the runner.
Description check ✅ Passed The description includes the required overview, testing steps, and checklist, and it is specific to the change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-hash-dependency-resolution-runtime-isolate

Comment @coderabbitai help to get the list of available commands.

@michael-pr

Copy link
Copy Markdown
Contributor Author

CodeRabbit (@coderabbitai) review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/domains/runtimeEnv/execSubpathImports.test.ts`:
- Around line 88-96: The existing recovery test only covers malformed JSON, so
add a case in execSubpathImports.test.ts that uses a custom Fs mock for
writeExecSubpathImports/readPackageJson where readFile rejects with a non-ENOENT
error on an existing package.json. Exercise the readPackageJson path in
execSubpathImports.ts and assert the behavior after the fix, using the same
helpers like makeExecDir and writeExecSubpathImports to keep the test aligned
with the current setup.

In `@src/domains/runtimeEnv/execSubpathImports.ts`:
- Around line 61-67: `readExistingImports` currently treats arrays as valid
objects, which can let malformed `imports` data merge numeric keys into the
result. Harden the guard in `readExistingImports` so it only returns plain
objects and falls back to `{}` for arrays or any non-plain object. Keep the fix
localized to this helper so `execSubpathImports` continues to merge imports
safely.
- Around line 42-59: `readPackageJson` is treating every `fs.readFile` failure
as a missing file, which can cause `writeExecSubpathImports` to overwrite an
existing `package.json` with only `imports`. Update `readPackageJson` to only
return an empty object for the expected missing-file case (for example, ENOENT)
and rethrow or propagate other I/O errors. Keep the existing JSON parse fallback
for invalid content, and preserve the merge behavior in
`writeExecSubpathImports` so existing fields and pre-existing imports remain
intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4bc99ef5-07d5-4836-b0f1-58019fbddc2f

📥 Commits

Reviewing files that changed from the base of the PR and between f2ceb83 and 4757e6b.

📒 Files selected for processing (3)
  • src/domains/runtimeEnv/execSubpathImports.test.ts
  • src/domains/runtimeEnv/execSubpathImports.ts
  • src/domains/runtimeEnv/prepareRunDir.ts

Comment thread src/domains/runtimeEnv/execSubpathImports.test.ts
Comment thread src/domains/runtimeEnv/execSubpathImports.ts Outdated
Comment thread src/domains/runtimeEnv/execSubpathImports.ts Outdated
@michael-pr

Copy link
Copy Markdown
Contributor Author

CodeRabbit (@coderabbitai) review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/domains/runtimeEnv/execSubpathImports.test.ts`:
- Around line 98-111: The test in execSubpathImports.test.ts is asserting a
rejected promise without awaiting or returning it, so the runner may finish
before the assertion settles. Update the writeExecSubpathImports rejection check
in this test to return the expect(...).rejects.toThrow(...) promise from the
async test callback so the failure is properly observed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5735157e-fb65-4b53-a309-739d6de53bcb

📥 Commits

Reviewing files that changed from the base of the PR and between 4757e6b and 2e75b05.

📒 Files selected for processing (2)
  • src/domains/runtimeEnv/execSubpathImports.test.ts
  • src/domains/runtimeEnv/execSubpathImports.ts

Comment thread src/domains/runtimeEnv/execSubpathImports.test.ts
@michael-pr

Copy link
Copy Markdown
Contributor Author

CodeRabbit (@coderabbitai) review

@michael-pr Michael Price (michael-pr) marked this pull request as ready for review July 1, 2026 20:17
@michael-pr Michael Price (michael-pr) merged commit 88aeae1 into main Jul 1, 2026
2 checks passed
@michael-pr Michael Price (michael-pr) deleted the fix-hash-dependency-resolution-runtime-isolate branch July 1, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants