mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 22:03:58 +00:00
- Rename packages/opencode → packages/tfcode (directory only) - Rename bin/opencode → bin/tfcode (CLI binary) - Rename .opencode → .tfcode (config directory) - Update package.json name and bin field - Update config directory path references (.tfcode) - Keep internal code references as 'opencode' for easy upstream sync - Keep @opencode-ai/* workspace package names This minimal branding approach allows clean merges from upstream opencode repository while providing tfcode branding for users.
109 lines
3.4 KiB
TypeScript
109 lines
3.4 KiB
TypeScript
import { describe, expect, test, spyOn, beforeEach, afterEach } from "bun:test"
|
|
import { z } from "zod"
|
|
import { QuestionTool } from "../../src/tool/question"
|
|
import * as QuestionModule from "../../src/question"
|
|
import { SessionID, MessageID } from "../../src/session/schema"
|
|
|
|
const ctx = {
|
|
sessionID: SessionID.make("ses_test-session"),
|
|
messageID: MessageID.make("test-message"),
|
|
callID: "test-call",
|
|
agent: "test-agent",
|
|
abort: AbortSignal.any([]),
|
|
messages: [],
|
|
metadata: () => {},
|
|
ask: async () => {},
|
|
}
|
|
|
|
describe("tool.question", () => {
|
|
let askSpy: any
|
|
|
|
beforeEach(() => {
|
|
askSpy = spyOn(QuestionModule.Question, "ask").mockImplementation(async () => {
|
|
return []
|
|
})
|
|
})
|
|
|
|
afterEach(() => {
|
|
askSpy.mockRestore()
|
|
})
|
|
|
|
test("should successfully execute with valid question parameters", async () => {
|
|
const tool = await QuestionTool.init()
|
|
const questions = [
|
|
{
|
|
question: "What is your favorite color?",
|
|
header: "Color",
|
|
options: [
|
|
{ label: "Red", description: "The color of passion" },
|
|
{ label: "Blue", description: "The color of sky" },
|
|
],
|
|
multiple: false,
|
|
},
|
|
]
|
|
|
|
askSpy.mockResolvedValueOnce([["Red"]])
|
|
|
|
const result = await tool.execute({ questions }, ctx)
|
|
expect(askSpy).toHaveBeenCalledTimes(1)
|
|
expect(result.title).toBe("Asked 1 question")
|
|
})
|
|
|
|
test("should now pass with a header longer than 12 but less than 30 chars", async () => {
|
|
const tool = await QuestionTool.init()
|
|
const questions = [
|
|
{
|
|
question: "What is your favorite animal?",
|
|
header: "This Header is Over 12",
|
|
options: [{ label: "Dog", description: "Man's best friend" }],
|
|
},
|
|
]
|
|
|
|
askSpy.mockResolvedValueOnce([["Dog"]])
|
|
|
|
const result = await tool.execute({ questions }, ctx)
|
|
expect(result.output).toContain(`"What is your favorite animal?"="Dog"`)
|
|
})
|
|
|
|
// intentionally removed the zod validation due to tool call errors, hoping prompting is gonna be good enough
|
|
// test("should throw an Error for header exceeding 30 characters", async () => {
|
|
// const tool = await QuestionTool.init()
|
|
// const questions = [
|
|
// {
|
|
// question: "What is your favorite animal?",
|
|
// header: "This Header is Definitely More Than Thirty Characters Long",
|
|
// options: [{ label: "Dog", description: "Man's best friend" }],
|
|
// },
|
|
// ]
|
|
// try {
|
|
// await tool.execute({ questions }, ctx)
|
|
// // If it reaches here, the test should fail
|
|
// expect(true).toBe(false)
|
|
// } catch (e: any) {
|
|
// expect(e).toBeInstanceOf(Error)
|
|
// expect(e.cause).toBeInstanceOf(z.ZodError)
|
|
// }
|
|
// })
|
|
|
|
// test("should throw an Error for label exceeding 30 characters", async () => {
|
|
// const tool = await QuestionTool.init()
|
|
// const questions = [
|
|
// {
|
|
// question: "A question with a very long label",
|
|
// header: "Long Label",
|
|
// options: [
|
|
// { label: "This is a very, very, very long label that will exceed the limit", description: "A description" },
|
|
// ],
|
|
// },
|
|
// ]
|
|
// try {
|
|
// await tool.execute({ questions }, ctx)
|
|
// // If it reaches here, the test should fail
|
|
// expect(true).toBe(false)
|
|
// } catch (e: any) {
|
|
// expect(e).toBeInstanceOf(Error)
|
|
// expect(e.cause).toBeInstanceOf(z.ZodError)
|
|
// }
|
|
// })
|
|
})
|