Files
oh-my-opencode/src/plugin-handlers/agent-key-remapper.test.ts
T

152 lines
5.0 KiB
TypeScript

import { describe, it, expect } from "bun:test"
import { remapAgentKeysToDisplayNames } from "./agent-key-remapper"
import { getAgentDisplayName, getAgentRuntimeName } from "../shared/agent-display-names"
describe("remapAgentKeysToDisplayNames", () => {
it("remaps known agent keys to display names", () => {
// given agents with lowercase keys
const agents = {
sisyphus: { prompt: "test", mode: "primary" },
oracle: { prompt: "test", mode: "subagent" },
}
// when remapping
const result = remapAgentKeysToDisplayNames(agents)
// then known agents get display name keys only
expect(result[getAgentDisplayName("sisyphus")]).toBeDefined()
expect(result["oracle"]).toBeDefined()
expect(result["sisyphus"]).toBeUndefined()
})
it("preserves unknown agent keys unchanged", () => {
// given agents with a custom key
const agents = {
"custom-agent": { prompt: "custom" },
}
// when remapping
const result = remapAgentKeysToDisplayNames(agents)
// then custom key is unchanged
expect(result["custom-agent"]).toBeDefined()
})
it("remaps all core agents to display names", () => {
// given all core agents
const agents = {
sisyphus: {},
hephaestus: {},
prometheus: {},
atlas: {},
athena: {},
metis: {},
momus: {},
"sisyphus-junior": {},
}
// when remapping
const result = remapAgentKeysToDisplayNames(agents)
// then all get display name keys
expect(result[getAgentDisplayName("sisyphus")]).toBeDefined()
expect(result["sisyphus"]).toBeUndefined()
expect(result[getAgentDisplayName("hephaestus")]).toBeDefined()
expect(result["hephaestus"]).toBeUndefined()
expect(result[getAgentDisplayName("prometheus")]).toBeDefined()
expect(result["prometheus"]).toBeUndefined()
expect(result[getAgentDisplayName("atlas")]).toBeDefined()
expect(result["atlas"]).toBeUndefined()
expect(result[getAgentDisplayName("athena")]).toBeDefined()
expect(result["athena"]).toBeUndefined()
expect(result[getAgentDisplayName("metis")]).toBeDefined()
expect(result["metis"]).toBeUndefined()
expect(result[getAgentDisplayName("momus")]).toBeDefined()
expect(result["momus"]).toBeUndefined()
expect(result[getAgentDisplayName("sisyphus-junior")]).toBeDefined()
expect(result["sisyphus-junior"]).toBeUndefined()
})
it("does not emit both config and display keys for remapped agents", () => {
// given one remapped agent
const agents = {
sisyphus: { prompt: "test", mode: "primary" },
}
// when remapping
const result = remapAgentKeysToDisplayNames(agents)
// then only display key is emitted
expect(Object.keys(result)).toEqual([getAgentDisplayName("sisyphus")])
expect(result[getAgentDisplayName("sisyphus")]).toBeDefined()
expect(result["sisyphus"]).toBeUndefined()
})
it("returns clean core agent display names without ZWSP prefixes", () => {
// given
const result = remapAgentKeysToDisplayNames({
atlas: {},
prometheus: {},
hephaestus: {},
sisyphus: {},
})
// when
const remappedNames = Object.keys(result)
// then
expect(remappedNames).toEqual([
getAgentDisplayName("atlas"),
getAgentDisplayName("prometheus"),
getAgentDisplayName("hephaestus"),
getAgentDisplayName("sisyphus"),
])
for (const name of remappedNames) {
expect(name).not.toContain("\u200B")
}
})
it("preserves clean keys but rewrites core agent name fields to list-display names for tab cycling", () => {
// given agents with raw config-key names
const agents = {
sisyphus: { name: "sisyphus", prompt: "test", mode: "primary" },
hephaestus: { name: "hephaestus", prompt: "test", mode: "primary" },
prometheus: { name: "prometheus", prompt: "test", mode: "all" },
atlas: { name: "atlas", prompt: "test", mode: "primary" },
oracle: { name: "oracle", prompt: "test", mode: "subagent" },
}
// when remapping
const result = remapAgentKeysToDisplayNames(agents)
// then keys stay HTTP-header-safe, but nested names carry stable list ordering
expect(Object.keys(result).slice(0, 4)).toEqual([
getAgentDisplayName("sisyphus"),
getAgentDisplayName("hephaestus"),
getAgentDisplayName("prometheus"),
getAgentDisplayName("atlas"),
])
expect(result[getAgentDisplayName("sisyphus")]).toEqual({
name: getAgentRuntimeName("sisyphus"),
prompt: "test",
mode: "primary",
})
expect(result[getAgentDisplayName("hephaestus")]).toEqual({
name: getAgentRuntimeName("hephaestus"),
prompt: "test",
mode: "primary",
})
expect(result[getAgentDisplayName("prometheus")]).toEqual({
name: getAgentRuntimeName("prometheus"),
prompt: "test",
mode: "all",
})
expect(result[getAgentDisplayName("atlas")]).toEqual({
name: getAgentRuntimeName("atlas"),
prompt: "test",
mode: "primary",
})
expect(result.oracle).toEqual({ name: "oracle", prompt: "test", mode: "subagent" })
})
})