|
1 | 1 | import { describe, test, expect } from "bun:test" |
2 | 2 | import { createBuiltinAgents } from "./utils" |
| 3 | +import type { AgentConfig } from "@opencode-ai/sdk" |
3 | 4 |
|
4 | 5 | describe("createBuiltinAgents with model overrides", () => { |
5 | 6 | test("Sisyphus with default model has thinking config", () => { |
@@ -85,3 +86,182 @@ describe("createBuiltinAgents with model overrides", () => { |
85 | 86 | expect(agents.Sisyphus.temperature).toBe(0.5) |
86 | 87 | }) |
87 | 88 | }) |
| 89 | + |
| 90 | +describe("buildAgent with category and skills", () => { |
| 91 | + const { buildAgent } = require("./utils") |
| 92 | + |
| 93 | + test("agent with category inherits category settings", () => { |
| 94 | + // #given |
| 95 | + const source = { |
| 96 | + "test-agent": () => |
| 97 | + ({ |
| 98 | + description: "Test agent", |
| 99 | + category: "visual-engineering", |
| 100 | + }) as AgentConfig, |
| 101 | + } |
| 102 | + |
| 103 | + // #when |
| 104 | + const agent = buildAgent(source["test-agent"]) |
| 105 | + |
| 106 | + // #then |
| 107 | + expect(agent.model).toBe("google/gemini-3-pro-preview") |
| 108 | + expect(agent.temperature).toBe(0.7) |
| 109 | + }) |
| 110 | + |
| 111 | + test("agent with category and existing model keeps existing model", () => { |
| 112 | + // #given |
| 113 | + const source = { |
| 114 | + "test-agent": () => |
| 115 | + ({ |
| 116 | + description: "Test agent", |
| 117 | + category: "visual-engineering", |
| 118 | + model: "custom/model", |
| 119 | + }) as AgentConfig, |
| 120 | + } |
| 121 | + |
| 122 | + // #when |
| 123 | + const agent = buildAgent(source["test-agent"]) |
| 124 | + |
| 125 | + // #then |
| 126 | + expect(agent.model).toBe("custom/model") |
| 127 | + expect(agent.temperature).toBe(0.7) |
| 128 | + }) |
| 129 | + |
| 130 | + test("agent with skills has content prepended to prompt", () => { |
| 131 | + // #given |
| 132 | + const source = { |
| 133 | + "test-agent": () => |
| 134 | + ({ |
| 135 | + description: "Test agent", |
| 136 | + skills: ["frontend-ui-ux"], |
| 137 | + prompt: "Original prompt content", |
| 138 | + }) as AgentConfig, |
| 139 | + } |
| 140 | + |
| 141 | + // #when |
| 142 | + const agent = buildAgent(source["test-agent"]) |
| 143 | + |
| 144 | + // #then |
| 145 | + expect(agent.prompt).toContain("Role: Designer-Turned-Developer") |
| 146 | + expect(agent.prompt).toContain("Original prompt content") |
| 147 | + expect(agent.prompt).toMatch(/Designer-Turned-Developer[\s\S]*Original prompt content/s) |
| 148 | + }) |
| 149 | + |
| 150 | + test("agent with multiple skills has all content prepended", () => { |
| 151 | + // #given |
| 152 | + const source = { |
| 153 | + "test-agent": () => |
| 154 | + ({ |
| 155 | + description: "Test agent", |
| 156 | + skills: ["frontend-ui-ux"], |
| 157 | + prompt: "Agent prompt", |
| 158 | + }) as AgentConfig, |
| 159 | + } |
| 160 | + |
| 161 | + // #when |
| 162 | + const agent = buildAgent(source["test-agent"]) |
| 163 | + |
| 164 | + // #then |
| 165 | + expect(agent.prompt).toContain("Role: Designer-Turned-Developer") |
| 166 | + expect(agent.prompt).toContain("Agent prompt") |
| 167 | + }) |
| 168 | + |
| 169 | + test("agent without category or skills works as before", () => { |
| 170 | + // #given |
| 171 | + const source = { |
| 172 | + "test-agent": () => |
| 173 | + ({ |
| 174 | + description: "Test agent", |
| 175 | + model: "custom/model", |
| 176 | + temperature: 0.5, |
| 177 | + prompt: "Base prompt", |
| 178 | + }) as AgentConfig, |
| 179 | + } |
| 180 | + |
| 181 | + // #when |
| 182 | + const agent = buildAgent(source["test-agent"]) |
| 183 | + |
| 184 | + // #then |
| 185 | + expect(agent.model).toBe("custom/model") |
| 186 | + expect(agent.temperature).toBe(0.5) |
| 187 | + expect(agent.prompt).toBe("Base prompt") |
| 188 | + }) |
| 189 | + |
| 190 | + test("agent with category and skills applies both", () => { |
| 191 | + // #given |
| 192 | + const source = { |
| 193 | + "test-agent": () => |
| 194 | + ({ |
| 195 | + description: "Test agent", |
| 196 | + category: "high-iq", |
| 197 | + skills: ["frontend-ui-ux"], |
| 198 | + prompt: "Task description", |
| 199 | + }) as AgentConfig, |
| 200 | + } |
| 201 | + |
| 202 | + // #when |
| 203 | + const agent = buildAgent(source["test-agent"]) |
| 204 | + |
| 205 | + // #then |
| 206 | + expect(agent.model).toBe("openai/gpt-5.2") |
| 207 | + expect(agent.temperature).toBe(0.1) |
| 208 | + expect(agent.prompt).toContain("Role: Designer-Turned-Developer") |
| 209 | + expect(agent.prompt).toContain("Task description") |
| 210 | + }) |
| 211 | + |
| 212 | + test("agent with non-existent category has no effect", () => { |
| 213 | + // #given |
| 214 | + const source = { |
| 215 | + "test-agent": () => |
| 216 | + ({ |
| 217 | + description: "Test agent", |
| 218 | + category: "non-existent", |
| 219 | + prompt: "Base prompt", |
| 220 | + }) as AgentConfig, |
| 221 | + } |
| 222 | + |
| 223 | + // #when |
| 224 | + const agent = buildAgent(source["test-agent"]) |
| 225 | + |
| 226 | + // #then |
| 227 | + expect(agent.model).toBeUndefined() |
| 228 | + expect(agent.prompt).toBe("Base prompt") |
| 229 | + }) |
| 230 | + |
| 231 | + test("agent with non-existent skills only prepends found ones", () => { |
| 232 | + // #given |
| 233 | + const source = { |
| 234 | + "test-agent": () => |
| 235 | + ({ |
| 236 | + description: "Test agent", |
| 237 | + skills: ["frontend-ui-ux", "non-existent-skill"], |
| 238 | + prompt: "Base prompt", |
| 239 | + }) as AgentConfig, |
| 240 | + } |
| 241 | + |
| 242 | + // #when |
| 243 | + const agent = buildAgent(source["test-agent"]) |
| 244 | + |
| 245 | + // #then |
| 246 | + expect(agent.prompt).toContain("Role: Designer-Turned-Developer") |
| 247 | + expect(agent.prompt).toContain("Base prompt") |
| 248 | + }) |
| 249 | + |
| 250 | + test("agent with empty skills array keeps original prompt", () => { |
| 251 | + // #given |
| 252 | + const source = { |
| 253 | + "test-agent": () => |
| 254 | + ({ |
| 255 | + description: "Test agent", |
| 256 | + skills: [], |
| 257 | + prompt: "Base prompt", |
| 258 | + }) as AgentConfig, |
| 259 | + } |
| 260 | + |
| 261 | + // #when |
| 262 | + const agent = buildAgent(source["test-agent"]) |
| 263 | + |
| 264 | + // #then |
| 265 | + expect(agent.prompt).toBe("Base prompt") |
| 266 | + }) |
| 267 | +}) |
0 commit comments