mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 06:40:45 +00:00
test: tighten boot hook assertions
This commit is contained in:
@@ -22,6 +22,22 @@ const { default: runBootChecklist } = await import("./handler.js");
|
||||
const { clearInternalHooks, createInternalHookEvent, registerInternalHook, triggerInternalHook } =
|
||||
await import("../../internal-hooks.js");
|
||||
|
||||
function expectBootCall(
|
||||
index: number,
|
||||
expected: { cfg: OpenClawConfig; deps: CliDeps; workspaceDir: string; agentId: string },
|
||||
) {
|
||||
const params = runBootOnce.mock.calls[index]?.[0] as
|
||||
| { cfg?: unknown; deps?: unknown; workspaceDir?: unknown; agentId?: unknown }
|
||||
| undefined;
|
||||
if (!params) {
|
||||
throw new Error(`missing boot call ${index}`);
|
||||
}
|
||||
expect(params.cfg).toBe(expected.cfg);
|
||||
expect(params.deps).toBe(expected.deps);
|
||||
expect(params.workspaceDir).toBe(expected.workspaceDir);
|
||||
expect(params.agentId).toBe(expected.agentId);
|
||||
}
|
||||
|
||||
describe("boot-md startup hook integration", () => {
|
||||
beforeEach(() => {
|
||||
runBootOnce.mockClear();
|
||||
@@ -53,13 +69,7 @@ describe("boot-md startup hook integration", () => {
|
||||
const opsWorkspaceDir = resolveAgentWorkspaceDir(cfg, "ops");
|
||||
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(2);
|
||||
expect(runBootOnce).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.objectContaining({ cfg, deps, workspaceDir: mainWorkspaceDir, agentId: "main" }),
|
||||
);
|
||||
expect(runBootOnce).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({ cfg, deps, workspaceDir: opsWorkspaceDir, agentId: "ops" }),
|
||||
);
|
||||
expectBootCall(0, { cfg, deps, workspaceDir: mainWorkspaceDir, agentId: "main" });
|
||||
expectBootCall(1, { cfg, deps, workspaceDir: opsWorkspaceDir, agentId: "ops" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,6 +41,21 @@ function makeEvent(overrides?: Partial<InternalHookEvent>): InternalHookEvent {
|
||||
};
|
||||
}
|
||||
|
||||
function expectBootCall(
|
||||
index: number,
|
||||
expected: { cfg: unknown; workspaceDir: string; agentId: string },
|
||||
) {
|
||||
const params = runBootOnce.mock.calls[index]?.[0] as
|
||||
| { cfg?: unknown; workspaceDir?: unknown; agentId?: unknown }
|
||||
| undefined;
|
||||
if (!params) {
|
||||
throw new Error(`missing boot call ${index}`);
|
||||
}
|
||||
expect(params.cfg).toBe(expected.cfg);
|
||||
expect(params.workspaceDir).toBe(expected.workspaceDir);
|
||||
expect(params.agentId).toBe(expected.agentId);
|
||||
}
|
||||
|
||||
describe("boot-md handler", () => {
|
||||
function setupTwoAgentBootConfig() {
|
||||
const cfg = { agents: { list: [{ id: "main" }, { id: "ops" }] } };
|
||||
@@ -84,12 +99,8 @@ describe("boot-md handler", () => {
|
||||
|
||||
expect(listAgentIds).toHaveBeenCalledWith(cfg);
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(2);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }),
|
||||
);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: OPS_WORKSPACE_DIR, agentId: "ops" }),
|
||||
);
|
||||
expectBootCall(0, { cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" });
|
||||
expectBootCall(1, { cfg, workspaceDir: OPS_WORKSPACE_DIR, agentId: "ops" });
|
||||
});
|
||||
|
||||
it("runs boot for single default agent when no agents configured", async () => {
|
||||
@@ -99,9 +110,7 @@ describe("boot-md handler", () => {
|
||||
await runBootChecklist(makeEvent({ context: { cfg } }));
|
||||
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(1);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }),
|
||||
);
|
||||
expectBootCall(0, { cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" });
|
||||
});
|
||||
|
||||
it("logs warning details when a per-agent boot run fails", async () => {
|
||||
@@ -144,8 +153,6 @@ describe("boot-md handler", () => {
|
||||
await runBootChecklist(makeEvent({ context: { cfg } }));
|
||||
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(1);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }),
|
||||
);
|
||||
expectBootCall(0, { cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user