From b4fa31a47a8144a567b98532766368f5d8d000f4 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Sat, 17 Jan 2026 16:57:31 +0900 Subject: [PATCH] fix(test): add _resetForTesting for proper test isolation --- src/features/claude-code-session-state/state.test.ts | 10 ++-------- src/features/claude-code-session-state/state.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/features/claude-code-session-state/state.test.ts b/src/features/claude-code-session-state/state.test.ts index 813bc197..887add7e 100644 --- a/src/features/claude-code-session-state/state.test.ts +++ b/src/features/claude-code-session-state/state.test.ts @@ -6,17 +6,16 @@ import { updateSessionAgent, setMainSession, getMainSessionID, - subagentSessions, + _resetForTesting, } from "./state" describe("claude-code-session-state", () => { beforeEach(() => { // #given - clean state before each test + _resetForTesting() clearSessionAgent("test-session-1") clearSessionAgent("test-session-2") clearSessionAgent("test-prometheus-session") - setMainSession(undefined) - subagentSessions.clear() }) describe("setSessionAgent", () => { @@ -82,11 +81,6 @@ describe("claude-code-session-state", () => { }) describe("mainSessionID", () => { - beforeEach(() => { - // #given - ensure clean state for mainSessionID tests - setMainSession(undefined) - }) - test("should store and retrieve main session ID", () => { // #given const mainID = "main-session-123" diff --git a/src/features/claude-code-session-state/state.ts b/src/features/claude-code-session-state/state.ts index a864b75d..2f1e69ed 100644 --- a/src/features/claude-code-session-state/state.ts +++ b/src/features/claude-code-session-state/state.ts @@ -1,13 +1,19 @@ export const subagentSessions = new Set() -export let mainSessionID: string | undefined +let _mainSessionID: string | undefined export function setMainSession(id: string | undefined) { - mainSessionID = id + _mainSessionID = id } export function getMainSessionID(): string | undefined { - return mainSessionID + return _mainSessionID +} + +/** @internal For testing only */ +export function _resetForTesting(): void { + _mainSessionID = undefined + subagentSessions.clear() } const sessionAgentMap = new Map()