|
1 | 1 | import { tmpdir } from "os"; |
2 | 2 | import { describe, expect, test } from "vite-plus/test"; |
3 | | -import { isDashScopeE2EReady, isKnowledgeAkSkReady, parseStdoutJson, runCli } from "./helpers.ts"; |
| 3 | +import { parseStdoutJson, runCli } from "./helpers.ts"; |
4 | 4 |
|
5 | 5 | // ---- Types ---- |
6 | 6 |
|
7 | | -interface ApiKeyRetrieveBody { |
8 | | - request_id?: string; |
9 | | - data?: { total?: number; nodes?: Array<{ text: string; score: number }> }; |
10 | | - code?: string; |
11 | | - message?: string; |
12 | | -} |
13 | | - |
14 | | -interface AkSkRetrieveBody { |
15 | | - Success?: boolean; |
16 | | - Code?: string; |
17 | | - Data?: { Nodes?: Array<{ Text: string; Score: number }> }; |
18 | | -} |
19 | | - |
20 | 7 | interface DryRunBody { |
21 | 8 | endpoint?: string; |
22 | 9 | request?: { |
@@ -48,7 +35,7 @@ describe("e2e: knowledge retrieve", () => { |
48 | 35 | expect(stderr).toMatch(/--query/i); |
49 | 36 | expect(stderr).toMatch(/--rerank-top-n/i); |
50 | 37 | expect(stderr).toMatch(/deprecated/i); |
51 | | - expect(stderr).toMatch(/API-KEY only/i); |
| 38 | + expect(stderr).toMatch(/--workspace-id/i); |
52 | 39 | }); |
53 | 40 |
|
54 | 41 | test("缺少 --index-id 时打印帮助并退出 (0)", async () => { |
@@ -217,102 +204,3 @@ describe("e2e: knowledge retrieve dry-run", () => { |
217 | 204 | expect(data.request?.rerank?.[0]?.rerank_instruct).toBe("按相关性排序"); |
218 | 205 | }); |
219 | 206 | }); |
220 | | - |
221 | | -// ---- API-KEY path (real network call) ---- |
222 | | - |
223 | | -describe.skipIf(!isDashScopeE2EReady() || !process.env.BAILIAN_E2E_INDEX_ID)( |
224 | | - "e2e: knowledge retrieve (API-KEY)", |
225 | | - () => { |
226 | | - test("API-KEY 知识库检索", async () => { |
227 | | - const indexId = process.env.BAILIAN_E2E_INDEX_ID!; |
228 | | - const { stdout, stderr, exitCode } = await runCli([ |
229 | | - "knowledge", |
230 | | - "retrieve", |
231 | | - "--index-id", |
232 | | - indexId, |
233 | | - "--query", |
234 | | - "端到端检索测试", |
235 | | - "--rerank-top-n", |
236 | | - "3", |
237 | | - "--non-interactive", |
238 | | - "--output", |
239 | | - "json", |
240 | | - ]); |
241 | | - expect(exitCode, stderr).toBe(0); |
242 | | - const data = parseStdoutJson<ApiKeyRetrieveBody>(stdout); |
243 | | - expect(Array.isArray(data.data?.nodes)).toBe(true); |
244 | | - }, 120_000); |
245 | | - }, |
246 | | -); |
247 | | - |
248 | | -// ---- API-KEY error paths (real network call) ---- |
249 | | - |
250 | | -describe.skipIf(!isDashScopeE2EReady())("e2e: knowledge retrieve API-KEY errors", () => { |
251 | | - test("无效 API-KEY 返回认证错误", async () => { |
252 | | - const { stderr, exitCode } = await runCli([ |
253 | | - "knowledge", |
254 | | - "retrieve", |
255 | | - "--api-key", |
256 | | - "sk-invalid-key-for-test", |
257 | | - "--index-id", |
258 | | - "idx_test", |
259 | | - "--query", |
260 | | - "test", |
261 | | - "--non-interactive", |
262 | | - "--output", |
263 | | - "json", |
264 | | - ]); |
265 | | - expect(exitCode).not.toBe(0); |
266 | | - expect(stderr).toMatch(/InvalidApiKey|401|auth/i); |
267 | | - }, 30_000); |
268 | | - |
269 | | - test("无效 index_id 返回索引不存在错误", async () => { |
270 | | - const { stderr, exitCode } = await runCli([ |
271 | | - "knowledge", |
272 | | - "retrieve", |
273 | | - "--index-id", |
274 | | - "idx_nonexistent_test", |
275 | | - "--query", |
276 | | - "test", |
277 | | - "--non-interactive", |
278 | | - "--output", |
279 | | - "json", |
280 | | - ]); |
281 | | - expect(exitCode).not.toBe(0); |
282 | | - expect(stderr).toMatch(/IndexNotExist|not exist|400/i); |
283 | | - }, 30_000); |
284 | | -}); |
285 | | - |
286 | | -// ---- AK/SK deprecated path (real network call) ---- |
287 | | - |
288 | | -describe.skipIf(!isKnowledgeAkSkReady())("e2e: knowledge retrieve (AK/SK deprecated)", () => { |
289 | | - test("AK/SK 知识库检索输出废弃警告", async () => { |
290 | | - const indexId = process.env.BAILIAN_E2E_INDEX_ID!; |
291 | | - const { stdout, stderr, exitCode } = await runCli( |
292 | | - [ |
293 | | - "knowledge", |
294 | | - "retrieve", |
295 | | - "--index-id", |
296 | | - indexId, |
297 | | - "--query", |
298 | | - "端到端检索测试", |
299 | | - "--rerank-top-n", |
300 | | - "3", |
301 | | - "--non-interactive", |
302 | | - "--output", |
303 | | - "json", |
304 | | - ], |
305 | | - { |
306 | | - DASHSCOPE_API_KEY: undefined, |
307 | | - DASHSCOPE_ACCESS_TOKEN: undefined, |
308 | | - BAILIAN_CONFIG_DIR: tmpdir(), |
309 | | - }, |
310 | | - ); |
311 | | - expect(exitCode, stderr).toBe(0); |
312 | | - expect(stderr).toMatch(/deprecated/i); |
313 | | - const data = parseStdoutJson<AkSkRetrieveBody>(stdout); |
314 | | - const ok = data.Success === true || data.Code === "Success"; |
315 | | - expect(ok).toBe(true); |
316 | | - expect(Array.isArray(data.Data?.Nodes)).toBe(true); |
317 | | - }, 120_000); |
318 | | -}); |
0 commit comments