refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { RuntimeEnv } from "../runtime.js";
import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js";
const configMocks = vi.hoisted(() => ({
readConfigFileSnapshot: vi.fn(),
@@ -26,22 +26,7 @@ vi.mock("../wizard/clack-prompter.js", () => ({
import { WizardCancelledError } from "../wizard/prompts.js";
import { agentsAddCommand } from "./agents.js";
const runtime: RuntimeEnv = {
log: vi.fn(),
error: vi.fn(),
exit: vi.fn(),
};
const baseSnapshot = {
path: "/tmp/openclaw.json",
exists: true,
raw: "{}",
parsed: {},
valid: true,
config: {},
issues: [],
legacyIssues: [],
};
const runtime = createTestRuntime();
describe("agents add command", () => {
beforeEach(() => {
@@ -54,7 +39,7 @@ describe("agents add command", () => {
});
it("requires --workspace when flags are present", async () => {
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseSnapshot });
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseConfigSnapshot });
await agentsAddCommand({ name: "Work" }, runtime, { hasFlags: true });
@@ -64,7 +49,7 @@ describe("agents add command", () => {
});
it("requires --workspace in non-interactive mode", async () => {
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseSnapshot });
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseConfigSnapshot });
await agentsAddCommand({ name: "Work", nonInteractive: true }, runtime, {
hasFlags: false,
@@ -76,7 +61,7 @@ describe("agents add command", () => {
});
it("exits with code 1 when the interactive wizard is cancelled", async () => {
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseSnapshot });
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseConfigSnapshot });
wizardMocks.createClackPrompter.mockReturnValue({
intro: vi.fn().mockRejectedValue(new WizardCancelledError()),
text: vi.fn(),