test: stabilize windows registry cleanup flows

This commit is contained in:
Shakker
2026-03-30 21:35:54 +01:00
committed by Shakker
parent 72cb2a88f1
commit 7d70b1b51e
3 changed files with 20 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ import { setTimeout as sleep } from "node:timers/promises";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import type { AcpSessionRuntimeOptions, SessionAcpMeta } from "../../config/sessions/types.js";
import { resetFlowRegistryForTests } from "../../tasks/flow-registry.js";
import { findTaskByRunId, resetTaskRegistryForTests } from "../../tasks/task-registry.js";
import { withTempDir } from "../../test-helpers/temp-dir.js";
import type { AcpRuntime, AcpRuntimeCapabilities } from "../runtime/types.js";
@@ -52,10 +53,12 @@ async function withAcpManagerTaskStateDir(run: (root: string) => Promise<void>):
await withTempDir({ prefix: "openclaw-acp-manager-task-" }, async (root) => {
process.env.OPENCLAW_STATE_DIR = root;
resetTaskRegistryForTests();
resetFlowRegistryForTests();
try {
await run(root);
} finally {
resetTaskRegistryForTests();
resetFlowRegistryForTests();
}
});
}
@@ -190,6 +193,7 @@ describe("AcpSessionManager", () => {
process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR;
}
resetTaskRegistryForTests();
resetFlowRegistryForTests();
});
it("marks ACP-shaped sessions without metadata as stale", () => {

View File

@@ -102,11 +102,13 @@ async function withTaskRegistryTempDir<T>(run: (root: string) => Promise<T>): Pr
return await withTempDir({ prefix: "openclaw-task-registry-" }, async (root) => {
process.env.OPENCLAW_STATE_DIR = root;
resetTaskRegistryForTests();
resetFlowRegistryForTests();
try {
return await run(root);
} finally {
// Close the sqlite-backed registry before Windows temp-dir cleanup tries to remove it.
resetTaskRegistryForTests();
resetFlowRegistryForTests();
}
});
}
@@ -1128,7 +1130,7 @@ describe("task-registry", () => {
});
it("routes state-change updates through the parent flow owner when a task is flow-linked", async () => {
await withTempDir({ prefix: "openclaw-task-registry-" }, async (root) => {
await withTaskRegistryTempDir(async (root) => {
process.env.OPENCLAW_STATE_DIR = root;
resetTaskRegistryForTests();
resetFlowRegistryForTests();
@@ -1315,7 +1317,7 @@ describe("task-registry", () => {
});
it("routes terminal delivery through the parent flow owner when a task is flow-linked", async () => {
await withTempDir({ prefix: "openclaw-task-registry-" }, async (root) => {
await withTaskRegistryTempDir(async (root) => {
process.env.OPENCLAW_STATE_DIR = root;
resetTaskRegistryForTests();
resetFlowRegistryForTests();
@@ -1385,7 +1387,7 @@ describe("task-registry", () => {
});
it("queues fallback terminal delivery on the parent flow owner session when a task is flow-linked", async () => {
await withTempDir({ prefix: "openclaw-task-registry-" }, async (root) => {
await withTaskRegistryTempDir(async (root) => {
process.env.OPENCLAW_STATE_DIR = root;
resetTaskRegistryForTests();
resetFlowRegistryForTests();

View File

@@ -2,10 +2,13 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { resetSessionWriteLockStateForTest } from "../agents/session-write-lock.js";
import {
clearSessionStoreCacheForTest,
getSessionStoreLockQueueSizeForTest,
withSessionStoreLockForTest,
} from "../config/sessions/store.js";
import { resetFileLockStateForTest } from "../infra/file-lock.js";
import { cleanupSessionStateForTest } from "./session-state-cleanup.js";
const acquireSessionWriteLockMock = vi.hoisted(() =>
@@ -31,15 +34,19 @@ function createDeferred<T>() {
}
describe("cleanupSessionStateForTest", () => {
beforeEach(async () => {
beforeEach(() => {
vi.useRealTimers();
await cleanupSessionStateForTest();
clearSessionStoreCacheForTest();
resetFileLockStateForTest();
resetSessionWriteLockStateForTest();
acquireSessionWriteLockMock.mockClear();
});
afterEach(async () => {
afterEach(() => {
vi.useRealTimers();
await cleanupSessionStateForTest();
clearSessionStoreCacheForTest();
resetFileLockStateForTest();
resetSessionWriteLockStateForTest();
vi.restoreAllMocks();
});