Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/DogPawHat/drudger.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { expect, test } from "bun:test";import { dirname, join } from "node:path";import { fileURLToPath } from "node:url";
const TEST_FILE_DIR = dirname(fileURLToPath(import.meta.url));const REPO_ROOT = join(TEST_FILE_DIR, "..");const CLI_PATH = join(REPO_ROOT, "src", "cli.ts");
type CliResult = { exitCode: number; stdout: string; stderr: string;};
function runCli(args: string[]): CliResult { const proc = Bun.spawnSync({ cmd: ["bun", "run", CLI_PATH, ...args], cwd: REPO_ROOT, env: process.env, stdout: "pipe", stderr: "pipe", });
return { exitCode: proc.exitCode, stdout: new TextDecoder().decode(proc.stdout).trim(), stderr: new TextDecoder().decode(proc.stderr).trim(), };}
function parseJsonOutput(stdout: string): any { return JSON.parse(stdout);}
test("missing --vault-root returns clear validation error", () => { const result = runCli(["exists", "--job-spec-url", "https://example.com/jobs/123"]);
expect(result.exitCode).toBe(2); const payload = parseJsonOutput(result.stdout); expect(payload.ok).toBe(false); expect(payload.error.code).toBe("VALIDATION_ERROR"); expect(payload.error.message.includes("--vault-root")).toBe(true); expect(payload.error.message.includes("Obsidian vault")).toBe(true);});