Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

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

liuzixiang9ac4292240c5
diff --git a/apps/desktop/test/gen-ui-protocol.test.mjs b/apps/desktop/test/gen-ui-protocol.test.mjs
index ed2a84b27..6304f6135 100644
--- a/apps/desktop/test/gen-ui-protocol.test.mjs
+++ b/apps/desktop/test/gen-ui-protocol.test.mjs
@@ -3,6 +3,7 @@ import test from "node:test";
import { register } from "node:module";
import { readFileSync } from "node:fs";
import { join } from "node:path";
+import { fileURLToPath } from "node:url";
import { readMainModule, readMainSource } from "./helpers/source-contracts.mjs";
register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
@@ -37,7 +38,7 @@ const { genUiAssetFileFromUrl, loadGenUiKit, parseGenUiVendorManifest } = await
"../electron/main/gen-ui-kit.ts"
);
-const KIT_DIR = new URL("../resources/gen-ui/", import.meta.url).pathname;
+const KIT_DIR = fileURLToPath(new URL("../resources/gen-ui/", import.meta.url));
const kit = await loadGenUiKit(KIT_DIR);
const loadKit = async () => kit;
const D3_CDN = "https://cdn.jsdelivr.net/npm/[email protected]/dist/d3.min.js";
@@ -125,7 +126,7 @@ test("vendor manifest: only https URLs with plain .js file names are mapped", ()
"/kit/vendor",
);
assert.deepEqual([...vendorUrls], [["https://a.example/x.js", "pi-genui://assets/x.js"]]);
- assert.deepEqual([...vendorFiles], [["x.js", "/kit/vendor/x.js"]]);
+ assert.deepEqual([...vendorFiles], [["x.js", join("/kit/vendor", "x.js")]]);
assert.deepEqual(
[...kit.vendorFiles.keys()].sort(),
["d3-7.9.0.min.js", "floating-ui-core-1.7.3.min.js", "floating-ui-dom-1.7.4.min.js"],
diff --git a/apps/desktop/test/model-binding-catalog-source.test.mjs b/apps/desktop/test/model-binding-catalog-source.test.mjs
index 7c4a552a1..d2f6d2b91 100644
--- a/apps/desktop/test/model-binding-catalog-source.test.mjs
+++ b/apps/desktop/test/model-binding-catalog-source.test.mjs
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import { registerHooks } from "node:module";
import test from "node:test";
+import { fileURLToPath } from "node:url";
import { ModelsDevCatalog } from "../electron/main/models-dev-catalog.ts";
@@ -25,7 +26,7 @@ const CORRECTED_CONTEXT_WINDOW = 1_050_000;
async function fixtureRuntime() {
const catalog = new ModelsDevCatalog({
- catalogPath: new URL("../resources/models.dev/api.json", import.meta.url).pathname,
+ catalogPath: fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url)),
});
await catalog.loadLocal();
return createProviderCatalogRuntime({
diff --git a/apps/desktop/test/plugin-remote-files.test.mjs b/apps/desktop/test/plugin-remote-files.test.mjs
index b277f45a7..78859993e 100644
--- a/apps/desktop/test/plugin-remote-files.test.mjs
+++ b/apps/desktop/test/plugin-remote-files.test.mjs
@@ -5,6 +5,7 @@ import { register } from "node:module";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
+import { fileURLToPath } from "node:url";
const data = await mkdtemp(join(tmpdir(), "pi-remote-plugin-data-"));
process.env.PI_DESKTOP_DATA_DIR = data;
@@ -25,7 +26,7 @@ async function harness(t, { permissions = ["fs.read"], scope = ["docs/**"], read
const requests = []; const audits = [];
let workspace = REMOTE;
const runtime = new PluginRuntime({
- hostEntry: new URL("../electron/main/plugin-host-process.mjs", import.meta.url).pathname,
+ hostEntry: fileURLToPath(new URL("../electron/main/plugin-host-process.mjs", import.meta.url)),
spawnProcess({ entry }) {
const child = fork(entry, [], { stdio: ["ignore", "pipe", "pipe", "ipc"] });
return { postMessage: message => { if (child.connected) child.send(message); },
diff --git a/apps/desktop/test/provider-endpoint-metadata.test.mjs b/apps/desktop/test/provider-endpoint-metadata.test.mjs
index e744e91e6..bee343765 100644
--- a/apps/desktop/test/provider-endpoint-metadata.test.mjs
+++ b/apps/desktop/test/provider-endpoint-metadata.test.mjs
@@ -16,6 +16,7 @@
import assert from "node:assert/strict";
import { register } from "node:module";
import test from "node:test";
+import { fileURLToPath } from "node:url";
register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
@@ -23,7 +24,7 @@ const { registerProviderIpc } = await import("../electron/main/ipc/provider-ipc.
const { ModelsDevCatalog } = await import("../electron/main/models-dev-catalog.ts");
const { IPC } = await import("@pi-desktop/shared");
-const catalogPath = new URL("../resources/models.dev/api.json", import.meta.url).pathname;
+const catalogPath = fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url));
function jsonResponse(body, status = 200) {
return new Response(JSON.stringify(body), {
diff --git a/apps/desktop/test/provider-lookup-model-handler.test.mjs b/apps/desktop/test/provider-lookup-model-handler.test.mjs
index 8a6a42a52..badd044c7 100644
--- a/apps/desktop/test/provider-lookup-model-handler.test.mjs
+++ b/apps/desktop/test/provider-lookup-model-handler.test.mjs
@@ -13,6 +13,7 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
+import { fileURLToPath } from "node:url";
import ts from "typescript";
import { ErrorCodes } from "../../../packages/shared/src/errors.ts";
import { IPC } from "../../../packages/shared/src/protocol.ts";
@@ -39,7 +40,7 @@ function load(relative, imports) {
async function fixtureCatalog() {
const catalog = new modelsDev.ModelsDevCatalog({
- catalogPath: new URL("../resources/models.dev/api.json", import.meta.url).pathname,
+ catalogPath: fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url)),
});
assert.equal(await catalog.ensureLoaded(), true);
return catalog;
diff --git a/apps/desktop/test/provider-model-list-scope.test.mjs b/apps/desktop/test/provider-model-list-scope.test.mjs
index ef705b041..8328d9e0a 100644
--- a/apps/desktop/test/provider-model-list-scope.test.mjs
+++ b/apps/desktop/test/provider-model-list-scope.test.mjs
@@ -11,12 +11,13 @@
import assert from "node:assert/strict";
import { register } from "node:module";
import test from "node:test";
+import { fileURLToPath } from "node:url";
register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
const { ModelsDevCatalog } = await import("../electron/main/models-dev-catalog.ts");
-const catalogPath = new URL("../resources/models.dev/api.json", import.meta.url).pathname;
+const catalogPath = fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url));
async function loadedCatalog() {
const catalog = new ModelsDevCatalog({ catalogPath });
diff --git a/apps/desktop/test/sidecar-history-restore.test.mjs b/apps/desktop/test/sidecar-history-restore.test.mjs
index 0e316791c..290375c28 100644
--- a/apps/desktop/test/sidecar-history-restore.test.mjs
+++ b/apps/desktop/test/sidecar-history-restore.test.mjs
@@ -4,6 +4,7 @@ import { createServer } from "node:http";
import { once } from "node:events";
import { createInterface } from "node:readline";
import test from "node:test";
+import { fileURLToPath } from "node:url";
// Exercise the actual sidecar RPC boundary. Only the external Host service and
// provider endpoint are fixtures; runtime admission and restore wiring are real.
@@ -12,7 +13,7 @@ test("history restore failures cannot accept a clean prompt for stable or legacy
const server = createServer((_req, res) => { providerRequests++; res.writeHead(500); res.end(); });
server.listen(0, "127.0.0.1"); await once(server, "listening");
t.after(() => new Promise((resolve) => server.close(resolve)));
- const child = spawn(process.execPath, [new URL("../../../packages/agent-runtime/dist/sidecar.js", import.meta.url).pathname], { stdio: ["pipe", "pipe", "pipe"] });
+ const child = spawn(process.execPath, [fileURLToPath(new URL("../../../packages/agent-runtime/dist/sidecar.js", import.meta.url))], { stdio: ["pipe", "pipe", "pipe"] });
t.after(() => { child.kill(); });
let stderr = ""; child.stderr.on("data", (chunk) => { stderr += chunk; });
const lines = createInterface({ input: child.stdout }); t.after(() => lines.close());