Files
oh-my-pi/packages/ai/test/issue-945-repro.test.ts
T
can1357 bc39ffa265 feat: introduced omptype validation package and migrated workspace dependencies
- Introduce `@oh-my-pi/omptype` as a new ArkType-compatible schema validation package featuring a lazy JIT runtime, JSON Schema emission, and compatibility adapters.
- Replace `arktype` across workspace packages and test utilities with `@oh-my-pi/omptype`.
- Add benchmark suites, tests, and documentation for the new validation engine and adapters.
- Update workspace build, test runner, and release configurations to include the new package.
2026-08-03 21:56:48 +02:00

65 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { type } from "@oh-my-pi/omptype";
import { streamOpenAICompletions } from "@oh-my-pi/pi-ai/providers/openai-completions";
import type { Context, Model, Tool } from "@oh-my-pi/pi-ai/types";
import { getBundledModel } from "@oh-my-pi/pi-catalog/models";
const echoTool: Tool = {
name: "echo",
description: "Echo input",
parameters: type({ text: "string" }),
};
const context: Context = {
messages: [{ role: "user", content: "call echo", timestamp: Date.now() }],
tools: [echoTool],
};
function abortedSignal(): AbortSignal {
const controller = new AbortController();
controller.abort();
return controller.signal;
}
async function capturePayload(
model: Model<"openai-completions">,
opts: Parameters<typeof streamOpenAICompletions>[2],
): Promise<Record<string, unknown>> {
const { promise, resolve } = Promise.withResolvers<unknown>();
streamOpenAICompletions(model, context, {
...opts,
apiKey: "test-key",
signal: abortedSignal(),
onPayload: payload => resolve(payload),
});
return (await promise) as Record<string, unknown>;
}
describe("OpenCode Go tool_choice compatibility", () => {
it("marks deepseek-v4-pro as not supporting tool_choice via compat override", () => {
const model = getBundledModel("opencode-go", "deepseek-v4-pro") as Model<"openai-completions">;
expect(model.compat?.supportsToolChoice).toBe(false);
});
it("marks mimo-v2.5-pro as not supporting tool_choice via compat override", () => {
const model = getBundledModel("opencode-go", "mimo-v2.5-pro") as Model<"openai-completions">;
expect(model.compat?.supportsToolChoice).toBe(false);
});
it("omits tool_choice from MiMo title-style payloads while preserving tools", async () => {
const model = getBundledModel("opencode-go", "mimo-v2.5-pro") as Model<"openai-completions">;
const body = await capturePayload(model, { reasoning: "high", toolChoice: { type: "tool", name: "echo" } });
expect(body.tools).toBeDefined();
expect(body.tool_choice).toBeUndefined();
expect(body.reasoning_effort).toBe("high");
});
it("omits tool_choice from DeepSeek payloads but preserves tools and reasoning_effort", async () => {
const model = getBundledModel("opencode-go", "deepseek-v4-pro") as Model<"openai-completions">;
const body = await capturePayload(model, { reasoning: "high", toolChoice: "auto" });
expect(body.tools).toBeDefined();
expect(body.tool_choice).toBeUndefined();
expect(body.reasoning_effort).toBe("high");
});
});