Remove effect-zod bridge (#26956)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { Result, Schema } from "effect"
|
||||
import { toJsonSchema } from "@opencode-ai/core/effect-zod"
|
||||
import { ToolJsonSchema } from "../../src/tool/json-schema"
|
||||
|
||||
// Each tool exports its parameters schema at module scope so this test can
|
||||
// import them without running the tool's Effect-based init. The JSON Schema
|
||||
// snapshot captures what the LLM sees; the parse assertions pin down the
|
||||
// accepts/rejects contract. `toJsonSchema` is the same helper `session/
|
||||
// accepts/rejects contract. `ToolJsonSchema.fromSchema` is the same helper `session/
|
||||
// prompt.ts` uses to emit tool schemas to the LLM, so the snapshots stay
|
||||
// byte-identical regardless of whether a tool has migrated from zod to Schema.
|
||||
// provider-compatible while tools use Effect Schema internally.
|
||||
|
||||
import { Parameters as ApplyPatch } from "../../src/tool/apply_patch"
|
||||
import { Parameters as Edit } from "../../src/tool/edit"
|
||||
@@ -32,6 +32,8 @@ const parse = <S extends Schema.Decoder<unknown>>(schema: S, input: unknown): S[
|
||||
const accepts = (schema: Schema.Decoder<unknown>, input: unknown): boolean =>
|
||||
Result.isSuccess(Schema.decodeUnknownResult(schema)(input))
|
||||
|
||||
const toJsonSchema = ToolJsonSchema.fromSchema
|
||||
|
||||
describe("tool parameters", () => {
|
||||
describe("JSON Schema (wire shape)", () => {
|
||||
test("apply_patch", () => expect(toJsonSchema(ApplyPatch)).toMatchSnapshot())
|
||||
@@ -50,6 +52,36 @@ describe("tool parameters", () => {
|
||||
test("webfetch", () => expect(toJsonSchema(WebFetch)).toMatchSnapshot())
|
||||
test("websearch", () => expect(toJsonSchema(WebSearch)).toMatchSnapshot())
|
||||
test("write", () => expect(toJsonSchema(Write)).toMatchSnapshot())
|
||||
|
||||
test("inlines named child schemas for provider compatibility", () => {
|
||||
const schema = toJsonSchema(Question)
|
||||
expect(schema).not.toHaveProperty("$defs")
|
||||
expect(schema).toMatchObject({
|
||||
properties: {
|
||||
questions: { items: { properties: { options: { items: { properties: { label: { type: "string" } } } } } } },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("preserves required nullable fields", () => {
|
||||
expect(toJsonSchema(Schema.Struct({ value: Schema.NullOr(Schema.String) }))).toMatchObject({
|
||||
properties: { value: { anyOf: expect.arrayContaining([{ type: "null" }]) } },
|
||||
})
|
||||
})
|
||||
|
||||
test("keeps repeated allOf constraints instead of dropping duplicates", () => {
|
||||
expect(
|
||||
toJsonSchema(
|
||||
Schema.Struct({ value: Schema.String.check(Schema.isPattern(/^a/)).check(Schema.isPattern(/z$/)) }),
|
||||
),
|
||||
).toMatchObject({ properties: { value: { allOf: [{ pattern: "^a" }, { pattern: "z$" }] } } })
|
||||
})
|
||||
|
||||
test("bounds bare integer fields to safe integer range", () => {
|
||||
expect(toJsonSchema(Schema.Struct({ value: Schema.Int }))).toMatchObject({
|
||||
properties: { value: { minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER } },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("apply_patch", () => {
|
||||
|
||||
Reference in New Issue
Block a user