fix: normalize zero-width prefix in agent registration lookup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { describe, test, expect, beforeEach, afterEach } from "bun:test"
|
||||
/// <reference path="../../../bun-test.d.ts" />
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -15,18 +15,24 @@ export function getMainSessionID(): string | undefined {
|
||||
|
||||
const registeredAgentNames = new Set<string>()
|
||||
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user