Files
oh-my-pi/packages/coding-agent/test/discovery/disabled-extensions.test.ts
T
can1357 bdcc08a50c feat(coding-agent/session): added automatic migration of legacy session directories
- Added automatic migration of legacy absolute-path session directories with double-dash format to new canonical locations.
- Enhanced session directory encoding to use `-tmp-` prefix for temporary directories instead of legacy double-dash format for improved clarity.
- Extracted session directory migration logic into reusable helper functions for better maintainability.
- Updated test setup to mock home directory and verify session migration behavior with temporary paths.
2026-03-15 22:56:18 +01:00

62 lines
2.1 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, test, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { type ContextFile, contextFileCapability } from "@oh-my-pi/pi-coding-agent/capability/context-file";
import { _resetSettingsForTest, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { initializeWithSettings, loadCapability } from "@oh-my-pi/pi-coding-agent/discovery";
describe("disabledExtensions runtime filtering", () => {
let tempDir = "";
let tempHomeDir = "";
let originalHome: string | undefined;
beforeEach(async () => {
_resetSettingsForTest();
originalHome = process.env.HOME;
tempHomeDir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-disabled-ext-home-"));
process.env.HOME = tempHomeDir;
vi.spyOn(os, "homedir").mockReturnValue(tempHomeDir);
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-disabled-ext-"));
await fs.mkdir(path.join(tempDir, ".omp"), { recursive: true });
await fs.writeFile(path.join(tempDir, ".omp", "AGENTS.md"), "# project instructions\n");
const settings = await Settings.init({
inMemory: true,
cwd: tempDir,
overrides: {
disabledExtensions: ["context-file:project:AGENTS.md"],
},
});
initializeWithSettings(settings);
});
afterEach(async () => {
_resetSettingsForTest();
vi.restoreAllMocks();
if (originalHome === undefined) {
delete process.env.HOME;
} else {
process.env.HOME = originalHome;
}
await fs.rm(tempHomeDir, { recursive: true, force: true });
await fs.rm(tempDir, { recursive: true, force: true });
});
test("hides disabled context files from runtime loads by default", async () => {
const result = await loadCapability<ContextFile>(contextFileCapability.id, { cwd: tempDir });
expect(result.items).toHaveLength(0);
});
test("can include disabled context files for dashboard-style loads", async () => {
const result = await loadCapability<ContextFile>(contextFileCapability.id, {
cwd: tempDir,
includeDisabled: true,
});
expect(result.items).toHaveLength(1);
expect(path.basename(result.items[0]!.path)).toBe("AGENTS.md");
});
});