Skip to content
File

Blob: test/queue-malformed.worker.test.ts

typescript62 lines
1import { describe, expect, it } from "vitest";
2 
3import { runQueueMessage } from "./util/queue";
4 
5// Dashboard-sent or replayed payloads can drift from the current schema.
6// The dispatcher must ack-and-discard malformed bodies rather than retry
7// forever or throw on `body.kind` access.
8describe("repo task queue: malformed message handling", () => {
9 it("null body -> ack, no retry", async () => {
10 const result = await runQueueMessage(null);
11 expect(result.acked).toBe(true);
12 expect(result.retried).toBe(false);
13 });
14 
15 it("primitive body -> ack, no retry", async () => {
16 const result = await runQueueMessage("not-a-message");
17 expect(result.acked).toBe(true);
18 expect(result.retried).toBe(false);
19 });
20 
21 it("object with unknown kind -> ack, no retry", async () => {
22 const result = await runQueueMessage({ kind: "unknown-kind" });
23 expect(result.acked).toBe(true);
24 expect(result.retried).toBe(false);
25 });
26 
27 it("removed import message kind -> ack, no retry", async () => {
28 const result = await runQueueMessage({
29 kind: "legacy-backfill",
30 userId: "user_x",
31 namespaceSlug: "ns",
32 });
33 expect(result.acked).toBe(true);
34 expect(result.retried).toBe(false);
35 });
36 
37 it("known kind with missing required field -> ack, no retry", async () => {
38 // `route-cache-sync` requires repositoryId/namespaceSlug/repoSlug/enqueuedAt.
39 const result = await runQueueMessage({
40 kind: "route-cache-sync",
41 repositoryId: "repo_x",
42 });
43 expect(result.acked).toBe(true);
44 expect(result.retried).toBe(false);
45 });
46 
47 it("known kind with wrong field type -> ack, no retry", async () => {
48 const result = await runQueueMessage({
49 kind: "repository-delete",
50 repositoryId: 42,
51 namespaceId: "ns_x",
52 namespaceSlug: "ns",
53 repoSlug: "site",
54 doName: "ns/site",
55 actor: "user",
56 requestedAt: "now",
57 });
58 expect(result.acked).toBe(true);
59 expect(result.retried).toBe(false);
60 });
61});