feat: unify onboarding + config schema

This commit is contained in:
Peter Steinberger
2026-01-03 16:04:19 +01:00
parent 0f85080d81
commit 53baba71fa
43 changed files with 3478 additions and 1011 deletions

View File

@@ -0,0 +1,69 @@
import { describe, expect, test } from "vitest";
import { WizardSession } from "./session.js";
function noteRunner() {
return new WizardSession(async (prompter) => {
await prompter.note("Welcome");
const name = await prompter.text({ message: "Name" });
await prompter.note(`Hello ${name}`);
});
}
describe("WizardSession", () => {
test("steps progress in order", async () => {
const session = noteRunner();
const first = await session.next();
expect(first.done).toBe(false);
expect(first.step?.type).toBe("note");
const secondPeek = await session.next();
expect(secondPeek.step?.id).toBe(first.step?.id);
if (!first.step) throw new Error("expected first step");
await session.answer(first.step.id, null);
const second = await session.next();
expect(second.done).toBe(false);
expect(second.step?.type).toBe("text");
if (!second.step) throw new Error("expected second step");
await session.answer(second.step.id, "Peter");
const third = await session.next();
expect(third.step?.type).toBe("note");
if (!third.step) throw new Error("expected third step");
await session.answer(third.step.id, null);
const done = await session.next();
expect(done.done).toBe(true);
expect(done.status).toBe("done");
});
test("invalid answers throw", async () => {
const session = noteRunner();
const first = await session.next();
await expect(session.answer("bad-id", null)).rejects.toThrow(
/wizard: no pending step/i,
);
if (!first.step) throw new Error("expected first step");
await session.answer(first.step.id, null);
});
test("cancel marks session and unblocks", async () => {
const session = new WizardSession(async (prompter) => {
await prompter.text({ message: "Name" });
});
const step = await session.next();
expect(step.step?.type).toBe("text");
session.cancel();
const done = await session.next();
expect(done.done).toBe(true);
expect(done.status).toBe("cancelled");
});
});