fix(opencode): improve MFJS schema sanitizing
This commit is contained in:
@@ -100,6 +100,30 @@ describe("MFJS.sanitize", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("widens enums when structured values remain possible", () => {
|
||||
expect(
|
||||
MFJS.sanitize({
|
||||
type: "object",
|
||||
properties: {
|
||||
untyped: { enum: ["text", { kind: "legacy" }] },
|
||||
excluded: { type: "string", enum: ["text", { kind: "legacy" }] },
|
||||
union: {
|
||||
type: ["string", "object"],
|
||||
enum: ["text", { kind: "legacy" }],
|
||||
anyOf: [{ type: "string" }, { type: "object" }],
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
type: "object",
|
||||
properties: {
|
||||
untyped: {},
|
||||
excluded: { type: "string", enum: ["text"] },
|
||||
union: { anyOf: [{ type: "string" }, { type: "object" }] },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("drops tuple items instead of narrowing positional schemas", () => {
|
||||
expect(
|
||||
MFJS.sanitize({
|
||||
@@ -216,6 +240,26 @@ describe("MFJS.sanitize", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("drops recursive schemas with no finite instance", () => {
|
||||
expect(
|
||||
MFJS.sanitize({
|
||||
type: "object",
|
||||
properties: { node: { $ref: "#/$defs/Node" } },
|
||||
required: ["node"],
|
||||
$defs: {
|
||||
Node: {
|
||||
type: "object",
|
||||
properties: {
|
||||
value: { type: "string" },
|
||||
next: { $ref: "#/$defs/Node" },
|
||||
},
|
||||
required: ["value", "next"],
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toEqual({ type: "object", properties: {} })
|
||||
})
|
||||
|
||||
test("adds unconstrained schemas for dangling required properties", () => {
|
||||
expect(
|
||||
MFJS.sanitize({
|
||||
|
||||
@@ -1532,6 +1532,7 @@ describe("ProviderTransform.schema - MFJS selection", () => {
|
||||
const models = [
|
||||
["Moonshot providers", { providerID: "moonshotai", api: { id: "kimi-k2" } }],
|
||||
["Kimi API IDs", { providerID: "openrouter", api: { id: "moonshotai/kimi-k2" } }],
|
||||
["Kimi model families", { providerID: "custom", family: "kimi-k2", api: { id: "alias" } }],
|
||||
] as const
|
||||
|
||||
for (const [name, model] of models) {
|
||||
|
||||
Reference in New Issue
Block a user