unicode-surrogate.test.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. import { Type } from "typebox";
  2. import { describe, expect, it } from "vitest";
  3. import { getModel } from "../src/models.ts";
  4. import { complete } from "../src/stream.ts";
  5. import type { Api, Context, Model, StreamOptions, ToolResultMessage } from "../src/types.ts";
  6. type StreamOptionsWithExtras = StreamOptions & Record<string, unknown>;
  7. import { hasAzureOpenAICredentials, resolveAzureDeploymentName } from "./azure-utils.ts";
  8. import { hasBedrockCredentials } from "./bedrock-utils.ts";
  9. import { hasCloudflareAiGatewayCredentials, hasCloudflareWorkersAICredentials } from "./cloudflare-utils.ts";
  10. import { resolveApiKey } from "./oauth.ts";
  11. // Empty schema for test tools - must be proper OBJECT type for Cloud Code Assist
  12. const emptySchema = Type.Object({});
  13. // Resolve OAuth tokens at module level (async, runs before tests)
  14. const oauthTokens = await Promise.all([
  15. resolveApiKey("anthropic"),
  16. resolveApiKey("github-copilot"),
  17. resolveApiKey("openai-codex"),
  18. ]);
  19. const [anthropicOAuthToken, githubCopilotToken, openaiCodexToken] = oauthTokens;
  20. /**
  21. * Test for Unicode surrogate pair handling in tool results.
  22. *
  23. * Issue: When tool results contain emoji or other characters outside the Basic Multilingual Plane,
  24. * they may be incorrectly serialized as unpaired surrogates, causing "no low surrogate in string"
  25. * errors when sent to the API provider.
  26. *
  27. * Example error from Anthropic:
  28. * "The request body is not valid JSON: no low surrogate in string: line 1 column 197667"
  29. */
  30. async function testEmojiInToolResults<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  31. const toolCallId = llm.provider === "mistral" ? "testtool1" : "test_1";
  32. // Simulate a tool that returns emoji
  33. const context: Context = {
  34. systemPrompt: "You are a helpful assistant.",
  35. messages: [
  36. {
  37. role: "user",
  38. content: "Use the test tool",
  39. timestamp: Date.now(),
  40. },
  41. {
  42. role: "assistant",
  43. content: [
  44. {
  45. type: "toolCall",
  46. id: toolCallId,
  47. name: "test_tool",
  48. arguments: {},
  49. },
  50. ],
  51. api: llm.api,
  52. provider: llm.provider,
  53. model: llm.id,
  54. usage: {
  55. input: 0,
  56. output: 0,
  57. cacheRead: 0,
  58. cacheWrite: 0,
  59. totalTokens: 0,
  60. cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
  61. },
  62. stopReason: "toolUse",
  63. timestamp: Date.now(),
  64. },
  65. ],
  66. tools: [
  67. {
  68. name: "test_tool",
  69. description: "A test tool",
  70. parameters: emptySchema,
  71. },
  72. ],
  73. };
  74. // Add tool result with various problematic Unicode characters
  75. const toolResult: ToolResultMessage = {
  76. role: "toolResult",
  77. toolCallId: toolCallId,
  78. toolName: "test_tool",
  79. content: [
  80. {
  81. type: "text",
  82. text: `Test with emoji 🙈 and other characters:
  83. - Monkey emoji: 🙈
  84. - Thumbs up: 👍
  85. - Heart: ❤️
  86. - Thinking face: 🤔
  87. - Rocket: 🚀
  88. - Mixed text: Mario Zechner wann? Wo? Bin grad äußersr eventuninformiert 🙈
  89. - Japanese: こんにちは
  90. - Chinese: 你好
  91. - Mathematical symbols: ∑∫∂√
  92. - Special quotes: "curly" 'quotes'`,
  93. },
  94. ],
  95. isError: false,
  96. timestamp: Date.now(),
  97. };
  98. context.messages.push(toolResult);
  99. // Add follow-up user message
  100. context.messages.push({
  101. role: "user",
  102. content: "Summarize the tool result briefly.",
  103. timestamp: Date.now(),
  104. });
  105. // This should not throw a surrogate pair error
  106. const response = await complete(llm, context, options);
  107. expect(response.stopReason).not.toBe("error");
  108. expect(response.errorMessage).toBeFalsy();
  109. expect(response.content.length).toBeGreaterThan(0);
  110. }
  111. async function testRealWorldLinkedInData<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  112. const toolCallId = llm.provider === "mistral" ? "linkedin1" : "linkedin_1";
  113. const context: Context = {
  114. systemPrompt: "You are a helpful assistant.",
  115. messages: [
  116. {
  117. role: "user",
  118. content: "Use the linkedin tool to get comments",
  119. timestamp: Date.now(),
  120. },
  121. {
  122. role: "assistant",
  123. content: [
  124. {
  125. type: "toolCall",
  126. id: toolCallId,
  127. name: "linkedin_skill",
  128. arguments: {},
  129. },
  130. ],
  131. api: llm.api,
  132. provider: llm.provider,
  133. model: llm.id,
  134. usage: {
  135. input: 0,
  136. output: 0,
  137. cacheRead: 0,
  138. cacheWrite: 0,
  139. totalTokens: 0,
  140. cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
  141. },
  142. stopReason: "toolUse",
  143. timestamp: Date.now(),
  144. },
  145. ],
  146. tools: [
  147. {
  148. name: "linkedin_skill",
  149. description: "Get LinkedIn comments",
  150. parameters: emptySchema,
  151. },
  152. ],
  153. };
  154. // Real-world tool result from LinkedIn with emoji
  155. const toolResult: ToolResultMessage = {
  156. role: "toolResult",
  157. toolCallId: toolCallId,
  158. toolName: "linkedin_skill",
  159. content: [
  160. {
  161. type: "text",
  162. text: `Post: Hab einen "Generative KI für Nicht-Techniker" Workshop gebaut.
  163. Unanswered Comments: 2
  164. => {
  165. "comments": [
  166. {
  167. "author": "Matthias Neumayer's graphic link",
  168. "text": "Leider nehmen das viel zu wenige Leute ernst"
  169. },
  170. {
  171. "author": "Matthias Neumayer's graphic link",
  172. "text": "Mario Zechner wann? Wo? Bin grad äußersr eventuninformiert 🙈"
  173. }
  174. ]
  175. }`,
  176. },
  177. ],
  178. isError: false,
  179. timestamp: Date.now(),
  180. };
  181. context.messages.push(toolResult);
  182. context.messages.push({
  183. role: "user",
  184. content: "How many comments are there?",
  185. timestamp: Date.now(),
  186. });
  187. // This should not throw a surrogate pair error
  188. const response = await complete(llm, context, options);
  189. expect(response.stopReason).not.toBe("error");
  190. expect(response.errorMessage).toBeFalsy();
  191. expect(response.content.some((b) => b.type === "text")).toBe(true);
  192. }
  193. async function testUnpairedHighSurrogate<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  194. const toolCallId = llm.provider === "mistral" ? "testtool2" : "test_2";
  195. const context: Context = {
  196. systemPrompt: "You are a helpful assistant.",
  197. messages: [
  198. {
  199. role: "user",
  200. content: "Use the test tool",
  201. timestamp: Date.now(),
  202. },
  203. {
  204. role: "assistant",
  205. content: [
  206. {
  207. type: "toolCall",
  208. id: toolCallId,
  209. name: "test_tool",
  210. arguments: {},
  211. },
  212. ],
  213. api: llm.api,
  214. provider: llm.provider,
  215. model: llm.id,
  216. usage: {
  217. input: 0,
  218. output: 0,
  219. cacheRead: 0,
  220. cacheWrite: 0,
  221. totalTokens: 0,
  222. cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
  223. },
  224. stopReason: "toolUse",
  225. timestamp: Date.now(),
  226. },
  227. ],
  228. tools: [
  229. {
  230. name: "test_tool",
  231. description: "A test tool",
  232. parameters: emptySchema,
  233. },
  234. ],
  235. };
  236. // Construct a string with an intentionally unpaired high surrogate
  237. // This simulates what might happen if text processing corrupts emoji
  238. const unpairedSurrogate = String.fromCharCode(0xd83d); // High surrogate without low surrogate
  239. const toolResult: ToolResultMessage = {
  240. role: "toolResult",
  241. toolCallId: toolCallId,
  242. toolName: "test_tool",
  243. content: [{ type: "text", text: `Text with unpaired surrogate: ${unpairedSurrogate} <- should be sanitized` }],
  244. isError: false,
  245. timestamp: Date.now(),
  246. };
  247. context.messages.push(toolResult);
  248. context.messages.push({
  249. role: "user",
  250. content: "What did the tool return?",
  251. timestamp: Date.now(),
  252. });
  253. // This should not throw a surrogate pair error
  254. // The unpaired surrogate should be sanitized before sending to API
  255. const response = await complete(llm, context, options);
  256. expect(response.stopReason).not.toBe("error");
  257. expect(response.errorMessage).toBeFalsy();
  258. expect(response.content.length).toBeGreaterThan(0);
  259. }
  260. describe("AI Providers Unicode Surrogate Pair Tests", () => {
  261. describe.skipIf(!process.env.GEMINI_API_KEY)("Google Provider Unicode Handling", () => {
  262. const llm = getModel("google", "gemini-2.5-flash");
  263. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  264. await testEmojiInToolResults(llm);
  265. });
  266. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  267. await testRealWorldLinkedInData(llm);
  268. });
  269. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  270. await testUnpairedHighSurrogate(llm);
  271. });
  272. });
  273. describe.skipIf(!process.env.OPENAI_API_KEY)("OpenAI Completions Provider Unicode Handling", () => {
  274. const llm = getModel("openai", "gpt-4o-mini");
  275. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  276. await testEmojiInToolResults(llm);
  277. });
  278. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  279. await testRealWorldLinkedInData(llm);
  280. });
  281. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  282. await testUnpairedHighSurrogate(llm);
  283. });
  284. });
  285. describe.skipIf(!process.env.OPENAI_API_KEY)("OpenAI Responses Provider Unicode Handling", () => {
  286. const llm = getModel("openai", "gpt-5-mini");
  287. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  288. await testEmojiInToolResults(llm);
  289. });
  290. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  291. await testRealWorldLinkedInData(llm);
  292. });
  293. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  294. await testUnpairedHighSurrogate(llm);
  295. });
  296. });
  297. describe.skipIf(!hasAzureOpenAICredentials())("Azure OpenAI Responses Provider Unicode Handling", () => {
  298. const llm = getModel("azure-openai-responses", "gpt-4o-mini");
  299. const azureDeploymentName = resolveAzureDeploymentName(llm.id);
  300. const azureOptions = azureDeploymentName ? { azureDeploymentName } : {};
  301. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  302. await testEmojiInToolResults(llm, azureOptions);
  303. });
  304. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  305. await testRealWorldLinkedInData(llm, azureOptions);
  306. });
  307. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  308. await testUnpairedHighSurrogate(llm, azureOptions);
  309. });
  310. });
  311. describe.skipIf(!process.env.ANTHROPIC_API_KEY)("Anthropic Provider Unicode Handling", () => {
  312. const llm = getModel("anthropic", "claude-haiku-4-5");
  313. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  314. await testEmojiInToolResults(llm);
  315. });
  316. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  317. await testRealWorldLinkedInData(llm);
  318. });
  319. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  320. await testUnpairedHighSurrogate(llm);
  321. });
  322. });
  323. // =========================================================================
  324. // OAuth-based providers (credentials from ~/.pi/agent/oauth.json)
  325. // =========================================================================
  326. describe("Anthropic OAuth Provider Unicode Handling", () => {
  327. const llm = getModel("anthropic", "claude-haiku-4-5");
  328. it.skipIf(!anthropicOAuthToken)("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  329. await testEmojiInToolResults(llm, { apiKey: anthropicOAuthToken });
  330. });
  331. it.skipIf(!anthropicOAuthToken)(
  332. "should handle real-world LinkedIn comment data with emoji",
  333. { retry: 3, timeout: 30000 },
  334. async () => {
  335. await testRealWorldLinkedInData(llm, { apiKey: anthropicOAuthToken });
  336. },
  337. );
  338. it.skipIf(!anthropicOAuthToken)(
  339. "should handle unpaired high surrogate (0xD83D) in tool results",
  340. { retry: 3, timeout: 30000 },
  341. async () => {
  342. await testUnpairedHighSurrogate(llm, { apiKey: anthropicOAuthToken });
  343. },
  344. );
  345. });
  346. describe("GitHub Copilot Provider Unicode Handling", () => {
  347. it.skipIf(!githubCopilotToken)(
  348. "claude-haiku-4.5 - should handle emoji in tool results",
  349. { retry: 3, timeout: 30000 },
  350. async () => {
  351. const llm = getModel("github-copilot", "claude-haiku-4.5");
  352. await testEmojiInToolResults(llm, { apiKey: githubCopilotToken });
  353. },
  354. );
  355. it.skipIf(!githubCopilotToken)(
  356. "claude-haiku-4.5 - should handle real-world LinkedIn comment data with emoji",
  357. { retry: 3, timeout: 30000 },
  358. async () => {
  359. const llm = getModel("github-copilot", "claude-haiku-4.5");
  360. await testRealWorldLinkedInData(llm, { apiKey: githubCopilotToken });
  361. },
  362. );
  363. it.skipIf(!githubCopilotToken)(
  364. "claude-haiku-4.5 - should handle unpaired high surrogate (0xD83D) in tool results",
  365. { retry: 3, timeout: 30000 },
  366. async () => {
  367. const llm = getModel("github-copilot", "claude-haiku-4.5");
  368. await testUnpairedHighSurrogate(llm, { apiKey: githubCopilotToken });
  369. },
  370. );
  371. it.skipIf(!githubCopilotToken)(
  372. "claude-sonnet-4 - should handle emoji in tool results",
  373. { retry: 3, timeout: 30000 },
  374. async () => {
  375. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  376. await testEmojiInToolResults(llm, { apiKey: githubCopilotToken });
  377. },
  378. );
  379. it.skipIf(!githubCopilotToken)(
  380. "claude-sonnet-4 - should handle real-world LinkedIn comment data with emoji",
  381. { retry: 3, timeout: 30000 },
  382. async () => {
  383. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  384. await testRealWorldLinkedInData(llm, { apiKey: githubCopilotToken });
  385. },
  386. );
  387. it.skipIf(!githubCopilotToken)(
  388. "claude-sonnet-4 - should handle unpaired high surrogate (0xD83D) in tool results",
  389. { retry: 3, timeout: 30000 },
  390. async () => {
  391. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  392. await testUnpairedHighSurrogate(llm, { apiKey: githubCopilotToken });
  393. },
  394. );
  395. });
  396. describe.skipIf(!process.env.XAI_API_KEY)("xAI Provider Unicode Handling", () => {
  397. const llm = getModel("xai", "grok-3");
  398. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  399. await testEmojiInToolResults(llm);
  400. });
  401. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  402. await testRealWorldLinkedInData(llm);
  403. });
  404. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  405. await testUnpairedHighSurrogate(llm);
  406. });
  407. });
  408. describe.skipIf(!process.env.GROQ_API_KEY)("Groq Provider Unicode Handling", () => {
  409. const llm = getModel("groq", "openai/gpt-oss-20b");
  410. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  411. await testEmojiInToolResults(llm);
  412. });
  413. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  414. await testRealWorldLinkedInData(llm);
  415. });
  416. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  417. await testUnpairedHighSurrogate(llm);
  418. });
  419. });
  420. describe.skipIf(!process.env.CEREBRAS_API_KEY)("Cerebras Provider Unicode Handling", () => {
  421. const llm = getModel("cerebras", "gpt-oss-120b");
  422. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  423. await testEmojiInToolResults(llm);
  424. });
  425. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  426. await testRealWorldLinkedInData(llm);
  427. });
  428. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  429. await testUnpairedHighSurrogate(llm);
  430. });
  431. });
  432. describe.skipIf(!hasCloudflareWorkersAICredentials())("Cloudflare Workers AI Provider Unicode Handling", () => {
  433. const llm = getModel("cloudflare-workers-ai", "@cf/moonshotai/kimi-k2.6");
  434. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  435. await testEmojiInToolResults(llm);
  436. });
  437. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  438. await testRealWorldLinkedInData(llm);
  439. });
  440. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  441. await testUnpairedHighSurrogate(llm);
  442. });
  443. });
  444. describe.skipIf(!hasCloudflareAiGatewayCredentials())("Cloudflare AI Gateway Provider Unicode Handling", () => {
  445. const llm = getModel("cloudflare-ai-gateway", "workers-ai/@cf/moonshotai/kimi-k2.6");
  446. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  447. await testEmojiInToolResults(llm);
  448. });
  449. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  450. await testRealWorldLinkedInData(llm);
  451. });
  452. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  453. await testUnpairedHighSurrogate(llm);
  454. });
  455. });
  456. describe.skipIf(!process.env.HF_TOKEN)("Hugging Face Provider Unicode Handling", () => {
  457. const llm = getModel("huggingface", "moonshotai/Kimi-K2.5");
  458. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  459. await testEmojiInToolResults(llm);
  460. });
  461. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  462. await testRealWorldLinkedInData(llm);
  463. });
  464. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  465. await testUnpairedHighSurrogate(llm);
  466. });
  467. });
  468. describe.skipIf(!process.env.TOGETHER_API_KEY)("Together AI Provider Unicode Handling", () => {
  469. const llm = getModel("together", "moonshotai/Kimi-K2.6");
  470. const options = { reasoningEffort: "high" } satisfies StreamOptionsWithExtras;
  471. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  472. await testEmojiInToolResults(llm, options);
  473. });
  474. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  475. await testRealWorldLinkedInData(llm, options);
  476. });
  477. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  478. await testUnpairedHighSurrogate(llm, options);
  479. });
  480. });
  481. describe.skipIf(!process.env.ZAI_API_KEY)("zAI Provider Unicode Handling", () => {
  482. const llm = getModel("zai", "glm-4.5-air");
  483. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  484. await testEmojiInToolResults(llm);
  485. });
  486. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  487. await testRealWorldLinkedInData(llm);
  488. });
  489. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  490. await testUnpairedHighSurrogate(llm);
  491. });
  492. });
  493. describe.skipIf(!process.env.MISTRAL_API_KEY)("Mistral Provider Unicode Handling", () => {
  494. const llm = getModel("mistral", "devstral-medium-latest");
  495. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  496. await testEmojiInToolResults(llm);
  497. });
  498. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  499. await testRealWorldLinkedInData(llm);
  500. });
  501. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  502. await testUnpairedHighSurrogate(llm);
  503. });
  504. });
  505. describe.skipIf(!process.env.MINIMAX_API_KEY)("MiniMax Provider Unicode Handling", () => {
  506. const llm = getModel("minimax", "MiniMax-M2.7");
  507. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  508. await testEmojiInToolResults(llm);
  509. });
  510. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  511. await testRealWorldLinkedInData(llm);
  512. });
  513. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  514. await testUnpairedHighSurrogate(llm);
  515. });
  516. });
  517. describe.skipIf(!process.env.XIAOMI_API_KEY)("Xiaomi MiMo (API billing) Provider Unicode Handling", () => {
  518. const llm = getModel("xiaomi", "mimo-v2.5-pro");
  519. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  520. await testEmojiInToolResults(llm);
  521. });
  522. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  523. await testRealWorldLinkedInData(llm);
  524. });
  525. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  526. await testUnpairedHighSurrogate(llm);
  527. });
  528. });
  529. describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_CN_API_KEY)(
  530. "Xiaomi MiMo Token Plan (CN) Provider Unicode Handling",
  531. () => {
  532. const llm = getModel("xiaomi-token-plan-cn", "mimo-v2.5-pro");
  533. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  534. await testEmojiInToolResults(llm);
  535. });
  536. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  537. await testRealWorldLinkedInData(llm);
  538. });
  539. it(
  540. "should handle unpaired high surrogate (0xD83D) in tool results",
  541. { retry: 3, timeout: 30000 },
  542. async () => {
  543. await testUnpairedHighSurrogate(llm);
  544. },
  545. );
  546. },
  547. );
  548. describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_AMS_API_KEY)(
  549. "Xiaomi MiMo Token Plan (AMS) Provider Unicode Handling",
  550. () => {
  551. const llm = getModel("xiaomi-token-plan-ams", "mimo-v2.5-pro");
  552. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  553. await testEmojiInToolResults(llm);
  554. });
  555. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  556. await testRealWorldLinkedInData(llm);
  557. });
  558. it(
  559. "should handle unpaired high surrogate (0xD83D) in tool results",
  560. { retry: 3, timeout: 30000 },
  561. async () => {
  562. await testUnpairedHighSurrogate(llm);
  563. },
  564. );
  565. },
  566. );
  567. describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_SGP_API_KEY)(
  568. "Xiaomi MiMo Token Plan (SGP) Provider Unicode Handling",
  569. () => {
  570. const llm = getModel("xiaomi-token-plan-sgp", "mimo-v2.5-pro");
  571. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  572. await testEmojiInToolResults(llm);
  573. });
  574. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  575. await testRealWorldLinkedInData(llm);
  576. });
  577. it(
  578. "should handle unpaired high surrogate (0xD83D) in tool results",
  579. { retry: 3, timeout: 30000 },
  580. async () => {
  581. await testUnpairedHighSurrogate(llm);
  582. },
  583. );
  584. },
  585. );
  586. describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider Unicode Handling", () => {
  587. const llm = getModel("kimi-coding", "kimi-k2-thinking");
  588. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  589. await testEmojiInToolResults(llm);
  590. });
  591. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  592. await testRealWorldLinkedInData(llm);
  593. });
  594. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  595. await testUnpairedHighSurrogate(llm);
  596. });
  597. });
  598. describe.skipIf(!process.env.AI_GATEWAY_API_KEY)("Vercel AI Gateway Provider Unicode Handling", () => {
  599. const llm = getModel("vercel-ai-gateway", "google/gemini-2.5-flash");
  600. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  601. await testEmojiInToolResults(llm);
  602. });
  603. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  604. await testRealWorldLinkedInData(llm);
  605. });
  606. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  607. await testUnpairedHighSurrogate(llm);
  608. });
  609. });
  610. describe.skipIf(!hasBedrockCredentials())("Amazon Bedrock Provider Unicode Handling", () => {
  611. const llm = getModel("amazon-bedrock", "global.anthropic.claude-sonnet-4-5-20250929-v1:0");
  612. it("should handle emoji in tool results", { retry: 3, timeout: 30000 }, async () => {
  613. await testEmojiInToolResults(llm);
  614. });
  615. it("should handle real-world LinkedIn comment data with emoji", { retry: 3, timeout: 30000 }, async () => {
  616. await testRealWorldLinkedInData(llm);
  617. });
  618. it("should handle unpaired high surrogate (0xD83D) in tool results", { retry: 3, timeout: 30000 }, async () => {
  619. await testUnpairedHighSurrogate(llm);
  620. });
  621. });
  622. describe("OpenAI Codex Provider Unicode Handling", () => {
  623. it.skipIf(!openaiCodexToken)(
  624. "gpt-5.5 - should handle emoji in tool results",
  625. { retry: 3, timeout: 30000 },
  626. async () => {
  627. const llm = getModel("openai-codex", "gpt-5.5");
  628. await testEmojiInToolResults(llm, { apiKey: openaiCodexToken });
  629. },
  630. );
  631. it.skipIf(!openaiCodexToken)(
  632. "gpt-5.5 - should handle real-world LinkedIn comment data with emoji",
  633. { retry: 3, timeout: 30000 },
  634. async () => {
  635. const llm = getModel("openai-codex", "gpt-5.5");
  636. await testRealWorldLinkedInData(llm, { apiKey: openaiCodexToken });
  637. },
  638. );
  639. it.skipIf(!openaiCodexToken)(
  640. "gpt-5.5 - should handle unpaired high surrogate (0xD83D) in tool results",
  641. { retry: 3, timeout: 30000 },
  642. async () => {
  643. const llm = getModel("openai-codex", "gpt-5.5");
  644. await testUnpairedHighSurrogate(llm, { apiKey: openaiCodexToken });
  645. },
  646. );
  647. });
  648. });