36 lines
1010 B
TypeScript
36 lines
1010 B
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import type { Agent } from "@opencode-ai/sdk/v2/client"
|
|
import { normalizeAgentList } from "./utils"
|
|
|
|
const agent = (name = "build") =>
|
|
({
|
|
name,
|
|
mode: "primary",
|
|
permission: {},
|
|
options: {},
|
|
}) as Agent
|
|
|
|
describe("normalizeAgentList", () => {
|
|
test("keeps array payloads", () => {
|
|
expect(normalizeAgentList([agent("build"), agent("docs")])).toEqual([agent("build"), agent("docs")])
|
|
})
|
|
|
|
test("wraps a single agent payload", () => {
|
|
expect(normalizeAgentList(agent("docs"))).toEqual([agent("docs")])
|
|
})
|
|
|
|
test("extracts agents from keyed objects", () => {
|
|
expect(
|
|
normalizeAgentList({
|
|
build: agent("build"),
|
|
docs: agent("docs"),
|
|
}),
|
|
).toEqual([agent("build"), agent("docs")])
|
|
})
|
|
|
|
test("drops invalid payloads", () => {
|
|
expect(normalizeAgentList({ name: "AbortError" })).toEqual([])
|
|
expect(normalizeAgentList([{ name: "build" }, agent("docs")])).toEqual([agent("docs")])
|
|
})
|
|
})
|