mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: snapshot flows state env
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Flows command tests cover task creation, task execution, and runtime command output.
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { createRunningTaskRun as createRunningTaskRunOrNull } from "../tasks/task-executor.js";
|
||||
import {
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
resetTaskRegistryForTests,
|
||||
} from "../tasks/task-registry.js";
|
||||
import type { TaskRecord } from "../tasks/task-registry.types.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js";
|
||||
import { flowsCancelCommand, flowsListCommand, flowsShowCommand } from "./flows.js";
|
||||
|
||||
@@ -20,8 +21,6 @@ vi.mock("../config/config.js", () => ({
|
||||
loadConfig: vi.fn(() => ({})),
|
||||
}));
|
||||
|
||||
const ORIGINAL_STATE_DIR = process.env.OPENCLAW_STATE_DIR;
|
||||
|
||||
function jsonRoundTrip<T>(value: T): T {
|
||||
const serialized = JSON.stringify(value);
|
||||
return JSON.parse(serialized) as T;
|
||||
@@ -84,12 +83,14 @@ async function withTaskFlowCommandStateDir(run: (root: string) => Promise<void>)
|
||||
}
|
||||
|
||||
describe("flows commands", () => {
|
||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||
|
||||
beforeEach(() => {
|
||||
envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (ORIGINAL_STATE_DIR === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR;
|
||||
}
|
||||
envSnapshot.restore();
|
||||
resetTaskRegistryDeliveryRuntimeForTests();
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
|
||||
Reference in New Issue
Block a user