mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test: normalize boot-md mock workspace paths for cross-platform
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { InternalHookEvent } from "../../internal-hooks.js";
|
||||
|
||||
@@ -6,6 +7,8 @@ const listAgentIds = vi.fn();
|
||||
const resolveAgentWorkspaceDir = vi.fn();
|
||||
const logWarn = vi.fn();
|
||||
const logDebug = vi.fn();
|
||||
const MAIN_WORKSPACE_DIR = path.join(path.sep, "ws", "main");
|
||||
const OPS_WORKSPACE_DIR = path.join(path.sep, "ws", "ops");
|
||||
|
||||
vi.mock("../../../gateway/boot.js", () => ({ runBootOnce }));
|
||||
vi.mock("../../../agents/agent-scope.js", () => ({
|
||||
@@ -58,7 +61,9 @@ describe("boot-md handler", () => {
|
||||
it("runs boot for each agent", async () => {
|
||||
const cfg = { agents: { list: [{ id: "main" }, { id: "ops" }] } };
|
||||
listAgentIds.mockReturnValue(["main", "ops"]);
|
||||
resolveAgentWorkspaceDir.mockImplementation((_cfg: unknown, id: string) => `/ws/${id}`);
|
||||
resolveAgentWorkspaceDir.mockImplementation((_cfg: unknown, id: string) =>
|
||||
id === "main" ? MAIN_WORKSPACE_DIR : OPS_WORKSPACE_DIR,
|
||||
);
|
||||
runBootOnce.mockResolvedValue({ status: "ran" });
|
||||
|
||||
await runBootChecklist(makeEvent({ context: { cfg } }));
|
||||
@@ -66,31 +71,33 @@ describe("boot-md handler", () => {
|
||||
expect(listAgentIds).toHaveBeenCalledWith(cfg);
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(2);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: "/ws/main", agentId: "main" }),
|
||||
expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }),
|
||||
);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: "/ws/ops", agentId: "ops" }),
|
||||
expect.objectContaining({ cfg, workspaceDir: OPS_WORKSPACE_DIR, agentId: "ops" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("runs boot for single default agent when no agents configured", async () => {
|
||||
const cfg = {};
|
||||
listAgentIds.mockReturnValue(["main"]);
|
||||
resolveAgentWorkspaceDir.mockReturnValue("/ws/main");
|
||||
resolveAgentWorkspaceDir.mockReturnValue(MAIN_WORKSPACE_DIR);
|
||||
runBootOnce.mockResolvedValue({ status: "skipped", reason: "missing" });
|
||||
|
||||
await runBootChecklist(makeEvent({ context: { cfg } }));
|
||||
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(1);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: "/ws/main", agentId: "main" }),
|
||||
expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("logs warning details when a per-agent boot run fails", async () => {
|
||||
const cfg = { agents: { list: [{ id: "main" }, { id: "ops" }] } };
|
||||
listAgentIds.mockReturnValue(["main", "ops"]);
|
||||
resolveAgentWorkspaceDir.mockImplementation((_cfg: unknown, id: string) => `/ws/${id}`);
|
||||
resolveAgentWorkspaceDir.mockImplementation((_cfg: unknown, id: string) =>
|
||||
id === "main" ? MAIN_WORKSPACE_DIR : OPS_WORKSPACE_DIR,
|
||||
);
|
||||
runBootOnce
|
||||
.mockResolvedValueOnce({ status: "ran" })
|
||||
.mockResolvedValueOnce({ status: "failed", reason: "agent failed" });
|
||||
@@ -100,7 +107,7 @@ describe("boot-md handler", () => {
|
||||
expect(logWarn).toHaveBeenCalledTimes(1);
|
||||
expect(logWarn).toHaveBeenCalledWith("boot-md failed for agent startup run", {
|
||||
agentId: "ops",
|
||||
workspaceDir: "/ws/ops",
|
||||
workspaceDir: OPS_WORKSPACE_DIR,
|
||||
reason: "agent failed",
|
||||
});
|
||||
});
|
||||
@@ -108,14 +115,14 @@ describe("boot-md handler", () => {
|
||||
it("logs debug details when a per-agent boot run is skipped", async () => {
|
||||
const cfg = { agents: { list: [{ id: "main" }] } };
|
||||
listAgentIds.mockReturnValue(["main"]);
|
||||
resolveAgentWorkspaceDir.mockReturnValue("/ws/main");
|
||||
resolveAgentWorkspaceDir.mockReturnValue(MAIN_WORKSPACE_DIR);
|
||||
runBootOnce.mockResolvedValue({ status: "skipped", reason: "missing" });
|
||||
|
||||
await runBootChecklist(makeEvent({ context: { cfg } }));
|
||||
|
||||
expect(logDebug).toHaveBeenCalledWith("boot-md skipped for agent startup run", {
|
||||
agentId: "main",
|
||||
workspaceDir: "/ws/main",
|
||||
workspaceDir: MAIN_WORKSPACE_DIR,
|
||||
reason: "missing",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user