From 54a7256a7123c593cdd042bdfdbf0b26a4dc3c57 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 16 May 2026 00:14:06 +0900 Subject: [PATCH] test(tmux): align placeholder command expectations --- .../tmux-subagent/polling-manager.test.ts | 13 ++++++------ .../tmux/tmux-utils/pane-spawn-runner.test.ts | 21 +++++++++++-------- .../tmux/tmux-utils/session-spawn.test.ts | 21 +++++++++++-------- .../tmux/tmux-utils/window-spawn.test.ts | 21 +++++++++++-------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/features/tmux-subagent/polling-manager.test.ts b/src/features/tmux-subagent/polling-manager.test.ts index f9dd28359..76496e39d 100644 --- a/src/features/tmux-subagent/polling-manager.test.ts +++ b/src/features/tmux-subagent/polling-manager.test.ts @@ -298,7 +298,7 @@ describe("TmuxPollingManager overlap", () => { expect(tracked.attachActivated).toBe(true) }) - test("does not close non-activated panes before focus activation", async () => { + test("does not close non-activated panes before they report any session status", async () => { //#given const sessions = new Map() sessions.set("ses-1", { @@ -318,7 +318,7 @@ describe("TmuxPollingManager overlap", () => { const closedSessionIds: string[] = [] const client = { session: { - status: async () => ({ data: { "ses-1": { type: "idle" } } }), + status: async () => ({ data: {} }), messages: async () => ({ data: [] }), }, } @@ -384,11 +384,12 @@ describe("TmuxPollingManager overlap", () => { } const manager = new TmuxPollingManager( - client as unknown as import("../../tools/delegate-task/types").OpencodeClient, + unsafeTestValue(client), sessions, async (sessionId) => { closedSessionIds.push(sessionId) }, + undefined, getWindowState, async () => { activationCount += 1 @@ -397,7 +398,7 @@ describe("TmuxPollingManager overlap", () => { ) //#when - const pollSessions = (manager as unknown as { pollSessions: () => Promise }).pollSessions + const pollSessions = unsafeTestValue<{ pollSessions: () => Promise }>(manager).pollSessions await pollSessions.call(manager) await pollSessions.call(manager) await pollSessions.call(manager) @@ -437,7 +438,7 @@ describe("TmuxPollingManager overlap", () => { } const manager = new TmuxPollingManager( - client as unknown as import("../../tools/delegate-task/types").OpencodeClient, + unsafeTestValue(client), sessions, async (sessionId) => { closedSessionIds.push(sessionId) @@ -450,7 +451,7 @@ describe("TmuxPollingManager overlap", () => { }) //#when - const pollSessions = (manager as unknown as { pollSessions: () => Promise }).pollSessions + const pollSessions = unsafeTestValue<{ pollSessions: () => Promise }>(manager).pollSessions await pollSessions.call(manager) await pollSessions.call(manager) await pollSessions.call(manager) diff --git a/src/shared/tmux/tmux-utils/pane-spawn-runner.test.ts b/src/shared/tmux/tmux-utils/pane-spawn-runner.test.ts index 5c2b2b96f..7df92b841 100644 --- a/src/shared/tmux/tmux-utils/pane-spawn-runner.test.ts +++ b/src/shared/tmux/tmux-utils/pane-spawn-runner.test.ts @@ -115,21 +115,23 @@ describe("spawnTmuxPane runner integration", () => { expect(result).toEqual({ success: true, paneId: "%42" }) expect(firstCall[1].slice(0, 8)).toEqual(["split-window", "-h", "-d", "-P", "-F", "#{pane_id}", "-t", "%0"]) expect(secondCall[1]).toEqual(["select-pane", "-t", "%42", "-T", "omo-subagent-worker"]) - expect(getSplitWindowCommand()).toContain(` --dir '${directory}'`) + expect(getSplitWindowCommand()).toContain("Focus this pane to attach.") + expect(getSplitWindowCommand()).toContain("tail -f /dev/null") + expect(getSplitWindowCommand()).not.toContain("opencode attach") }) - it("#given directory with spaces #when spawnTmuxPane called #then wraps --dir value in single quotes", async () => { + it("#given description with spaces #when spawnTmuxPane called #then includes it in the placeholder", async () => { // given const spawnTmuxPane = await loadSpawnTmuxPane() // when - await spawnTmuxPane("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "/path with spaces/here", "%0", "-h", createDeps()) + await spawnTmuxPane("session-1", "worker with spaces", enabledTmuxConfig, "http://127.0.0.1:1234", "/path with spaces/here", "%0", "-h", createDeps()) // then - expect(getSplitWindowCommand()).toContain("--dir '/path with spaces/here'") + expect(getSplitWindowCommand()).toContain("OMO subagent pane ready: worker with spaces") }) - it("#given empty directory #when spawnTmuxPane called #then falls back to process cwd", async () => { + it("#given empty directory #when spawnTmuxPane called #then keeps the placeholder detached from attach", async () => { // given const spawnTmuxPane = await loadSpawnTmuxPane() @@ -137,17 +139,18 @@ describe("spawnTmuxPane runner integration", () => { await spawnTmuxPane("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "", "%0", "-h", createDeps()) // then - expect(getSplitWindowCommand()).toContain(`--dir '${process.cwd()}'`) + expect(getSplitWindowCommand()).not.toContain("--dir") }) - it("#given directory with single quotes #when spawnTmuxPane called #then escapes the value with POSIX-safe single quoting", async () => { + it("#given description with shell metacharacters #when spawnTmuxPane called #then escapes the placeholder", async () => { // given const spawnTmuxPane = await loadSpawnTmuxPane() // when - await spawnTmuxPane("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "/path/with'quote", "%0", "-h", createDeps()) + await spawnTmuxPane("session-1", 'worker "$(whoami)"', enabledTmuxConfig, "http://127.0.0.1:1234", "/path/with'quote", "%0", "-h", createDeps()) // then - expect(getSplitWindowCommand()).toContain("--dir '/path/with'\\''quote'") + expect(getSplitWindowCommand()).toContain('\\"') + expect(getSplitWindowCommand()).toContain("\\$") }) }) diff --git a/src/shared/tmux/tmux-utils/session-spawn.test.ts b/src/shared/tmux/tmux-utils/session-spawn.test.ts index 689ad7c5d..9958e883d 100644 --- a/src/shared/tmux/tmux-utils/session-spawn.test.ts +++ b/src/shared/tmux/tmux-utils/session-spawn.test.ts @@ -102,21 +102,23 @@ describe("spawnTmuxSession runner integration", () => { expect(newSessionCall[1].slice(0, 4)).toEqual(["new-session", "-d", "-s", newSessionCall[1][3]]) expect(String(newSessionCall[1][3]).startsWith("omo-agents-")).toBe(true) expect(selectPaneCall[1]).toEqual(["select-pane", "-t", "%42", "-T", "omo-subagent-worker"]) - expect(harness.getSpawnCommand()).toContain(` --dir '${directory}'`) + expect(harness.getSpawnCommand()).toContain("Focus this pane to attach.") + expect(harness.getSpawnCommand()).toContain("tail -f /dev/null") + expect(harness.getSpawnCommand()).not.toContain("opencode attach") }) - it("#given directory with spaces #when spawnTmuxSession called #then wraps --dir value in single quotes", async () => { + it("#given description with spaces #when spawnTmuxSession called #then includes it in the placeholder", async () => { // given const harness = createHarness() // when - await spawnTmuxSession("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "/path with spaces/here", "%0", harness.deps) + await spawnTmuxSession("session-1", "worker with spaces", enabledTmuxConfig, "http://127.0.0.1:1234", "/path with spaces/here", "%0", harness.deps) // then - expect(harness.getSpawnCommand()).toContain("--dir '/path with spaces/here'") + expect(harness.getSpawnCommand()).toContain("OMO subagent pane ready: worker with spaces") }) - it("#given empty directory #when spawnTmuxSession called #then falls back to process cwd", async () => { + it("#given empty directory #when spawnTmuxSession called #then keeps the placeholder detached from attach", async () => { // given const harness = createHarness() @@ -124,17 +126,18 @@ describe("spawnTmuxSession runner integration", () => { await spawnTmuxSession("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "", "%0", harness.deps) // then - expect(harness.getSpawnCommand()).toContain(`--dir '${process.cwd()}'`) + expect(harness.getSpawnCommand()).not.toContain("--dir") }) - it("#given directory with single quotes #when spawnTmuxSession called #then escapes the value with POSIX-safe single quoting", async () => { + it("#given description with shell metacharacters #when spawnTmuxSession called #then escapes the placeholder", async () => { // given const harness = createHarness() // when - await spawnTmuxSession("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "/path/with'quote", "%0", harness.deps) + await spawnTmuxSession("session-1", 'worker "$(whoami)"', enabledTmuxConfig, "http://127.0.0.1:1234", "/path/with'quote", "%0", harness.deps) // then - expect(harness.getSpawnCommand()).toContain("--dir '/path/with'\\''quote'") + expect(harness.getSpawnCommand()).toContain('\\"') + expect(harness.getSpawnCommand()).toContain("\\$") }) }) diff --git a/src/shared/tmux/tmux-utils/window-spawn.test.ts b/src/shared/tmux/tmux-utils/window-spawn.test.ts index 03d7e46ef..4f0d18b09 100644 --- a/src/shared/tmux/tmux-utils/window-spawn.test.ts +++ b/src/shared/tmux/tmux-utils/window-spawn.test.ts @@ -90,21 +90,23 @@ describe("spawnTmuxWindow runner integration", () => { expect(result).toEqual({ success: true, paneId: "%42" }) expect(firstCall[1].slice(0, 7)).toEqual(["new-window", "-d", "-n", "omo-agents", "-P", "-F", "#{pane_id}"]) expect(secondCall[1]).toEqual(["select-pane", "-t", "%42", "-T", "omo-subagent-worker"]) - expect(harness.getNewWindowCommand()).toContain(` --dir '${directory}'`) + expect(harness.getNewWindowCommand()).toContain("Focus this pane to attach.") + expect(harness.getNewWindowCommand()).toContain("tail -f /dev/null") + expect(harness.getNewWindowCommand()).not.toContain("opencode attach") }) - it("#given directory with spaces #when spawnTmuxWindow called #then wraps --dir value in single quotes", async () => { + it("#given description with spaces #when spawnTmuxWindow called #then includes it in the placeholder", async () => { // given const harness = createHarness() // when - await spawnTmuxWindow("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "/path with spaces/here", harness.deps) + await spawnTmuxWindow("session-1", "worker with spaces", enabledTmuxConfig, "http://127.0.0.1:1234", "/path with spaces/here", harness.deps) // then - expect(harness.getNewWindowCommand()).toContain("--dir '/path with spaces/here'") + expect(harness.getNewWindowCommand()).toContain("OMO subagent pane ready: worker with spaces") }) - it("#given empty directory #when spawnTmuxWindow called #then falls back to process cwd", async () => { + it("#given empty directory #when spawnTmuxWindow called #then keeps the placeholder detached from attach", async () => { // given const harness = createHarness() @@ -112,17 +114,18 @@ describe("spawnTmuxWindow runner integration", () => { await spawnTmuxWindow("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "", harness.deps) // then - expect(harness.getNewWindowCommand()).toContain(`--dir '${process.cwd()}'`) + expect(harness.getNewWindowCommand()).not.toContain("--dir") }) - it("#given directory with single quotes #when spawnTmuxWindow called #then escapes the value with POSIX-safe single quoting", async () => { + it("#given description with shell metacharacters #when spawnTmuxWindow called #then escapes the placeholder", async () => { // given const harness = createHarness() // when - await spawnTmuxWindow("session-1", "worker", enabledTmuxConfig, "http://127.0.0.1:1234", "/path/with'quote", harness.deps) + await spawnTmuxWindow("session-1", 'worker "$(whoami)"', enabledTmuxConfig, "http://127.0.0.1:1234", "/path/with'quote", harness.deps) // then - expect(harness.getNewWindowCommand()).toContain("--dir '/path/with'\\''quote'") + expect(harness.getNewWindowCommand()).toContain('\\"') + expect(harness.getNewWindowCommand()).toContain("\\$") }) })