From 91a3554cd7c2048ed7172f06bb2a3dc5945b45b8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 3 Apr 2026 18:55:20 +0100 Subject: [PATCH] test: trim session status module resets --- .../openclaw-tools.session-status.test.ts | 85 ++++++++----------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/src/agents/openclaw-tools.session-status.test.ts b/src/agents/openclaw-tools.session-status.test.ts index 56ad71c44a7..d628449a367 100644 --- a/src/agents/openclaw-tools.session-status.test.ts +++ b/src/agents/openclaw-tools.session-status.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { SessionEntry } from "../config/sessions.js"; import { resolvePreferredSessionKeyForSessionIdMatches } from "../sessions/session-id-resolution.js"; import type { TaskRecord } from "../tasks/task-registry.types.js"; @@ -79,10 +79,9 @@ function installScopedSessionStores(syncUpdates = false) { return stores; } -async function createSessionsModuleMock( - importOriginal: () => Promise, -) { - const actual = await importOriginal(); +async function createSessionsModuleMock() { + const actual = + await vi.importActual("../config/sessions.js"); return { ...actual, loadSessionStore: (storePath: string) => loadSessionStoreMock(storePath), @@ -106,10 +105,10 @@ function createGatewayCallModuleMock() { }; } -async function createGatewaySessionUtilsModuleMock( - importOriginal: () => Promise, -) { - const actual = await importOriginal(); +async function createGatewaySessionUtilsModuleMock() { + const actual = await vi.importActual( + "../gateway/session-utils.js", + ); return { ...actual, loadCombinedSessionStoreForGateway: (cfg: unknown) => @@ -117,10 +116,8 @@ async function createGatewaySessionUtilsModuleMock( }; } -async function createConfigModuleMock( - importOriginal: () => Promise, -) { - const actual = await importOriginal(); +async function createConfigModuleMock() { + const actual = await vi.importActual("../config/config.js"); return { ...actual, loadConfig: () => mockConfig, @@ -181,44 +178,35 @@ vi.mock("../agents/model-catalog.js", createModelCatalogModuleMock); vi.mock("../agents/auth-profiles.js", createAuthProfilesModuleMock); vi.mock("../agents/model-auth.js", createModelAuthModuleMock); vi.mock("../infra/provider-usage.js", createProviderUsageModuleMock); +vi.mock("../auto-reply/group-activation.js", () => ({ + normalizeGroupActivation: (value: unknown) => value ?? "always", +})); +vi.mock("../auto-reply/reply/queue.js", () => ({ + getFollowupQueueDepth: () => 0, + resolveQueueSettings: resolveQueueSettingsMock, +})); +vi.mock("../auto-reply/status.js", () => ({ + buildStatusMessage: buildStatusMessageMock, +})); +vi.mock("../tasks/task-owner-access.js", () => ({ + listTasksForRelatedSessionKeyForOwner: (params: { + relatedSessionKey: string; + callerOwnerKey: string; + }) => listTasksForRelatedSessionKeyForOwnerMock(params), + buildTaskStatusSnapshotForRelatedSessionKeyForOwner: (params: { + relatedSessionKey: string; + callerOwnerKey: string; + }) => + buildTaskStatusSnapshot(listTasksForRelatedSessionKeyForOwnerMock(params) as TaskRecord[], { + now: TASK_STATUS_SNAPSHOT_NOW, + }), +})); let createSessionStatusTool: typeof import("./tools/session-status-tool.js").createSessionStatusTool; -async function loadFreshOpenClawToolsForSessionStatusTest() { - vi.resetModules(); - vi.doMock("../config/sessions.js", createSessionsModuleMock); - vi.doMock("../gateway/call.js", createGatewayCallModuleMock); - vi.doMock("../gateway/session-utils.js", createGatewaySessionUtilsModuleMock); - vi.doMock("../config/config.js", createConfigModuleMock); - vi.doMock("../agents/model-catalog.js", createModelCatalogModuleMock); - vi.doMock("../agents/auth-profiles.js", createAuthProfilesModuleMock); - vi.doMock("../agents/model-auth.js", createModelAuthModuleMock); - vi.doMock("../infra/provider-usage.js", createProviderUsageModuleMock); - vi.doMock("../auto-reply/group-activation.js", () => ({ - normalizeGroupActivation: (value: unknown) => value ?? "always", - })); - vi.doMock("../auto-reply/reply/queue.js", () => ({ - getFollowupQueueDepth: () => 0, - resolveQueueSettings: resolveQueueSettingsMock, - })); - vi.doMock("../auto-reply/status.js", () => ({ - buildStatusMessage: buildStatusMessageMock, - })); - vi.doMock("../tasks/task-owner-access.js", () => ({ - listTasksForRelatedSessionKeyForOwner: (params: { - relatedSessionKey: string; - callerOwnerKey: string; - }) => listTasksForRelatedSessionKeyForOwnerMock(params), - buildTaskStatusSnapshotForRelatedSessionKeyForOwner: (params: { - relatedSessionKey: string; - callerOwnerKey: string; - }) => - buildTaskStatusSnapshot(listTasksForRelatedSessionKeyForOwnerMock(params) as TaskRecord[], { - now: TASK_STATUS_SNAPSHOT_NOW, - }), - })); +beforeAll(async () => { ({ createSessionStatusTool } = await import("./tools/session-status-tool.js")); -} +}); function resetSessionStore(store: Record) { buildStatusMessageMock.mockClear(); @@ -325,9 +313,8 @@ function getSessionStatusTool(agentSessionKey = "main", options?: { sandboxed?: } describe("session_status tool", () => { - beforeEach(async () => { + beforeEach(() => { buildStatusMessageMock.mockClear(); - await loadFreshOpenClawToolsForSessionStatusTest(); }); it("returns a status card for the current session", async () => {