diff --git a/packages/kscli/tests/e2e/chat.e2e.test.ts b/packages/kscli/tests/e2e/chat.e2e.test.ts deleted file mode 100644 index 0286ab2..0000000 --- a/packages/kscli/tests/e2e/chat.e2e.test.ts +++ /dev/null @@ -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(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(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(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(); - }); -}); diff --git a/packages/kscli/tests/e2e/search.e2e.test.ts b/packages/kscli/tests/e2e/search.e2e.test.ts deleted file mode 100644 index 77518c6..0000000 --- a/packages/kscli/tests/e2e/search.e2e.test.ts +++ /dev/null @@ -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(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(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(); - }); -});