diff options
| author | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-06 00:47:15 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-06 00:47:15 +0530 |
| commit | d49068d9ae55ca15f3b58c000fcbb27a59bdb895 (patch) | |
| tree | c848dacf3d4e79995c9012a40e43a7d064a0fd07 /test/util/daemon-socket-test.ts | |
| parent | d9bc46b508f8c6f7e0f0ff5d54d804340f3e6c80 (diff) | |
fix: accept Windows script paths and start the daemon from a real install (#23)
Two independent Windows/production defects reported in #22.
browser_run_script rejected every absolute path on Windows. The allowed-root
check compared with a hardcoded `${root}/`, but path.resolve returns
backslash-separated paths there, so a file inside os.tmpdir() was refused even
though the rejection message listed tmpdir as allowed. Decide containment with
path.relative instead: it is separator-agnostic and carries each platform's own
case rules, so it also accepts a differing drive-letter case that a path.sep
patch would still reject. Escapes via `..` and sibling directories sharing the
root's name prefix stay rejected, as before.
The daemon could not start under `npm omit=dev`: it is spawned through tsx,
which was declared only as a dev dependency. Moving tsx to dependencies is not
enough on its own — pi installs extensions into one flat hoisted tree, so tsx
lands beside the package and the fixed <pkg>/node_modules/.bin/tsx lookup still
misses, falling through to an `npx tsx` that resolves against the wrong cwd and
dies against stdio: "ignore". Resolve the CLI entry with Node's own resolver,
which walks up to the hoisted copy. That removes the shell entirely, and with it
the Windows .cmd shim, windowsVerbatimArguments, and the manual quoting that
paths containing spaces needed.
Both fixes live in platform-branching code, so their tests are registered in the
three-OS CI matrix that already exists for that purpose — a Linux-only run
cannot exercise either one.
Diffstat (limited to 'test/util/daemon-socket-test.ts')
| -rw-r--r-- | test/util/daemon-socket-test.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/test/util/daemon-socket-test.ts b/test/util/daemon-socket-test.ts index eee0500..80a03e4 100644 --- a/test/util/daemon-socket-test.ts +++ b/test/util/daemon-socket-test.ts @@ -1,10 +1,11 @@ import { test, describe } from "node:test"; import assert from "node:assert/strict"; import { fileURLToPath } from "node:url"; +import { existsSync } from "node:fs"; import { Type } from "typebox"; import type { ExtensionAPI, ToolDefinition } from "@mariozechner/pi-coding-agent"; import type { TSchema } from "typebox"; -import { daemonSocketMayExist } from "../../src/daemon/spawn"; +import { daemonSocketMayExist, daemonSpawnCommand } from "../../src/daemon/spawn"; import { type AnyBrowserToolDefinition, registerBrowserTool } from "../../src/util/tool"; import type { BrowserClient } from "../../src/client"; import { ok } from "../../src/util/result"; @@ -32,6 +33,28 @@ describe("daemon socket presence check", () => { }); }); +describe("daemon spawn command", () => { + test("the daemon runs on this process's node, not a shell", () => { + const spec = daemonSpawnCommand(); + assert.notEqual(spec, null); + assert.equal(spec?.command, process.execPath); + }); + + test("the resolved tsx CLI is a real file on disk", () => { + const cli = daemonSpawnCommand()?.args[0]; + assert.equal(typeof cli, "string"); + // A hoisted install puts tsx beside the package, so a `<pkg>/node_modules/.bin` guess would miss it. + assert.equal(existsSync(String(cli)), true, `tsx CLI not found at ${String(cli)}`); + assert.match(String(cli), /cli\.mjs$/); + }); + + test("the daemon entrypoint is passed to tsx", () => { + const script = daemonSpawnCommand()?.args[1]; + assert.match(String(script), /[\\/]daemon[\\/]index\.ts$/); + assert.equal(existsSync(String(script)), true); + }); +}); + type GateProbe = { readonly ran: ReadonlyArray<string>; readonly text: string }; const runGate = async (ensureAlive: boolean | undefined): Promise<GateProbe> => { |
