Files
oh-my-pi/packages/coding-agent/test/discovery/pi-config-dir.test.ts
T
汐 af383e5618 fix(path): PI_CONFIG_DIR discovery (#358)
* fix(path): PI_CONFIG_DIR discovery

* refactor: centralize agent dir name into getConfigAgentDirName()

- Add getConfigAgentDirName() to utils/dirs.ts as single source of truth
- Replace duplicated "/agent" suffix construction in helpers.ts and config.ts
- Let biome format mcp/manager.ts canonically

---------

Co-authored-by: can1357 <me@can.ac>
2026-03-11 01:07:57 +01:00

37 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, test } from "bun:test";
import * as os from "node:os";
import * as path from "node:path";
import type { LoadContext } from "@oh-my-pi/pi-coding-agent/capability/types";
import { getConfigDirs } from "@oh-my-pi/pi-coding-agent/config";
import { getUserPath } from "@oh-my-pi/pi-coding-agent/discovery/helpers";
describe("PI_CONFIG_DIR", () => {
const original = process.env.PI_CONFIG_DIR;
afterEach(() => {
if (original === undefined) {
delete process.env.PI_CONFIG_DIR;
} else {
process.env.PI_CONFIG_DIR = original;
}
});
test("getUserPath uses PI_CONFIG_DIR for native userAgent", () => {
process.env.PI_CONFIG_DIR = ".config/omp";
const ctx: LoadContext = {
cwd: "/work/project",
home: "/home/tester",
repoRoot: null,
};
const result = getUserPath(ctx, "native", "commands");
expect(result).toBe(path.join(ctx.home, ".config/omp/agent", "commands"));
});
test("getConfigDirs respects PI_CONFIG_DIR for user base", () => {
process.env.PI_CONFIG_DIR = ".config/omp";
const result = getConfigDirs("commands", { project: false });
const expected = path.resolve(path.join(os.homedir(), ".config/omp", "agent", "commands"));
expect(result[0]).toEqual({ path: expected, source: ".omp", level: "user" });
});
});