test: remove redundant task flow temp dir args

This commit is contained in:
Peter Steinberger
2026-06-04 23:39:00 +01:00
parent 4f7b5d8f44
commit bfd9fcac18

View File

@@ -6,7 +6,6 @@ import { executeSqliteQuerySync, getNodeSqliteKysely } from "../infra/kysely-syn
import type { DB as OpenClawStateKyselyDatabase } from "../state/openclaw-state-db.generated.js"; import type { DB as OpenClawStateKyselyDatabase } from "../state/openclaw-state-db.generated.js";
import { openOpenClawStateDatabase } from "../state/openclaw-state-db.js"; import { openOpenClawStateDatabase } from "../state/openclaw-state-db.js";
import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js"; import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js";
import { withEnvAsync } from "../test-utils/env.js";
import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js"; import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js";
import { import {
createManagedTaskFlow as createManagedTaskFlowOrNull, createManagedTaskFlow as createManagedTaskFlowOrNull,
@@ -69,9 +68,10 @@ async function withFlowRegistryTempDir<T>(run: (root: string) => Promise<T>): Pr
}, },
async (state) => { async (state) => {
const root = state.stateDir; const root = state.stateDir;
process.env.OPENCLAW_STATE_DIR = root;
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
try { try {
return await withEnvAsync({ OPENCLAW_STATE_DIR: root }, async () => await run(root)); return await run(root);
} finally { } finally {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
} }
@@ -79,6 +79,16 @@ async function withFlowRegistryTempDir<T>(run: (root: string) => Promise<T>): Pr
); );
} }
const ORIGINAL_STATE_DIR = process.env.OPENCLAW_STATE_DIR;
function restoreOriginalStateDir(): void {
if (ORIGINAL_STATE_DIR === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR;
}
}
describe("task-flow-registry store runtime", () => { describe("task-flow-registry store runtime", () => {
beforeEach(() => { beforeEach(() => {
vi.useRealTimers(); vi.useRealTimers();
@@ -86,6 +96,7 @@ describe("task-flow-registry store runtime", () => {
afterEach(() => { afterEach(() => {
vi.useRealTimers(); vi.useRealTimers();
restoreOriginalStateDir();
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
}); });
@@ -150,7 +161,7 @@ describe("task-flow-registry store runtime", () => {
}); });
it("rejects corrupt persisted flow rows during sqlite restore", async () => { it("rejects corrupt persisted flow rows during sqlite restore", async () => {
await withFlowRegistryTempDir(async (root) => { await withFlowRegistryTempDir(async () => {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
const created = createManagedTaskFlow({ const created = createManagedTaskFlow({
@@ -174,7 +185,7 @@ describe("task-flow-registry store runtime", () => {
}); });
it("drops invalid requester origins during sqlite restore", async () => { it("drops invalid requester origins during sqlite restore", async () => {
await withFlowRegistryTempDir(async (root) => { await withFlowRegistryTempDir(async () => {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
const created = createManagedTaskFlow({ const created = createManagedTaskFlow({
@@ -203,7 +214,7 @@ describe("task-flow-registry store runtime", () => {
}); });
it("restores persisted wait-state, revision, and cancel intent from sqlite", async () => { it("restores persisted wait-state, revision, and cancel intent from sqlite", async () => {
await withFlowRegistryTempDir(async (root) => { await withFlowRegistryTempDir(async () => {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
const created = createManagedTaskFlow({ const created = createManagedTaskFlow({
@@ -248,7 +259,7 @@ describe("task-flow-registry store runtime", () => {
}); });
it("round-trips explicit json null through sqlite", async () => { it("round-trips explicit json null through sqlite", async () => {
await withFlowRegistryTempDir(async (root) => { await withFlowRegistryTempDir(async () => {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
const created = createManagedTaskFlow({ const created = createManagedTaskFlow({
@@ -269,7 +280,7 @@ describe("task-flow-registry store runtime", () => {
}); });
it("prunes large sqlite snapshots without binding every flow id at once", async () => { it("prunes large sqlite snapshots without binding every flow id at once", async () => {
await withFlowRegistryTempDir(async (root) => { await withFlowRegistryTempDir(async () => {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
const flows = new Map<string, TaskFlowRecord>(); const flows = new Map<string, TaskFlowRecord>();
@@ -299,7 +310,7 @@ describe("task-flow-registry store runtime", () => {
if (process.platform === "win32") { if (process.platform === "win32") {
return; return;
} }
await withFlowRegistryTempDir(async (root) => { await withFlowRegistryTempDir(async () => {
resetTaskFlowRegistryForTests(); resetTaskFlowRegistryForTests();
createManagedTaskFlow({ createManagedTaskFlow({