mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
d24104f7dc
包名 @ali/bailian-kb-dsh → bailian-kb-dsh(公开 npm):package.json name + cordis.patch.yml insert.name + tsdown PLUGIN_ID 三处同步(漏一处即 dsh 运行时崩)。 产物 lib/ → dist/(本仓 .gitignore 忽略 dist 不忽略 lib),连带 main/types/ exports/files/tsdown outDir 同步;.gitignore 补 *.tsbuildinfo。 依赖接 catalog(yaml/typescript/@types/node/vite-plus);测试导入 vitest → vite-plus/test(全仓统一约定,消掉唯一的 vitest 依赖漂移)。 tsconfig 拆三件套:tsconfig.json 纯类型检查覆盖 src+tests(供 oxlint 自动发现, 含 jsx/DOM),tsconfig.build.json 产出 node 半,tsconfig.web.json 隔离检查 web 半。 补齐 tests 从未被类型检查暴露的一处 partial 输入类型错误。 根 vite.config.ts 新增两条 override:web 半 no-restricted-imports 把 tsdown 构建期 的 bundle purity gate 提前到 lint 期;全包放开 _ 前缀的 no-unused-vars。 文档:新增 docs/agents/dsh-plugin.md,AGENTS.md 项目地图/版本锁步例外/分层边界/ 场景索引同步,packages.mjs 注释说明故意不进发布白名单。 格式化(单引号无分号 → 双引号加分号)由 pre-commit 的 vp check --fix 自动完成, 无法单独成 commit,一并纳入。 全仓 vp check 0 error;插件 13 文件 85 测试全绿;build + typecheck 通过。
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
import { consumeChatStream } from "../src/chat.js";
|
|
|
|
function sse(text: string): Response {
|
|
return new Response(text, { status: 200 });
|
|
}
|
|
|
|
function chunk(content: string, finish = ""): string {
|
|
return `data: ${JSON.stringify({ output: { choices: [{ message: { content }, finish_reason: finish }] }, request_id: "r-1" })}\n\n`;
|
|
}
|
|
|
|
describe("consumeChatStream", () => {
|
|
it("concatenates delta content across chunks until [DONE]", async () => {
|
|
const res = sse(chunk("Hello") + chunk(" world", "stop") + "data: [DONE]\n\n");
|
|
const out = await consumeChatStream(res);
|
|
expect(out.answer).toBe("Hello world");
|
|
expect(out.requestId).toBe("r-1");
|
|
});
|
|
|
|
it("ignores step_change progress chunks with empty content", async () => {
|
|
const progress = `data: ${JSON.stringify({ output: { choices: [{ message: { content: "", extra: { step_change: "tool_calling" } }, finish_reason: "" }] } })}\n\n`;
|
|
const res = sse(progress + chunk("answer", "stop") + "data: [DONE]\n\n");
|
|
expect((await consumeChatStream(res)).answer).toBe("answer");
|
|
});
|
|
|
|
it("throws on an SSE error event with the server message", async () => {
|
|
const res = sse('event: error\ndata: {"code":"Throttling","message":"rate limited"}\n\n');
|
|
await expect(consumeChatStream(res)).rejects.toThrow(/Throttling.*rate limited/);
|
|
});
|
|
});
|