diff options
| author | Kit Langton <[email protected]> | 2026-04-01 19:47:26 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-01 23:47:26 +0000 |
| commit | d9d4f895bcf5f95bd853fe2921de3e6a2798798f (patch) | |
| tree | a04d6bfc6f4c4bfdc7e94f4f55bb1acebeb07f7a /packages/app/test | |
| parent | 48db7cf07a651895341e019604d4ad485b97866d (diff) | |
| download | opencode-d9d4f895bcf5f95bd853fe2921de3e6a2798798f.tar.gz opencode-d9d4f895bcf5f95bd853fe2921de3e6a2798798f.zip | |
fix(test): auto-acknowledge tool-result follow-ups in mock LLM server (#20528)
Diffstat (limited to 'packages/app/test')
| -rw-r--r-- | packages/app/test/e2e/mock.test.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/app/test/e2e/mock.test.ts b/packages/app/test/e2e/mock.test.ts new file mode 100644 index 000000000..3bd80f34d --- /dev/null +++ b/packages/app/test/e2e/mock.test.ts @@ -0,0 +1,66 @@ +import { describe, expect, test } from "bun:test" +import { bodyText, inputMatch, promptMatch } from "../../e2e/prompt/mock" + +function hit(body: Record<string, unknown>) { + return { body } +} + +describe("promptMatch", () => { + test("matches token in serialized body", () => { + const match = promptMatch("hello") + expect(match(hit({ messages: [{ role: "user", content: "say hello" }] }))).toBe(true) + expect(match(hit({ messages: [{ role: "user", content: "say goodbye" }] }))).toBe(false) + }) +}) + +describe("inputMatch", () => { + test("matches exact tool input in chat completions body", () => { + const input = { questions: [{ header: "Need input", question: "Pick one" }] } + const match = inputMatch(input) + + // The seed prompt embeds JSON.stringify(input) in the user message + const prompt = `Use this JSON input: ${JSON.stringify(input)}` + const body = { messages: [{ role: "user", content: prompt }] } + expect(match(hit(body))).toBe(true) + }) + + test("matches exact tool input in responses API body", () => { + const input = { questions: [{ header: "Need input", question: "Pick one" }] } + const match = inputMatch(input) + + const prompt = `Use this JSON input: ${JSON.stringify(input)}` + const body = { model: "test", input: [{ role: "user", content: [{ type: "input_text", text: prompt }] }] } + expect(match(hit(body))).toBe(true) + }) + + test("matches patchText with newlines", () => { + const patchText = "*** Begin Patch\n*** Add File: test.txt\n+line1\n*** End Patch" + const match = inputMatch({ patchText }) + + const prompt = `Use this JSON input: ${JSON.stringify({ patchText })}` + const body = { messages: [{ role: "user", content: prompt }] } + expect(match(hit(body))).toBe(true) + + // Also works in responses API format + const respBody = { model: "test", input: [{ role: "user", content: [{ type: "input_text", text: prompt }] }] } + expect(match(hit(respBody))).toBe(true) + }) + + test("does not match unrelated requests", () => { + const input = { questions: [{ header: "Need input" }] } + const match = inputMatch(input) + + expect(match(hit({ messages: [{ role: "user", content: "hello" }] }))).toBe(false) + expect(match(hit({ model: "test", input: [] }))).toBe(false) + }) + + test("does not match partial input", () => { + const input = { questions: [{ header: "Need input", question: "Pick one" }] } + const match = inputMatch(input) + + // Only header, missing question + const partial = `Use this JSON input: ${JSON.stringify({ questions: [{ header: "Need input" }] })}` + const body = { messages: [{ role: "user", content: partial }] } + expect(match(hit(body))).toBe(false) + }) +}) |
