refactor(test): share onboarding and model auth test helpers

This commit is contained in:
Peter Steinberger
2026-02-16 16:48:36 +00:00
parent ac5f6e7c9d
commit 2d8edf85ad
10 changed files with 253 additions and 244 deletions

View File

@@ -34,6 +34,23 @@ describe("applyAuthChoice (moonshot)", () => {
}>(requireOpenClawAgentDir());
}
async function runMoonshotCnFlow(params: {
config: Record<string, unknown>;
setDefaultModel: boolean;
}) {
const text = vi.fn().mockResolvedValue("sk-moonshot-cn-test");
const prompter = createPrompter({ text: text as unknown as WizardPrompter["text"] });
const runtime = createExitThrowingRuntime();
const result = await applyAuthChoice({
authChoice: "moonshot-api-key-cn",
config: params.config,
prompter,
runtime,
setDefaultModel: params.setDefaultModel,
});
return { result, text };
}
afterEach(async () => {
await lifecycle.cleanup();
});
@@ -41,12 +58,7 @@ describe("applyAuthChoice (moonshot)", () => {
it("keeps the .cn baseUrl when setDefaultModel is false", async () => {
await setupTempState();
const text = vi.fn().mockResolvedValue("sk-moonshot-cn-test");
const prompter = createPrompter({ text: text as unknown as WizardPrompter["text"] });
const runtime = createExitThrowingRuntime();
const result = await applyAuthChoice({
authChoice: "moonshot-api-key-cn",
const { result, text } = await runMoonshotCnFlow({
config: {
agents: {
defaults: {
@@ -54,8 +66,6 @@ describe("applyAuthChoice (moonshot)", () => {
},
},
},
prompter,
runtime,
setDefaultModel: false,
});
@@ -73,15 +83,8 @@ describe("applyAuthChoice (moonshot)", () => {
it("sets the default model when setDefaultModel is true", async () => {
await setupTempState();
const text = vi.fn().mockResolvedValue("sk-moonshot-cn-test");
const prompter = createPrompter({ text: text as unknown as WizardPrompter["text"] });
const runtime = createExitThrowingRuntime();
const result = await applyAuthChoice({
authChoice: "moonshot-api-key-cn",
const { result } = await runMoonshotCnFlow({
config: {},
prompter,
runtime,
setDefaultModel: true,
});