mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
test(e2e): 删除kscli的chat和search端到端测试
- 移除chat命令的多种输出模式测试(JSON、文本、流模式) - 删除多轮对话上下文感知回答的测试用例 - 删除chat命令无效agent_id时的容错测试 - 移除search命令的JSON和文本模式搜索测试 - 删除带查询历史的搜索功能测试 - 删除search命令无效agent_id时的错误处理测试 - 清理与测试相关的类型定义和辅助函数调用
This commit is contained in:
@@ -1,137 +0,0 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { isChatE2EReady, parseStdoutJson, runKscli } from "./helpers.ts";
|
||||
|
||||
// ---- Types ----
|
||||
|
||||
interface ChatJsonResult {
|
||||
answer: string;
|
||||
request_id: string;
|
||||
}
|
||||
|
||||
// ---- Real API call tests (gated by BAILIAN_E2E + credentials) ----
|
||||
|
||||
describe.skipIf(!isChatE2EReady())("e2e: kscli chat (live)", () => {
|
||||
const agentId = process.env.BAILIAN_E2E_CHAT_AGENT_ID!;
|
||||
const workspaceId = process.env.BAILIAN_WORKSPACE_ID!;
|
||||
|
||||
test("chat (JSON mode) returns answer", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"chat",
|
||||
"--message",
|
||||
"什么是大模型?",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<ChatJsonResult>(stdout);
|
||||
expect(data.answer).toBeTruthy();
|
||||
expect(data.answer.length).toBeGreaterThan(0);
|
||||
expect(data.request_id).toBeTruthy();
|
||||
});
|
||||
|
||||
test("chat (text mode) returns plain text", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"chat",
|
||||
"--message",
|
||||
"什么是RAG?",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"text",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
expect(stdout.trim().length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("chat (stream, JSON mode) collects and returns answer", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"chat",
|
||||
"--message",
|
||||
"什么是检索增强生成?",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<ChatJsonResult>(stdout);
|
||||
expect(data.answer).toBeTruthy();
|
||||
expect(data.answer.length).toBeGreaterThan(0);
|
||||
expect(data.request_id).toBeTruthy();
|
||||
});
|
||||
|
||||
test("chat (stream, text mode) outputs streaming text", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"chat",
|
||||
"--message",
|
||||
"什么是向量检索?",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"text",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
// Streaming text mode: output should contain some text content
|
||||
expect(stdout.trim().length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("chat with multi-turn messages returns context-aware answer", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"chat",
|
||||
"--message",
|
||||
"user:什么是大模型",
|
||||
"--message",
|
||||
"assistant:大模型是大规模语言模型,具有强大的理解和生成能力",
|
||||
"--message",
|
||||
"它有哪些应用场景?",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<ChatJsonResult>(stdout);
|
||||
expect(data.answer).toBeTruthy();
|
||||
expect(data.answer.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("chat with invalid agent_id fails gracefully", async () => {
|
||||
const { stderr, exitCode } = await runKscli([
|
||||
"chat",
|
||||
"--message",
|
||||
"test",
|
||||
"--agent-id",
|
||||
"aid-invalid-not-exist",
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode).not.toBe(0);
|
||||
expect(stderr).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,126 +0,0 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { isSearchE2EReady, parseStdoutJson, runKscli } from "./helpers.ts";
|
||||
|
||||
// ---- Types ----
|
||||
|
||||
interface SearchResponse {
|
||||
code: string;
|
||||
status_code: number;
|
||||
request_id: string;
|
||||
data: {
|
||||
total: number;
|
||||
cost_time: number;
|
||||
nodes: Array<{
|
||||
score: number;
|
||||
text: string;
|
||||
metadata: {
|
||||
content?: string;
|
||||
title?: string;
|
||||
doc_id?: string;
|
||||
doc_name?: string;
|
||||
doc_url?: string;
|
||||
pipeline_id?: string;
|
||||
workspace_id?: string;
|
||||
page_number?: number;
|
||||
image_url?: string;
|
||||
_knowledge_type?: string;
|
||||
_citation_index?: number;
|
||||
_score?: number;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
// ---- Real API call tests (gated by BAILIAN_E2E + credentials) ----
|
||||
|
||||
describe.skipIf(!isSearchE2EReady())("e2e: kscli search (live)", () => {
|
||||
const agentId = process.env.BAILIAN_E2E_SEARCH_AGENT_ID!;
|
||||
const workspaceId = process.env.BAILIAN_WORKSPACE_ID!;
|
||||
|
||||
test("search returns results in JSON mode", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"search",
|
||||
"--query",
|
||||
"什么是大模型",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<SearchResponse>(stdout);
|
||||
expect(data.code).toBe("Success");
|
||||
expect(data.request_id).toBeTruthy();
|
||||
expect(data.data.total).toBeGreaterThan(0);
|
||||
expect(data.data.nodes.length).toBeGreaterThan(0);
|
||||
|
||||
const firstNode = data.data.nodes[0]!;
|
||||
expect(typeof firstNode.score).toBe("number");
|
||||
expect(firstNode.score).toBeGreaterThanOrEqual(0);
|
||||
expect(typeof firstNode.text).toBe("string");
|
||||
expect(firstNode.text.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("search returns results in text mode", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"search",
|
||||
"--query",
|
||||
"RAG",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"text",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
// Text mode: [1] (score: 0.xxxx) followed by text content
|
||||
expect(stdout).toMatch(/\[1\].*score/);
|
||||
});
|
||||
|
||||
test("search with --query-history returns results", async () => {
|
||||
const { stdout, stderr, exitCode } = await runKscli([
|
||||
"search",
|
||||
"--query",
|
||||
"它怎么工作",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--query-history",
|
||||
'[{"role":"user","content":"什么是大模型"},{"role":"assistant","content":"大模型是大规模语言模型"}]',
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<SearchResponse>(stdout);
|
||||
expect(data.code).toBe("Success");
|
||||
expect(data.data.nodes.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("search with invalid agent_id fails gracefully", async () => {
|
||||
const { stderr, exitCode } = await runKscli([
|
||||
"search",
|
||||
"--query",
|
||||
"test",
|
||||
"--agent-id",
|
||||
"aid-invalid-not-exist",
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode).not.toBe(0);
|
||||
expect(stderr).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user