Two related fixes from the architecture review: Typed job seam. Job payloads were `unknown` end-to-end: every handler opened with `job.data as SomePayload`, every enqueue site passed a bare string queue name and an unchecked object, and a typo meant a runtime failure in a background worker. packages/jobs gains defineJob(), which keeps the payload typed inside the handler and performs the contravariance cast once inside the package. The journal declares all 14 queues and their payload shapes in app/jobs/payloads.ts; enqueue()/ enqueueOptional() and defineJournalJob() key off that map, so enqueue sites and handlers cannot drift and queue names are compile-checked. Komoot credential bypass. The bulk-import route enqueued the raw credentials JSONB in the pg-boss payload, skipping withFreshCredentials entirely: credentials sat at rest in the job table, were never refreshed if stale, and markNeedsRelink never fired. The payload now carries only the serviceId; the handler resolves fresh credentials through the ConnectedServiceManager at execution time, and marks the import batch failed (instead of leaving it pending forever) when credential resolution itself fails. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
|
|
// Importing every job module pulls in their (transitively heavy)
|
|
// server deps; mock the leaf modules with side effects so this stays a
|
|
// unit test of the registry wiring.
|
|
import { vi } from "vitest";
|
|
vi.mock("../lib/db.ts", () => ({ getDb: vi.fn() }));
|
|
vi.mock("../lib/logger.server.ts", () => ({
|
|
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
|
|
}));
|
|
|
|
describe("job registry", () => {
|
|
it("every job's queue name is unique and a key of JobPayloads", async () => {
|
|
const modules = await Promise.all([
|
|
import("./backfill-user-keypairs.ts"),
|
|
import("./consumed-jti-sweep.ts"),
|
|
import("./deliver-activity.ts"),
|
|
import("./demo-bot-generate.ts"),
|
|
import("./demo-bot-prune.ts"),
|
|
import("./federation-kv-sweep.ts"),
|
|
import("./garmin-import-activity.ts"),
|
|
import("./import-batches-sweep.ts"),
|
|
import("./komoot-bulk-import.ts"),
|
|
import("./notifications-fanout.ts"),
|
|
import("./notifications-purge.ts"),
|
|
import("./poll-remote-actor.ts"),
|
|
import("./poll-remote-outboxes.ts"),
|
|
import("./send-welcome-email.ts"),
|
|
]);
|
|
|
|
const names = modules.flatMap((m) =>
|
|
Object.values(m as Record<string, unknown>)
|
|
.filter(
|
|
(v): v is { name: string; handler: unknown } =>
|
|
typeof v === "object" && v !== null && "handler" in v && "name" in v,
|
|
)
|
|
.map((def) => def.name),
|
|
);
|
|
|
|
expect(names).toHaveLength(14);
|
|
expect(new Set(names).size).toBe(names.length);
|
|
// pg-boss v11+ queue-name constraint, mirrored from packages/jobs
|
|
for (const name of names) {
|
|
expect(name).toMatch(/^[A-Za-z0-9_.-]+$/);
|
|
}
|
|
});
|
|
});
|