Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pm-stack/aggregator/scripts/sync-decision-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ async function main(): Promise<number> {
const opts = parseArgs();
const files = opts.files.length > 0 ? [...opts.files] : [defaultDecisionEventsOutboxFile()];
if (opts.outboxDir) {
const entries = await readdir(opts.outboxDir).catch(() => [] as string[]);
let entries: string[];
try {
entries = await readdir(opts.outboxDir);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
console.error(`sync-decision-events: cannot read --outbox-dir ${JSON.stringify(opts.outboxDir)}: ${msg}`);
return 1;
}
for (const name of entries.filter((n) => n.endsWith(".jsonl")).sort()) files.push(join(opts.outboxDir, name));
}

Expand Down
38 changes: 38 additions & 0 deletions pm-stack/aggregator/test/sync-decision-events.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

const SCRIPT = join(import.meta.dir, "..", "scripts", "sync-decision-events.ts");

describe("sync-decision-events CLI --outbox-dir", () => {
test("exits non-zero when --outbox-dir does not exist", async () => {
const missing = join(tmpdir(), `missing-outbox-${Date.now()}-${Math.random()}`);
const proc = Bun.spawn(["bun", "run", SCRIPT, "--outbox-dir", missing, "--dry-run"], {
stderr: "pipe",
stdout: "pipe",
});
const code = await proc.exited;
const stderr = await new Response(proc.stderr).text();
expect(code).toBe(1);
expect(stderr).toContain("cannot read --outbox-dir");
});

test("exits non-zero when --outbox-dir is a regular file", async () => {
const dir = mkdtempSync(join(tmpdir(), "outbox-file-"));
try {
const file = join(dir, "not-a-dir");
writeFileSync(file, "hello");
const proc = Bun.spawn(["bun", "run", SCRIPT, "--outbox-dir", file, "--dry-run"], {
stderr: "pipe",
stdout: "pipe",
});
const code = await proc.exited;
const stderr = await new Response(proc.stderr).text();
expect(code).toBe(1);
expect(stderr).toContain("cannot read --outbox-dir");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});