diff --git a/src/tools/agent-teams/paths.test.ts b/src/tools/agent-teams/paths.test.ts index ab5de9a1..b91d6251 100644 --- a/src/tools/agent-teams/paths.test.ts +++ b/src/tools/agent-teams/paths.test.ts @@ -1,7 +1,6 @@ /// -import { afterEach, beforeEach, describe, expect, test } from "bun:test" -import { mkdtempSync, rmSync } from "node:fs" -import { tmpdir } from "node:os" +import { describe, expect, test } from "bun:test" +import { homedir } from "node:os" import { join } from "node:path" import { getAgentTeamsRootDir, @@ -16,23 +15,9 @@ import { } from "./paths" describe("agent-teams paths", () => { - let originalCwd: string - let tempProjectDir: string - - beforeEach(() => { - originalCwd = process.cwd() - tempProjectDir = mkdtempSync(join(tmpdir(), "agent-teams-paths-")) - process.chdir(tempProjectDir) - }) - - afterEach(() => { - process.chdir(originalCwd) - rmSync(tempProjectDir, { recursive: true, force: true }) - }) - - test("uses project-local .sisyphus directory as storage root", () => { + test("uses user-global .sisyphus directory as storage root", () => { //#given - const expectedRoot = join(tempProjectDir, ".sisyphus", "agent-teams") + const expectedRoot = join(homedir(), ".sisyphus", "agent-teams") //#when const root = getAgentTeamsRootDir() @@ -43,7 +28,7 @@ describe("agent-teams paths", () => { test("builds expected teams and tasks root directories", () => { //#given - const expectedRoot = join(tempProjectDir, ".sisyphus", "agent-teams") + const expectedRoot = join(homedir(), ".sisyphus", "agent-teams") //#when const teamsRoot = getTeamsRootDir() @@ -59,7 +44,7 @@ describe("agent-teams paths", () => { const teamName = "alpha_team" const agentName = "worker_1" const taskId = "T-123" - const expectedTeamDir = join(getTeamsRootDir(), teamName) + const expectedTeamDir = join(getTeamsRootDir(), "alpha_team") //#when const teamDir = getTeamDir(teamName) @@ -74,7 +59,23 @@ describe("agent-teams paths", () => { expect(configPath).toBe(join(expectedTeamDir, "config.json")) expect(inboxDir).toBe(join(expectedTeamDir, "inboxes")) expect(inboxPath).toBe(join(expectedTeamDir, "inboxes", `${agentName}.json`)) - expect(taskDir).toBe(join(getTeamTasksRootDir(), teamName)) - expect(taskPath).toBe(join(getTeamTasksRootDir(), teamName, `${taskId}.json`)) + expect(taskDir).toBe(join(getTeamTasksRootDir(), "alpha_team")) + expect(taskPath).toBe(join(getTeamTasksRootDir(), "alpha_team", `${taskId}.json`)) + }) + + test("sanitizes team names with invalid characters", () => { + //#given + const invalidTeamName = "team space/with@special#chars" + const expectedSanitized = "team-space-with-special-chars" + + //#when + const teamDir = getTeamDir(invalidTeamName) + const configPath = getTeamConfigPath(invalidTeamName) + const taskDir = getTeamTaskDir(invalidTeamName) + + //#then + expect(teamDir).toBe(join(getTeamsRootDir(), expectedSanitized)) + expect(configPath).toBe(join(getTeamsRootDir(), expectedSanitized, "config.json")) + expect(taskDir).toBe(join(getTeamTasksRootDir(), expectedSanitized)) }) }) diff --git a/src/tools/agent-teams/paths.ts b/src/tools/agent-teams/paths.ts index 064a41c1..f1ce51c6 100644 --- a/src/tools/agent-teams/paths.ts +++ b/src/tools/agent-teams/paths.ts @@ -1,10 +1,12 @@ import { join } from "node:path" +import { homedir } from "node:os" +import { sanitizePathSegment } from "../../features/claude-tasks/storage" const SISYPHUS_DIR = ".sisyphus" const AGENT_TEAMS_DIR = "agent-teams" export function getAgentTeamsRootDir(): string { - return join(process.cwd(), SISYPHUS_DIR, AGENT_TEAMS_DIR) + return join(homedir(), SISYPHUS_DIR, AGENT_TEAMS_DIR) } export function getTeamsRootDir(): string { @@ -16,7 +18,7 @@ export function getTeamTasksRootDir(): string { } export function getTeamDir(teamName: string): string { - return join(getTeamsRootDir(), teamName) + return join(getTeamsRootDir(), sanitizePathSegment(teamName)) } export function getTeamConfigPath(teamName: string): string { @@ -32,7 +34,7 @@ export function getTeamInboxPath(teamName: string, agentName: string): string { } export function getTeamTaskDir(teamName: string): string { - return join(getTeamTasksRootDir(), teamName) + return join(getTeamTasksRootDir(), sanitizePathSegment(teamName)) } export function getTeamTaskPath(teamName: string, taskId: string): string {