mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-26 15:55:45 +00:00
Simplify tool initialization by removing unnecessary agent context parameter from tool.init() calls. This makes tool behavior more predictable and consistent regardless of which agent is using them. Replace hardcoded named tool references (registry.named.task, registry.named.read) with a cleaner fromID() lookup method that works for any tool. Update TaskTool to display all available subagents without permission-based filtering, making it easier to discover and use subagents from any context.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { afterEach, describe, expect, test } from "bun:test"
|
|
import { Agent } from "../../src/agent/agent"
|
|
import { Instance } from "../../src/project/instance"
|
|
import { TaskTool } from "../../src/tool/task"
|
|
import { tmpdir } from "../fixture/fixture"
|
|
|
|
afterEach(async () => {
|
|
await Instance.disposeAll()
|
|
})
|
|
|
|
describe("tool.task", () => {
|
|
test("description sorts subagents by name and is stable across calls", async () => {
|
|
await using tmp = await tmpdir({
|
|
config: {
|
|
agent: {
|
|
zebra: {
|
|
description: "Zebra agent",
|
|
mode: "subagent",
|
|
},
|
|
alpha: {
|
|
description: "Alpha agent",
|
|
mode: "subagent",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
await Instance.provide({
|
|
directory: tmp.path,
|
|
fn: async () => {
|
|
const first = await TaskTool.init()
|
|
const second = await TaskTool.init()
|
|
|
|
expect(first.description).toBe(second.description)
|
|
|
|
const alpha = first.description.indexOf("- alpha: Alpha agent")
|
|
const explore = first.description.indexOf("- explore:")
|
|
const general = first.description.indexOf("- general:")
|
|
const zebra = first.description.indexOf("- zebra: Zebra agent")
|
|
|
|
expect(alpha).toBeGreaterThan(-1)
|
|
expect(explore).toBeGreaterThan(alpha)
|
|
expect(general).toBeGreaterThan(explore)
|
|
expect(zebra).toBeGreaterThan(general)
|
|
},
|
|
})
|
|
})
|
|
})
|