diff --git a/src/features/claude-code-session-state/state.test.ts b/src/features/claude-code-session-state/state.test.ts index 7a08f676d..a0f1e0420 100644 --- a/src/features/claude-code-session-state/state.test.ts +++ b/src/features/claude-code-session-state/state.test.ts @@ -1,4 +1,6 @@ -import { describe, test, expect, beforeEach, afterEach } from "bun:test" +/// + +import { describe, it as test, expect, beforeEach, afterEach } from "bun:test" import { setSessionAgent, getSessionAgent, @@ -51,7 +53,7 @@ describe("claude-code-session-state", () => { // given - no session set // when / then - expect(getSessionAgent("unknown-session")).toBeUndefined() + expect(getSessionAgent("unknown-session")).toBe(undefined) }) }) @@ -80,7 +82,7 @@ describe("claude-code-session-state", () => { clearSessionAgent(sessionID) // then - expect(getSessionAgent(sessionID)).toBeUndefined() + expect(getSessionAgent(sessionID)).toBe(undefined) }) }) @@ -100,7 +102,7 @@ describe("claude-code-session-state", () => { // given - explicit reset to ensure clean state (parallel test isolation) _resetForTesting() // then - expect(getMainSessionID()).toBeUndefined() + expect(getMainSessionID()).toBe(undefined) }) }) @@ -113,6 +115,21 @@ describe("claude-code-session-state", () => { expect(isAgentRegistered("atlas")).toBe(true) expect(isAgentRegistered("Atlas (Plan Executor)")).toBe(true) }) + + describe("#given atlas display name with zero-width prefix", () => { + describe("#when checking registration without the zero-width prefix", () => { + test("#then it treats the display name as registered", () => { + // given + registerAgentName("\u200BAtlas (Plan Executor)") + + // when + const isRegistered = isAgentRegistered("Atlas (Plan Executor)") + + // then + expect(isRegistered).toBe(true) + }) + }) + }) }) describe("prometheus-md-only integration scenario", () => { @@ -135,7 +152,7 @@ describe("claude-code-session-state", () => { const sessionID = "test-prometheus-session" // when / then - this is the bug: agent is undefined - expect(getSessionAgent(sessionID)).toBeUndefined() + expect(getSessionAgent(sessionID)).toBe(undefined) }) }) diff --git a/src/features/claude-code-session-state/state.ts b/src/features/claude-code-session-state/state.ts index f0a167b06..929661d2c 100644 --- a/src/features/claude-code-session-state/state.ts +++ b/src/features/claude-code-session-state/state.ts @@ -15,18 +15,24 @@ export function getMainSessionID(): string | undefined { const registeredAgentNames = new Set() +const ZERO_WIDTH_CHARACTERS_REGEX = /[\u200B\u200C\u200D\uFEFF]/g + +function normalizeRegisteredAgentName(name: string): string { + return name.replace(ZERO_WIDTH_CHARACTERS_REGEX, "").toLowerCase() +} + export function registerAgentName(name: string): void { - const normalizedName = name.toLowerCase() + const normalizedName = normalizeRegisteredAgentName(name) registeredAgentNames.add(normalizedName) - const configKey = getAgentConfigKey(name).toLowerCase() + const configKey = normalizeRegisteredAgentName(getAgentConfigKey(name)) if (configKey !== normalizedName) { registeredAgentNames.add(configKey) } } export function isAgentRegistered(name: string): boolean { - return registeredAgentNames.has(name.toLowerCase()) + return registeredAgentNames.has(normalizeRegisteredAgentName(name)) } /** @internal For testing only */