

























@@ -1297,6 +1297,69 @@ describe("createOllamaStreamFn streaming events", () => {
12971297);
12981298});
129912991300+it("emits an error instead of accepting garbled Kimi visible text", async () => {
1301+const garbled =
1302+'$$"##"%#"##"####""$""""##""$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' +
1303+'#"$"$"""$""""#$"""$"""%"%###"""#%""""&"#"""$"""#"#""""%#""""&"#"""$"""$"""#%"""';
1304+await withMockNdjsonFetch(
1305+[
1306+JSON.stringify({
1307+model: "kimi-k2.5:cloud",
1308+created_at: "t",
1309+message: { role: "assistant", content: garbled },
1310+done: false,
1311+}),
1312+'{"model":"kimi-k2.5:cloud","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":20,"eval_count":40}',
1313+],
1314+async () => {
1315+const stream = await createOllamaTestStream({
1316+baseUrl: "http://ollama-host:11434",
1317+model: { id: "kimi-k2.5:cloud", provider: "ollama" },
1318+});
1319+const events = await collectStreamEvents(stream);
1320+1321+const types = events.map((e) => e.type);
1322+expect(types).toEqual(["start", "text_start", "text_delta", "error"]);
1323+const errorEvent = events.at(-1);
1324+expect(errorEvent).toMatchObject({
1325+type: "error",
1326+error: expect.objectContaining({
1327+errorMessage: expect.stringContaining("garbled visible text"),
1328+}),
1329+});
1330+},
1331+);
1332+});
1333+1334+it("does not reject punctuation-heavy text from unrelated Ollama models", async () => {
1335+const punctuationHeavy =
1336+'$$"##"%#"##"####""$""""##""$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' +
1337+'#"$"$"""$""""#$"""$"""%"%###"""#%""""&"#"""$"""#"#""""%#""""&"#"""$"""$"""#%"""';
1338+await withMockNdjsonFetch(
1339+[
1340+JSON.stringify({
1341+model: "qwen3:32b",
1342+created_at: "t",
1343+message: { role: "assistant", content: punctuationHeavy },
1344+done: false,
1345+}),
1346+'{"model":"qwen3:32b","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":20,"eval_count":40}',
1347+],
1348+async () => {
1349+const stream = await createOllamaTestStream({ baseUrl: "http://ollama-host:11434" });
1350+const events = await collectStreamEvents(stream);
1351+1352+expect(events.map((e) => e.type)).toEqual([
1353+"start",
1354+"text_start",
1355+"text_delta",
1356+"text_end",
1357+"done",
1358+]);
1359+},
1360+);
1361+});
1362+13001363it("emits a single text_delta for single-chunk responses", async () => {
13011364await withMockNdjsonFetch(
13021365[
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。