Skip to content

Commit a04de1a

Browse files
committed
test: scope subagent attachment home env
1 parent ca7047e commit a04de1a

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

src/agents/subagent-spawn.attachments.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from "node:fs";
44
import os from "node:os";
55
import path from "node:path";
66
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
7+
import { withEnvAsync } from "../test-utils/env.js";
78
import {
89
createSubagentSpawnTestConfig,
910
loadSubagentSpawnModuleForTest,
@@ -218,22 +219,23 @@ describe("spawnSubagentDirect filename validation", () => {
218219
return store;
219220
});
220221
try {
221-
vi.stubEnv("HOME", homeDir);
222-
const { spawnSubagentDirect } = subagentSpawnModule;
223-
const result = await spawnSubagentDirect(
224-
{
225-
task: "test",
226-
cwd: "~/task-repo",
227-
attachments: [{ name: "file.txt", content: validContent, encoding: "base64" }],
228-
},
229-
ctx,
230-
);
222+
await withEnvAsync({ HOME: homeDir }, async () => {
223+
const { spawnSubagentDirect } = subagentSpawnModule;
224+
const result = await spawnSubagentDirect(
225+
{
226+
task: "test",
227+
cwd: "~/task-repo",
228+
attachments: [{ name: "file.txt", content: validContent, encoding: "base64" }],
229+
},
230+
ctx,
231+
);
231232

232-
expect(result.status).toBe("accepted");
233-
const attachmentsRoot = path.join(expectedCwd, ".openclaw", "attachments");
234-
expect(fs.existsSync(attachmentsRoot)).toBe(true);
235-
const childSessionKey = result.childSessionKey as string;
236-
expect(persistedStore?.[childSessionKey]?.spawnedCwd).toBe(expectedCwd);
233+
expect(result.status).toBe("accepted");
234+
const attachmentsRoot = path.join(expectedCwd, ".openclaw", "attachments");
235+
expect(fs.existsSync(attachmentsRoot)).toBe(true);
236+
const childSessionKey = result.childSessionKey as string;
237+
expect(persistedStore?.[childSessionKey]?.spawnedCwd).toBe(expectedCwd);
238+
});
237239
} finally {
238240
fs.rmSync(homeDir, { recursive: true, force: true });
239241
}

0 commit comments

Comments
 (0)