Files
modelstudioai__cli/packages/commands/tests/knowledge/knowledge-upload-support.test.ts
T
zeyu.fz 43abf0aca5 feat(knowledge): 新增知识库管理及用户旅程端到端测试支持
- 增加test:journey脚本,覆盖知识库跨命令全链路用户旅程测试
- 在文档中新增Journey E2E章节,详细说明用户旅程测试定位及断言机制
- 完善commands模块,新增知识库相关命令包括知识库列表、信息、创建、更新、删除
- 新增知识库文档相关命令,如文档列表、状态、上传、删除、打标签及OSS导入
- 添加知识服务管理命令,支持列表、创建、更新、部署、删除及复制
- 支持知识块增删查改命令,完善知识点的灵活操作能力
- 实现数据中心分类管理命令,支持分类增删查操作
- 优化knowledge chat命令,增加workspace-id统一解析及agent-version版本控制
- 重构与知识库相关命令的导出与注册,完善CLI整体能力覆盖
- 新增命令详尽的帮助文档,包含参数说明、使用示例及错误边界
- 实现批量删除知识块的自动分批处理逻辑,易于操作大规模数据
- 添加必要的输入校验与安全提示,确保操作安全且符合规范
2026-08-05 12:02:32 +08:00

63 lines
2.3 KiB
TypeScript

import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, test } from "vite-plus/test";
import { ExitCode } from "bailian-cli-core";
import {
checkUploadFile,
UPLOAD_FORMAT_RULES,
} from "../../src/commands/knowledge/upload-support.ts";
const fixtureDir = mkdtempSync(join(tmpdir(), "upload-support-"));
function writeFixture(fileName: string, content: string): string {
const filePath = join(fixtureDir, fileName);
writeFileSync(filePath, content);
return filePath;
}
describe("checkUploadFile", () => {
test("白名单内的小文件通过且无警告", () => {
const filePath = writeFixture("note.md", "# hello");
const result = checkUploadFile(filePath);
expect(result.sizeBytes).toBeGreaterThan(0);
expect(result.warning).toBeUndefined();
});
test("白名单外扩展名 (.zip) 抛 USAGE 并列出支持格式", () => {
const filePath = writeFixture("archive.zip", "PK");
try {
checkUploadFile(filePath);
expect.unreachable("should throw");
} catch (error) {
expect((error as { exitCode: number }).exitCode).toBe(ExitCode.USAGE);
expect((error as { hint?: string }).hint).toMatch(/\.pdf/);
}
});
test("文件不存在抛 GENERAL 且 hint 含 errno", () => {
try {
checkUploadFile(join(fixtureDir, "missing.md"));
expect.unreachable("should throw");
} catch (error) {
expect((error as { exitCode: number }).exitCode).toBe(ExitCode.GENERAL);
expect((error as { hint?: string }).hint).toMatch(/ENOENT/);
}
});
test("软限类型 (.md) 超 10MB 返回警告不拦截", () => {
const filePath = writeFixture("big.md", "x".repeat(11 * 1024 * 1024));
const result = checkUploadFile(filePath);
expect(result.warning).toMatch(/10 MB/);
});
});
describe("UPLOAD_FORMAT_RULES", () => {
test("硬限/软限分类符合设计表", () => {
expect(UPLOAD_FORMAT_RULES[".pdf"]).toEqual({ maxBytes: 150 * 1024 * 1024, enforce: "block" });
expect(UPLOAD_FORMAT_RULES[".png"]).toEqual({ maxBytes: 20 * 1024 * 1024, enforce: "block" });
expect(UPLOAD_FORMAT_RULES[".xlsx"]).toEqual({ maxBytes: 10 * 1024 * 1024, enforce: "warn" });
expect(UPLOAD_FORMAT_RULES[".csv"]).toBeDefined(); // inconsistent across public docs; kept in the allowlist
});
});