| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- import { Type } from "typebox";
- import { describe, expect, it } from "vitest";
- import { getModel } from "../src/models.ts";
- import { complete } from "../src/stream.ts";
- import type { Api, Context, Model, StreamOptions, ToolResultMessage } from "../src/types.ts";
- type StreamOptionsWithExtras = StreamOptions & Record<string, unknown>;
- import { hasAzureOpenAICredentials, resolveAzureDeploymentName } from "./azure-utils.ts";
- import { hasBedrockCredentials } from "./bedrock-utils.ts";
- import { hasCloudflareAiGatewayCredentials, hasCloudflareWorkersAICredentials } from "./cloudflare-utils.ts";
- import { resolveApiKey } from "./oauth.ts";
- // Empty schema for test tools - must be proper OBJECT type for Cloud Code Assist
- const emptySchema = Type.Object({});
- // Resolve OAuth tokens at module level (async, runs before tests)
- const oauthTokens = await Promise.all([
- resolveApiKey("anthropic"),
- resolveApiKey("github-copilot"),
- resolveApiKey("openai-codex"),
- ]);
- const [anthropicOAuthToken, githubCopilotToken, openaiCodexToken] = oauthTokens;
- /**
- * Test for Unicode surrogate pair handling in tool results.
- *
- * Issue: When tool results contain emoji or other characters outside the Basic Multilingual Plane,
- * they may be incorrectly serialized as unpaired surrogates, causing "no low surrogate in string"
- * errors when sent to the API provider.
- *
- * Example error from Anthropic:
- * "The request body is not valid JSON: no low surrogate in string: line 1 column 197667"
- */
- async function testEmojiInToolResults<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
- const toolCallId = llm.provider === "mistral" ? "testtool1" : "test_1";
- // Simulate a tool that returns emoji
- const context: Context = {
- systemPrompt: "You are a helpful assistant.",
- messages: [
- {
- role: "user",
- content: "Use the test tool",
- timestamp: Date.now(),
- },
- {
- role: "assistant",
- content: [
- {
- type: "toolCall",
- id: toolCallId,
- name: "test_tool",
- arguments: {},
- },
- ],
- api: llm.api,
- provider: llm.provider,
- model: llm.id,
- usage: {
- input: 0,
- output: 0,
- cacheRead: 0,
- cacheWrite: 0,
- totalTokens: 0,
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
- },
- stopReason: "toolUse",
- timestamp: Date.now(),
- },
- ],
- tools: [
- {
- name: "test_tool",
- description: "A test tool",
- parameters: emptySchema,
- },
- ],
- };
- // Add tool result with various problematic Unicode characters
- const toolResult: ToolResultMessage = {
- role: "toolResult",
- toolCallId: toolCallId,
- toolName: "test_tool",
- content: [
- {
- type: "text",
- text: `Test with emoji 🙈 and other characters:
- - Monkey emoji: 🙈
- - Thumbs up: 👍
- - Heart: ❤️
- - Thinking face: 🤔
- - Rocket: 🚀
- - Mixed text: Mario Zechner wann? Wo? Bin grad äußersr eventuninformiert 🙈
- - Japanese: こんにちは
- - Chinese: 你好
- - Mathematical symbols: ∑∫∂√
- - Special quotes: "curly" 'quotes'`,
- },
- ],
- isError: false,
- timestamp: Date.now(),
- };
- context.messages.push(toolResult);
- // Add follow-up user message
- context.messages.push({
- role: "user",
- content: "Summarize the tool result briefly.",
- timestamp: Date.now(),
- });
- // This should not throw a surrogate pair error
- const response = await complete(llm, context, options);
- expect(response.stopReason).not.toBe("error");
- expect(response.errorMessage).toBeFalsy();
- expect(response.content.length).toBeGreaterThan(0);
- }
- async function testRealWorldLinkedInData<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
- const toolCallId = llm.provider === "mistral" ? "linkedin1" : "linkedin_1";
- const context: Context = {
- systemPrompt: "You are a helpful assistant.",
- messages: [
- {
- role: "user",
- content: "Use the linkedin tool to get comments",
- timestamp: Date.now(),
- },
- {
- role: "assistant",
- content: [
- {
- type: "toolCall",
- id: toolCallId,
- name: "linkedin_skill",
- arguments: {},
- },
- ],
- api: llm.api,
- provider: llm.provider,
- model: llm.id,
- usage: {
- input: 0,
- output: 0,
- cacheRead: 0,
- cacheWrite: 0,
- totalTokens: 0,
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
- },
- stopReason: "toolUse",
- timestamp: Date.now(),
- },
- ],
- tools: [
- {
- name: "linkedin_skill",
- description: "Get LinkedIn comments",
- parameters: emptySchema,
- },
- ],
- };
- // Real-world tool result from LinkedIn with emoji
- const toolResult: ToolResultMessage = {
- role: "toolResult",
- toolCallId: toolCallId,
- toolName: "linkedin_skill",
- content: [
- {
- type: "text",
- text: `Post: Hab einen "Generative KI für Nicht-Techniker" Workshop gebaut.
- Unanswered Comments: 2
- => {
- "comments": [
- {
- "author": "Matthias Neumayer's graphic link",
- "text": "Leider nehmen das viel zu wenige Leute ernst"
- },
- {
- "author": "Matthias Neumayer's graphic link",
- "text": "Mario Zechner wann? Wo? Bin grad äußersr eventuninformiert 🙈"
- }
- ]
- }`,
- },
- ],
- isError: false,
- timestamp: Date.now(),
- };
- context.messages.push(toolResult);
- context.messages.push({
- role: "user",
- content: "How many comments are there?",
- timestamp: Date.now(),
- });
- // This should not throw a surrogate pair error
- const response = await complete(llm, context, options);
- expect(response.stopReason).not.toBe("error");
- expect(response.errorMessage).toBeFalsy();
- expect(response.content.some((b) => b.type === "text")).toBe(true);
- }
- async function testUnpairedHighSurrogate<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
- const toolCallId = llm.provider === "mistral" ? "testtool2" : "test_2";
- const context: Context = {
- systemPrompt: "You are a helpful assistant.",
- messages: [
- {
- role: "user",
- content: "Use the test tool",
- timestamp: Date.now(),
- },
- {
- role: "assistant",
- content: [
- {
- type: "toolCall",
- id: toolCallId,
- name: "test_tool",
- arguments: {},
- },
- ],
- api: llm.api,
- provider: llm.provider,
- model: llm.id,
- usage: {
- input: 0,
- output: 0,
- cacheRead: 0,
- cacheWrite: 0,
- totalTokens: 0,
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
- },
- stopReason: "toolUse",
- timestamp: Date.now(),
- },
- ],
- tools: [
- {
- name: "test_tool",
- description: "A test tool",
- parameters: emptySchema,
- },
- ],
- };
- // Construct a string with an intentionally unpaired high surrogate
- // This simulates what might happen if text processing corrupts emoji
- const unpairedSurrogate = String.fromCharCode(0xd83d); // High surrogate without low surrogate
- const toolResult: ToolResultMessage = {
- role: "toolResult",
- toolCallId: toolCallId,
- toolName: "test_tool",
- content: [{ type: "text", text: `Text with unpaired surrogate: ${unpairedSurrogate} <- should be sanitized` }],
- isError: false,
- timestamp: Date.now(),
- };
- context.messages.push(toolResult);
- context.messages.push({
- role: "user",
- content: "What did the tool return?",
- timestamp: Date.now(),
- });
- // This should not throw a surrogate pair error
- // The unpaired surrogate should be sanitized before sending to API
- const response = await complete(llm, context, options);
- expect(response.stopReason).not.toBe("error");
- expect(response.errorMessage).toBeFalsy();
- expect(response.content.length).toBeGreaterThan(0);
- }
- describe("AI Providers Unicode Surrogate Pair Tests", () => {
- describe.skipIf(!process.env.GEMINI_API_KEY)("Google Provider Unicode Handling", () => {
- const llm = getModel("google", "gemini-2.5-flash");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.OPENAI_API_KEY)("OpenAI Completions Provider Unicode Handling", () => {
- const llm = getModel("openai", "gpt-4o-mini");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.OPENAI_API_KEY)("OpenAI Responses Provider Unicode Handling", () => {
- const llm = getModel("openai", "gpt-5-mini");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!hasAzureOpenAICredentials())("Azure OpenAI Responses Provider Unicode Handling", () => {
- const llm = getModel("azure-openai-responses", "gpt-4o-mini");
- const azureDeploymentName = resolveAzureDeploymentName(llm.id);
- const azureOptions = azureDeploymentName ? { azureDeploymentName } : {};
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm, azureOptions);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm, azureOptions);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm, azureOptions);
- });
- });
- describe.skipIf(!process.env.ANTHROPIC_API_KEY)("Anthropic Provider Unicode Handling", () => {
- const llm = getModel("anthropic", "claude-haiku-4-5");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- // =========================================================================
- // OAuth-based providers (credentials from ~/.pi/agent/oauth.json)
- // =========================================================================
- describe("Anthropic OAuth Provider Unicode Handling", () => {
- const llm = getModel("anthropic", "claude-haiku-4-5");
- it.skipIf(!anthropicOAuthToken)("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm, { apiKey: anthropicOAuthToken });
- });
- it.skipIf(!anthropicOAuthToken)(
- "should handle real-world LinkedIn comment data with emoji",
- { retry: 3, timeout: 30000 },
- async () => {
- await testRealWorldLinkedInData(llm, { apiKey: anthropicOAuthToken });
- },
- );
- it.skipIf(!anthropicOAuthToken)(
- "should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- await testUnpairedHighSurrogate(llm, { apiKey: anthropicOAuthToken });
- },
- );
- });
- describe("GitHub Copilot Provider Unicode Handling", () => {
- it.skipIf(!githubCopilotToken)(
- "claude-haiku-4.5 - should handle emoji in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("github-copilot", "claude-haiku-4.5");
- await testEmojiInToolResults(llm, { apiKey: githubCopilotToken });
- },
- );
- it.skipIf(!githubCopilotToken)(
- "claude-haiku-4.5 - should handle real-world LinkedIn comment data with emoji",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("github-copilot", "claude-haiku-4.5");
- await testRealWorldLinkedInData(llm, { apiKey: githubCopilotToken });
- },
- );
- it.skipIf(!githubCopilotToken)(
- "claude-haiku-4.5 - should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("github-copilot", "claude-haiku-4.5");
- await testUnpairedHighSurrogate(llm, { apiKey: githubCopilotToken });
- },
- );
- it.skipIf(!githubCopilotToken)(
- "claude-sonnet-4 - should handle emoji in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("github-copilot", "claude-sonnet-4.6");
- await testEmojiInToolResults(llm, { apiKey: githubCopilotToken });
- },
- );
- it.skipIf(!githubCopilotToken)(
- "claude-sonnet-4 - should handle real-world LinkedIn comment data with emoji",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("github-copilot", "claude-sonnet-4.6");
- await testRealWorldLinkedInData(llm, { apiKey: githubCopilotToken });
- },
- );
- it.skipIf(!githubCopilotToken)(
- "claude-sonnet-4 - should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("github-copilot", "claude-sonnet-4.6");
- await testUnpairedHighSurrogate(llm, { apiKey: githubCopilotToken });
- },
- );
- });
- describe.skipIf(!process.env.XAI_API_KEY)("xAI Provider Unicode Handling", () => {
- const llm = getModel("xai", "grok-3");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.GROQ_API_KEY)("Groq Provider Unicode Handling", () => {
- const llm = getModel("groq", "openai/gpt-oss-20b");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.CEREBRAS_API_KEY)("Cerebras Provider Unicode Handling", () => {
- const llm = getModel("cerebras", "gpt-oss-120b");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!hasCloudflareWorkersAICredentials())("Cloudflare Workers AI Provider Unicode Handling", () => {
- const llm = getModel("cloudflare-workers-ai", "@cf/moonshotai/kimi-k2.6");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!hasCloudflareAiGatewayCredentials())("Cloudflare AI Gateway Provider Unicode Handling", () => {
- const llm = getModel("cloudflare-ai-gateway", "workers-ai/@cf/moonshotai/kimi-k2.6");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.HF_TOKEN)("Hugging Face Provider Unicode Handling", () => {
- const llm = getModel("huggingface", "moonshotai/Kimi-K2.5");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.TOGETHER_API_KEY)("Together AI Provider Unicode Handling", () => {
- const llm = getModel("together", "moonshotai/Kimi-K2.6");
- const options = { reasoningEffort: "high" } satisfies StreamOptionsWithExtras;
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm, options);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm, options);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm, options);
- });
- });
- describe.skipIf(!process.env.ZAI_API_KEY)("zAI Provider Unicode Handling", () => {
- const llm = getModel("zai", "glm-4.5-air");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.MISTRAL_API_KEY)("Mistral Provider Unicode Handling", () => {
- const llm = getModel("mistral", "devstral-medium-latest");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.MINIMAX_API_KEY)("MiniMax Provider Unicode Handling", () => {
- const llm = getModel("minimax", "MiniMax-M2.7");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.XIAOMI_API_KEY)("Xiaomi MiMo (API billing) Provider Unicode Handling", () => {
- const llm = getModel("xiaomi", "mimo-v2.5-pro");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_CN_API_KEY)(
- "Xiaomi MiMo Token Plan (CN) Provider Unicode Handling",
- () => {
- const llm = getModel("xiaomi-token-plan-cn", "mimo-v2.5-pro");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it(
- "should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- await testUnpairedHighSurrogate(llm);
- },
- );
- },
- );
- describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_AMS_API_KEY)(
- "Xiaomi MiMo Token Plan (AMS) Provider Unicode Handling",
- () => {
- const llm = getModel("xiaomi-token-plan-ams", "mimo-v2.5-pro");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it(
- "should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- await testUnpairedHighSurrogate(llm);
- },
- );
- },
- );
- describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_SGP_API_KEY)(
- "Xiaomi MiMo Token Plan (SGP) Provider Unicode Handling",
- () => {
- const llm = getModel("xiaomi-token-plan-sgp", "mimo-v2.5-pro");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it(
- "should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- await testUnpairedHighSurrogate(llm);
- },
- );
- },
- );
- describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider Unicode Handling", () => {
- const llm = getModel("kimi-coding", "kimi-k2-thinking");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!process.env.AI_GATEWAY_API_KEY)("Vercel AI Gateway Provider Unicode Handling", () => {
- const llm = getModel("vercel-ai-gateway", "google/gemini-2.5-flash");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe.skipIf(!hasBedrockCredentials())("Amazon Bedrock Provider Unicode Handling", () => {
- const llm = getModel("amazon-bedrock", "global.anthropic.claude-sonnet-4-5-20250929-v1:0");
- it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testEmojiInToolResults(llm);
- });
- it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
- await testRealWorldLinkedInData(llm);
- });
- it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
- await testUnpairedHighSurrogate(llm);
- });
- });
- describe("OpenAI Codex Provider Unicode Handling", () => {
- it.skipIf(!openaiCodexToken)(
- "gpt-5.5 - should handle emoji in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("openai-codex", "gpt-5.5");
- await testEmojiInToolResults(llm, { apiKey: openaiCodexToken });
- },
- );
- it.skipIf(!openaiCodexToken)(
- "gpt-5.5 - should handle real-world LinkedIn comment data with emoji",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("openai-codex", "gpt-5.5");
- await testRealWorldLinkedInData(llm, { apiKey: openaiCodexToken });
- },
- );
- it.skipIf(!openaiCodexToken)(
- "gpt-5.5 - should handle unpaired high surrogate (0xD83D) in tool results",
- { retry: 3, timeout: 30000 },
- async () => {
- const llm = getModel("openai-codex", "gpt-5.5");
- await testUnpairedHighSurrogate(llm, { apiKey: openaiCodexToken });
- },
- );
- });
- });
|