Files
oh-my-pi/packages/utils/test/cli-help.test.ts
T
can1357 f2137becb8 fix: fixed prompt parsing, startup tracing, and help-command behavior
- Fixed help rendering so `--help` no longer triggers unrelated command loaders.
- Fixed startup span logging to emit markers only with PI_DEBUG_STARTUP set.
- Fixed logger startup trace behavior for `:start`, `:done`, and `:fail` phases.
- Fixed prompt template processing with cached raw-template compilation and safer formatting.
- Optimized symbol and tag parsing in prompt templates via manual parsers.
2026-06-10 02:17:35 +02:00

43 lines
1.3 KiB
TypeScript

import { describe, expect, it, spyOn } from "bun:test";
import { Command, type CommandEntry, Flags, run } from "@oh-my-pi/pi-utils/cli";
class GoodCommand extends Command {
static description = "prints good things";
static flags = {
verbose: Flags.boolean({ description: "be loud" }),
};
async run(): Promise<void> {}
}
describe("run() per-command help", () => {
// Contract: `omp <cmd> --help` must load only the requested command module.
// Loading the whole table would let any unrelated command whose import
// hangs or crashes take down every per-command help invocation.
it("loads only the requested command", async () => {
let brokenLoads = 0;
const commands: CommandEntry[] = [
{ name: "good", load: async () => GoodCommand },
{
name: "broken",
load: async () => {
brokenLoads++;
throw new Error("import-time crash");
},
},
];
const writes: string[] = [];
const stdoutSpy = spyOn(process.stdout, "write").mockImplementation(chunk => {
writes.push(String(chunk));
return true;
});
try {
await run({ bin: "omp", version: "0.0.0", argv: ["good", "--help"], commands });
} finally {
stdoutSpy.mockRestore();
}
expect(brokenLoads).toBe(0);
expect(writes.join("")).toContain("prints good things");
expect(writes.join("")).toContain("--verbose");
});
});