mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
Configure: show Keep existing only when auth exists
This commit is contained in:
@@ -57,7 +57,7 @@ describe("auth choice keep existing", () => {
|
||||
expect(lines).toContain("OAuth: openai-codex:default (openai-codex)");
|
||||
});
|
||||
|
||||
it("offers Keep Existing in the method selector and returns skip", async () => {
|
||||
it("offers Keep existing in the method selector and returns skip", async () => {
|
||||
process.env.OPENAI_API_KEY = "sk-test";
|
||||
const store = createStore();
|
||||
|
||||
@@ -67,7 +67,7 @@ describe("auth choice keep existing", () => {
|
||||
}
|
||||
if (params.message === "OpenAI auth method") {
|
||||
const keepExisting = params.options.find((option) => option.value === "skip");
|
||||
expect(keepExisting?.label).toBe("Keep Existing");
|
||||
expect(keepExisting?.label).toBe("Keep existing");
|
||||
expect(keepExisting?.hint).toContain("APIKey:");
|
||||
expect(keepExisting?.hint).toContain("OAuth:");
|
||||
expect(keepExisting?.hint).toContain("\n");
|
||||
@@ -89,4 +89,33 @@ describe("auth choice keep existing", () => {
|
||||
}),
|
||||
).resolves.toBe("skip");
|
||||
});
|
||||
|
||||
it("does not show Keep existing when provider has no existing auth", async () => {
|
||||
delete process.env.OPENAI_API_KEY;
|
||||
const store: AuthProfileStore = { version: 1, profiles: {} };
|
||||
|
||||
const select: WizardPrompter["select"] = vi.fn(async (params: WizardSelectParams) => {
|
||||
if (params.message === "Model/auth provider") {
|
||||
return "openai";
|
||||
}
|
||||
if (params.message === "OpenAI auth method") {
|
||||
expect(params.options.some((option) => option.value === "skip")).toBe(false);
|
||||
return "openai-api-key";
|
||||
}
|
||||
return params.options[0]?.value ?? "openai-api-key";
|
||||
});
|
||||
|
||||
const prompter = createWizardPrompter(
|
||||
{ select: select as unknown as WizardPrompter["select"] },
|
||||
{ defaultSelect: "" },
|
||||
);
|
||||
|
||||
await expect(
|
||||
promptAuthChoiceGrouped({
|
||||
prompter,
|
||||
store,
|
||||
includeSkip: true,
|
||||
}),
|
||||
).resolves.toBe("openai-api-key");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,12 +58,15 @@ export function resolveExistingAuthLinesForGroup(params: {
|
||||
export function buildKeepExistingOption(params: {
|
||||
group: AuthChoiceGroup;
|
||||
store: AuthProfileStore;
|
||||
}): AuthChoiceOption {
|
||||
}): AuthChoiceOption | undefined {
|
||||
const lines = resolveExistingAuthLinesForGroup(params);
|
||||
if (lines.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
value: "skip",
|
||||
label: "Keep Existing",
|
||||
hint: lines.length > 0 ? lines.join("\n") : "Use existing auth",
|
||||
label: "Keep existing",
|
||||
hint: lines.join("\n"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -108,9 +111,12 @@ export async function promptAuthChoiceGrouped(params: {
|
||||
return group.options[0].value;
|
||||
}
|
||||
|
||||
const keepExistingOption = params.includeSkip
|
||||
? buildKeepExistingOption({ group, store: params.store })
|
||||
: undefined;
|
||||
const methodOptions: Array<{ value: string; label: string; hint?: string }> = [
|
||||
...group.options,
|
||||
...(params.includeSkip ? [buildKeepExistingOption({ group, store: params.store })] : []),
|
||||
...(keepExistingOption ? [keepExistingOption] : []),
|
||||
{ value: BACK_VALUE, label: "Back" },
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user