Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,162 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OutboxRequeueOutput } from "./_lib.js";
const runById = vi.fn();
const runBulk = vi.fn();
vi.mock("./_lib.js", () => ({
runOutboxRequeueById: (...args: unknown[]) => runById(...args),
runOutboxRequeueBulk: (...args: unknown[]) => runBulk(...args),
}));
vi.mock("@hivegrid/db/client.server", () => ({
getDbClient: () => ({ outboxEvent: {} }),
}));
vi.mock("consola", () => ({
default: {
log: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
success: vi.fn(),
},
}));
import consola from "consola";
import { outboxRequeueCommand } from "./requeue.js";
const consoleMock = vi.mocked(consola);
describe("outbox requeue command wrapper", () => {
beforeEach(() => {
vi.clearAllMocks();
process.exitCode = undefined;
runById.mockResolvedValue({ exitCode: 0 });
runBulk.mockResolvedValue({ exitCode: 0 });
});
afterEach(() => {
process.exitCode = undefined;
});
it("rejects passing both --event-id and --type", async () => {
await outboxRequeueCommand.run?.({ args: { "event-id": "evt-1", type: "a.b.c" } } as never);
expect(consoleMock.error).toHaveBeenCalledWith("Pass --event-id OR (--type + --since), not both.");
expect(process.exitCode).toBe(1);
expect(runById).not.toHaveBeenCalled();
expect(runBulk).not.toHaveBeenCalled();
});
it("rejects when neither mode is fully specified", async () => {
await outboxRequeueCommand.run?.({ args: { type: "a.b.c" } } as never);
expect(consoleMock.error).toHaveBeenCalledWith("Either --event-id or (--type + --since) is required.");
expect(process.exitCode).toBe(1);
expect(runById).not.toHaveBeenCalled();
expect(runBulk).not.toHaveBeenCalled();
});
it("delegates single-event mode and adopts the lib outcome exit code", async () => {
runById.mockResolvedValueOnce({ exitCode: 0 });
await outboxRequeueCommand.run?.({ args: { "event-id": "evt-1" } } as never);
expect(runById).toHaveBeenCalledWith(
{ eventId: "evt-1", json: false },
expect.objectContaining({ client: expect.anything(), output: expect.anything() }),
);
expect(runBulk).not.toHaveBeenCalled();
expect(process.exitCode).toBe(0);
});
it("delegates bulk mode with a parsed limit and apply flags", async () => {
runBulk.mockResolvedValueOnce({ exitCode: 0 });
await outboxRequeueCommand.run?.({
args: {
type: "billing.subscription.ended",
since: "2026-05-01T00:00:00Z",
apply: true,
"include-done": true,
limit: "42",
},
} as never);
expect(runBulk).toHaveBeenCalledWith(
{
type: "billing.subscription.ended",
since: "2026-05-01T00:00:00Z",
apply: true,
includeDone: true,
limit: 42,
json: false,
},
expect.objectContaining({ client: expect.anything(), output: expect.anything() }),
);
expect(process.exitCode).toBe(0);
});
it("omits limit from the bulk payload when not parseable", async () => {
await outboxRequeueCommand.run?.({
args: { type: "a.b.c", since: "2026-05-01T00:00:00Z", limit: "not-a-number" },
} as never);
const payload = runBulk.mock.calls[0]?.[0] as Record<string, unknown>;
expect(payload).not.toHaveProperty("limit");
expect(payload).toMatchObject({ apply: false, includeDone: false, json: false });
});
it("routes the lib output sink through consola (text mode)", async () => {
runById.mockImplementationOnce(async (_input: unknown, ctx: { output: OutboxRequeueOutput }) => {
ctx.output.log("done");
ctx.output.warn("careful");
ctx.output.error("nope");
ctx.output.json({ a: 1 });
return { exitCode: 0 };
});
await outboxRequeueCommand.run?.({ args: { "event-id": "evt-1" } } as never);
expect(consoleMock.success).toHaveBeenCalledWith("done");
expect(consoleMock.warn).toHaveBeenCalledWith("careful");
expect(consoleMock.error).toHaveBeenCalledWith("nope");
expect(consoleMock.log).toHaveBeenCalledWith(JSON.stringify({ a: 1 }));
});
it("suppresses log/error decorations in JSON mode but keeps warnings", async () => {
runById.mockImplementationOnce(async (_input: unknown, ctx: { output: OutboxRequeueOutput }) => {
ctx.output.log("done");
ctx.output.warn("careful");
ctx.output.error("nope");
return { exitCode: 0 };
});
await outboxRequeueCommand.run?.({ args: { "event-id": "evt-1", json: true } } as never);
expect(consoleMock.success).not.toHaveBeenCalled();
expect(consoleMock.error).not.toHaveBeenCalled();
expect(consoleMock.warn).toHaveBeenCalledWith("careful");
});
it("catches lib exceptions and reports a human error in text mode", async () => {
runById.mockRejectedValueOnce(new Error("db down"));
await outboxRequeueCommand.run?.({ args: { "event-id": "evt-1" } } as never);
expect(consoleMock.error).toHaveBeenCalledWith("outbox requeue failed: db down");
expect(process.exitCode).toBe(1);
});
it("catches lib exceptions and emits a JSON failure envelope in JSON mode", async () => {
runBulk.mockRejectedValueOnce("boom");
await outboxRequeueCommand.run?.({
args: { type: "a.b.c", since: "2026-05-01T00:00:00Z", json: true },
} as never);
expect(consoleMock.log).toHaveBeenCalledWith(
JSON.stringify({ ok: false, reason: "exception", message: "boom" }),
);
expect(process.exitCode).toBe(1);
});
});