agent.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. import { afterEach, expect } from "bun:test"
  2. import { LayerNode } from "@kirincode-ai/core/effect/layer-node"
  3. import { Cause, Effect, Exit, Layer } from "effect"
  4. import path from "path"
  5. import { disposeAllInstances, TestInstance } from "../fixture/fixture"
  6. import { testEffect } from "../lib/effect"
  7. import { Agent } from "../../src/agent/agent"
  8. import { Auth } from "../../src/auth"
  9. import { Config } from "../../src/config/config"
  10. import { RuntimeFlags } from "../../src/effect/runtime-flags"
  11. import { Global } from "@kirincode-ai/core/global"
  12. import { Permission } from "../../src/permission"
  13. import { PermissionV1 } from "@kirincode-ai/core/v1/permission"
  14. import { Plugin } from "../../src/plugin"
  15. import { Provider } from "../../src/provider/provider"
  16. import { Skill } from "../../src/skill"
  17. import { Truncate } from "../../src/tool/truncate"
  18. const agentLayer = (flags: Partial<RuntimeFlags.Info> = {}) =>
  19. LayerNode.compile(
  20. LayerNode.group([Agent.node, Plugin.node, Provider.node, Auth.node, Config.node, Skill.node, RuntimeFlags.node]),
  21. [[RuntimeFlags.node, RuntimeFlags.layer(flags)]],
  22. )
  23. const it = testEffect(agentLayer())
  24. // Helper to evaluate permission for a tool with wildcard pattern
  25. function evalPerm(agent: Agent.Info | undefined, permission: string): PermissionV1.Action | undefined {
  26. if (!agent) return undefined
  27. return Permission.evaluate(permission, "*", agent.permission).action
  28. }
  29. function load<A>(fn: (svc: Agent.Interface) => Effect.Effect<A>) {
  30. return Agent.Service.use(fn)
  31. }
  32. const expectDefaultAgentError = Effect.fn("AgentTest.expectDefaultAgentError")(function* (message: string) {
  33. const exit = yield* load((svc) => svc.defaultAgent()).pipe(Effect.exit)
  34. expect(Exit.isFailure(exit)).toBe(true)
  35. if (Exit.isFailure(exit)) expect(Cause.pretty(exit.cause)).toContain(message)
  36. })
  37. afterEach(async () => {
  38. await disposeAllInstances()
  39. })
  40. it.instance("returns default native agents when no config", () =>
  41. Effect.gen(function* () {
  42. const agents = yield* load((svc) => svc.list())
  43. const names = agents.map((a) => a.name)
  44. expect(names).toContain("build")
  45. expect(names).toContain("plan")
  46. expect(names).toContain("general")
  47. expect(names).toContain("explore")
  48. expect(names).toContain("compaction")
  49. expect(names).toContain("title")
  50. expect(names).toContain("summary")
  51. }),
  52. )
  53. it.instance("build agent has correct default properties", () =>
  54. Effect.gen(function* () {
  55. const build = yield* load((svc) => svc.get("build"))
  56. expect(build).toBeDefined()
  57. expect(build?.mode).toBe("primary")
  58. expect(build?.native).toBe(true)
  59. expect(evalPerm(build, "edit")).toBe("allow")
  60. expect(evalPerm(build, "bash")).toBe("allow")
  61. }),
  62. )
  63. it.instance("plan agent denies edits except .kirincode/plans/*", () =>
  64. Effect.gen(function* () {
  65. const plan = yield* load((svc) => svc.get("plan"))
  66. expect(plan).toBeDefined()
  67. // Wildcard is denied
  68. expect(evalPerm(plan, "edit")).toBe("deny")
  69. // But specific path is allowed
  70. expect(Permission.evaluate("edit", ".kirincode/plans/foo.md", plan!.permission).action).toBe("allow")
  71. }),
  72. )
  73. it.instance("plan agent denies the general subagent by default", () =>
  74. Effect.gen(function* () {
  75. const plan = yield* load((svc) => svc.get("plan"))
  76. expect(plan).toBeDefined()
  77. expect(Permission.evaluate("task", "general", plan!.permission).action).toBe("deny")
  78. expect(Permission.evaluate("task", "explore", plan!.permission).action).toBe("allow")
  79. expect(Permission.evaluate("task", "custom", plan!.permission).action).toBe("allow")
  80. }),
  81. )
  82. it.instance(
  83. "user permission can allow the general subagent from plan mode",
  84. () =>
  85. Effect.gen(function* () {
  86. const plan = yield* load((svc) => svc.get("plan"))
  87. expect(plan).toBeDefined()
  88. expect(Permission.evaluate("task", "general", plan!.permission).action).toBe("allow")
  89. }),
  90. {
  91. config: {
  92. permission: {
  93. task: {
  94. general: "allow",
  95. },
  96. },
  97. },
  98. },
  99. )
  100. it.instance("explore agent denies edit and write", () =>
  101. Effect.gen(function* () {
  102. const explore = yield* load((svc) => svc.get("explore"))
  103. expect(explore).toBeDefined()
  104. expect(explore?.mode).toBe("subagent")
  105. expect(evalPerm(explore, "edit")).toBe("deny")
  106. expect(evalPerm(explore, "write")).toBe("deny")
  107. expect(evalPerm(explore, "todowrite")).toBe("deny")
  108. }),
  109. )
  110. it.instance("explore agent asks for external directories and allows whitelisted external paths", () =>
  111. Effect.gen(function* () {
  112. const explore = yield* load((svc) => svc.get("explore"))
  113. expect(explore).toBeDefined()
  114. expect(Permission.evaluate("external_directory", "/some/other/path", explore!.permission).action).toBe("ask")
  115. expect(Permission.evaluate("external_directory", Truncate.GLOB, explore!.permission).action).toBe("allow")
  116. expect(
  117. Permission.evaluate("external_directory", path.join(Global.Path.tmp, "agent-work"), explore!.permission).action,
  118. ).toBe("allow")
  119. }),
  120. )
  121. it.instance(
  122. "reference config does not create subagents",
  123. () =>
  124. Effect.gen(function* () {
  125. const agents = yield* load((svc) => svc.list())
  126. const names = agents.map((agent) => agent.name)
  127. expect(names).not.toContain("effect")
  128. expect(names).not.toContain("effectFull")
  129. expect(names).not.toContain("localdocs")
  130. expect(names).not.toContain("localdocsFull")
  131. }),
  132. {
  133. config: {
  134. references: {
  135. effect: "github.com/effect/effect-smol",
  136. effectFull: {
  137. repository: "Effect-TS/effect",
  138. branch: "main",
  139. },
  140. localdocs: "../docs",
  141. localdocsFull: {
  142. path: "../local-docs",
  143. },
  144. },
  145. },
  146. },
  147. )
  148. it.instance("general agent denies todo tools", () =>
  149. Effect.gen(function* () {
  150. const general = yield* load((svc) => svc.get("general"))
  151. expect(general).toBeDefined()
  152. expect(general?.mode).toBe("subagent")
  153. expect(general?.hidden).toBeUndefined()
  154. expect(evalPerm(general, "todowrite")).toBe("deny")
  155. }),
  156. )
  157. it.instance("compaction agent denies all permissions", () =>
  158. Effect.gen(function* () {
  159. const compaction = yield* load((svc) => svc.get("compaction"))
  160. expect(compaction).toBeDefined()
  161. expect(compaction?.hidden).toBe(true)
  162. expect(evalPerm(compaction, "bash")).toBe("deny")
  163. expect(evalPerm(compaction, "edit")).toBe("deny")
  164. expect(evalPerm(compaction, "read")).toBe("deny")
  165. }),
  166. )
  167. it.instance(
  168. "custom agent from config creates new agent",
  169. () =>
  170. Effect.gen(function* () {
  171. const custom = yield* load((svc) => svc.get("my_custom_agent"))
  172. expect(custom).toBeDefined()
  173. expect(String(custom?.model?.providerID)).toBe("openai")
  174. expect(String(custom?.model?.modelID)).toBe("gpt-4")
  175. expect(custom?.description).toBe("My custom agent")
  176. expect(custom?.temperature).toBe(0.5)
  177. expect(custom?.topP).toBe(0.9)
  178. expect(custom?.native).toBe(false)
  179. expect(custom?.mode).toBe("all")
  180. }),
  181. {
  182. config: {
  183. agent: {
  184. my_custom_agent: {
  185. model: "openai/gpt-4",
  186. description: "My custom agent",
  187. temperature: 0.5,
  188. top_p: 0.9,
  189. },
  190. },
  191. },
  192. },
  193. )
  194. it.instance(
  195. "custom agent config overrides native agent properties",
  196. () =>
  197. Effect.gen(function* () {
  198. const build = yield* load((svc) => svc.get("build"))
  199. expect(build).toBeDefined()
  200. expect(String(build?.model?.providerID)).toBe("anthropic")
  201. expect(String(build?.model?.modelID)).toBe("claude-3")
  202. expect(build?.description).toBe("Custom build agent")
  203. expect(build?.temperature).toBe(0.7)
  204. expect(build?.color).toBe("#FF0000")
  205. expect(build?.native).toBe(true)
  206. }),
  207. {
  208. config: {
  209. agent: {
  210. build: {
  211. model: "anthropic/claude-3",
  212. description: "Custom build agent",
  213. temperature: 0.7,
  214. color: "#FF0000",
  215. },
  216. },
  217. },
  218. },
  219. )
  220. it.instance(
  221. "agent disable removes agent from list",
  222. () =>
  223. Effect.gen(function* () {
  224. const explore = yield* load((svc) => svc.get("explore"))
  225. expect(explore).toBeUndefined()
  226. const agents = yield* load((svc) => svc.list())
  227. const names = agents.map((a) => a.name)
  228. expect(names).not.toContain("explore")
  229. }),
  230. {
  231. config: {
  232. agent: {
  233. explore: { disable: true },
  234. },
  235. },
  236. },
  237. )
  238. it.instance(
  239. "agent permission config merges with defaults",
  240. () =>
  241. Effect.gen(function* () {
  242. const build = yield* load((svc) => svc.get("build"))
  243. expect(build).toBeDefined()
  244. // Specific pattern is denied
  245. expect(Permission.evaluate("bash", "rm -rf *", build!.permission).action).toBe("deny")
  246. // Edit still allowed
  247. expect(evalPerm(build, "edit")).toBe("allow")
  248. }),
  249. {
  250. config: {
  251. agent: {
  252. build: {
  253. permission: {
  254. bash: {
  255. "rm -rf *": "deny",
  256. },
  257. },
  258. },
  259. },
  260. },
  261. },
  262. )
  263. it.instance(
  264. "global permission config applies to all agents",
  265. () =>
  266. Effect.gen(function* () {
  267. const build = yield* load((svc) => svc.get("build"))
  268. expect(build).toBeDefined()
  269. expect(evalPerm(build, "bash")).toBe("deny")
  270. }),
  271. {
  272. config: {
  273. permission: {
  274. bash: "deny",
  275. },
  276. },
  277. },
  278. )
  279. it.instance(
  280. "agent steps/maxSteps config sets steps property",
  281. () =>
  282. Effect.gen(function* () {
  283. const build = yield* load((svc) => svc.get("build"))
  284. const plan = yield* load((svc) => svc.get("plan"))
  285. expect(build?.steps).toBe(50)
  286. expect(plan?.steps).toBe(100)
  287. }),
  288. {
  289. config: {
  290. agent: {
  291. build: { steps: 50 },
  292. plan: { maxSteps: 100 },
  293. },
  294. },
  295. },
  296. )
  297. it.instance(
  298. "agent mode can be overridden",
  299. () =>
  300. Effect.gen(function* () {
  301. const explore = yield* load((svc) => svc.get("explore"))
  302. expect(explore?.mode).toBe("primary")
  303. }),
  304. {
  305. config: {
  306. agent: {
  307. explore: { mode: "primary" },
  308. },
  309. },
  310. },
  311. )
  312. it.instance(
  313. "agent name can be overridden",
  314. () =>
  315. Effect.gen(function* () {
  316. const build = yield* load((svc) => svc.get("build"))
  317. expect(build?.name).toBe("Builder")
  318. }),
  319. {
  320. config: {
  321. agent: {
  322. build: { name: "Builder" },
  323. },
  324. },
  325. },
  326. )
  327. it.instance(
  328. "agent prompt can be set from config",
  329. () =>
  330. Effect.gen(function* () {
  331. const build = yield* load((svc) => svc.get("build"))
  332. expect(build?.prompt).toBe("Custom system prompt")
  333. }),
  334. {
  335. config: {
  336. agent: {
  337. build: { prompt: "Custom system prompt" },
  338. },
  339. },
  340. },
  341. )
  342. it.instance(
  343. "unknown agent properties are placed into options",
  344. () =>
  345. Effect.gen(function* () {
  346. const build = yield* load((svc) => svc.get("build"))
  347. expect(build?.options.random_property).toBe("hello")
  348. expect(build?.options.another_random).toBe(123)
  349. }),
  350. {
  351. config: {
  352. agent: {
  353. build: {
  354. random_property: "hello",
  355. another_random: 123,
  356. },
  357. },
  358. },
  359. },
  360. )
  361. it.instance(
  362. "agent options merge correctly",
  363. () =>
  364. Effect.gen(function* () {
  365. const build = yield* load((svc) => svc.get("build"))
  366. expect(build?.options.custom_option).toBe(true)
  367. expect(build?.options.another_option).toBe("value")
  368. }),
  369. {
  370. config: {
  371. agent: {
  372. build: {
  373. options: {
  374. custom_option: true,
  375. another_option: "value",
  376. },
  377. },
  378. },
  379. },
  380. },
  381. )
  382. it.instance(
  383. "multiple custom agents can be defined",
  384. () =>
  385. Effect.gen(function* () {
  386. const agentA = yield* load((svc) => svc.get("agent_a"))
  387. const agentB = yield* load((svc) => svc.get("agent_b"))
  388. expect(agentA?.description).toBe("Agent A")
  389. expect(agentA?.mode).toBe("subagent")
  390. expect(agentB?.description).toBe("Agent B")
  391. expect(agentB?.mode).toBe("primary")
  392. }),
  393. {
  394. config: {
  395. agent: {
  396. agent_a: {
  397. description: "Agent A",
  398. mode: "subagent",
  399. },
  400. agent_b: {
  401. description: "Agent B",
  402. mode: "primary",
  403. },
  404. },
  405. },
  406. },
  407. )
  408. it.instance(
  409. "Agent.list keeps the default agent first and sorts the rest by name",
  410. () =>
  411. Effect.gen(function* () {
  412. const names = (yield* load((svc) => svc.list())).map((a) => a.name)
  413. expect(names[0]).toBe("plan")
  414. expect(names.slice(1)).toEqual(names.slice(1).toSorted((a, b) => a.localeCompare(b)))
  415. }),
  416. {
  417. config: {
  418. default_agent: "plan",
  419. agent: {
  420. zebra: {
  421. description: "Zebra",
  422. mode: "subagent",
  423. },
  424. alpha: {
  425. description: "Alpha",
  426. mode: "subagent",
  427. },
  428. },
  429. },
  430. },
  431. )
  432. it.instance("Agent.get returns undefined for non-existent agent", () =>
  433. Effect.gen(function* () {
  434. const nonExistent = yield* load((svc) => svc.get("does_not_exist"))
  435. expect(nonExistent).toBeUndefined()
  436. }),
  437. )
  438. it.instance("default permission includes doom_loop and external_directory as ask", () =>
  439. Effect.gen(function* () {
  440. const build = yield* load((svc) => svc.get("build"))
  441. expect(evalPerm(build, "doom_loop")).toBe("ask")
  442. expect(evalPerm(build, "external_directory")).toBe("ask")
  443. }),
  444. )
  445. it.instance("webfetch is allowed by default", () =>
  446. Effect.gen(function* () {
  447. const build = yield* load((svc) => svc.get("build"))
  448. expect(evalPerm(build, "webfetch")).toBe("allow")
  449. }),
  450. )
  451. it.instance(
  452. "legacy tools config converts to permissions",
  453. () =>
  454. Effect.gen(function* () {
  455. const build = yield* load((svc) => svc.get("build"))
  456. expect(evalPerm(build, "bash")).toBe("deny")
  457. expect(evalPerm(build, "read")).toBe("deny")
  458. }),
  459. {
  460. config: {
  461. agent: {
  462. build: {
  463. tools: {
  464. bash: false,
  465. read: false,
  466. },
  467. },
  468. },
  469. },
  470. },
  471. )
  472. it.instance(
  473. "legacy tools config maps write/edit/patch to edit permission",
  474. () =>
  475. Effect.gen(function* () {
  476. const build = yield* load((svc) => svc.get("build"))
  477. expect(evalPerm(build, "edit")).toBe("deny")
  478. }),
  479. {
  480. config: {
  481. agent: {
  482. build: {
  483. tools: {
  484. write: false,
  485. },
  486. },
  487. },
  488. },
  489. },
  490. )
  491. it.instance(
  492. "Truncate.GLOB is allowed even when user denies external_directory globally",
  493. () =>
  494. Effect.gen(function* () {
  495. const build = yield* load((svc) => svc.get("build"))
  496. expect(Permission.evaluate("external_directory", Truncate.GLOB, build!.permission).action).toBe("allow")
  497. expect(Permission.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
  498. expect(Permission.evaluate("external_directory", "/some/other/path", build!.permission).action).toBe("deny")
  499. }),
  500. {
  501. config: {
  502. permission: {
  503. external_directory: "deny",
  504. },
  505. },
  506. },
  507. )
  508. it.instance("global tmp directory children are allowed for external_directory", () =>
  509. Effect.gen(function* () {
  510. const build = yield* load((svc) => svc.get("build"))
  511. expect(
  512. Permission.evaluate("external_directory", path.join(Global.Path.tmp, "scratch"), build!.permission).action,
  513. ).toBe("allow")
  514. expect(Permission.evaluate("external_directory", "/some/other/path", build!.permission).action).toBe("ask")
  515. }),
  516. )
  517. it.instance(
  518. "Truncate.GLOB is allowed even when user denies external_directory per-agent",
  519. () =>
  520. Effect.gen(function* () {
  521. const build = yield* load((svc) => svc.get("build"))
  522. expect(Permission.evaluate("external_directory", Truncate.GLOB, build!.permission).action).toBe("allow")
  523. expect(Permission.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
  524. expect(Permission.evaluate("external_directory", "/some/other/path", build!.permission).action).toBe("deny")
  525. }),
  526. {
  527. config: {
  528. agent: {
  529. build: {
  530. permission: {
  531. external_directory: "deny",
  532. },
  533. },
  534. },
  535. },
  536. },
  537. )
  538. it.instance(
  539. "explicit Truncate.GLOB deny is respected",
  540. () =>
  541. Effect.gen(function* () {
  542. const build = yield* load((svc) => svc.get("build"))
  543. expect(Permission.evaluate("external_directory", Truncate.GLOB, build!.permission).action).toBe("deny")
  544. expect(Permission.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
  545. }),
  546. {
  547. config: {
  548. permission: {
  549. external_directory: {
  550. "*": "deny",
  551. [Truncate.GLOB]: "deny",
  552. },
  553. },
  554. },
  555. },
  556. )
  557. it.instance(
  558. "skill directories are allowed for external_directory",
  559. () =>
  560. Effect.gen(function* () {
  561. const test = yield* TestInstance
  562. const skillDir = path.join(test.directory, ".kirincode", "skill", "perm-skill")
  563. yield* Effect.promise(() =>
  564. Bun.write(
  565. path.join(skillDir, "SKILL.md"),
  566. `---
  567. name: perm-skill
  568. description: Permission skill.
  569. ---
  570. # Permission Skill
  571. `,
  572. ),
  573. )
  574. const home = process.env.KIRINCODE_TEST_HOME
  575. process.env.KIRINCODE_TEST_HOME = test.directory
  576. yield* Effect.addFinalizer(() =>
  577. Effect.sync(() => {
  578. process.env.KIRINCODE_TEST_HOME = home
  579. }),
  580. )
  581. const build = yield* load((svc) => svc.get("build"))
  582. const target = path.join(skillDir, "reference", "notes.md")
  583. expect(Permission.evaluate("external_directory", target, build!.permission).action).toBe("allow")
  584. }),
  585. { git: true },
  586. )
  587. it.instance(
  588. "project reference directories are allowed for external_directory",
  589. () =>
  590. Effect.gen(function* () {
  591. const test = yield* TestInstance
  592. const build = yield* load((svc) => svc.get("build"))
  593. const target = path.resolve(test.directory, "../docs/reference/notes.md")
  594. expect(Permission.evaluate("external_directory", target, build!.permission).action).toBe("allow")
  595. }),
  596. {
  597. git: true,
  598. config: {
  599. references: {
  600. docs: "../docs",
  601. },
  602. },
  603. },
  604. )
  605. it.instance("defaultAgent returns build when no default_agent config", () =>
  606. Effect.gen(function* () {
  607. const agent = yield* load((svc) => svc.defaultAgent())
  608. expect(agent).toBe("build")
  609. }),
  610. )
  611. it.instance("defaultInfo returns resolved build agent when no default_agent config", () =>
  612. Effect.gen(function* () {
  613. const agent = yield* load((svc) => svc.defaultInfo())
  614. expect(agent.name).toBe("build")
  615. expect(agent.mode).toBe("primary")
  616. }),
  617. )
  618. it.instance(
  619. "defaultAgent respects default_agent config set to plan",
  620. () =>
  621. Effect.gen(function* () {
  622. const agent = yield* load((svc) => svc.defaultAgent())
  623. expect(agent).toBe("plan")
  624. }),
  625. {
  626. config: {
  627. default_agent: "plan",
  628. },
  629. },
  630. )
  631. it.instance(
  632. "defaultAgent respects default_agent config set to custom agent with mode all",
  633. () =>
  634. Effect.gen(function* () {
  635. const agent = yield* load((svc) => svc.defaultAgent())
  636. expect(agent).toBe("my_custom")
  637. }),
  638. {
  639. config: {
  640. default_agent: "my_custom",
  641. agent: {
  642. my_custom: {
  643. description: "My custom agent",
  644. },
  645. },
  646. },
  647. },
  648. )
  649. it.instance(
  650. "defaultAgent throws when default_agent points to subagent",
  651. () => expectDefaultAgentError('default agent "explore" is a subagent'),
  652. {
  653. config: {
  654. default_agent: "explore",
  655. },
  656. },
  657. )
  658. it.instance(
  659. "defaultAgent throws when default_agent points to hidden agent",
  660. () => expectDefaultAgentError('default agent "compaction" is hidden'),
  661. {
  662. config: {
  663. default_agent: "compaction",
  664. },
  665. },
  666. )
  667. it.instance(
  668. "defaultAgent throws when default_agent points to non-existent agent",
  669. () => expectDefaultAgentError('default agent "does_not_exist" not found'),
  670. {
  671. config: {
  672. default_agent: "does_not_exist",
  673. },
  674. },
  675. )
  676. it.instance(
  677. "defaultAgent returns plan when build is disabled and default_agent not set",
  678. () =>
  679. Effect.gen(function* () {
  680. const agent = yield* load((svc) => svc.defaultAgent())
  681. // build is disabled, so it should return plan (next primary agent)
  682. expect(agent).toBe("plan")
  683. }),
  684. {
  685. config: {
  686. agent: {
  687. build: { disable: true },
  688. },
  689. },
  690. },
  691. )
  692. it.instance(
  693. "defaultAgent throws when all primary agents are disabled",
  694. () => expectDefaultAgentError("no primary visible agent found"),
  695. {
  696. config: {
  697. agent: {
  698. build: { disable: true },
  699. plan: { disable: true },
  700. },
  701. },
  702. },
  703. )