debug(cli): 增加文件上传测试对配置文件读取的调试日志

- 添加对用户主目录下配置文件路径的打印和存在性检查
- 打印环境变量 HOME 及 BAILIAN_CONFIG_DIR 的值
- 调用 readConfigFile 并打印返回内容及 api_key 相关信息
- 捕获并打印 readConfigFile 的异常信息
- 如果配置文件存在,读取并打印其原始内容
- 保留现有环境变量和功能状态的调试输出
This commit is contained in:
zeyu.fz
2026-07-02 16:08:36 +08:00
parent e2efcfda77
commit 6dd206eda9
+25 -1
View File
@@ -1,7 +1,10 @@
import { describe, expect, test } from "vite-plus/test";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import { homedir } from "os";
import { existsSync, readFileSync } from "fs";
import { isBailianE2EEnabled, isDashScopeE2EReady, parseStdoutJson, runCli } from "./helpers.ts";
import { readConfigFile } from "bailian-cli-core";
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -24,13 +27,34 @@ describe("e2e: file upload", () => {
});
});
// === DEBUG: worker 进程中的环境变量 ===
// === DEBUG: 深入排查 readConfigFile 来源 ===
const _configPath = join(homedir(), ".bailian", "config.json");
const _configDir = process.env.BAILIAN_CONFIG_DIR;
const _homedir = homedir();
const _homeEnv = process.env.HOME;
console.log(
"[worker:file-upload] DASHSCOPE_API_KEY =",
JSON.stringify(process.env.DASHSCOPE_API_KEY),
);
console.log("[worker:file-upload] isDashScopeE2EReady() =", isDashScopeE2EReady());
console.log("[worker:file-upload] isBailianE2EEnabled() =", isBailianE2EEnabled());
console.log("[worker:file-upload] homedir() =", JSON.stringify(_homedir));
console.log("[worker:file-upload] process.env.HOME =", JSON.stringify(_homeEnv));
console.log("[worker:file-upload] BAILIAN_CONFIG_DIR =", JSON.stringify(_configDir));
console.log("[worker:file-upload] configPath (homedir) =", JSON.stringify(_configPath));
console.log("[worker:file-upload] configPath exists =", existsSync(_configPath));
try {
const _cfg = readConfigFile();
console.log("[worker:file-upload] readConfigFile() =", JSON.stringify(_cfg));
console.log("[worker:file-upload] readConfigFile().api_key =", JSON.stringify(_cfg.api_key));
console.log("[worker:file-upload] readConfigFile().api_key length =", _cfg.api_key?.length);
} catch (err) {
console.log("[worker:file-upload] readConfigFile() threw:", err);
}
// 如果文件存在,直接读内容
if (existsSync(_configPath)) {
console.log("[worker:file-upload] RAW config.json content =", readFileSync(_configPath, "utf8"));
}
// === DEBUG END ===
describe.skipIf(!isDashScopeE2EReady())("e2e: file uploadDashScope", () => {