refactor(test): reuse env snapshot helper

This commit is contained in:
Peter Steinberger
2026-02-15 23:51:24 +00:00
parent d27a763eec
commit f809ff5e55
3 changed files with 16 additions and 36 deletions

View File

@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { captureEnv } from "../test-utils/env.js";
import {
initSubagentRegistry,
registerSubagentRun,
@@ -29,7 +30,7 @@ vi.mock("./subagent-announce.js", () => ({
}));
describe("subagent registry persistence", () => {
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
let tempStateDir: string | null = null;
afterEach(async () => {
@@ -39,11 +40,7 @@ describe("subagent registry persistence", () => {
await fs.rm(tempStateDir, { recursive: true, force: true });
tempStateDir = null;
}
if (previousStateDir === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
envSnapshot.restore();
});
it("persists runs to disk and resumes after restart", async () => {