Merge PR #8018: test(coding-agent): hermeticize agent dir in claude-plugins discovery tests (@szavadsky)
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
} from "@oh-my-pi/pi-coding-agent/discovery/helpers";
|
||||
import { loadSlashCommands } from "@oh-my-pi/pi-coding-agent/extensibility/slash-commands";
|
||||
import { discoverAgents } from "@oh-my-pi/pi-coding-agent/task/discovery";
|
||||
import { removeWithRetries } from "@oh-my-pi/pi-utils";
|
||||
import { __resetDirsFromEnvForTests, removeWithRetries, setAgentDir } from "@oh-my-pi/pi-utils";
|
||||
import "@oh-my-pi/pi-coding-agent/discovery/claude-plugins";
|
||||
import { type MCPServer, mcpCapability } from "@oh-my-pi/pi-coding-agent/capability/mcp";
|
||||
import type { Skill } from "@oh-my-pi/pi-coding-agent/capability/skill";
|
||||
@@ -60,29 +60,53 @@ describe("parseClaudePluginsRegistry", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function restoreEnvValue(key: string, value: string | undefined): void {
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
delete Bun.env[key];
|
||||
return;
|
||||
}
|
||||
process.env[key] = value;
|
||||
Bun.env[key] = value;
|
||||
}
|
||||
|
||||
describe("listClaudePluginRoots", () => {
|
||||
let tempDir: string;
|
||||
let testAgentDir: string;
|
||||
let originalHome: string | undefined;
|
||||
let originalAgentDirEnv: string | undefined;
|
||||
let originalOmpProfileEnv: string | undefined;
|
||||
let originalPiProfileEnv: string | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
clearClaudePluginRootsCache();
|
||||
clearFsCache();
|
||||
originalHome = process.env.HOME;
|
||||
originalAgentDirEnv = process.env.PI_CODING_AGENT_DIR;
|
||||
originalOmpProfileEnv = process.env.OMP_PROFILE;
|
||||
originalPiProfileEnv = process.env.PI_PROFILE;
|
||||
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "claude-plugins-test-"));
|
||||
testAgentDir = await fs.mkdtemp(path.join(os.tmpdir(), "claude-plugins-test-agent-"));
|
||||
process.env.HOME = tempDir;
|
||||
vi.spyOn(os, "homedir").mockReturnValue(tempDir);
|
||||
// Point the agent dir at a temp dir so user-scope discovery (native MCP
|
||||
// config, skills, etc.) cannot read the real ~/.omp/agent profile.
|
||||
setAgentDir(testAgentDir);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
clearClaudePluginRootsCache();
|
||||
clearFsCache();
|
||||
vi.restoreAllMocks();
|
||||
if (originalHome === undefined) {
|
||||
delete process.env.HOME;
|
||||
} else {
|
||||
process.env.HOME = originalHome;
|
||||
}
|
||||
// setAgentDir() clears the profile env vars and snapshots the agent dir,
|
||||
// so restore every env var it can touch before rebuilding the resolver.
|
||||
restoreEnvValue("HOME", originalHome);
|
||||
restoreEnvValue("OMP_PROFILE", originalOmpProfileEnv);
|
||||
restoreEnvValue("PI_PROFILE", originalPiProfileEnv);
|
||||
restoreEnvValue("PI_CODING_AGENT_DIR", originalAgentDirEnv);
|
||||
__resetDirsFromEnvForTests();
|
||||
await removeWithRetries(tempDir);
|
||||
await removeWithRetries(testAgentDir);
|
||||
});
|
||||
|
||||
test("returns empty roots when no registry file exists", async () => {
|
||||
|
||||
Reference in New Issue
Block a user