Repository navigation
fix(tests): resolve test resource URLs to real paths on Windows - #1959
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
Fixed in fb6d1b6: the banner now derives 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
left a comment
There was a problem hiding this comment.
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.
Summary
Seven desktop test files passed
new URL(..., import.meta.url).pathnamewhere a filesystem path was needed. That string is a usable path on the POSIX CI runners, but on Windows it yields/C:/Users/..., whichfsandchild_processreject withENOENT. Running the desktop suite locally on Windows, 22 tests across six files failed andgen-ui-protocol.test.mjsfailed to load at all. Production code builds all of these paths withjoin(...)(e.g. the catalog path inelectron/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: theModelsDevCatalogcatalogPathplugin-remote-files: thehostEntryhanded to the forked plugin host child - the bogus path made all seven of its tests die withPLUGIN_CRASHEDsidecar-history-restore: the spawned sidecar entry pathgen-ui-protocol: theKIT_DIRpassed toloadGenUiKitOne more assertion pinned a POSIX-joined literal (
"/kit/vendor/x.js") while production joins withpath.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:POSIX results are unchanged:
fileURLToPathmaps these URLs to the same stringpathnameproduced there, and the joined expectation equals the old literal exactly.