From 91adcc68feac7067c12d7ca908565bbf96cc8041 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 12:50:53 +0100 Subject: [PATCH] test: tighten boot hook assertions --- ...andler.gateway-startup.integration.test.ts | 26 +++++++++++----- src/hooks/bundled/boot-md/handler.test.ts | 31 ++++++++++++------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/hooks/bundled/boot-md/handler.gateway-startup.integration.test.ts b/src/hooks/bundled/boot-md/handler.gateway-startup.integration.test.ts index d4d441fa687..27221fbda48 100644 --- a/src/hooks/bundled/boot-md/handler.gateway-startup.integration.test.ts +++ b/src/hooks/bundled/boot-md/handler.gateway-startup.integration.test.ts @@ -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" }); }); }); diff --git a/src/hooks/bundled/boot-md/handler.test.ts b/src/hooks/bundled/boot-md/handler.test.ts index 258a58b84e3..e0a2c5f55dc 100644 --- a/src/hooks/bundled/boot-md/handler.test.ts +++ b/src/hooks/bundled/boot-md/handler.test.ts @@ -41,6 +41,21 @@ function makeEvent(overrides?: Partial): 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" }); }); });