|
| 1 | +import type OpenAI from "openai" |
| 2 | +import { apply_diff } from "../apply_diff" |
| 3 | + |
| 4 | +// Helper type to access function tools |
| 5 | +type FunctionTool = OpenAI.Chat.ChatCompletionTool & { type: "function" } |
| 6 | + |
| 7 | +// Helper to get function definition from tool |
| 8 | +const getFunctionDef = (tool: OpenAI.Chat.ChatCompletionTool) => (tool as FunctionTool).function |
| 9 | + |
| 10 | +// OpenAI types the parameter schema as FunctionParameters (Record<string, unknown>). |
| 11 | +// Narrow it with runtime checks instead of assertions so the spec tracks schema changes. |
| 12 | +function asRecord(value: unknown): Record<string, unknown> { |
| 13 | + if (typeof value !== "object" || value === null) { |
| 14 | + throw new Error("expected an object value in the apply_diff parameter schema") |
| 15 | + } |
| 16 | + return value as Record<string, unknown> |
| 17 | +} |
| 18 | + |
| 19 | +const getDiffParameterDescription = (): string => { |
| 20 | + const parameters = asRecord(getFunctionDef(apply_diff).parameters) |
| 21 | + const properties = asRecord(parameters["properties"]) |
| 22 | + const diff = asRecord(properties["diff"]) |
| 23 | + const description = diff["description"] |
| 24 | + if (typeof description !== "string") { |
| 25 | + throw new Error("diff parameter must declare a string description") |
| 26 | + } |
| 27 | + return description |
| 28 | +} |
| 29 | + |
| 30 | +describe("apply_diff diff parameter description", () => { |
| 31 | + const diffDescription = getDiffParameterDescription() |
| 32 | + |
| 33 | + it("should require complete, whole lines in the SEARCH block", () => { |
| 34 | + expect(diffDescription).toContain("The SEARCH block must contain complete, whole lines") |
| 35 | + }) |
| 36 | + |
| 37 | + it("should warn that partial-line (substring) matching is not supported", () => { |
| 38 | + expect(diffDescription).toContain("partial-line (substring) matching is not supported") |
| 39 | + }) |
| 40 | +}) |
0 commit comments