mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:17:39 +00:00
refactor(test): reuse provider-auth onboarding config helper
This commit is contained in:
@@ -239,15 +239,12 @@ describe("onboard (non-interactive): provider auth", () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
it("stores Z.AI API key and uses global baseUrl by default", async () => {
|
it("stores Z.AI API key and uses global baseUrl by default", async () => {
|
||||||
await withOnboardEnv("openclaw-onboard-zai-", async ({ configPath, runtime }) => {
|
await withOnboardEnv("openclaw-onboard-zai-", async (env) => {
|
||||||
await runNonInteractiveWithDefaults(runtime, {
|
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
|
||||||
authChoice: "zai-api-key",
|
authChoice: "zai-api-key",
|
||||||
zaiApiKey: "zai-test-key",
|
zaiApiKey: "zai-test-key",
|
||||||
skipSkills: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cfg = await readJsonFile<ProviderAuthConfigSnapshot>(configPath);
|
|
||||||
|
|
||||||
expect(cfg.auth?.profiles?.["zai:default"]?.provider).toBe("zai");
|
expect(cfg.auth?.profiles?.["zai:default"]?.provider).toBe("zai");
|
||||||
expect(cfg.auth?.profiles?.["zai:default"]?.mode).toBe("api_key");
|
expect(cfg.auth?.profiles?.["zai:default"]?.mode).toBe("api_key");
|
||||||
expect(cfg.models?.providers?.zai?.baseUrl).toBe("https://api.z.ai/api/paas/v4");
|
expect(cfg.models?.providers?.zai?.baseUrl).toBe("https://api.z.ai/api/paas/v4");
|
||||||
@@ -257,15 +254,12 @@ describe("onboard (non-interactive): provider auth", () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
it("supports Z.AI CN coding endpoint auth choice", async () => {
|
it("supports Z.AI CN coding endpoint auth choice", async () => {
|
||||||
await withOnboardEnv("openclaw-onboard-zai-cn-", async ({ configPath, runtime }) => {
|
await withOnboardEnv("openclaw-onboard-zai-cn-", async (env) => {
|
||||||
await runNonInteractiveWithDefaults(runtime, {
|
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
|
||||||
authChoice: "zai-coding-cn",
|
authChoice: "zai-coding-cn",
|
||||||
zaiApiKey: "zai-test-key",
|
zaiApiKey: "zai-test-key",
|
||||||
skipSkills: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cfg = await readJsonFile<ProviderAuthConfigSnapshot>(configPath);
|
|
||||||
|
|
||||||
expect(cfg.models?.providers?.zai?.baseUrl).toBe(
|
expect(cfg.models?.providers?.zai?.baseUrl).toBe(
|
||||||
"https://open.bigmodel.cn/api/coding/paas/v4",
|
"https://open.bigmodel.cn/api/coding/paas/v4",
|
||||||
);
|
);
|
||||||
@@ -273,16 +267,13 @@ describe("onboard (non-interactive): provider auth", () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
it("stores xAI API key and sets default model", async () => {
|
it("stores xAI API key and sets default model", async () => {
|
||||||
await withOnboardEnv("openclaw-onboard-xai-", async ({ configPath, runtime }) => {
|
await withOnboardEnv("openclaw-onboard-xai-", async (env) => {
|
||||||
const rawKey = "xai-test-\r\nkey";
|
const rawKey = "xai-test-\r\nkey";
|
||||||
await runNonInteractiveWithDefaults(runtime, {
|
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
|
||||||
authChoice: "xai-api-key",
|
authChoice: "xai-api-key",
|
||||||
xaiApiKey: rawKey,
|
xaiApiKey: rawKey,
|
||||||
skipSkills: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cfg = await readJsonFile<ProviderAuthConfigSnapshot>(configPath);
|
|
||||||
|
|
||||||
expect(cfg.auth?.profiles?.["xai:default"]?.provider).toBe("xai");
|
expect(cfg.auth?.profiles?.["xai:default"]?.provider).toBe("xai");
|
||||||
expect(cfg.auth?.profiles?.["xai:default"]?.mode).toBe("api_key");
|
expect(cfg.auth?.profiles?.["xai:default"]?.mode).toBe("api_key");
|
||||||
expect(cfg.agents?.defaults?.model?.primary).toBe("xai/grok-4");
|
expect(cfg.agents?.defaults?.model?.primary).toBe("xai/grok-4");
|
||||||
@@ -291,15 +282,12 @@ describe("onboard (non-interactive): provider auth", () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
it("stores Vercel AI Gateway API key and sets default model", async () => {
|
it("stores Vercel AI Gateway API key and sets default model", async () => {
|
||||||
await withOnboardEnv("openclaw-onboard-ai-gateway-", async ({ configPath, runtime }) => {
|
await withOnboardEnv("openclaw-onboard-ai-gateway-", async (env) => {
|
||||||
await runNonInteractiveWithDefaults(runtime, {
|
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
|
||||||
authChoice: "ai-gateway-api-key",
|
authChoice: "ai-gateway-api-key",
|
||||||
aiGatewayApiKey: "gateway-test-key",
|
aiGatewayApiKey: "gateway-test-key",
|
||||||
skipSkills: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cfg = await readJsonFile<ProviderAuthConfigSnapshot>(configPath);
|
|
||||||
|
|
||||||
expect(cfg.auth?.profiles?.["vercel-ai-gateway:default"]?.provider).toBe("vercel-ai-gateway");
|
expect(cfg.auth?.profiles?.["vercel-ai-gateway:default"]?.provider).toBe("vercel-ai-gateway");
|
||||||
expect(cfg.auth?.profiles?.["vercel-ai-gateway:default"]?.mode).toBe("api_key");
|
expect(cfg.auth?.profiles?.["vercel-ai-gateway:default"]?.mode).toBe("api_key");
|
||||||
expect(cfg.agents?.defaults?.model?.primary).toBe(
|
expect(cfg.agents?.defaults?.model?.primary).toBe(
|
||||||
@@ -342,15 +330,12 @@ describe("onboard (non-interactive): provider auth", () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
it("stores OpenAI API key and sets OpenAI default model", async () => {
|
it("stores OpenAI API key and sets OpenAI default model", async () => {
|
||||||
await withOnboardEnv("openclaw-onboard-openai-", async ({ configPath, runtime }) => {
|
await withOnboardEnv("openclaw-onboard-openai-", async (env) => {
|
||||||
await runNonInteractiveWithDefaults(runtime, {
|
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
|
||||||
authChoice: "openai-api-key",
|
authChoice: "openai-api-key",
|
||||||
openaiApiKey: "sk-openai-test",
|
openaiApiKey: "sk-openai-test",
|
||||||
skipSkills: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cfg = await readJsonFile<ProviderAuthConfigSnapshot>(configPath);
|
|
||||||
|
|
||||||
expect(cfg.agents?.defaults?.model?.primary).toBe(OPENAI_DEFAULT_MODEL);
|
expect(cfg.agents?.defaults?.model?.primary).toBe(OPENAI_DEFAULT_MODEL);
|
||||||
});
|
});
|
||||||
}, 60_000);
|
}, 60_000);
|
||||||
@@ -367,15 +352,12 @@ describe("onboard (non-interactive): provider auth", () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
it("stores LiteLLM API key and sets default model", async () => {
|
it("stores LiteLLM API key and sets default model", async () => {
|
||||||
await withOnboardEnv("openclaw-onboard-litellm-", async ({ configPath, runtime }) => {
|
await withOnboardEnv("openclaw-onboard-litellm-", async (env) => {
|
||||||
await runNonInteractiveWithDefaults(runtime, {
|
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
|
||||||
authChoice: "litellm-api-key",
|
authChoice: "litellm-api-key",
|
||||||
litellmApiKey: "litellm-test-key",
|
litellmApiKey: "litellm-test-key",
|
||||||
skipSkills: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cfg = await readJsonFile<ProviderAuthConfigSnapshot>(configPath);
|
|
||||||
|
|
||||||
expect(cfg.auth?.profiles?.["litellm:default"]?.provider).toBe("litellm");
|
expect(cfg.auth?.profiles?.["litellm:default"]?.provider).toBe("litellm");
|
||||||
expect(cfg.auth?.profiles?.["litellm:default"]?.mode).toBe("api_key");
|
expect(cfg.auth?.profiles?.["litellm:default"]?.mode).toBe("api_key");
|
||||||
expect(cfg.agents?.defaults?.model?.primary).toBe("litellm/claude-opus-4-6");
|
expect(cfg.agents?.defaults?.model?.primary).toBe("litellm/claude-opus-4-6");
|
||||||
|
|||||||
Reference in New Issue
Block a user