mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:34:32 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -2,13 +2,11 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import { applyAuthChoice } from "./auth-choice.js";
|
||||
import { createExitThrowingRuntime, createWizardPrompter } from "./test-wizard-helpers.js";
|
||||
|
||||
const noopAsync = async () => {};
|
||||
const noop = () => {};
|
||||
const authProfilePathFor = (agentDir: string) => path.join(agentDir, "auth-profiles.json");
|
||||
const requireAgentDir = () => {
|
||||
const agentDir = process.env.OPENCLAW_AGENT_DIR;
|
||||
@@ -18,28 +16,8 @@ const requireAgentDir = () => {
|
||||
return agentDir;
|
||||
};
|
||||
|
||||
function createRuntime(): RuntimeEnv {
|
||||
return {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn((code: number) => {
|
||||
throw new Error(`exit:${code}`);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function createPrompter(overrides: Partial<WizardPrompter>): WizardPrompter {
|
||||
return {
|
||||
intro: vi.fn(noopAsync),
|
||||
outro: vi.fn(noopAsync),
|
||||
note: vi.fn(noopAsync),
|
||||
select: vi.fn(async () => "" as never),
|
||||
multiselect: vi.fn(async () => []),
|
||||
text: vi.fn(async () => "") as unknown as WizardPrompter["text"],
|
||||
confirm: vi.fn(async () => false),
|
||||
progress: vi.fn(() => ({ update: noop, stop: noop })),
|
||||
...overrides,
|
||||
};
|
||||
return createWizardPrompter(overrides, { defaultSelect: "" });
|
||||
}
|
||||
|
||||
describe("applyAuthChoice (moonshot)", () => {
|
||||
@@ -72,7 +50,7 @@ describe("applyAuthChoice (moonshot)", () => {
|
||||
|
||||
const text = vi.fn().mockResolvedValue("sk-moonshot-cn-test");
|
||||
const prompter = createPrompter({ text: text as unknown as WizardPrompter["text"] });
|
||||
const runtime = createRuntime();
|
||||
const runtime = createExitThrowingRuntime();
|
||||
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: "moonshot-api-key-cn",
|
||||
@@ -108,7 +86,7 @@ describe("applyAuthChoice (moonshot)", () => {
|
||||
|
||||
const text = vi.fn().mockResolvedValue("sk-moonshot-cn-test");
|
||||
const prompter = createPrompter({ text: text as unknown as WizardPrompter["text"] });
|
||||
const runtime = createRuntime();
|
||||
const runtime = createExitThrowingRuntime();
|
||||
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: "moonshot-api-key-cn",
|
||||
|
||||
Reference in New Issue
Block a user