diff --git a/packages/cli-workflow/src/__tests__/config.test.ts b/packages/cli-workflow/src/__tests__/config.test.ts index 078c2f2..4f6b5e6 100644 --- a/packages/cli-workflow/src/__tests__/config.test.ts +++ b/packages/cli-workflow/src/__tests__/config.test.ts @@ -143,6 +143,44 @@ defaultModel: default const masked = maskApiKeys(config); expect(masked).toEqual(config); }); + + test("does not mask non-provider apiKey fields", () => { + const config = { + apiKey: "root-level-key", + providers: { + dashscope: { apiKey: "sk-secret" }, + }, + models: { + default: { provider: "dashscope" }, + }, + }; + const masked = maskApiKeys(config); + // Root-level apiKey should NOT be masked + expect(masked.apiKey).toBe("root-level-key"); + // Provider apiKey SHOULD be masked + const providers = masked.providers as Record>; + expect(providers.dashscope.apiKey).toBe("***MASKED***"); + }); + + test("handles empty provider object", () => { + const config = { + providers: { dashscope: {} }, + }; + const masked = maskApiKeys(config); + expect(masked).toEqual({ providers: { dashscope: {} } }); + }); + + test("handles provider with null apiKey", () => { + const config = { + providers: { + dashscope: { apiKey: null, baseUrl: "https://example.com" }, + }, + }; + const masked = maskApiKeys(config); + const providers = masked.providers as Record>; + expect(providers.dashscope.apiKey).toBe("***MASKED***"); + expect(providers.dashscope.baseUrl).toBe("https://example.com"); + }); }); }); @@ -679,4 +717,21 @@ defaultModel: default } }); }); + + describe("no legacy apiKeyEnv references", () => { + test("config.ts has no references to apiKeyEnv", () => { + const configSource = readFileSync(join(__dirname, "..", "commands", "config.ts"), "utf8"); + expect(configSource).not.toContain("apiKeyEnv"); + }); + + test("config.test.ts has no references to apiKeyEnv (except this test)", () => { + const testSource = readFileSync(__filename, "utf8"); + // Remove this test block's own mentions before checking + const withoutThisTest = testSource.replace( + /describe\("no legacy apiKeyEnv references"[\s\S]*$/, + "", + ); + expect(withoutThisTest).not.toContain("apiKeyEnv"); + }); + }); });