






















@@ -12,7 +12,7 @@ import {
1212} from "../config/sessions/store.js";
1313import { callGateway } from "../gateway/call.js";
1414import { onAgentEvent } from "../infra/agent-events.js";
15-import { captureEnv, withEnv } from "../test-utils/env.js";
15+import { captureEnv, deleteTestEnvValue, setTestEnvValue, withEnv } from "../test-utils/env.js";
1616import { persistSubagentSessionTiming } from "./subagent-registry-helpers.js";
1717import { getSubagentRunsSnapshotForRead } from "./subagent-registry-state.js";
1818import {
@@ -128,7 +128,7 @@ describe("subagent registry persistence", () => {
128128// Each persisted-registry fixture gets its own state dir so session stores
129129// and registry files are tested through the same paths production resolves.
130130tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
131-process.env.OPENCLAW_STATE_DIR = tempStateDir;
131+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
132132const registryPath = path.join(tempStateDir, "subagents", "runs.json");
133133await fs.mkdir(path.dirname(registryPath), { recursive: true });
134134await fs.writeFile(registryPath, `${JSON.stringify(persisted)}\n`, "utf8");
@@ -236,7 +236,7 @@ describe("subagent registry persistence", () => {
236236237237it("persists completed subagent timing into the child session entry", async () => {
238238tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
239-process.env.OPENCLAW_STATE_DIR = tempStateDir;
239+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
240240241241const now = Date.now();
242242const startedAt = now;
@@ -273,7 +273,7 @@ describe("subagent registry persistence", () => {
273273274274it("skips cleanup when cleanupHandled was persisted", async () => {
275275tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
276-process.env.OPENCLAW_STATE_DIR = tempStateDir;
276+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
277277278278const registryPath = path.join(tempStateDir, "subagents", "runs.json");
279279const persisted = {
@@ -454,7 +454,7 @@ describe("subagent registry persistence", () => {
454454455455it("returns empty maps for unchanged invalid persisted registry snapshots", async () => {
456456tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
457-process.env.OPENCLAW_STATE_DIR = tempStateDir;
457+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
458458const registryPath = path.join(tempStateDir, "subagents", "runs.json");
459459await fs.mkdir(path.dirname(registryPath), { recursive: true });
460460await fs.writeFile(registryPath, "{invalid", "utf8");
@@ -501,7 +501,7 @@ describe("subagent registry persistence", () => {
501501502502resetSubagentRegistryForTests({ persist: false });
503503tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
504-process.env.OPENCLAW_STATE_DIR = tempStateDir;
504+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
505505506506vi.mocked(callGateway).mockResolvedValueOnce({
507507status: "pending",
@@ -778,7 +778,7 @@ describe("subagent registry persistence", () => {
778778779779it("removes attachments when pruning orphaned restored runs", async () => {
780780tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
781-process.env.OPENCLAW_STATE_DIR = tempStateDir;
781+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
782782const attachmentsRootDir = path.join(tempStateDir, "attachments");
783783const attachmentsDir = path.join(attachmentsRootDir, "ghost");
784784await fs.mkdir(attachmentsDir, { recursive: true });
@@ -910,7 +910,7 @@ describe("subagent registry persistence", () => {
910910911911it("resume guard prunes orphan runs before announce retry", async () => {
912912tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
913-process.env.OPENCLAW_STATE_DIR = tempStateDir;
913+setTestEnvValue("OPENCLAW_STATE_DIR", tempStateDir);
914914const runId = "run-orphan-resume-guard";
915915const childSessionKey = "agent:main:subagent:ghost-resume";
916916const now = Date.now();
@@ -946,7 +946,7 @@ describe("subagent registry persistence", () => {
946946});
947947948948it("uses isolated temp state when OPENCLAW_STATE_DIR is unset in tests", () => {
949-delete process.env.OPENCLAW_STATE_DIR;
949+deleteTestEnvValue("OPENCLAW_STATE_DIR");
950950const registryPath = resolveSubagentRegistryPath();
951951expect(registryPath).toContain(path.join(os.tmpdir(), "openclaw-test-state"));
952952});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。