Skip to content

fix(tests): resolve test resource URLs to real paths on Windows - #1959

Merged
vastsa merged 5 commits into
vastsa:mainfrom
SeanLiu326:fix/windows-test-url-pathnames
Oct 29, 2026
Merged

vastsa merged 5 commits into
vastsa:mainfrom
SeanLiu326:fix/windows-test-url-pathnames

Conversation

@SeanLiu326

Copy link
Copy Markdown
Contributor

Summary

Seven desktop test files passed new URL(..., import.meta.url).pathname where a filesystem path was needed. That string is a usable path on the POSIX CI runners, but on Windows it yields /C:/Users/..., which fs and child_process reject with ENOENT. Running the desktop suite locally on Windows, 22 tests across six files failed and gen-ui-protocol.test.mjs failed to load at all. Production code builds all of these paths with join(...) (e.g. the catalog path in electron/main/index.ts) and is unaffected.

Convert each URL with fileURLToPath(...):

  • provider-lookup-model-handler, provider-model-list-scope, provider-endpoint-metadata, model-binding-catalog-source: the ModelsDevCatalog catalogPath
  • plugin-remote-files: the hostEntry handed to the forked plugin host child - the bogus path made all seven of its tests die with PLUGIN_CRASHED
  • sidecar-history-restore: the spawned sidecar entry path
  • gen-ui-protocol: the KIT_DIR passed to loadGenUiKit

One more assertion pinned a POSIX-joined literal ("/kit/vendor/x.js") while production joins with path.join (gen-ui-kit.ts:63), so its expectation now mirrors that expression, join("/kit/vendor", "x.js") - identical on POSIX, matching the launch-resolver precedent.

Verification

Windows 11 (unprivileged, NTFS), node --test <file> with node 22.19, before -> after:

file before after
plugin-remote-files 0/7 (PLUGIN_CRASHED x7) 7/7
provider-lookup-model-handler 1/4 4/4
provider-model-list-scope 0/2 2/2
provider-endpoint-metadata 0/6 6/6
model-binding-catalog-source 4/7 7/7
gen-ui-protocol file failed to load 15/15
sidecar-history-restore 0/1 1/1

POSIX results are unchanged: fileURLToPath maps these URLs to the same string pathname produced there, and the joined expectation equals the old literal exactly.

Seven desktop tests passed new URL(..., import.meta.url).pathname where a
filesystem path was needed. That string is a usable path on POSIX CI but
yields /C:/... on Windows, which fs and child_process reject with ENOENT:
22 tests failed locally and gen-ui-protocol.test.mjs failed to load at all.
Production code builds these paths with join() and is unaffected.

Convert each URL with fileURLToPath(): the ModelsDevCatalog catalogPath in
four provider suites, the forked plugin-host entry in plugin-remote-files
(all seven of its tests died with PLUGIN_CRASHED), the spawned sidecar
entry in sidecar-history-restore, and the GenUI kit directory. One more
assertion pinned a POSIX-joined literal while production joins with
path.join (gen-ui-kit.ts), so its expectation now mirrors that expression,
identical on POSIX.

Verified on Windows 11: every touched file goes from failing (or not
loading) to fully passing under node 22.19, with no POSIX change.

@muzimu217 muzimu217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix is right and the diagnosis is exact: new URL(..., import.meta.url).pathname yields /C:/Users/... on Windows, which fs and child_process reject, while fileURLToPath gives the native path. Replacing it per file rather than papering over it in a helper is the correct call, since each of these is a module-level constant.

One occurrence of the same pattern is left, and it is the one that would be hardest to notice: scripts/e2e-provider-certificates.mjs:71 builds its bundle with

const __dirname = new URL('.', import.meta.url).pathname;

inside the esbuild banner. The comment above it explains why fileURLToPath cannot simply be added to the banner (the bundled sources import it themselves, so a same-scope redeclare is a syntax error), but that constraint does not force the broken form — the banner already injects require, so __piCreateRequire("node:url").fileURLToPath(import.meta.url) works without adding an import. Either that, or say in the PR that the script is Linux-only and deliberately excluded.

On upstream/main those eight files are the complete set of .pathname uses in apps/desktop/test and scripts, so fixing the seventh without the eighth leaves exactly one Windows-broken path behind.

…Require

The e2e certificate probe's esbuild banner derived __dirname with
new URL('.', import.meta.url).pathname - the same Windows-broken form the
rest of this branch fixes, and the one occurrence outside apps/desktop/test.
The banner cannot declare fileURLToPath (the bundled sources import it from
node:url; a same-scope redeclare is a syntax error), but it already injects
createRequire, so resolve through that instead. Both bundles build and pass
node --check with the new banner.
@SeanLiu326

Copy link
Copy Markdown
Contributor Author

Fixed in fb6d1b6: the banner now derives __dirname through the injected __piCreateRequire - __piCreateRequire('node:url').fileURLToPath(new URL('.', import.meta.url)) - keeping the directory semantics while leaving fileURLToPath itself undeclared in banner scope. The banner comment records why. Both bundles build and pass node --check with the new banner; the branch also carries a merge of current main, and all eight .pathname uses in apps/desktop/test + scripts are now converted.

Thanks for the precise review - the createRequire route is exactly the constraint-respecting form.

The Windows path fix used createRequire with a module specifier, which aborts the certificate E2E before any TLS check. Use the injected require function to resolve the URL module and preserve the Windows path conversion.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Confirmed the Windows URL pathname issue. The eight affected sites now use fileURLToPath; I fixed the certificate probe banner's module-loading typo on your branch. The 42 targeted tests and the local TLS certificate E2E (rejection, trusted CA, hostname mismatch) pass on the latest main integration tree. Thanks for the fix.

@vastsa
vastsa merged commit f0c4095 into vastsa:main Oct 29, 2026
5 checks passed
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.

3 participants