From 677b78fe3b6171c85bdbdc38886301da763eb922 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 6 May 2026 11:05:38 +0900 Subject: [PATCH] test(agents): cover default-agent sort shim ordering --- src/shared/agent-sort-shim.test.ts | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/shared/agent-sort-shim.test.ts b/src/shared/agent-sort-shim.test.ts index 33352aa30..647b86f80 100644 --- a/src/shared/agent-sort-shim.test.ts +++ b/src/shared/agent-sort-shim.test.ts @@ -3,6 +3,12 @@ import { beforeAll, describe, expect, test } from "bun:test" import { installAgentSortShim } from "./agent-sort-shim" +import { AGENT_DISPLAY_NAMES } from "./agent-display-names" + +type AgentListItem = { + name: string + default_agent?: boolean +} describe("agent-sort-shim", () => { beforeAll(() => { @@ -49,6 +55,32 @@ describe("agent-sort-shim", () => { }) }) + describe("#given OpenCode Agent.list style sort with default agent priority", () => { + describe("#when toSorted compares default_agent first and then name", () => { + test("#then core agents stay in canonical order before non-core agents", () => { + // given + const sisyphus = { name: AGENT_DISPLAY_NAMES.sisyphus, default_agent: true } + const hephaestus = { name: AGENT_DISPLAY_NAMES.hephaestus } + const prometheus = { name: AGENT_DISPLAY_NAMES.prometheus } + const atlas = { name: AGENT_DISPLAY_NAMES.atlas } + const oracle = { name: AGENT_DISPLAY_NAMES.oracle } + const explore = { name: AGENT_DISPLAY_NAMES.explore } + const input: AgentListItem[] = [oracle, atlas, explore, prometheus, hephaestus, sisyphus] + + // when + const result = input.toSorted((left, right) => { + const leftDefault = left.default_agent ? 1 : 0 + const rightDefault = right.default_agent ? 1 : 0 + if (leftDefault !== rightDefault) return rightDefault - leftDefault + return left.name.localeCompare(right.name) + }) + + // then + expect(result).toEqual([sisyphus, hephaestus, prometheus, atlas, explore, oracle]) + }) + }) + }) + describe("#given an array with only one core agent and several non-core agent-like objects", () => { describe("#when toSorted with case-sensitive string-comparison compareFn", () => { test("#then activation predicate fails and result is ASCII-sensitive order with capital S before lowercase letters", () => {