Skip to content

test: keep browser-run temp dirs in the OS temp dir - #476

Open
Agnik47 wants to merge 1 commit into
agentrhq:mainfrom
Agnik47:fix/tests-os-tmpdir-persistent-context
Open

test: keep browser-run temp dirs in the OS temp dir#476
Agnik47 wants to merge 1 commit into
agentrhq:mainfrom
Agnik47:fix/tests-os-tmpdir-persistent-context

Conversation

@Agnik47

@Agnik47 Agnik47 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Two unit tests fail on my Windows box against main, and the cause turned out to be a POSIX-absolute path used where the OS temp dir was meant.

What happens

src/browser/run/runner.test.ts seeds its persistent-context tests with:

const userDataDir = fs.mkdtempSync('/tmp/webcmd-persistent-browser-run-');

/tmp is not the OS temp dir off POSIX. On Windows it resolves against the current drive, so the tests either write into <drive>:\tmp when that directory happens to exist, or fail outright with ENOENT when it does not. I found a stale D:\tmp\ on my machine that these runs had created.

The same file already gets this right ~350 lines further down:

const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), 'webcmd-artifact-'));

so this looks like a slip rather than a deliberate choice. os and path are already imported at the top of the file.

On top of that, both tests call chromium.launchPersistentContext() inside the test body while still on Vitest's 5s default. A cold persistent-context launch does not reliably fit in that budget, and under a full-suite run they time out:

FAIL |unit| src/browser/run/runner.test.ts > runBrowserProgram > hides sibling Session pages in a persistent context
Error: Test timed out in 5000ms.

Run on their own with a wider budget, the same two tests finish in ~3.5s — the launch is fine, the 5s allowance is not.

src/pipeline/steps/download.test.ts has the same slip: the cookie test passes a hardcoded dir: '/tmp/webcmd-download-test' and really does create that directory in the drive root, while the sibling test right above it already resolves the identical name through os.tmpdir().

Change

  • Resolve all three temp paths through path.join(os.tmpdir(), ...).
  • Give the two persistent-context tests 20_000, matching the per-test budget already used for process-launching tests in src/hosted/main-lifecycle.test.ts.

Five lines, tests only, no production code touched.

Why CI is green today

The unit job does not install Playwright browsers, so describeWithChromium (runner.test.ts:35) skips this whole block on CI. The failures only surface for a contributor who has Chromium locally — which is exactly where they are most annoying.

Verification

On Windows, against main:

  • Full unit suite: 32 failures before, 30 after. Both runner.test.ts failures are gone. The other 30 are pre-existing and unrelated to this change — 26 need Windows symlink privileges (EPERM: operation not permitted, symlink), and 4 are separate hosted-path and timeout issues that also fail on unmodified main.
  • runner.test.ts alone: 89/89 pass. Together with download.test.ts: 92/92.
  • npm run typecheck clean.
  • No webcmd-download-test is recreated in the drive root after a run.

Left out on purpose

session-manager.test.ts and provider.test.ts pass baseDir: '/tmp/webcmd-test' in ~40 places and do create <drive>:\tmp\webcmd-test\cloak\profiles. Those tests currently pass, and converting them is mechanical churn that would bury this diff, so I left them for a separate change. Happy to do that one next if you want it.

Two browser-run tests seed a persistent context with
`fs.mkdtempSync('/tmp/webcmd-persistent-browser-run-')`. Off POSIX that
POSIX-absolute path is not the OS temp dir: on Windows it resolves against the
current drive, so the tests write to `<drive>:\tmp` when that directory happens
to exist and fail with ENOENT when it does not. Use `path.join(os.tmpdir(),
...)`, which the same file already uses for its artifact temp dir.

Both tests also launch their own Chromium persistent context inside the test
body while still on Vitest's 5s default, so they time out under a loaded full
suite run even when the launch itself succeeds. Give them the 20s budget this
repo already uses for process-launching tests.

`stepDownload` gets the same treatment: its cookie test passed a hardcoded
`/tmp/webcmd-download-test` and created that directory in the drive root, while
the sibling test above it already resolved the same name through `os.tmpdir()`.

CI does not install Playwright browsers for the unit job, so
`describeWithChromium` skips this block there; the failures only show up on a
contributor machine that has Chromium.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🟢 No documentation gap found — high confidence

The pull request only changes tests, lockfiles, generated metadata, or dependency metadata.

This review is advisory and does not block merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant