fix: QuickStart provider selection (#485)
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
- macOS: replace relay smoke test with version check in packaging script. (#615) — thanks @YuriNachos
|
- macOS: replace relay smoke test with version check in packaging script. (#615) — thanks @YuriNachos
|
||||||
- macOS: avoid clearing Launch at Login during app initialization. (#607) — thanks @wes-davis
|
- macOS: avoid clearing Launch at Login during app initialization. (#607) — thanks @wes-davis
|
||||||
- Onboarding: skip systemd checks/daemon installs when systemd user services are unavailable; add onboarding flags to skip flow steps and stabilize Docker E2E. (#573) — thanks @steipete
|
- Onboarding: skip systemd checks/daemon installs when systemd user services are unavailable; add onboarding flags to skip flow steps and stabilize Docker E2E. (#573) — thanks @steipete
|
||||||
|
- Onboarding: QuickStart provider picker uses single-select to avoid accidental Telegram token prompts when choosing WhatsApp. (#485) — thanks @frankstallone
|
||||||
- macOS: add node bridge heartbeat pings to detect half-open sockets and reconnect cleanly. (#572) — thanks @ngutman
|
- macOS: add node bridge heartbeat pings to detect half-open sockets and reconnect cleanly. (#572) — thanks @ngutman
|
||||||
- Node bridge: harden keepalive + heartbeat handling (TCP keepalive, better disconnects, and keepalive config tests). (#577) — thanks @steipete
|
- Node bridge: harden keepalive + heartbeat handling (TCP keepalive, better disconnects, and keepalive config tests). (#577) — thanks @steipete
|
||||||
- Control UI: improve mobile responsiveness. (#558) — thanks @carlulsoe
|
- Control UI: improve mobile responsiveness. (#558) — thanks @carlulsoe
|
||||||
|
|||||||
@@ -1,81 +1,70 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
import {
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
mergeWhatsAppConfig,
|
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||||
setWhatsAppAllowFrom,
|
import { setupProviders } from "./onboard-providers.js";
|
||||||
setWhatsAppDmPolicy,
|
|
||||||
setWhatsAppSelfChatMode,
|
|
||||||
} from "./onboard-providers.js";
|
|
||||||
|
|
||||||
describe("onboard-providers WhatsApp setters", () => {
|
vi.mock("node:fs/promises", () => ({
|
||||||
it("preserves existing WhatsApp fields when updating allowFrom", () => {
|
default: {
|
||||||
const cfg: ClawdbotConfig = {
|
access: vi.fn(async () => {
|
||||||
whatsapp: {
|
throw new Error("ENOENT");
|
||||||
selfChatMode: true,
|
}),
|
||||||
dmPolicy: "pairing",
|
|
||||||
allowFrom: ["*"],
|
|
||||||
accounts: {
|
|
||||||
default: { enabled: false },
|
|
||||||
},
|
},
|
||||||
},
|
}));
|
||||||
};
|
|
||||||
|
|
||||||
const next = setWhatsAppAllowFrom(cfg, ["+15555550123"]);
|
vi.mock("../provider-web.js", () => ({
|
||||||
|
loginWeb: vi.fn(async () => {}),
|
||||||
|
}));
|
||||||
|
|
||||||
expect(next.whatsapp?.selfChatMode).toBe(true);
|
vi.mock("./onboard-helpers.js", () => ({
|
||||||
expect(next.whatsapp?.dmPolicy).toBe("pairing");
|
detectBinary: vi.fn(async () => false),
|
||||||
expect(next.whatsapp?.allowFrom).toEqual(["+15555550123"]);
|
}));
|
||||||
expect(next.whatsapp?.accounts?.default?.enabled).toBe(false);
|
|
||||||
|
describe("setupProviders", () => {
|
||||||
|
it("QuickStart uses single-select (no multiselect) and doesn't prompt for Telegram token when WhatsApp is chosen", async () => {
|
||||||
|
const select = vi.fn(async () => "whatsapp");
|
||||||
|
const multiselect = vi.fn(async () => {
|
||||||
|
throw new Error("unexpected multiselect");
|
||||||
|
});
|
||||||
|
const text = vi.fn(async ({ message }: { message: string }) => {
|
||||||
|
if (message.includes("Enter Telegram bot token")) {
|
||||||
|
throw new Error("unexpected Telegram token prompt");
|
||||||
|
}
|
||||||
|
if (message.includes("Your personal WhatsApp number")) {
|
||||||
|
return "+15555550123";
|
||||||
|
}
|
||||||
|
throw new Error(`unexpected text prompt: ${message}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates dmPolicy without dropping selfChatMode", () => {
|
const prompter: WizardPrompter = {
|
||||||
const cfg: ClawdbotConfig = {
|
intro: vi.fn(async () => {}),
|
||||||
whatsapp: {
|
outro: vi.fn(async () => {}),
|
||||||
selfChatMode: true,
|
note: vi.fn(async () => {}),
|
||||||
dmPolicy: "pairing",
|
select,
|
||||||
},
|
multiselect,
|
||||||
|
text: text as unknown as WizardPrompter["text"],
|
||||||
|
confirm: vi.fn(async () => false),
|
||||||
|
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
||||||
};
|
};
|
||||||
|
|
||||||
const next = setWhatsAppDmPolicy(cfg, "open");
|
const runtime: RuntimeEnv = {
|
||||||
|
log: vi.fn(),
|
||||||
expect(next.whatsapp?.dmPolicy).toBe("open");
|
error: vi.fn(),
|
||||||
expect(next.whatsapp?.selfChatMode).toBe(true);
|
exit: vi.fn((code: number) => {
|
||||||
});
|
throw new Error(`exit:${code}`);
|
||||||
|
}),
|
||||||
it("updates selfChatMode without dropping allowFrom", () => {
|
|
||||||
const cfg: ClawdbotConfig = {
|
|
||||||
whatsapp: {
|
|
||||||
allowFrom: ["+15555550123"],
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const next = setWhatsAppSelfChatMode(cfg, true);
|
await setupProviders({} as ClawdbotConfig, runtime, prompter, {
|
||||||
|
skipConfirm: true,
|
||||||
expect(next.whatsapp?.selfChatMode).toBe(true);
|
quickstartDefaults: true,
|
||||||
expect(next.whatsapp?.allowFrom).toEqual(["+15555550123"]);
|
forceAllowFromProviders: ["whatsapp"],
|
||||||
});
|
});
|
||||||
|
|
||||||
it("merges WhatsApp config without clobbering fields", () => {
|
expect(select).toHaveBeenCalledWith(
|
||||||
const cfg: ClawdbotConfig = {
|
expect.objectContaining({ message: "Select provider (QuickStart)" }),
|
||||||
whatsapp: {
|
|
||||||
dmPolicy: "pairing",
|
|
||||||
allowFrom: ["*"],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const merged = mergeWhatsAppConfig(cfg, {
|
|
||||||
dmPolicy: "open",
|
|
||||||
allowFrom: undefined,
|
|
||||||
});
|
|
||||||
const cleared = mergeWhatsAppConfig(
|
|
||||||
cfg,
|
|
||||||
{ allowFrom: undefined },
|
|
||||||
{ unsetOnUndefined: ["allowFrom"] },
|
|
||||||
);
|
);
|
||||||
|
expect(multiselect).not.toHaveBeenCalled();
|
||||||
expect(merged.whatsapp?.dmPolicy).toBe("open");
|
|
||||||
expect(merged.whatsapp?.allowFrom).toEqual(["*"]);
|
|
||||||
expect(cleared.whatsapp?.allowFrom).toBeUndefined();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -872,14 +872,31 @@ export async function setupProviders(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const initialSelection =
|
let selection: ProviderChoice[];
|
||||||
options?.initialSelection ??
|
if (options?.quickstartDefaults) {
|
||||||
(options?.quickstartDefaults && !telegramConfigured ? ["telegram"] : []);
|
const choice = (await prompter.select({
|
||||||
const selection = (await prompter.multiselect({
|
message: "Select provider (QuickStart)",
|
||||||
message: "Select providers",
|
options: [
|
||||||
|
...selectionOptions,
|
||||||
|
{
|
||||||
|
value: "__skip__",
|
||||||
|
label: "Skip for now",
|
||||||
|
hint: "You can add providers later via `clawdbot providers add`",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
initialValue:
|
||||||
|
options?.initialSelection?.[0] ??
|
||||||
|
(!telegramConfigured ? "telegram" : "whatsapp"),
|
||||||
|
})) as ProviderChoice | "__skip__";
|
||||||
|
selection = choice === "__skip__" ? [] : [choice];
|
||||||
|
} else {
|
||||||
|
const initialSelection = options?.initialSelection ?? [];
|
||||||
|
selection = (await prompter.multiselect({
|
||||||
|
message: "Select providers (Space to toggle, Enter to continue)",
|
||||||
options: selectionOptions,
|
options: selectionOptions,
|
||||||
initialValues: initialSelection.length ? initialSelection : undefined,
|
initialValues: initialSelection.length ? initialSelection : undefined,
|
||||||
})) as ProviderChoice[];
|
})) as ProviderChoice[];
|
||||||
|
}
|
||||||
|
|
||||||
options?.onSelection?.(selection);
|
options?.onSelection?.(selection);
|
||||||
const accountOverrides: Partial<Record<ProviderChoice, string>> = {
|
const accountOverrides: Partial<Record<ProviderChoice, string>> = {
|
||||||
|
|||||||
Reference in New Issue
Block a user