From 3d68c78c8357b79f3354d108ebc7e3e4524e6420 Mon Sep 17 00:00:00 2001 From: Federico Jaramillo Martinez Date: Sat, 13 Jun 2026 11:48:06 +0200 Subject: [PATCH] test: make working-directory tests pass on Windows Drive-qualify resolved paths in fixtures and assert against normalized cwds so route tests match the values normalizeRequestCwd produces. Skip the POSIX-shell TerminalService suite on native Windows, where the terminal feature is unsupported. --- src/server/sessions/sessionRoutes.test.ts | 10 +++++++--- src/server/terminals/terminalRoutes.test.ts | 8 ++++++-- src/server/terminals/terminalService.test.ts | 5 ++++- src/server/workingDirectory.test.ts | 6 ++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/server/sessions/sessionRoutes.test.ts b/src/server/sessions/sessionRoutes.test.ts index 67727c7..a219dbe 100644 --- a/src/server/sessions/sessionRoutes.test.ts +++ b/src/server/sessions/sessionRoutes.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path"; import Fastify, { type FastifyInstance } from "fastify"; import fastifyWebsocket from "@fastify/websocket"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; @@ -60,12 +61,15 @@ describe("session routes", () => { registerSessionRoutes(routeApp, routeService, eventHub); try { - const statusResponse = await routeApp.inject({ method: "GET", url: `/sessions/session-1/status?cwd=${encodeURIComponent("/repo")}` }); - const promptResponse = await routeApp.inject({ method: "POST", url: "/sessions/session-1/prompt", payload: { cwd: "/repo", text: "hello" } }); + // The route normalizes the request cwd, so the service sees the resolved + // absolute path (drive-qualified on Windows). + const requestCwd = resolve("/repo"); + const statusResponse = await routeApp.inject({ method: "GET", url: `/sessions/session-1/status?cwd=${encodeURIComponent(requestCwd)}` }); + const promptResponse = await routeApp.inject({ method: "POST", url: "/sessions/session-1/prompt", payload: { cwd: requestCwd, text: "hello" } }); expect(statusResponse.statusCode).toBe(200); expect(promptResponse.statusCode).toBe(200); - expect(routeService.calls).toEqual([{ id: "session-1", cwd: "/repo" }, { lookup: { id: "session-1", cwd: "/repo" }, text: "hello" }]); + expect(routeService.calls).toEqual([{ id: "session-1", cwd: requestCwd }, { lookup: { id: "session-1", cwd: requestCwd }, text: "hello" }]); } finally { await routeService.dispose(); await routeApp.close(); diff --git a/src/server/terminals/terminalRoutes.test.ts b/src/server/terminals/terminalRoutes.test.ts index e66ac80..815d1ee 100644 --- a/src/server/terminals/terminalRoutes.test.ts +++ b/src/server/terminals/terminalRoutes.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path"; import Fastify, { type FastifyInstance } from "fastify"; import fastifyWebsocket from "@fastify/websocket"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; @@ -32,11 +33,14 @@ describe("terminal routes", () => { }); it("closes all terminals for a cwd", async () => { - const response = await app.inject({ method: "DELETE", url: `/terminals?cwd=${encodeURIComponent("/repo/worktree")}` }); + // The route normalizes the request cwd, so the service receives the + // resolved absolute path (drive-qualified on Windows). + const requestCwd = resolve("/repo/worktree"); + const response = await app.inject({ method: "DELETE", url: `/terminals?cwd=${encodeURIComponent(requestCwd)}` }); expect(response.statusCode).toBe(200); expect(response.json()).toEqual({ closed: true }); - expect(terminals.events).toEqual(["close-cwd:/repo/worktree"]); + expect(terminals.events).toEqual([`close-cwd:${requestCwd}`]); }); it("creates and lists terminal command runs with filters", async () => { diff --git a/src/server/terminals/terminalService.test.ts b/src/server/terminals/terminalService.test.ts index 9aabbeb..4ff3986 100644 --- a/src/server/terminals/terminalService.test.ts +++ b/src/server/terminals/terminalService.test.ts @@ -1,7 +1,10 @@ import { describe, expect, it } from "vitest"; import { TerminalService } from "./terminalService"; -describe("TerminalService command runs", () => { +// TerminalService spawns a POSIX shell (/bin/bash with -lc and commands like +// printf/true/exit). The terminal feature is not supported on native Windows, +// so these tests are skipped there rather than asserting Unix shell behavior. +describe.skipIf(process.platform === "win32")("TerminalService command runs", () => { it("closes all terminal records for a cwd", () => { const service = new TerminalService(); try { diff --git a/src/server/workingDirectory.test.ts b/src/server/workingDirectory.test.ts index 5f41064..f542d08 100644 --- a/src/server/workingDirectory.test.ts +++ b/src/server/workingDirectory.test.ts @@ -1,8 +1,10 @@ -import { join, sep } from "node:path"; +import { join, resolve, sep } from "node:path"; import { describe, expect, it } from "vitest"; import { canonicalizeStoredCwd, cwdPathsEqual, normalizeRequestCwd } from "./workingDirectory.js"; -const absoluteBase = join(sep, "srv", "projects", "demo"); +// resolve() so the base already carries a drive letter on Windows, matching +// what normalizeRequestCwd/canonicalizeStoredCwd produce. +const absoluteBase = resolve(sep, "srv", "projects", "demo"); describe("normalizeRequestCwd", () => { it("returns absolute paths in canonical form", () => {