The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { expect, it } from "@effect/vitest"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | import { Tool } from "effect/ai"; |
| 4 | |
| 5 | import { PreviewToolkit } from "./tools.ts"; |
| 6 | |
| 7 | const schemaHasMultipleAllOfDescriptions = (schema: unknown): boolean => { |
| 8 | if (!schema || typeof schema !== "object") return false; |
| 9 | const record = schema as Record<string, unknown>; |
| 10 | const allOf = Array.isArray(record.allOf) ? record.allOf : []; |
| 11 | const descriptionCount = allOf.filter( |
| 12 | (member) => |
| 13 | member !== null && |
| 14 | typeof member === "object" && |
| 15 | typeof (member as Record<string, unknown>).description === "string", |
| 16 | ).length; |
| 17 | return descriptionCount > 1 || Object.values(record).some(schemaHasMultipleAllOfDescriptions); |
| 18 | }; |
| 19 | |
| 20 | it("exports provider-compatible object schemas", () => { |
| 21 | for (const tool of Object.values(PreviewToolkit.tools)) { |
| 22 | const schema = Tool.getJsonSchema(tool) as { |
| 23 | readonly type?: unknown; |
| 24 | readonly properties?: Readonly<Record<string, unknown>>; |
| 25 | readonly anyOf?: unknown; |
| 26 | readonly oneOf?: unknown; |
| 27 | }; |
| 28 | expect(schema.type, `${tool.name} must export a top-level object schema`).toBe("object"); |
| 29 | expect(schema.anyOf, `${tool.name} must not export a root anyOf`).toBeUndefined(); |
| 30 | expect(schema.oneOf, `${tool.name} must not export a root oneOf`).toBeUndefined(); |
| 31 | if (tool.name === "preview_navigate") { |
| 32 | expect(schemaHasMultipleAllOfDescriptions(schema)).toBe(false); |
| 33 | } |
| 34 | expect( |
| 35 | schema.properties?.tabId, |
| 36 | `${tool.name} must allow an explicit collaborative browser tab target`, |
| 37 | ).toBeDefined(); |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | it("preview_open accepts a target while preserving open input constraints", () => { |
| 42 | const decode = Schema.decodeUnknownSync(PreviewToolkit.tools.preview_open.parametersSchema); |
| 43 | const target = { kind: "environment-port", port: 3000 }; |
| 44 | expect(decode({ target })).toEqual({ target }); |
| 45 | expect(decode({})).toEqual({}); |
| 46 | expect(decode({ url: "https://example.com" })).toEqual({ url: "https://example.com" }); |
| 47 | expect(decode({ url: "http://localhost:3000", target })).toEqual({ |
| 48 | url: "http://localhost:3000", |
| 49 | target, |
| 50 | }); |
| 51 | expect(() => decode({ target: { ...target, port: 0 } })).toThrow(); |
| 52 | expect(() => decode({ target, tabId: "tab-1", reuseExistingTab: false })).toThrow(); |
| 53 | }); |