mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 19:01:47 +03:00
refactor(test): dedupe onboarding tui hatch setup
This commit is contained in:
+59
-101
@@ -175,119 +175,77 @@ describe("runOnboardingWizard", () => {
|
|||||||
expect(runTui).not.toHaveBeenCalled();
|
expect(runTui).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("launches TUI without auto-delivery when hatching", async () => {
|
async function runTuiHatchTest(params: {
|
||||||
|
writeBootstrapFile: boolean;
|
||||||
|
expectedMessage: string | undefined;
|
||||||
|
}) {
|
||||||
runTui.mockClear();
|
runTui.mockClear();
|
||||||
|
|
||||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-onboard-"));
|
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-onboard-"));
|
||||||
await fs.writeFile(path.join(workspaceDir, DEFAULT_BOOTSTRAP_FILENAME), "{}");
|
try {
|
||||||
|
if (params.writeBootstrapFile) {
|
||||||
const select: WizardPrompter["select"] = vi.fn(async (opts) => {
|
await fs.writeFile(path.join(workspaceDir, DEFAULT_BOOTSTRAP_FILENAME), "{}");
|
||||||
if (opts.message === "How do you want to hatch your bot?") {
|
|
||||||
return "tui";
|
|
||||||
}
|
}
|
||||||
return "quickstart";
|
|
||||||
});
|
|
||||||
|
|
||||||
const prompter: WizardPrompter = {
|
const select: WizardPrompter["select"] = vi.fn(async (opts) => {
|
||||||
intro: vi.fn(async () => {}),
|
if (opts.message === "How do you want to hatch your bot?") {
|
||||||
outro: vi.fn(async () => {}),
|
return "tui";
|
||||||
note: vi.fn(async () => {}),
|
}
|
||||||
select,
|
return "quickstart";
|
||||||
multiselect: vi.fn(async () => []),
|
});
|
||||||
text: vi.fn(async () => ""),
|
|
||||||
confirm: vi.fn(async () => false),
|
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
};
|
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
const prompter: WizardPrompter = {
|
||||||
log: vi.fn(),
|
intro: vi.fn(async () => {}),
|
||||||
error: vi.fn(),
|
outro: vi.fn(async () => {}),
|
||||||
exit: vi.fn((code: number) => {
|
note: vi.fn(async () => {}),
|
||||||
throw new Error(`exit:${code}`);
|
select,
|
||||||
}),
|
multiselect: vi.fn(async () => []),
|
||||||
};
|
text: vi.fn(async () => ""),
|
||||||
|
confirm: vi.fn(async () => false),
|
||||||
|
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
||||||
|
};
|
||||||
|
|
||||||
await runOnboardingWizard(
|
const runtime: RuntimeEnv = {
|
||||||
{
|
log: vi.fn(),
|
||||||
acceptRisk: true,
|
error: vi.fn(),
|
||||||
flow: "quickstart",
|
exit: vi.fn((code: number) => {
|
||||||
mode: "local",
|
throw new Error(`exit:${code}`);
|
||||||
workspace: workspaceDir,
|
}),
|
||||||
authChoice: "skip",
|
};
|
||||||
skipProviders: true,
|
|
||||||
skipSkills: true,
|
|
||||||
skipHealth: true,
|
|
||||||
installDaemon: false,
|
|
||||||
},
|
|
||||||
runtime,
|
|
||||||
prompter,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(runTui).toHaveBeenCalledWith(
|
await runOnboardingWizard(
|
||||||
expect.objectContaining({
|
{
|
||||||
deliver: false,
|
acceptRisk: true,
|
||||||
message: "Wake up, my friend!",
|
flow: "quickstart",
|
||||||
}),
|
mode: "local",
|
||||||
);
|
workspace: workspaceDir,
|
||||||
|
authChoice: "skip",
|
||||||
|
skipProviders: true,
|
||||||
|
skipSkills: true,
|
||||||
|
skipHealth: true,
|
||||||
|
installDaemon: false,
|
||||||
|
},
|
||||||
|
runtime,
|
||||||
|
prompter,
|
||||||
|
);
|
||||||
|
|
||||||
await fs.rm(workspaceDir, { recursive: true, force: true });
|
expect(runTui).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
deliver: false,
|
||||||
|
message: params.expectedMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await fs.rm(workspaceDir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it("launches TUI without auto-delivery when hatching", async () => {
|
||||||
|
await runTuiHatchTest({ writeBootstrapFile: true, expectedMessage: "Wake up, my friend!" });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("offers TUI hatch even without BOOTSTRAP.md", async () => {
|
it("offers TUI hatch even without BOOTSTRAP.md", async () => {
|
||||||
runTui.mockClear();
|
await runTuiHatchTest({ writeBootstrapFile: false, expectedMessage: undefined });
|
||||||
|
|
||||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-onboard-"));
|
|
||||||
|
|
||||||
const select: WizardPrompter["select"] = vi.fn(async (opts) => {
|
|
||||||
if (opts.message === "How do you want to hatch your bot?") {
|
|
||||||
return "tui";
|
|
||||||
}
|
|
||||||
return "quickstart";
|
|
||||||
});
|
|
||||||
|
|
||||||
const prompter: WizardPrompter = {
|
|
||||||
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() })),
|
|
||||||
};
|
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn((code: number) => {
|
|
||||||
throw new Error(`exit:${code}`);
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
await runOnboardingWizard(
|
|
||||||
{
|
|
||||||
acceptRisk: true,
|
|
||||||
flow: "quickstart",
|
|
||||||
mode: "local",
|
|
||||||
workspace: workspaceDir,
|
|
||||||
authChoice: "skip",
|
|
||||||
skipProviders: true,
|
|
||||||
skipSkills: true,
|
|
||||||
skipHealth: true,
|
|
||||||
installDaemon: false,
|
|
||||||
},
|
|
||||||
runtime,
|
|
||||||
prompter,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(runTui).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
deliver: false,
|
|
||||||
message: undefined,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await fs.rm(workspaceDir, { recursive: true, force: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows the web search hint at the end of onboarding", async () => {
|
it("shows the web search hint at the end of onboarding", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user