empty.test.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. import { describe, expect, it } from "vitest";
  2. import { getModel } from "../src/models.ts";
  3. import { complete } from "../src/stream.ts";
  4. import type { Api, AssistantMessage, Context, Model, StreamOptions, UserMessage } from "../src/types.ts";
  5. type StreamOptionsWithExtras = StreamOptions & Record<string, unknown>;
  6. import { hasAzureOpenAICredentials, resolveAzureDeploymentName } from "./azure-utils.ts";
  7. import { hasBedrockCredentials } from "./bedrock-utils.ts";
  8. import { hasCloudflareAiGatewayCredentials, hasCloudflareWorkersAICredentials } from "./cloudflare-utils.ts";
  9. import { resolveApiKey } from "./oauth.ts";
  10. // Resolve OAuth tokens at module level (async, runs before tests)
  11. const oauthTokens = await Promise.all([
  12. resolveApiKey("anthropic"),
  13. resolveApiKey("github-copilot"),
  14. resolveApiKey("openai-codex"),
  15. ]);
  16. const [anthropicOAuthToken, githubCopilotToken, openaiCodexToken] = oauthTokens;
  17. async function testEmptyMessage<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  18. // Test with completely empty content array
  19. const emptyMessage: UserMessage = {
  20. role: "user",
  21. content: [],
  22. timestamp: Date.now(),
  23. };
  24. const context: Context = {
  25. messages: [emptyMessage],
  26. };
  27. const response = await complete(llm, context, options);
  28. // Should either handle gracefully or return an error
  29. expect(response).toBeDefined();
  30. expect(response.role).toBe("assistant");
  31. // Should handle empty string gracefully
  32. if (response.stopReason === "error") {
  33. expect(response.errorMessage).toBeDefined();
  34. } else {
  35. expect(response.content).toBeDefined();
  36. }
  37. }
  38. async function testEmptyStringMessage<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  39. // Test with empty string content
  40. const context: Context = {
  41. messages: [
  42. {
  43. role: "user",
  44. content: "",
  45. timestamp: Date.now(),
  46. },
  47. ],
  48. };
  49. const response = await complete(llm, context, options);
  50. expect(response).toBeDefined();
  51. expect(response.role).toBe("assistant");
  52. // Should handle empty string gracefully
  53. if (response.stopReason === "error") {
  54. expect(response.errorMessage).toBeDefined();
  55. } else {
  56. expect(response.content).toBeDefined();
  57. }
  58. }
  59. async function testWhitespaceOnlyMessage<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  60. // Test with whitespace-only content
  61. const context: Context = {
  62. messages: [
  63. {
  64. role: "user",
  65. content: " \n\t ",
  66. timestamp: Date.now(),
  67. },
  68. ],
  69. };
  70. const response = await complete(llm, context, options);
  71. expect(response).toBeDefined();
  72. expect(response.role).toBe("assistant");
  73. // Should handle whitespace-only gracefully
  74. if (response.stopReason === "error") {
  75. expect(response.errorMessage).toBeDefined();
  76. } else {
  77. expect(response.content).toBeDefined();
  78. }
  79. }
  80. async function testEmptyAssistantMessage<TApi extends Api>(llm: Model<TApi>, options: StreamOptionsWithExtras = {}) {
  81. // Test with empty assistant message in conversation flow
  82. // User -> Empty Assistant -> User
  83. const emptyAssistant: AssistantMessage = {
  84. role: "assistant",
  85. content: [],
  86. api: llm.api,
  87. provider: llm.provider,
  88. model: llm.id,
  89. usage: {
  90. input: 10,
  91. output: 0,
  92. cacheRead: 0,
  93. cacheWrite: 0,
  94. totalTokens: 10,
  95. cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
  96. },
  97. stopReason: "stop",
  98. timestamp: Date.now(),
  99. };
  100. const context: Context = {
  101. messages: [
  102. {
  103. role: "user",
  104. content: "Hello, how are you?",
  105. timestamp: Date.now(),
  106. },
  107. emptyAssistant,
  108. {
  109. role: "user",
  110. content: "Please respond this time.",
  111. timestamp: Date.now(),
  112. },
  113. ],
  114. };
  115. const response = await complete(llm, context, options);
  116. expect(response).toBeDefined();
  117. expect(response.role).toBe("assistant");
  118. // Should handle empty assistant message in context gracefully
  119. if (response.stopReason === "error") {
  120. expect(response.errorMessage).toBeDefined();
  121. } else {
  122. expect(response.content).toBeDefined();
  123. expect(response.content.length).toBeGreaterThan(0);
  124. }
  125. }
  126. describe("AI Providers Empty Message Tests", () => {
  127. describe.skipIf(!process.env.GEMINI_API_KEY)("Google Provider Empty Messages", () => {
  128. const llm = getModel("google", "gemini-2.5-flash");
  129. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  130. await testEmptyMessage(llm);
  131. });
  132. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  133. await testEmptyStringMessage(llm);
  134. });
  135. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  136. await testWhitespaceOnlyMessage(llm);
  137. });
  138. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  139. await testEmptyAssistantMessage(llm);
  140. });
  141. });
  142. describe.skipIf(!process.env.OPENAI_API_KEY)("OpenAI Completions Provider Empty Messages", () => {
  143. const llm = getModel("openai", "gpt-4o-mini");
  144. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  145. await testEmptyMessage(llm);
  146. });
  147. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  148. await testEmptyStringMessage(llm);
  149. });
  150. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  151. await testWhitespaceOnlyMessage(llm);
  152. });
  153. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  154. await testEmptyAssistantMessage(llm);
  155. });
  156. });
  157. describe.skipIf(!process.env.OPENAI_API_KEY)("OpenAI Responses Provider Empty Messages", () => {
  158. const llm = getModel("openai", "gpt-5-mini");
  159. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  160. await testEmptyMessage(llm);
  161. });
  162. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  163. await testEmptyStringMessage(llm);
  164. });
  165. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  166. await testWhitespaceOnlyMessage(llm);
  167. });
  168. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  169. await testEmptyAssistantMessage(llm);
  170. });
  171. });
  172. describe.skipIf(!hasAzureOpenAICredentials())("Azure OpenAI Responses Provider Empty Messages", () => {
  173. const llm = getModel("azure-openai-responses", "gpt-4o-mini");
  174. const azureDeploymentName = resolveAzureDeploymentName(llm.id);
  175. const azureOptions = azureDeploymentName ? { azureDeploymentName } : {};
  176. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  177. await testEmptyMessage(llm, azureOptions);
  178. });
  179. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  180. await testEmptyStringMessage(llm, azureOptions);
  181. });
  182. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  183. await testWhitespaceOnlyMessage(llm, azureOptions);
  184. });
  185. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  186. await testEmptyAssistantMessage(llm, azureOptions);
  187. });
  188. });
  189. describe.skipIf(!process.env.ANTHROPIC_API_KEY)("Anthropic Provider Empty Messages", () => {
  190. const llm = getModel("anthropic", "claude-haiku-4-5");
  191. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  192. await testEmptyMessage(llm);
  193. });
  194. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  195. await testEmptyStringMessage(llm);
  196. });
  197. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  198. await testWhitespaceOnlyMessage(llm);
  199. });
  200. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  201. await testEmptyAssistantMessage(llm);
  202. });
  203. });
  204. describe.skipIf(!process.env.XAI_API_KEY)("xAI Provider Empty Messages", () => {
  205. const llm = getModel("xai", "grok-3");
  206. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  207. await testEmptyMessage(llm);
  208. });
  209. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  210. await testEmptyStringMessage(llm);
  211. });
  212. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  213. await testWhitespaceOnlyMessage(llm);
  214. });
  215. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  216. await testEmptyAssistantMessage(llm);
  217. });
  218. });
  219. describe.skipIf(!process.env.GROQ_API_KEY)("Groq Provider Empty Messages", () => {
  220. const llm = getModel("groq", "openai/gpt-oss-20b");
  221. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  222. await testEmptyMessage(llm);
  223. });
  224. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  225. await testEmptyStringMessage(llm);
  226. });
  227. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  228. await testWhitespaceOnlyMessage(llm);
  229. });
  230. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  231. await testEmptyAssistantMessage(llm);
  232. });
  233. });
  234. describe.skipIf(!process.env.CEREBRAS_API_KEY)("Cerebras Provider Empty Messages", () => {
  235. const llm = getModel("cerebras", "gpt-oss-120b");
  236. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  237. await testEmptyMessage(llm);
  238. });
  239. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  240. await testEmptyStringMessage(llm);
  241. });
  242. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  243. await testWhitespaceOnlyMessage(llm);
  244. });
  245. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  246. await testEmptyAssistantMessage(llm);
  247. });
  248. });
  249. describe.skipIf(!hasCloudflareWorkersAICredentials())("Cloudflare Workers AI Provider Empty Messages", () => {
  250. const llm = getModel("cloudflare-workers-ai", "@cf/moonshotai/kimi-k2.6");
  251. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  252. await testEmptyMessage(llm);
  253. });
  254. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  255. await testEmptyStringMessage(llm);
  256. });
  257. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  258. await testWhitespaceOnlyMessage(llm);
  259. });
  260. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  261. await testEmptyAssistantMessage(llm);
  262. });
  263. });
  264. describe.skipIf(!hasCloudflareAiGatewayCredentials())("Cloudflare AI Gateway Provider Empty Messages", () => {
  265. const llm = getModel("cloudflare-ai-gateway", "workers-ai/@cf/moonshotai/kimi-k2.6");
  266. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  267. await testEmptyMessage(llm);
  268. });
  269. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  270. await testEmptyStringMessage(llm);
  271. });
  272. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  273. await testWhitespaceOnlyMessage(llm);
  274. });
  275. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  276. await testEmptyAssistantMessage(llm);
  277. });
  278. });
  279. describe.skipIf(!process.env.HF_TOKEN)("Hugging Face Provider Empty Messages", () => {
  280. const llm = getModel("huggingface", "moonshotai/Kimi-K2.5");
  281. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  282. await testEmptyMessage(llm);
  283. });
  284. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  285. await testEmptyStringMessage(llm);
  286. });
  287. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  288. await testWhitespaceOnlyMessage(llm);
  289. });
  290. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  291. await testEmptyAssistantMessage(llm);
  292. });
  293. });
  294. describe.skipIf(!process.env.TOGETHER_API_KEY)("Together AI Provider Empty Messages", () => {
  295. const llm = getModel("together", "moonshotai/Kimi-K2.6");
  296. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  297. await testEmptyMessage(llm);
  298. });
  299. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  300. await testEmptyStringMessage(llm);
  301. });
  302. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  303. await testWhitespaceOnlyMessage(llm);
  304. });
  305. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  306. await testEmptyAssistantMessage(llm);
  307. });
  308. });
  309. describe.skipIf(!process.env.ZAI_API_KEY)("zAI Provider Empty Messages", () => {
  310. const llm = getModel("zai", "glm-4.5-air");
  311. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  312. await testEmptyMessage(llm);
  313. });
  314. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  315. await testEmptyStringMessage(llm);
  316. });
  317. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  318. await testWhitespaceOnlyMessage(llm);
  319. });
  320. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  321. await testEmptyAssistantMessage(llm);
  322. });
  323. });
  324. describe.skipIf(!process.env.MISTRAL_API_KEY)("Mistral Provider Empty Messages", () => {
  325. const llm = getModel("mistral", "devstral-medium-latest");
  326. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  327. await testEmptyMessage(llm);
  328. });
  329. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  330. await testEmptyStringMessage(llm);
  331. });
  332. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  333. await testWhitespaceOnlyMessage(llm);
  334. });
  335. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  336. await testEmptyAssistantMessage(llm);
  337. });
  338. });
  339. describe.skipIf(!process.env.MINIMAX_API_KEY)("MiniMax Provider Empty Messages", () => {
  340. const llm = getModel("minimax", "MiniMax-M2.7");
  341. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  342. await testEmptyMessage(llm);
  343. });
  344. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  345. await testEmptyStringMessage(llm);
  346. });
  347. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  348. await testWhitespaceOnlyMessage(llm);
  349. });
  350. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  351. await testEmptyAssistantMessage(llm);
  352. });
  353. });
  354. describe.skipIf(!process.env.XIAOMI_API_KEY)("Xiaomi MiMo (API billing) Provider Empty Messages", () => {
  355. const llm = getModel("xiaomi", "mimo-v2.5-pro");
  356. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  357. await testEmptyMessage(llm);
  358. });
  359. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  360. await testEmptyStringMessage(llm);
  361. });
  362. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  363. await testWhitespaceOnlyMessage(llm);
  364. });
  365. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  366. await testEmptyAssistantMessage(llm);
  367. });
  368. });
  369. describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_CN_API_KEY)(
  370. "Xiaomi MiMo Token Plan (CN) Provider Empty Messages",
  371. () => {
  372. const llm = getModel("xiaomi-token-plan-cn", "mimo-v2.5-pro");
  373. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  374. await testEmptyMessage(llm);
  375. });
  376. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  377. await testEmptyStringMessage(llm);
  378. });
  379. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  380. await testWhitespaceOnlyMessage(llm);
  381. });
  382. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  383. await testEmptyAssistantMessage(llm);
  384. });
  385. },
  386. );
  387. describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_AMS_API_KEY)(
  388. "Xiaomi MiMo Token Plan (AMS) Provider Empty Messages",
  389. () => {
  390. const llm = getModel("xiaomi-token-plan-ams", "mimo-v2.5-pro");
  391. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  392. await testEmptyMessage(llm);
  393. });
  394. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  395. await testEmptyStringMessage(llm);
  396. });
  397. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  398. await testWhitespaceOnlyMessage(llm);
  399. });
  400. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  401. await testEmptyAssistantMessage(llm);
  402. });
  403. },
  404. );
  405. describe.skipIf(!process.env.XIAOMI_TOKEN_PLAN_SGP_API_KEY)(
  406. "Xiaomi MiMo Token Plan (SGP) Provider Empty Messages",
  407. () => {
  408. const llm = getModel("xiaomi-token-plan-sgp", "mimo-v2.5-pro");
  409. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  410. await testEmptyMessage(llm);
  411. });
  412. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  413. await testEmptyStringMessage(llm);
  414. });
  415. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  416. await testWhitespaceOnlyMessage(llm);
  417. });
  418. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  419. await testEmptyAssistantMessage(llm);
  420. });
  421. },
  422. );
  423. describe.skipIf(!process.env.KIMI_API_KEY)("Kimi For Coding Provider Empty Messages", () => {
  424. const llm = getModel("kimi-coding", "kimi-k2-thinking");
  425. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  426. await testEmptyMessage(llm);
  427. });
  428. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  429. await testEmptyStringMessage(llm);
  430. });
  431. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  432. await testWhitespaceOnlyMessage(llm);
  433. });
  434. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  435. await testEmptyAssistantMessage(llm);
  436. });
  437. });
  438. describe.skipIf(!process.env.AI_GATEWAY_API_KEY)("Vercel AI Gateway Provider Empty Messages", () => {
  439. const llm = getModel("vercel-ai-gateway", "google/gemini-2.5-flash");
  440. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  441. await testEmptyMessage(llm);
  442. });
  443. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  444. await testEmptyStringMessage(llm);
  445. });
  446. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  447. await testWhitespaceOnlyMessage(llm);
  448. });
  449. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  450. await testEmptyAssistantMessage(llm);
  451. });
  452. });
  453. describe.skipIf(!hasBedrockCredentials())("Amazon Bedrock Provider Empty Messages", () => {
  454. const llm = getModel("amazon-bedrock", "global.anthropic.claude-sonnet-4-5-20250929-v1:0");
  455. it("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  456. await testEmptyMessage(llm);
  457. });
  458. it("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  459. await testEmptyStringMessage(llm);
  460. });
  461. it("should handle whitespace-only content", { retry: 3, timeout: 30000 }, async () => {
  462. await testWhitespaceOnlyMessage(llm);
  463. });
  464. it("should handle empty assistant message in conversation", { retry: 3, timeout: 30000 }, async () => {
  465. await testEmptyAssistantMessage(llm);
  466. });
  467. });
  468. // =========================================================================
  469. // OAuth-based providers (credentials from ~/.pi/agent/oauth.json)
  470. // =========================================================================
  471. describe("Anthropic OAuth Provider Empty Messages", () => {
  472. const llm = getModel("anthropic", "claude-haiku-4-5");
  473. it.skipIf(!anthropicOAuthToken)("should handle empty content array", { retry: 3, timeout: 30000 }, async () => {
  474. await testEmptyMessage(llm, { apiKey: anthropicOAuthToken });
  475. });
  476. it.skipIf(!anthropicOAuthToken)("should handle empty string content", { retry: 3, timeout: 30000 }, async () => {
  477. await testEmptyStringMessage(llm, { apiKey: anthropicOAuthToken });
  478. });
  479. it.skipIf(!anthropicOAuthToken)(
  480. "should handle whitespace-only content",
  481. { retry: 3, timeout: 30000 },
  482. async () => {
  483. await testWhitespaceOnlyMessage(llm, { apiKey: anthropicOAuthToken });
  484. },
  485. );
  486. it.skipIf(!anthropicOAuthToken)(
  487. "should handle empty assistant message in conversation",
  488. { retry: 3, timeout: 30000 },
  489. async () => {
  490. await testEmptyAssistantMessage(llm, { apiKey: anthropicOAuthToken });
  491. },
  492. );
  493. });
  494. describe("GitHub Copilot Provider Empty Messages", () => {
  495. it.skipIf(!githubCopilotToken)(
  496. "claude-haiku-4.5 - should handle empty content array",
  497. { retry: 3, timeout: 30000 },
  498. async () => {
  499. const llm = getModel("github-copilot", "claude-haiku-4.5");
  500. await testEmptyMessage(llm, { apiKey: githubCopilotToken });
  501. },
  502. );
  503. it.skipIf(!githubCopilotToken)(
  504. "claude-haiku-4.5 - should handle empty string content",
  505. { retry: 3, timeout: 30000 },
  506. async () => {
  507. const llm = getModel("github-copilot", "claude-haiku-4.5");
  508. await testEmptyStringMessage(llm, { apiKey: githubCopilotToken });
  509. },
  510. );
  511. it.skipIf(!githubCopilotToken)(
  512. "claude-haiku-4.5 - should handle whitespace-only content",
  513. { retry: 3, timeout: 30000 },
  514. async () => {
  515. const llm = getModel("github-copilot", "claude-haiku-4.5");
  516. await testWhitespaceOnlyMessage(llm, { apiKey: githubCopilotToken });
  517. },
  518. );
  519. it.skipIf(!githubCopilotToken)(
  520. "claude-haiku-4.5 - should handle empty assistant message in conversation",
  521. { retry: 3, timeout: 30000 },
  522. async () => {
  523. const llm = getModel("github-copilot", "claude-haiku-4.5");
  524. await testEmptyAssistantMessage(llm, { apiKey: githubCopilotToken });
  525. },
  526. );
  527. it.skipIf(!githubCopilotToken)(
  528. "claude-sonnet-4 - should handle empty content array",
  529. { retry: 3, timeout: 30000 },
  530. async () => {
  531. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  532. await testEmptyMessage(llm, { apiKey: githubCopilotToken });
  533. },
  534. );
  535. it.skipIf(!githubCopilotToken)(
  536. "claude-sonnet-4 - should handle empty string content",
  537. { retry: 3, timeout: 30000 },
  538. async () => {
  539. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  540. await testEmptyStringMessage(llm, { apiKey: githubCopilotToken });
  541. },
  542. );
  543. it.skipIf(!githubCopilotToken)(
  544. "claude-sonnet-4 - should handle whitespace-only content",
  545. { retry: 3, timeout: 30000 },
  546. async () => {
  547. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  548. await testWhitespaceOnlyMessage(llm, { apiKey: githubCopilotToken });
  549. },
  550. );
  551. it.skipIf(!githubCopilotToken)(
  552. "claude-sonnet-4 - should handle empty assistant message in conversation",
  553. { retry: 3, timeout: 30000 },
  554. async () => {
  555. const llm = getModel("github-copilot", "claude-sonnet-4.6");
  556. await testEmptyAssistantMessage(llm, { apiKey: githubCopilotToken });
  557. },
  558. );
  559. });
  560. describe("OpenAI Codex Provider Empty Messages", () => {
  561. it.skipIf(!openaiCodexToken)(
  562. "gpt-5.5 - should handle empty content array",
  563. { retry: 3, timeout: 30000 },
  564. async () => {
  565. const llm = getModel("openai-codex", "gpt-5.5");
  566. await testEmptyMessage(llm, { apiKey: openaiCodexToken });
  567. },
  568. );
  569. it.skipIf(!openaiCodexToken)(
  570. "gpt-5.5 - should handle empty string content",
  571. { retry: 3, timeout: 30000 },
  572. async () => {
  573. const llm = getModel("openai-codex", "gpt-5.5");
  574. await testEmptyStringMessage(llm, { apiKey: openaiCodexToken });
  575. },
  576. );
  577. it.skipIf(!openaiCodexToken)(
  578. "gpt-5.5 - should handle whitespace-only content",
  579. { retry: 3, timeout: 30000 },
  580. async () => {
  581. const llm = getModel("openai-codex", "gpt-5.5");
  582. await testWhitespaceOnlyMessage(llm, { apiKey: openaiCodexToken });
  583. },
  584. );
  585. it.skipIf(!openaiCodexToken)(
  586. "gpt-5.5 - should handle empty assistant message in conversation",
  587. { retry: 3, timeout: 30000 },
  588. async () => {
  589. const llm = getModel("openai-codex", "gpt-5.5");
  590. await testEmptyAssistantMessage(llm, { apiKey: openaiCodexToken });
  591. },
  592. );
  593. });
  594. });