fix(plugin): normalize bare schema refs

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-01 18:55:57 +09:00
parent 9ba676330a
commit 9c4bcebb22
2 changed files with 47 additions and 1 deletions
+34 -1
View File
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os"
import { dirname, join } from "node:path"
import { pathToFileURL } from "node:url"
import { tool } from "@opencode-ai/plugin"
import { normalizeToolArgSchemas } from "./normalize-tool-arg-schemas"
import { normalizeToolArgSchemas, sanitizeJsonSchema } from "./normalize-tool-arg-schemas"
const tempDirectories: string[] = []
@@ -95,3 +95,36 @@ describe("normalizeToolArgSchemas", () => {
expect(afterQuery?.examples).toEqual(["issue 2314"])
})
})
describe("sanitizeJsonSchema", () => {
it("rewrites bare $ref values to $defs JSON pointers", () => {
// given
const schema = {
type: "object",
properties: {
new_encoding: { $ref: "Encoding" },
existing_pointer: { $ref: "#/$defs/AlreadyValid" },
},
$defs: {
Encoding: { type: "string" },
AlreadyValid: { type: "string" },
},
}
// when
const sanitized = sanitizeJsonSchema(schema)
// then
expect(sanitized).toEqual({
type: "object",
properties: {
new_encoding: { $ref: "#/$defs/Encoding" },
existing_pointer: { $ref: "#/$defs/AlreadyValid" },
},
$defs: {
Encoding: { type: "string" },
AlreadyValid: { type: "string" },
},
})
})
})