From c0d27a96ffdda5254bf0db9e816fcd98ad2bc9db Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 21:23:10 +0100 Subject: [PATCH] test: rename state cleanup helper --- src/agents/models-config.e2e-harness.ts | 2 +- .../stage-sandbox-media.test-harness.ts | 2 +- src/commands/agent.session.test.ts | 2 +- src/commands/agent.test.ts | 2 +- src/commands/doctor-config-flow.test.ts | 8 ++++---- src/config/mcp-config.test.ts | 2 +- src/plugin-sdk/test-helpers/temp-home.ts | 8 ++++---- src/test-helpers/state-dir-env.ts | 4 ++-- ...up.test.ts => openclaw-state-cleanup.test.ts} | 16 ++++++++-------- ...tate-cleanup.ts => openclaw-state-cleanup.ts} | 6 +++--- src/test-utils/openclaw-test-state.ts | 4 ++-- src/test-utils/temp-home.ts | 4 ++-- 12 files changed, 30 insertions(+), 30 deletions(-) rename src/test-utils/{session-state-cleanup.test.ts => openclaw-state-cleanup.test.ts} (66%) rename src/test-utils/{session-state-cleanup.ts => openclaw-state-cleanup.ts} (77%) diff --git a/src/agents/models-config.e2e-harness.ts b/src/agents/models-config.e2e-harness.ts index a858d32e4aa..dd1131171c1 100644 --- a/src/agents/models-config.e2e-harness.ts +++ b/src/agents/models-config.e2e-harness.ts @@ -10,7 +10,7 @@ export function withModelsTempHome(fn: (home: string) => Promise): Promise // unrelated session database state during temp-home teardown. return withTempHomeBase(fn, { prefix: "openclaw-models-", - skipSessionCleanup: true, + skipStateCleanup: true, }); } diff --git a/src/auto-reply/stage-sandbox-media.test-harness.ts b/src/auto-reply/stage-sandbox-media.test-harness.ts index 27e2db70896..0b7666ae5d1 100644 --- a/src/auto-reply/stage-sandbox-media.test-harness.ts +++ b/src/auto-reply/stage-sandbox-media.test-harness.ts @@ -7,7 +7,7 @@ export async function withSandboxMediaTempHome( prefix: string, fn: (home: string) => Promise, ): Promise { - return withTempHomeBase(async (home) => await fn(home), { prefix, skipSessionCleanup: true }); + return withTempHomeBase(async (home) => await fn(home), { prefix, skipStateCleanup: true }); } export function createSandboxMediaContexts(mediaPath: string): { diff --git a/src/commands/agent.session.test.ts b/src/commands/agent.session.test.ts index 46989cf83fe..b3e26b9db3d 100644 --- a/src/commands/agent.session.test.ts +++ b/src/commands/agent.session.test.ts @@ -17,7 +17,7 @@ async function withTempHome(fn: (home: string) => Promise): Promise { }, { prefix: "openclaw-agent-session-", - skipSessionCleanup: true, + skipStateCleanup: true, }, ); } diff --git a/src/commands/agent.test.ts b/src/commands/agent.test.ts index a921c65e239..105a6cbd671 100644 --- a/src/commands/agent.test.ts +++ b/src/commands/agent.test.ts @@ -257,7 +257,7 @@ async function withTempHome(fn: (home: string) => Promise): Promise { { prefix: "openclaw-agent-", skipHomeCleanup: true, - skipSessionCleanup: true, + skipStateCleanup: true, }, ); } diff --git a/src/commands/doctor-config-flow.test.ts b/src/commands/doctor-config-flow.test.ts index 71c3bdbd427..d03c9c8e5ef 100644 --- a/src/commands/doctor-config-flow.test.ts +++ b/src/commands/doctor-config-flow.test.ts @@ -1848,7 +1848,7 @@ describe("doctor config flow", () => { blockStreaming: true, }); }, - { skipSessionCleanup: true }, + { skipStateCleanup: true }, ); }); @@ -2197,7 +2197,7 @@ describe("doctor config flow", () => { "1212", ]); }, - { skipSessionCleanup: true }, + { skipStateCleanup: true }, ); }); @@ -2307,7 +2307,7 @@ describe("doctor config flow", () => { confirm: async () => false, }); }, - { skipSessionCleanup: true }, + { skipStateCleanup: true }, ); const cfg = result.cfg as { @@ -2657,7 +2657,7 @@ describe("doctor config flow", () => { noteSpy.mockClear(); } }, - { skipSessionCleanup: true }, + { skipStateCleanup: true }, ); }); diff --git a/src/config/mcp-config.test.ts b/src/config/mcp-config.test.ts index e3d0c94ad36..272b0fea408 100644 --- a/src/config/mcp-config.test.ts +++ b/src/config/mcp-config.test.ts @@ -67,7 +67,7 @@ async function withMcpConfigHome( }, { prefix: "openclaw-mcp-config-", - skipSessionCleanup: true, + skipStateCleanup: true, env: { OPENCLAW_CONFIG_PATH: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: undefined, diff --git a/src/plugin-sdk/test-helpers/temp-home.ts b/src/plugin-sdk/test-helpers/temp-home.ts index a7c5de46fc4..bad73acffe2 100644 --- a/src/plugin-sdk/test-helpers/temp-home.ts +++ b/src/plugin-sdk/test-helpers/temp-home.ts @@ -1,7 +1,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { cleanupSessionStateForTest } from "../../test-utils/session-state-cleanup.js"; +import { cleanupOpenClawStateForTest } from "../../test-utils/openclaw-state-cleanup.js"; type EnvValue = string | undefined | ((home: string) => string | undefined); @@ -105,7 +105,7 @@ export async function withTempHome( env?: Record; prefix?: string; skipHomeCleanup?: boolean; - skipSessionCleanup?: boolean; + skipStateCleanup?: boolean; } = {}, ): Promise { const prefix = opts.prefix ?? "openclaw-test-home-"; @@ -135,8 +135,8 @@ export async function withTempHome( try { return await fn(base); } finally { - if (!opts.skipSessionCleanup) { - await cleanupSessionStateForTest().catch(() => undefined); + if (!opts.skipStateCleanup) { + await cleanupOpenClawStateForTest().catch(() => undefined); } restoreExtraEnv(envSnapshot); restoreEnv(snapshot); diff --git a/src/test-helpers/state-dir-env.ts b/src/test-helpers/state-dir-env.ts index ad0b5ec5f3f..890f445f285 100644 --- a/src/test-helpers/state-dir-env.ts +++ b/src/test-helpers/state-dir-env.ts @@ -2,7 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { captureEnv } from "../test-utils/env.js"; -import { cleanupSessionStateForTest } from "../test-utils/session-state-cleanup.js"; +import { cleanupOpenClawStateForTest } from "../test-utils/openclaw-state-cleanup.js"; export function snapshotStateDirEnv() { return captureEnv(["OPENCLAW_STATE_DIR"]); @@ -28,7 +28,7 @@ export async function withStateDirEnv( try { return await fn({ tempRoot, stateDir }); } finally { - await cleanupSessionStateForTest().catch(() => undefined); + await cleanupOpenClawStateForTest().catch(() => undefined); restoreStateDirEnv(snapshot); await fs.rm(tempRoot, { recursive: true, force: true }); } diff --git a/src/test-utils/session-state-cleanup.test.ts b/src/test-utils/openclaw-state-cleanup.test.ts similarity index 66% rename from src/test-utils/session-state-cleanup.test.ts rename to src/test-utils/openclaw-state-cleanup.test.ts index 9f589d33c68..72de6b56d9f 100644 --- a/src/test-utils/session-state-cleanup.test.ts +++ b/src/test-utils/openclaw-state-cleanup.test.ts @@ -1,19 +1,19 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { resetFileLockStateForTest } from "../infra/file-lock.js"; import { - cleanupSessionStateForTest, - resetSessionStateCleanupRuntimeForTests, - setSessionStateCleanupRuntimeForTests, -} from "./session-state-cleanup.js"; + cleanupOpenClawStateForTest, + resetOpenClawStateCleanupRuntimeForTests, + setOpenClawStateCleanupRuntimeForTests, +} from "./openclaw-state-cleanup.js"; const drainFileLockStateMock = vi.hoisted(() => vi.fn(async () => undefined)); -describe("cleanupSessionStateForTest", () => { +describe("cleanupOpenClawStateForTest", () => { beforeEach(() => { vi.useRealTimers(); resetFileLockStateForTest(); drainFileLockStateMock.mockClear(); - setSessionStateCleanupRuntimeForTests({ + setOpenClawStateCleanupRuntimeForTests({ drainFileLockStateForTest: drainFileLockStateMock, }); }); @@ -21,12 +21,12 @@ describe("cleanupSessionStateForTest", () => { afterEach(() => { vi.useRealTimers(); resetFileLockStateForTest(); - resetSessionStateCleanupRuntimeForTests(); + resetOpenClawStateCleanupRuntimeForTests(); vi.restoreAllMocks(); }); it("cleans file locks and closes SQLite state", async () => { - await cleanupSessionStateForTest(); + await cleanupOpenClawStateForTest(); expect(drainFileLockStateMock).toHaveBeenCalledTimes(1); }); diff --git a/src/test-utils/session-state-cleanup.ts b/src/test-utils/openclaw-state-cleanup.ts similarity index 77% rename from src/test-utils/session-state-cleanup.ts rename to src/test-utils/openclaw-state-cleanup.ts index 46ca7b21224..29fcfc7fae0 100644 --- a/src/test-utils/session-state-cleanup.ts +++ b/src/test-utils/openclaw-state-cleanup.ts @@ -4,7 +4,7 @@ import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js let fileLockDrainerForTests: typeof drainFileLockStateForTest | null = null; -export function setSessionStateCleanupRuntimeForTests(params: { +export function setOpenClawStateCleanupRuntimeForTests(params: { drainFileLockStateForTest?: typeof drainFileLockStateForTest | null; }): void { if ("drainFileLockStateForTest" in params) { @@ -12,11 +12,11 @@ export function setSessionStateCleanupRuntimeForTests(params: { } } -export function resetSessionStateCleanupRuntimeForTests(): void { +export function resetOpenClawStateCleanupRuntimeForTests(): void { fileLockDrainerForTests = null; } -export async function cleanupSessionStateForTest(): Promise { +export async function cleanupOpenClawStateForTest(): Promise { await (fileLockDrainerForTests ?? drainFileLockStateForTest)(); closeOpenClawAgentDatabasesForTest(); closeOpenClawStateDatabaseForTest(); diff --git a/src/test-utils/openclaw-test-state.ts b/src/test-utils/openclaw-test-state.ts index 525c5c08bb2..6c6926693b7 100644 --- a/src/test-utils/openclaw-test-state.ts +++ b/src/test-utils/openclaw-test-state.ts @@ -2,7 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { captureEnv } from "./env.js"; -import { cleanupSessionStateForTest } from "./session-state-cleanup.js"; +import { cleanupOpenClawStateForTest } from "./openclaw-state-cleanup.js"; type OpenClawTestStateLayout = "home" | "state-only" | "split"; @@ -321,7 +321,7 @@ export async function createOpenClawTestState( return; } cleaned = true; - await cleanupSessionStateForTest().catch(() => undefined); + await cleanupOpenClawStateForTest().catch(() => undefined); state.restoreEnv(); await fs.rm(root, { recursive: true, force: true }); }, diff --git a/src/test-utils/temp-home.ts b/src/test-utils/temp-home.ts index 427c0f80ed2..8645c9c27e3 100644 --- a/src/test-utils/temp-home.ts +++ b/src/test-utils/temp-home.ts @@ -2,7 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { captureEnv } from "./env.js"; -import { cleanupSessionStateForTest } from "./session-state-cleanup.js"; +import { cleanupOpenClawStateForTest } from "./openclaw-state-cleanup.js"; const HOME_ENV_KEYS = [ "HOME", @@ -64,7 +64,7 @@ export async function createTempHomeEnv(prefix: string): Promise { return { home, restore: async () => { - await cleanupSessionStateForTest().catch(() => undefined); + await cleanupOpenClawStateForTest().catch(() => undefined); snapshot.restore(); await fs.rm(home, { recursive: true, force: true }); },