Skip to content

Commit 03541b4

Browse files
committed
test(e2e): 移除多处测试调试信息并优化 runCli 调用参数
- 从 file-upload.e2e.test.ts 中删除无用的调试日志代码 - global-setup.ts 中清理环境变量调试打印信息 - knowledge-chat.e2e.test.ts 和 knowledge-search.e2e.test.ts 中去除多余的环境变量传入 - knowledge.e2e.test.ts 中调整 runCli 调用,统一简化测试参数 - commands/knowledge 下 chat.ts 与 search.ts 增加 skipDefaultApiKeySetup 标记,避免默认 API Key 初始化
1 parent 6dd206e commit 03541b4

7 files changed

Lines changed: 247 additions & 355 deletions

File tree

packages/cli/tests/e2e/file-upload.e2e.test.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { describe, expect, test } from "vite-plus/test";
22
import { dirname, join } from "path";
33
import { fileURLToPath } from "url";
4-
import { homedir } from "os";
5-
import { existsSync, readFileSync } from "fs";
6-
import { isBailianE2EEnabled, isDashScopeE2EReady, parseStdoutJson, runCli } from "./helpers.ts";
7-
import { readConfigFile } from "bailian-cli-core";
4+
import { isDashScopeE2EReady, parseStdoutJson, runCli } from "./helpers.ts";
85

96
const __dirname = dirname(fileURLToPath(import.meta.url));
107

@@ -27,36 +24,6 @@ describe("e2e: file upload", () => {
2724
});
2825
});
2926

30-
// === DEBUG: 深入排查 readConfigFile 来源 ===
31-
const _configPath = join(homedir(), ".bailian", "config.json");
32-
const _configDir = process.env.BAILIAN_CONFIG_DIR;
33-
const _homedir = homedir();
34-
const _homeEnv = process.env.HOME;
35-
console.log(
36-
"[worker:file-upload] DASHSCOPE_API_KEY =",
37-
JSON.stringify(process.env.DASHSCOPE_API_KEY),
38-
);
39-
console.log("[worker:file-upload] isDashScopeE2EReady() =", isDashScopeE2EReady());
40-
console.log("[worker:file-upload] isBailianE2EEnabled() =", isBailianE2EEnabled());
41-
console.log("[worker:file-upload] homedir() =", JSON.stringify(_homedir));
42-
console.log("[worker:file-upload] process.env.HOME =", JSON.stringify(_homeEnv));
43-
console.log("[worker:file-upload] BAILIAN_CONFIG_DIR =", JSON.stringify(_configDir));
44-
console.log("[worker:file-upload] configPath (homedir) =", JSON.stringify(_configPath));
45-
console.log("[worker:file-upload] configPath exists =", existsSync(_configPath));
46-
try {
47-
const _cfg = readConfigFile();
48-
console.log("[worker:file-upload] readConfigFile() =", JSON.stringify(_cfg));
49-
console.log("[worker:file-upload] readConfigFile().api_key =", JSON.stringify(_cfg.api_key));
50-
console.log("[worker:file-upload] readConfigFile().api_key length =", _cfg.api_key?.length);
51-
} catch (err) {
52-
console.log("[worker:file-upload] readConfigFile() threw:", err);
53-
}
54-
// 如果文件存在,直接读内容
55-
if (existsSync(_configPath)) {
56-
console.log("[worker:file-upload] RAW config.json content =", readFileSync(_configPath, "utf8"));
57-
}
58-
// === DEBUG END ===
59-
6027
describe.skipIf(!isDashScopeE2EReady())("e2e: file upload(DashScope)", () => {
6128
test("file upload 缺少 --file 时打印子命令帮助并退出 (0)", async () => {
6229
const { stderr, exitCode } = await runCli([

packages/cli/tests/e2e/global-setup.ts

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
22
import { join } from "path";
33
import { parseEnv } from "util";
4-
import {
5-
E2E_RUN_SESSION_FILENAME,
6-
isDashScopeE2EReady,
7-
isConsoleE2EReady,
8-
isKnowledgeE2EReady,
9-
monorepoRoot,
10-
} from "./helpers.ts";
4+
import { E2E_RUN_SESSION_FILENAME, monorepoRoot } from "./helpers.ts";
115

126
/**
137
* Vitest 在所有 worker 启动前执行一次:写入共享会话 id,使多进程并行时仍共用一个 `test/output/<会话>/`。
@@ -50,37 +44,6 @@ BAILIAN_E2E_INDEX_ID=
5044
writeFileSync(rootEnv, envContent, "utf8");
5145
}
5246

53-
// === DEBUG: 排查 CI 中 DASHSCOPE_API_KEY 来源 ===
54-
console.log("\n========== [global-setup] DEBUG ==========");
55-
console.log("[global-setup] CI =", JSON.stringify(process.env.CI));
56-
console.log("[global-setup] BAILIAN_E2E =", JSON.stringify(process.env.BAILIAN_E2E));
57-
console.log("[global-setup] DASHSCOPE_API_KEY =", JSON.stringify(process.env.DASHSCOPE_API_KEY));
58-
console.log(
59-
"[global-setup] DASHSCOPE_API_KEY.trim() =",
60-
JSON.stringify(process.env.DASHSCOPE_API_KEY?.trim()),
61-
);
62-
console.log(
63-
"[global-setup] DASHSCOPE_ACCESS_TOKEN =",
64-
JSON.stringify(process.env.DASHSCOPE_ACCESS_TOKEN),
65-
);
66-
console.log(
67-
"[global-setup] BAILIAN_E2E_INDEX_ID =",
68-
JSON.stringify(process.env.BAILIAN_E2E_INDEX_ID),
69-
);
70-
console.log("[global-setup] isDashScopeE2EReady() =", isDashScopeE2EReady());
71-
console.log("[global-setup] isConsoleE2EReady() =", isConsoleE2EReady());
72-
console.log("[global-setup] isKnowledgeE2EReady() =", isKnowledgeE2EReady());
73-
try {
74-
const cfg = JSON.parse(
75-
readFileSync(join(process.env.HOME || "", ".bailian", "config.json"), "utf8"),
76-
);
77-
console.log("[global-setup] ~/.bailian/config.json exists, keys =", Object.keys(cfg));
78-
console.log("[global-setup] config.api_key length =", cfg.api_key?.length);
79-
} catch {
80-
console.log("[global-setup] ~/.bailian/config.json not found or unreadable");
81-
}
82-
console.log("========== [global-setup] DEBUG END ==========\n");
83-
8447
// 创建生成内容目录
8548
const now = new Date();
8649
const pad = (n: number) => n.toString().padStart(2, "0");

packages/cli/tests/e2e/knowledge-chat.e2e.test.ts

Lines changed: 89 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { tmpdir } from "os";
21
import { describe, expect, test } from "vite-plus/test";
32
import { parseStdoutJson, runCli } from "./helpers.ts";
43

@@ -33,64 +32,60 @@ describe("e2e: knowledge chat", () => {
3332
});
3433

3534
test("缺少 --message 时打印帮助并退出 (0)", async () => {
36-
const { stderr, exitCode } = await runCli(
37-
["knowledge", "chat", "--agent-id", "aid_test", "--non-interactive"],
38-
{ DASHSCOPE_API_KEY: "sk-fake", BAILIAN_CONFIG_DIR: tmpdir() },
39-
);
35+
const { stderr, exitCode } = await runCli([
36+
"knowledge",
37+
"chat",
38+
"--agent-id",
39+
"aid_test",
40+
"--non-interactive",
41+
]);
4042
expect(exitCode).toBe(0);
4143
expect(stderr).toMatch(/--message|Usage:/i);
4244
});
4345

4446
test("缺少 --agent-id 时打印帮助并退出 (0)", async () => {
45-
const { stderr, exitCode } = await runCli(
46-
["knowledge", "chat", "--message", "Hello", "--non-interactive"],
47-
{ DASHSCOPE_API_KEY: "sk-fake", BAILIAN_CONFIG_DIR: tmpdir() },
48-
);
47+
const { stderr, exitCode } = await runCli([
48+
"knowledge",
49+
"chat",
50+
"--message",
51+
"Hello",
52+
"--non-interactive",
53+
]);
4954
expect(exitCode).toBe(0);
5055
expect(stderr).toMatch(/--agent-id|Usage:/i);
5156
});
5257

5358
test("缺少 --workspace-id 时非零退出并提示", async () => {
54-
const { stderr, exitCode } = await runCli(
55-
[
56-
"knowledge",
57-
"chat",
58-
"--message",
59-
"Hello",
60-
"--agent-id",
61-
"aid_test",
62-
"--non-interactive",
63-
"--output",
64-
"json",
65-
],
66-
{
67-
DASHSCOPE_API_KEY: "sk-fake",
68-
BAILIAN_WORKSPACE_ID: undefined,
69-
BAILIAN_CONFIG_DIR: tmpdir(),
70-
},
71-
);
59+
const { stderr, exitCode } = await runCli([
60+
"knowledge",
61+
"chat",
62+
"--message",
63+
"Hello",
64+
"--agent-id",
65+
"aid_test",
66+
"--non-interactive",
67+
"--output",
68+
"json",
69+
]);
7270
expect(exitCode).not.toBe(0);
7371
expect(stderr).toMatch(/workspace.*required/i);
7472
});
7573

7674
test("--dry-run 输出 endpoint 和 request body", async () => {
77-
const { stdout, stderr, exitCode } = await runCli(
78-
[
79-
"knowledge",
80-
"chat",
81-
"--dry-run",
82-
"--message",
83-
"什么是RAG",
84-
"--agent-id",
85-
"aid_test",
86-
"--workspace-id",
87-
"ws_test",
88-
"--non-interactive",
89-
"--output",
90-
"json",
91-
],
92-
{ DASHSCOPE_API_KEY: "sk-fake-for-dryrun" },
93-
);
75+
const { stdout, stderr, exitCode } = await runCli([
76+
"knowledge",
77+
"chat",
78+
"--dry-run",
79+
"--message",
80+
"什么是RAG",
81+
"--agent-id",
82+
"aid_test",
83+
"--workspace-id",
84+
"ws_test",
85+
"--non-interactive",
86+
"--output",
87+
"json",
88+
]);
9489
expect(exitCode, stderr).toBe(0);
9590
const data = parseStdoutJson<DryRunBody>(stdout);
9691
expect(data.endpoint).toMatch(/ws_test\.cn-beijing\.maas\.aliyuncs\.com/);
@@ -101,27 +96,24 @@ describe("e2e: knowledge chat", () => {
10196
});
10297

10398
test("--dry-run 多轮消息解析 role:content 前缀", async () => {
104-
const { stdout, stderr, exitCode } = await runCli(
105-
[
106-
"knowledge",
107-
"chat",
108-
"--dry-run",
109-
"--message",
110-
"user:什么是RAG",
111-
"--message",
112-
"assistant:RAG是检索增强生成",
113-
"--message",
114-
"它怎么工作",
115-
"--agent-id",
116-
"aid_test",
117-
"--workspace-id",
118-
"ws_test",
119-
"--non-interactive",
120-
"--output",
121-
"json",
122-
],
123-
{ DASHSCOPE_API_KEY: "sk-fake-for-dryrun" },
124-
);
99+
const { stdout, stderr, exitCode } = await runCli([
100+
"knowledge",
101+
"chat",
102+
"--dry-run",
103+
"--message",
104+
"user:什么是RAG",
105+
"--message",
106+
"assistant:RAG是检索增强生成",
107+
"--message",
108+
"它怎么工作",
109+
"--agent-id",
110+
"aid_test",
111+
"--workspace-id",
112+
"ws_test",
113+
"--non-interactive",
114+
"--output",
115+
"json",
116+
]);
125117
expect(exitCode, stderr).toBe(0);
126118
const data = parseStdoutJson<DryRunBody>(stdout);
127119
const msgs = data.request?.input?.messages ?? [];
@@ -135,25 +127,22 @@ describe("e2e: knowledge chat", () => {
135127
});
136128

137129
test("--dry-run + --image 输出多模态 content 数组", async () => {
138-
const { stdout, stderr, exitCode } = await runCli(
139-
[
140-
"knowledge",
141-
"chat",
142-
"--dry-run",
143-
"--message",
144-
"描述这张图",
145-
"--agent-id",
146-
"aid_test",
147-
"--workspace-id",
148-
"ws_test",
149-
"--image",
150-
"https://example.com/img.jpg",
151-
"--non-interactive",
152-
"--output",
153-
"json",
154-
],
155-
{ DASHSCOPE_API_KEY: "sk-fake-for-dryrun" },
156-
);
130+
const { stdout, stderr, exitCode } = await runCli([
131+
"knowledge",
132+
"chat",
133+
"--dry-run",
134+
"--message",
135+
"描述这张图",
136+
"--agent-id",
137+
"aid_test",
138+
"--workspace-id",
139+
"ws_test",
140+
"--image",
141+
"https://example.com/img.jpg",
142+
"--non-interactive",
143+
"--output",
144+
"json",
145+
]);
157146
expect(exitCode, stderr).toBe(0);
158147
const data = parseStdoutJson<DryRunBody>(stdout);
159148
const lastMsg = data.request?.input?.messages?.[0];
@@ -168,25 +157,22 @@ describe("e2e: knowledge chat", () => {
168157
});
169158

170159
test("--dry-run + --image 无 --message 自动创建空 user message", async () => {
171-
const { stdout, stderr, exitCode } = await runCli(
172-
[
173-
"knowledge",
174-
"chat",
175-
"--dry-run",
176-
"--agent-id",
177-
"aid_test",
178-
"--workspace-id",
179-
"ws_test",
180-
"--image",
181-
"https://example.com/a.png",
182-
"--image",
183-
"https://example.com/b.png",
184-
"--non-interactive",
185-
"--output",
186-
"json",
187-
],
188-
{ DASHSCOPE_API_KEY: "sk-fake-for-dryrun" },
189-
);
160+
const { stdout, stderr, exitCode } = await runCli([
161+
"knowledge",
162+
"chat",
163+
"--dry-run",
164+
"--agent-id",
165+
"aid_test",
166+
"--workspace-id",
167+
"ws_test",
168+
"--image",
169+
"https://example.com/a.png",
170+
"--image",
171+
"https://example.com/b.png",
172+
"--non-interactive",
173+
"--output",
174+
"json",
175+
]);
190176
expect(exitCode, stderr).toBe(0);
191177
const data = parseStdoutJson<DryRunBody>(stdout);
192178
const lastMsg = data.request?.input?.messages?.[0];

0 commit comments

Comments
 (0)