+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
163 lines
5.8 KiB
TypeScript
163 lines
5.8 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { Effect, Exit, Fiber, Layer } from "effect"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { PermissionV2 } from "@opencode-ai/core/permission"
|
|
import { QuestionV2 } from "@opencode-ai/core/question"
|
|
import { SessionV2 } from "@opencode-ai/core/session"
|
|
import { ToolRegistry } from "@opencode-ai/core/tool/registry"
|
|
import { QuestionTool } from "@opencode-ai/core/tool/question"
|
|
import { ToolOutputStore } from "@opencode-ai/core/tool-output-store"
|
|
import { testEffect } from "./lib/effect"
|
|
import { toolIdentity, executeTool, settleTool, toolDefinitions } from "./lib/tool"
|
|
|
|
const sessionID = SessionV2.ID.make("ses_question_tool_test")
|
|
const assertions: PermissionV2.AssertInput[] = []
|
|
let captured: QuestionV2.AskInput | undefined
|
|
let reject = false
|
|
let deny = false
|
|
const capturedInput = () => captured
|
|
const permission = Layer.succeed(
|
|
PermissionV2.Service,
|
|
PermissionV2.Service.of({
|
|
assert: (input) =>
|
|
Effect.sync(() => assertions.push(input)).pipe(
|
|
Effect.andThen(deny ? Effect.fail(new PermissionV2.DeniedError({ rules: [] })) : Effect.void),
|
|
),
|
|
ask: () => Effect.die("unused"),
|
|
reply: () => Effect.die("unused"),
|
|
get: () => Effect.die("unused"),
|
|
forSession: () => Effect.die("unused"),
|
|
list: () => Effect.die("unused"),
|
|
}),
|
|
)
|
|
const question = Layer.succeed(
|
|
QuestionV2.Service,
|
|
QuestionV2.Service.of({
|
|
ask: (input: QuestionV2.AskInput) =>
|
|
Effect.sync(() => {
|
|
captured = input
|
|
}).pipe(Effect.andThen(reject ? Effect.fail(new QuestionV2.RejectedError()) : Effect.succeed([["Build"], []]))),
|
|
reply: () => Effect.die("unused"),
|
|
reject: () => Effect.die("unused"),
|
|
list: () => Effect.die("unused"),
|
|
}),
|
|
)
|
|
const it = testEffect(
|
|
AppNodeBuilder.build(LayerNode.group([ToolRegistry.node, ToolRegistry.toolsNode, QuestionTool.node]), [
|
|
[PermissionV2.node, permission],
|
|
[QuestionV2.node, question],
|
|
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
|
]),
|
|
)
|
|
|
|
describe("QuestionTool", () => {
|
|
it.effect("omits a denied built-in question and terminally settles a stale call", () =>
|
|
Effect.gen(function* () {
|
|
captured = undefined
|
|
deny = true
|
|
const registry = yield* ToolRegistry.Service
|
|
|
|
expect(yield* toolDefinitions(registry, [{ action: "question", resource: "*", effect: "deny" }])).toEqual([])
|
|
expect(
|
|
yield* settleTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-question-denied", name: "question", input: { questions: [] } },
|
|
}),
|
|
).toEqual({ result: { type: "error", value: "Permission denied: question" } })
|
|
expect(capturedInput()).toBeUndefined()
|
|
deny = false
|
|
}),
|
|
)
|
|
|
|
it.effect("registers question and projects user answers without a permission assertion", () =>
|
|
Effect.gen(function* () {
|
|
assertions.length = 0
|
|
captured = undefined
|
|
reject = false
|
|
deny = false
|
|
const registry = yield* ToolRegistry.Service
|
|
const questions = [
|
|
{
|
|
question: "What should happen?",
|
|
header: "Action",
|
|
options: [{ label: "Build", description: "Build it" }],
|
|
},
|
|
{
|
|
question: "Which environment?",
|
|
header: "Environment",
|
|
options: [{ label: "Dev", description: "Development" }],
|
|
},
|
|
]
|
|
|
|
expect((yield* toolDefinitions(registry)).map((definition) => definition.name)).toEqual(["question"])
|
|
expect(
|
|
yield* settleTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-question", name: "question", input: { questions } },
|
|
}),
|
|
).toEqual({
|
|
result: {
|
|
type: "text",
|
|
value:
|
|
'User has answered your questions: "What should happen?"="Build", "Which environment?"="Unanswered". You can now continue with the user\'s answers in mind.',
|
|
},
|
|
output: {
|
|
structured: { answers: [["Build"], []] },
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: 'User has answered your questions: "What should happen?"="Build", "Which environment?"="Unanswered". You can now continue with the user\'s answers in mind.',
|
|
},
|
|
],
|
|
},
|
|
})
|
|
expect(assertions).toMatchObject([{ sessionID, action: "question", resources: ["*"] }])
|
|
expect(capturedInput()).toEqual({
|
|
sessionID,
|
|
questions,
|
|
tool: { messageID: toolIdentity.assistantMessageID, callID: "call-question" },
|
|
})
|
|
}),
|
|
)
|
|
|
|
it.effect("does not invent tool ownership metadata without a durable registry source", () =>
|
|
Effect.gen(function* () {
|
|
captured = undefined
|
|
reject = false
|
|
deny = false
|
|
const registryService = yield* ToolRegistry.Service
|
|
|
|
yield* executeTool(registryService, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-question", name: "question", input: { questions: [] } },
|
|
})
|
|
expect(capturedInput()).toEqual({
|
|
sessionID,
|
|
questions: [],
|
|
tool: { messageID: toolIdentity.assistantMessageID, callID: "call-question" },
|
|
})
|
|
}),
|
|
)
|
|
|
|
it.effect("keeps dismissed questions out of model-facing output", () =>
|
|
Effect.gen(function* () {
|
|
captured = undefined
|
|
reject = true
|
|
deny = false
|
|
const registryService = yield* ToolRegistry.Service
|
|
const fiber = yield* executeTool(registryService, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-question", name: "question", input: { questions: [] } },
|
|
}).pipe(Effect.forkScoped)
|
|
|
|
const exit = yield* Fiber.await(fiber)
|
|
expect(Exit.isFailure(exit)).toBe(true)
|
|
}),
|
|
)
|
|
})
|