test: stabilize exec approvals homedir

This commit is contained in:
Peter Steinberger
2026-01-21 10:49:01 +00:00
parent 4e4f5558fc
commit cdb35c3aae
+6 -5
View File
@@ -2,7 +2,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import {
matchAllowlist,
@@ -111,9 +111,9 @@ describe("exec approvals policy helpers", () => {
describe("exec approvals wildcard agent", () => {
it("merges wildcard allowlist entries with agent entries", () => {
const dir = makeTempDir();
const oldHome = process.env.HOME;
process.env.HOME = dir;
const homedirSpy = vi.spyOn(os, "homedir").mockReturnValue(dir);
try {
const approvalsPath = path.join(dir, ".clawdbot", "exec-approvals.json");
fs.mkdirSync(path.dirname(approvalsPath), { recursive: true });
fs.writeFileSync(
@@ -136,7 +136,8 @@ describe("exec approvals wildcard agent", () => {
"/bin/hostname",
"/usr/bin/uname",
]);
process.env.HOME = oldHome;
} finally {
homedirSpy.mockRestore();
}
});
});