mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(wizard): share onboarding prompter scaffold
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import { createWizardPrompter as buildWizardPrompter } from "../../test/helpers/wizard-prompter.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import type { WizardPrompter, WizardSelectParams } from "./prompts.js";
|
import type { WizardPrompter, WizardSelectParams } from "./prompts.js";
|
||||||
|
|
||||||
@@ -28,16 +29,10 @@ describe("configureGatewayForOnboarding", () => {
|
|||||||
async (_params: WizardSelectParams<unknown>) => selectQueue.shift() as unknown,
|
async (_params: WizardSelectParams<unknown>) => selectQueue.shift() as unknown,
|
||||||
) as unknown as WizardPrompter["select"];
|
) as unknown as WizardPrompter["select"];
|
||||||
|
|
||||||
return {
|
return buildWizardPrompter({
|
||||||
intro: vi.fn(async () => {}),
|
|
||||||
outro: vi.fn(async () => {}),
|
|
||||||
note: vi.fn(async () => {}),
|
|
||||||
select,
|
select,
|
||||||
multiselect: vi.fn(async () => []),
|
|
||||||
text: vi.fn(async () => textQueue.shift() as string),
|
text: vi.fn(async () => textQueue.shift() as string),
|
||||||
confirm: vi.fn(async () => false),
|
});
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
} satisfies WizardPrompter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRuntime(): RuntimeEnv {
|
function createRuntime(): RuntimeEnv {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||||
|
import { createWizardPrompter as buildWizardPrompter } from "../../test/helpers/wizard-prompter.js";
|
||||||
import { DEFAULT_BOOTSTRAP_FILENAME } from "../agents/workspace.js";
|
import { DEFAULT_BOOTSTRAP_FILENAME } from "../agents/workspace.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { runOnboardingWizard } from "./onboarding.js";
|
import { runOnboardingWizard } from "./onboarding.js";
|
||||||
@@ -194,23 +195,6 @@ vi.mock("./onboarding.completion.js", () => ({
|
|||||||
setupOnboardingShellCompletion,
|
setupOnboardingShellCompletion,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
function createWizardPrompter(overrides?: Partial<WizardPrompter>): WizardPrompter {
|
|
||||||
const select = vi.fn(
|
|
||||||
async (_params: WizardSelectParams<unknown>) => "quickstart",
|
|
||||||
) as unknown as WizardPrompter["select"];
|
|
||||||
return {
|
|
||||||
intro: vi.fn(async () => {}),
|
|
||||||
outro: vi.fn(async () => {}),
|
|
||||||
note: vi.fn(async () => {}),
|
|
||||||
select,
|
|
||||||
multiselect: vi.fn(async () => []),
|
|
||||||
text: vi.fn(async () => ""),
|
|
||||||
confirm: vi.fn(async () => false),
|
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
...overrides,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createRuntime(opts?: { throwsOnExit?: boolean }): RuntimeEnv {
|
function createRuntime(opts?: { throwsOnExit?: boolean }): RuntimeEnv {
|
||||||
if (opts?.throwsOnExit) {
|
if (opts?.throwsOnExit) {
|
||||||
return {
|
return {
|
||||||
@@ -266,7 +250,7 @@ describe("runOnboardingWizard", () => {
|
|||||||
const select = vi.fn(
|
const select = vi.fn(
|
||||||
async (_params: WizardSelectParams<unknown>) => "quickstart",
|
async (_params: WizardSelectParams<unknown>) => "quickstart",
|
||||||
) as unknown as WizardPrompter["select"];
|
) as unknown as WizardPrompter["select"];
|
||||||
const prompter = createWizardPrompter({ select });
|
const prompter = buildWizardPrompter({ select });
|
||||||
const runtime = createRuntime({ throwsOnExit: true });
|
const runtime = createRuntime({ throwsOnExit: true });
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
@@ -295,7 +279,7 @@ describe("runOnboardingWizard", () => {
|
|||||||
async (_params: WizardSelectParams<unknown>) => "quickstart",
|
async (_params: WizardSelectParams<unknown>) => "quickstart",
|
||||||
) as unknown as WizardPrompter["select"];
|
) as unknown as WizardPrompter["select"];
|
||||||
const multiselect: WizardPrompter["multiselect"] = vi.fn(async () => []);
|
const multiselect: WizardPrompter["multiselect"] = vi.fn(async () => []);
|
||||||
const prompter = createWizardPrompter({ select, multiselect });
|
const prompter = buildWizardPrompter({ select, multiselect });
|
||||||
const runtime = createRuntime({ throwsOnExit: true });
|
const runtime = createRuntime({ throwsOnExit: true });
|
||||||
|
|
||||||
await runOnboardingWizard(
|
await runOnboardingWizard(
|
||||||
@@ -338,7 +322,7 @@ describe("runOnboardingWizard", () => {
|
|||||||
return "quickstart";
|
return "quickstart";
|
||||||
}) as unknown as WizardPrompter["select"];
|
}) as unknown as WizardPrompter["select"];
|
||||||
|
|
||||||
const prompter = createWizardPrompter({ select });
|
const prompter = buildWizardPrompter({ select });
|
||||||
const runtime = createRuntime({ throwsOnExit: true });
|
const runtime = createRuntime({ throwsOnExit: true });
|
||||||
|
|
||||||
await runOnboardingWizard(
|
await runOnboardingWizard(
|
||||||
@@ -379,7 +363,7 @@ describe("runOnboardingWizard", () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const note: WizardPrompter["note"] = vi.fn(async () => {});
|
const note: WizardPrompter["note"] = vi.fn(async () => {});
|
||||||
const prompter = createWizardPrompter({ note });
|
const prompter = buildWizardPrompter({ note });
|
||||||
const runtime = createRuntime();
|
const runtime = createRuntime();
|
||||||
|
|
||||||
await runOnboardingWizard(
|
await runOnboardingWizard(
|
||||||
|
|||||||
17
test/helpers/wizard-prompter.ts
Normal file
17
test/helpers/wizard-prompter.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
import type { WizardPrompter } from "../../src/wizard/prompts.js";
|
||||||
|
|
||||||
|
export function createWizardPrompter(overrides?: Partial<WizardPrompter>): WizardPrompter {
|
||||||
|
const select = vi.fn(async () => "quickstart") as unknown as WizardPrompter["select"];
|
||||||
|
return {
|
||||||
|
intro: vi.fn(async () => {}),
|
||||||
|
outro: vi.fn(async () => {}),
|
||||||
|
note: vi.fn(async () => {}),
|
||||||
|
select,
|
||||||
|
multiselect: vi.fn(async () => []),
|
||||||
|
text: vi.fn(async () => ""),
|
||||||
|
confirm: vi.fn(async () => false),
|
||||||
|
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user