mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 16:50:22 +00:00
test: debrand generic auth-choice placeholders
This commit is contained in:
@@ -131,12 +131,12 @@ async function runEnsureMinimaxApiKeyFlow(params: { confirmResult: boolean; text
|
||||
return { result, setCredential, confirm, text };
|
||||
}
|
||||
|
||||
async function runMaybeApplyHuggingFaceToken(tokenProvider: string) {
|
||||
async function runMaybeApplyDemoToken(tokenProvider: string) {
|
||||
const setCredential = vi.fn(async () => undefined);
|
||||
const result = await maybeApplyApiKeyFromOption({
|
||||
token: " opt-key ",
|
||||
tokenProvider,
|
||||
expectedProviders: ["huggingface"],
|
||||
expectedProviders: ["demo-provider"],
|
||||
normalize: (value) => value.trim(),
|
||||
setCredential,
|
||||
});
|
||||
@@ -187,21 +187,21 @@ afterEach(() => {
|
||||
|
||||
describe("normalizeTokenProviderInput", () => {
|
||||
it("trims and lowercases non-empty values", () => {
|
||||
expect(normalizeTokenProviderInput(" HuGgInGfAcE ")).toBe("huggingface");
|
||||
expect(normalizeTokenProviderInput(" DeMo-PrOvIdEr ")).toBe("demo-provider");
|
||||
expect(normalizeTokenProviderInput("")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("maybeApplyApiKeyFromOption", () => {
|
||||
it("stores normalized token when provider matches", async () => {
|
||||
const { result, setCredential } = await runMaybeApplyHuggingFaceToken("huggingface");
|
||||
const { result, setCredential } = await runMaybeApplyDemoToken("demo-provider");
|
||||
|
||||
expect(result).toBe("opt-key");
|
||||
expect(setCredential).toHaveBeenCalledWith("opt-key", undefined);
|
||||
});
|
||||
|
||||
it("matches provider with whitespace/case normalization", async () => {
|
||||
const { result, setCredential } = await runMaybeApplyHuggingFaceToken(" HuGgInGfAcE ");
|
||||
const { result, setCredential } = await runMaybeApplyDemoToken(" DeMo-PrOvIdEr ");
|
||||
|
||||
expect(result).toBe("opt-key");
|
||||
expect(setCredential).toHaveBeenCalledWith("opt-key", undefined);
|
||||
@@ -212,8 +212,8 @@ describe("maybeApplyApiKeyFromOption", () => {
|
||||
|
||||
const result = await maybeApplyApiKeyFromOption({
|
||||
token: "opt-key",
|
||||
tokenProvider: "openai",
|
||||
expectedProviders: ["huggingface"],
|
||||
tokenProvider: "other-provider",
|
||||
expectedProviders: ["demo-provider"],
|
||||
normalize: (value) => value.trim(),
|
||||
setCredential,
|
||||
});
|
||||
@@ -387,14 +387,14 @@ describe("ensureApiKeyFromOptionEnvOrPrompt", () => {
|
||||
|
||||
const result = await ensureWithOptionEnvOrPrompt({
|
||||
token: " opts-key ",
|
||||
tokenProvider: " HUGGINGFACE ",
|
||||
expectedProviders: ["huggingface"],
|
||||
provider: "huggingface",
|
||||
envLabel: "HF_TOKEN",
|
||||
tokenProvider: " DEMO-PROVIDER ",
|
||||
expectedProviders: ["demo-provider"],
|
||||
provider: "demo-provider",
|
||||
envLabel: "DEMO_TOKEN",
|
||||
confirm,
|
||||
note,
|
||||
noteMessage: "Hugging Face note",
|
||||
noteTitle: "Hugging Face",
|
||||
noteMessage: "Demo note",
|
||||
noteTitle: "Demo",
|
||||
setCredential,
|
||||
text,
|
||||
});
|
||||
@@ -417,20 +417,20 @@ describe("ensureApiKeyFromOptionEnvOrPrompt", () => {
|
||||
|
||||
const result = await ensureWithOptionEnvOrPrompt({
|
||||
token: "opts-key",
|
||||
tokenProvider: "openai",
|
||||
tokenProvider: "other-provider",
|
||||
expectedProviders: ["minimax"],
|
||||
provider: "minimax",
|
||||
envLabel: "MINIMAX_API_KEY",
|
||||
confirm,
|
||||
note,
|
||||
noteMessage: "MiniMax note",
|
||||
noteTitle: "MiniMax",
|
||||
noteMessage: "Demo provider note",
|
||||
noteTitle: "Demo provider",
|
||||
setCredential,
|
||||
text,
|
||||
});
|
||||
|
||||
expect(result).toBe("env-key");
|
||||
expect(note).toHaveBeenCalledWith("MiniMax note", "MiniMax");
|
||||
expect(note).toHaveBeenCalledWith("Demo provider note", "Demo provider");
|
||||
expect(confirm).toHaveBeenCalled();
|
||||
expect(text).not.toHaveBeenCalled();
|
||||
expect(setCredential).toHaveBeenCalledWith("env-key", "plaintext");
|
||||
|
||||
@@ -35,12 +35,12 @@ describe("applyNonInteractiveAuthChoice", () => {
|
||||
it("resolves plugin provider auth before builtin custom-provider handling", async () => {
|
||||
const runtime = createRuntime();
|
||||
const nextConfig = { agents: { defaults: {} } } as OpenClawConfig;
|
||||
const resolvedConfig = { auth: { profiles: { "openai:default": { mode: "api_key" } } } };
|
||||
const resolvedConfig = { auth: { profiles: { "demo-provider:default": { mode: "api_key" } } } };
|
||||
applyNonInteractivePluginProviderChoice.mockResolvedValueOnce(resolvedConfig as never);
|
||||
|
||||
const result = await applyNonInteractiveAuthChoice({
|
||||
nextConfig,
|
||||
authChoice: "openai-api-key",
|
||||
authChoice: "demo-provider-api-key",
|
||||
opts: {} as never,
|
||||
runtime: runtime as never,
|
||||
baseConfig: nextConfig,
|
||||
@@ -54,12 +54,12 @@ describe("applyNonInteractiveAuthChoice", () => {
|
||||
const runtime = createRuntime();
|
||||
const nextConfig = { agents: { defaults: {} } } as OpenClawConfig;
|
||||
resolveManifestDeprecatedProviderAuthChoice.mockReturnValueOnce({
|
||||
choiceId: "minimax-global-api",
|
||||
choiceId: "demo-provider-modern-api",
|
||||
} as never);
|
||||
|
||||
const result = await applyNonInteractiveAuthChoice({
|
||||
nextConfig,
|
||||
authChoice: "minimax",
|
||||
authChoice: "demo-provider-legacy",
|
||||
opts: {} as never,
|
||||
runtime: runtime as never,
|
||||
baseConfig: nextConfig,
|
||||
@@ -67,7 +67,7 @@ describe("applyNonInteractiveAuthChoice", () => {
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(runtime.error).toHaveBeenCalledWith(
|
||||
'"minimax" is no longer supported. Use --auth-choice minimax-global-api instead.',
|
||||
'"demo-provider-legacy" is no longer supported. Use --auth-choice demo-provider-modern-api instead.',
|
||||
);
|
||||
expect(runtime.exit).toHaveBeenCalledWith(1);
|
||||
expect(applyNonInteractivePluginProviderChoice).toHaveBeenCalledOnce();
|
||||
|
||||
Reference in New Issue
Block a user