Skip to content

Commit f474d11

Browse files
author
Tehan
committed
test(skill-memory): isolate HOME in truncation-fallback tests
The fallback's global-dir walk reads $HOME at call time; a developer machine with a same-named global skill would flip the negative-registry assertions. Override HOME to an empty tmpdir for the describe block.
1 parent f9da661 commit f474d11

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/plugin/src/hooks/magic-context/skill-memory-injection.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, describe, expect, test } from "bun:test";
1+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
22
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { runMigrations } from "../../features/magic-context/migrations";
@@ -230,7 +230,20 @@ describe("createToolExecuteAfterHook skill registry (truncation fallback)", () =
230230
"---\nskill-memory:\n enabled: true\n max_tokens: 1500\n---\n\n# Truncated Skill\n",
231231
);
232232

233+
// Isolate HOME to an empty tmpdir so the global-dir fallback walk
234+
// doesn't accidentally hit a real developer skill (e.g. a global
235+
// skill named "truncated-skill" or "nonexistent-skill"). Without
236+
// this, negative-registry assertions flake on contaminated machines.
237+
const savedHome = process.env.HOME;
238+
const isolatedHome = `${tmpdir()}/skill-truncation-home-${Date.now()}`;
239+
beforeAll(() => {
240+
mkdirSync(isolatedHome, { recursive: true });
241+
process.env.HOME = isolatedHome;
242+
});
243+
233244
afterAll(() => {
245+
process.env.HOME = savedHome;
246+
rmSync(isolatedHome, { recursive: true, force: true });
234247
rmSync(projectDir, { recursive: true, force: true });
235248
});
236249

0 commit comments

Comments
 (0)