refactor(tests): share setup wizard prompter

This commit is contained in:
Peter Steinberger
2026-03-17 06:29:38 +00:00
parent cc35627c8f
commit d28cb8d821
9 changed files with 52 additions and 180 deletions

View File

@@ -1,32 +1,11 @@
import type { RuntimeEnv, WizardPrompter } from "openclaw/plugin-sdk/irc";
import type { RuntimeEnv } from "openclaw/plugin-sdk/irc";
import { describe, expect, it, vi } from "vitest";
import { buildChannelSetupWizardAdapterFromSetupWizard } from "../../../src/channels/plugins/setup-wizard.js";
import { createRuntimeEnv } from "../../test-utils/runtime-env.js";
import { createTestWizardPrompter, type WizardPrompter } from "../../test-utils/setup-wizard.js";
import { ircPlugin } from "./channel.js";
import type { CoreConfig } from "./types.js";
const selectFirstOption = async <T>(params: { options: Array<{ value: T }> }): Promise<T> => {
const first = params.options[0];
if (!first) {
throw new Error("no options");
}
return first.value;
};
function createPrompter(overrides: Partial<WizardPrompter>): WizardPrompter {
return {
intro: vi.fn(async () => {}),
outro: vi.fn(async () => {}),
note: vi.fn(async () => {}),
select: selectFirstOption as WizardPrompter["select"],
multiselect: vi.fn(async () => []),
text: vi.fn(async () => "") as WizardPrompter["text"],
confirm: vi.fn(async () => false),
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
...overrides,
};
}
const ircConfigureAdapter = buildChannelSetupWizardAdapterFromSetupWizard({
plugin: ircPlugin,
wizard: ircPlugin.setupWizard!,
@@ -34,7 +13,7 @@ const ircConfigureAdapter = buildChannelSetupWizardAdapterFromSetupWizard({
describe("irc setup wizard", () => {
it("configures host and nick via setup prompts", async () => {
const prompter = createPrompter({
const prompter = createTestWizardPrompter({
text: vi.fn(async ({ message }: { message: string }) => {
if (message === "IRC server host") {
return "irc.libera.chat";
@@ -93,7 +72,7 @@ describe("irc setup wizard", () => {
});
it("writes DM allowFrom to top-level config for non-default account prompts", async () => {
const prompter = createPrompter({
const prompter = createTestWizardPrompter({
text: vi.fn(async ({ message }: { message: string }) => {
if (message === "IRC allowFrom (nick or nick!user@host)") {
return "Alice, Bob!ident@example.org";