786c25e6c7
- Fixed root `cli --help` startup by preventing the config/model-registry initialization cycle. - Extracted config validation, migration, and loading logic from config.ts into config/config-file.ts. - Added ConfigFile helpers for migration, validated JSON/JSONC/YAML loading, status caching, and reset. - Added a regression test that runs `cli.ts --help` with temp HOME/XDG env paths and expects exit code 0.
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { afterEach, describe, expect, it } from "bun:test";
|
|
import * as fs from "node:fs/promises";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
|
|
const repoRoot = path.resolve(import.meta.dir, "..", "..", "..");
|
|
const cliEntry = path.join(repoRoot, "packages", "coding-agent", "src", "cli.ts");
|
|
|
|
let cleanupRoot: string | undefined;
|
|
|
|
async function readStream(stream: ReadableStream<Uint8Array>): Promise<string> {
|
|
const reader = stream.getReader();
|
|
const decoder = new TextDecoder();
|
|
let text = "";
|
|
try {
|
|
while (true) {
|
|
const { value, done } = await reader.read();
|
|
if (done) break;
|
|
text += decoder.decode(value, { stream: true });
|
|
}
|
|
return text + decoder.decode();
|
|
} finally {
|
|
reader.releaseLock();
|
|
}
|
|
}
|
|
|
|
afterEach(async () => {
|
|
if (cleanupRoot) {
|
|
await fs.rm(cleanupRoot, { recursive: true, force: true });
|
|
cleanupRoot = undefined;
|
|
}
|
|
});
|
|
|
|
describe("CLI help load order", () => {
|
|
it("loads the root help command without tripping config/model-registry cycles", async () => {
|
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "omp-help-load-order-"));
|
|
cleanupRoot = root;
|
|
const home = path.join(root, "home");
|
|
const xdg = path.join(root, "xdg");
|
|
const agentDir = path.join(root, "agent");
|
|
await fs.mkdir(home, { recursive: true });
|
|
await fs.mkdir(xdg, { recursive: true });
|
|
await fs.mkdir(agentDir, { recursive: true });
|
|
|
|
const proc = Bun.spawn([process.execPath, cliEntry, "--help"], {
|
|
cwd: repoRoot,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
env: {
|
|
...process.env,
|
|
HOME: home,
|
|
XDG_CONFIG_HOME: xdg,
|
|
XDG_DATA_HOME: xdg,
|
|
PI_CODING_AGENT_DIR: agentDir,
|
|
PI_NO_TITLE: "1",
|
|
NO_COLOR: "1",
|
|
},
|
|
});
|
|
|
|
const [, , exitCode] = await Promise.all([
|
|
readStream(proc.stdout as ReadableStream<Uint8Array>),
|
|
readStream(proc.stderr as ReadableStream<Uint8Array>),
|
|
proc.exited,
|
|
]);
|
|
|
|
expect(exitCode).toBe(0);
|
|
});
|
|
});
|