mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:57:40 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user