test(agents): drop unsafe AgentFactory cast and add typed empty skills

Tests that mock an AgentFactory were using an `as AgentFactory` cast
and a separate mutation of `mockFactory.mode` to satisfy the type.
Replace with Object.assign so the factory type is constructed correctly
without casts. Also type the empty discoveredSkills fixture so its
element type is inferred from the function signature instead of
collapsing to never[].
This commit is contained in:
YeonGyu-Kim
2026-05-17 00:09:21 +09:00
parent 791fbf3e55
commit cc97a023cc
2 changed files with 12 additions and 13 deletions
+8 -11
View File
@@ -1,16 +1,15 @@
import { describe, test, expect } from "bun:test"
import { describe, expect, test } from "bun:test"
import { buildAgent } from "./agent-builder"
import type { AgentFactory } from "./types"
describe("#given an agent factory with mode", () => {
const mockFactory = ((model: string) => ({
const mockFactory: AgentFactory = Object.assign((model: string) => ({
name: "test-agent",
description: "Test",
instructions: "test",
model,
temperature: 0.1,
})) as AgentFactory
mockFactory.mode = "subagent"
}), { mode: "subagent" as const })
test("#when building agent from factory", () => {
const agent = buildAgent(mockFactory, "test-model")
@@ -19,14 +18,13 @@ describe("#given an agent factory with mode", () => {
})
describe("#given an agent factory with mode=primary", () => {
const mockFactory = ((model: string) => ({
const mockFactory: AgentFactory = Object.assign((model: string) => ({
name: "primary-agent",
description: "Primary Test",
instructions: "test",
model,
temperature: 0.1,
})) as AgentFactory
mockFactory.mode = "primary"
}), { mode: "primary" as const })
test("#when building agent from factory", () => {
const agent = buildAgent(mockFactory, "test-model")
@@ -50,15 +48,14 @@ describe("#given an agent config object without mode", () => {
})
describe("#given an agent factory with mode but config already has mode", () => {
const mockFactory = ((model: string) => ({
const mockFactory: AgentFactory = Object.assign((model: string) => ({
name: "override-agent",
description: "Override Test",
instructions: "test",
model,
temperature: 0.1,
mode: "all",
})) as AgentFactory
mockFactory.mode = "subagent"
mode: "all" as const,
}), { mode: "subagent" as const })
test("#when building agent from factory", () => {
const agent = buildAgent(mockFactory, "test-model")
@@ -2,10 +2,12 @@ import { describe, expect, test } from "bun:test"
import { buildAvailableSkills } from "./available-skills"
type DiscoveredSkills = Parameters<typeof buildAvailableSkills>[0]
describe("buildAvailableSkills", () => {
test("includes team-mode when team mode is enabled", () => {
// given
const discoveredSkills = []
const discoveredSkills: DiscoveredSkills = []
// when
const availableSkills = buildAvailableSkills(discoveredSkills, undefined, undefined, true)
@@ -16,7 +18,7 @@ describe("buildAvailableSkills", () => {
test("excludes team-mode when team mode is disabled", () => {
// given
const discoveredSkills = []
const discoveredSkills: DiscoveredSkills = []
// when
const availableSkills = buildAvailableSkills(discoveredSkills, undefined, undefined, false)