






















@@ -1,25 +1,49 @@
11import fs from "node:fs/promises";
22import os from "node:os";
33import path from "node:path";
4-import { afterEach, describe, expect, it, vi } from "vitest";
5-import type { RuntimeEnv } from "../runtime.js";
4+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
65import { runCrestodian } from "./crestodian.js";
6+import { createCrestodianTestRuntime } from "./crestodian.test-helpers.js";
778-function createRuntime(): { runtime: RuntimeEnv; lines: string[] } {
9-const lines: string[] = [];
10-return {
11- lines,
12-runtime: {
13-log: (...args) => lines.push(args.join(" ")),
14-error: (...args) => lines.push(args.join(" ")),
15-exit: (code) => {
16-throw new Error(`exit ${code}`);
17-},
8+vi.mock("./probes.js", () => ({
9+probeLocalCommand: vi.fn(async (command: string) => ({
10+ command,
11+found: false,
12+error: "not found",
13+})),
14+probeGatewayUrl: vi.fn(async (url: string) => ({ reachable: false, url, error: "offline" })),
15+}));
16+17+vi.mock("./overview.js", () => ({
18+formatCrestodianOverview: () => "Default model: openai/gpt-5.5",
19+loadCrestodianOverview: vi.fn(async () => ({
20+defaultAgentId: "main",
21+defaultModel: "openai/gpt-5.5",
22+agents: [{ id: "main", isDefault: true, model: "openai/gpt-5.5" }],
23+config: { path: "/tmp/openclaw.json", exists: true, valid: true, issues: [], hash: null },
24+tools: {
25+codex: { command: "codex", found: false, error: "not found" },
26+claude: { command: "claude", found: false, error: "not found" },
27+apiKeys: { openai: true, anthropic: false },
28+},
29+gateway: {
30+url: "ws://127.0.0.1:18789",
31+source: "local loopback",
32+reachable: false,
33+error: "offline",
1834},
19-};
20-}
35+references: {
36+docsUrl: "https://docs.openclaw.ai",
37+sourceUrl: "https://github.com/openclaw/openclaw",
38+},
39+})),
40+}));
21412242describe("runCrestodian", () => {
43+beforeEach(() => {
44+vi.stubEnv("OPENCLAW_TEST_FAST", "1");
45+});
46+2347afterEach(() => {
2448vi.unstubAllEnvs();
2549});
@@ -28,7 +52,7 @@ describe("runCrestodian", () => {
2852const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-run-"));
2953vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
3054vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(tempDir, "openclaw.json"));
31-const { runtime, lines } = createRuntime();
55+const { runtime, lines } = createCrestodianTestRuntime();
3256const runGatewayRestart = vi.fn(async () => {});
33573458await runCrestodian(
@@ -54,7 +78,7 @@ describe("runCrestodian", () => {
5478const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-run-deterministic-"));
5579vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
5680vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(tempDir, "openclaw.json"));
57-const { runtime, lines } = createRuntime();
81+const { runtime, lines } = createCrestodianTestRuntime();
5882const planner = vi.fn(async () => ({ command: "restart gateway" }));
59836084await runCrestodian(
@@ -73,7 +97,7 @@ describe("runCrestodian", () => {
7397const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-run-tui-"));
7498vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
7599vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(tempDir, "openclaw.json"));
76-const { runtime, lines } = createRuntime();
100+const { runtime, lines } = createCrestodianTestRuntime();
77101const runInteractiveTui = vi.fn(async () => {});
7810279103await runCrestodian(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。