From 8d3d882578170a3fdeb6c985c0a5bd5f426ac257 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Tue, 28 Apr 2026 10:45:27 +0900 Subject: [PATCH] test(tmux-subagent): add manager project-directory resolution tests --- .../manager-project-directory.test.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/features/tmux-subagent/manager-project-directory.test.ts diff --git a/src/features/tmux-subagent/manager-project-directory.test.ts b/src/features/tmux-subagent/manager-project-directory.test.ts new file mode 100644 index 000000000..0e5d87e31 --- /dev/null +++ b/src/features/tmux-subagent/manager-project-directory.test.ts @@ -0,0 +1,65 @@ +/// +import { describe, expect, it, mock } from "bun:test" +import type { PluginInput } from "@opencode-ai/plugin" + +import type { TmuxConfig } from "../../config/schema" +import { TmuxSessionManager, type TmuxUtilDeps } from "./manager" + +const tmuxConfig = { + enabled: true, + isolation: "inline", + layout: "main-vertical", + main_pane_size: 60, + main_pane_min_width: 80, + agent_pane_min_width: 40, +} satisfies TmuxConfig + +const tmuxDeps: TmuxUtilDeps = { + isInsideTmux: () => true, + getCurrentPaneId: () => "%0", + queryWindowState: mock(async () => null), +} + +function createPluginInput(directory: string): PluginInput { + let shell: PluginInput["$"] + shell = Object.assign( + () => { + throw new Error("shell should not be used in this test") + }, + { + braces: (): string[] => [], + escape: (input: string): string => input, + env: (): PluginInput["$"] => shell, + cwd: (): PluginInput["$"] => shell, + nothrow: (): PluginInput["$"] => shell, + throws: (): PluginInput["$"] => shell, + }, + ) + + return { + client: Object.assign({} as PluginInput["client"], { + session: { + status: mock(async () => ({ data: {} })), + messages: mock(async () => ({ data: [] })), + }, + }), + project: {} as PluginInput["project"], + directory, + worktree: process.cwd(), + serverUrl: new URL("http://localhost:4096"), + $: shell, + } +} + +describe("TmuxSessionManager projectDirectory", () => { + it("#given empty ctx.directory #when manager is constructed #then it falls back to process.cwd()", () => { + // given + const ctx = createPluginInput("") + + // when + const manager = new TmuxSessionManager(ctx, tmuxConfig, tmuxDeps) + + // then + expect(Reflect.get(manager, "projectDirectory")).toBe(process.cwd()) + }) +})