|
| 1 | +import { expect, test } from "bun:test" |
| 2 | +import { tool } from "@opencode-ai/plugin/tool" |
| 3 | +import githubPrSearch from "../tool/github-pr-search.ts" |
| 4 | +import githubTriage from "../tool/github-triage.ts" |
| 5 | + |
| 6 | +test("GitHub tools load with the installed OpenCode tool SDK", () => { |
| 7 | + expect(githubPrSearch.description).toContain("search GitHub pull requests") |
| 8 | + expect(githubPrSearch.args.query).toBeInstanceOf(tool.schema.ZodString) |
| 9 | + expect(githubPrSearch.execute).toBeFunction() |
| 10 | + |
| 11 | + expect(githubTriage.description).toContain("assign a GitHub issue") |
| 12 | + expect(githubTriage.args.team).toBeInstanceOf(tool.schema.ZodEnum) |
| 13 | + expect(githubTriage.execute).toBeFunction() |
| 14 | +}) |
| 15 | + |
| 16 | +test("GitHub triage arguments validate and convert to JSON Schema", () => { |
| 17 | + const schema = tool.schema.object(githubTriage.args) |
| 18 | + expect(schema.parse({ team: "core" })).toEqual({ team: "core" }) |
| 19 | + expect(schema.safeParse({ team: "not-a-team" }).success).toBe(false) |
| 20 | + |
| 21 | + expect(tool.schema.toJSONSchema(schema, { io: "input" })).toMatchObject({ |
| 22 | + type: "object", |
| 23 | + properties: { |
| 24 | + team: { enum: ["tui", "desktop_web", "core", "inference", "windows"] }, |
| 25 | + }, |
| 26 | + required: ["team"], |
| 27 | + }) |
| 28 | +}) |
| 29 | + |
| 30 | +test("GitHub PR search arguments validate defaults and convert to JSON Schema", () => { |
| 31 | + const schema = tool.schema.object(githubPrSearch.args) |
| 32 | + expect(schema.parse({ query: "quota" })).toEqual({ query: "quota", limit: 10, offset: 0 }) |
| 33 | + expect(schema.parse({ query: "quota", limit: 5, offset: 10 })).toEqual({ |
| 34 | + query: "quota", |
| 35 | + limit: 5, |
| 36 | + offset: 10, |
| 37 | + }) |
| 38 | + expect(schema.safeParse({ query: 7 }).success).toBe(false) |
| 39 | + expect(schema.safeParse({ query: "quota", limit: "10" }).success).toBe(false) |
| 40 | + |
| 41 | + expect(tool.schema.toJSONSchema(schema, { io: "input" })).toMatchObject({ |
| 42 | + type: "object", |
| 43 | + properties: { |
| 44 | + query: { type: "string" }, |
| 45 | + limit: { type: "number", default: 10 }, |
| 46 | + offset: { type: "number", default: 0 }, |
| 47 | + }, |
| 48 | + required: ["query"], |
| 49 | + }) |
| 50 | +}) |
0 commit comments