|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { InvalidPayloadError } from "./slim-mirror-payload.ts"; |
| 4 | +import { |
| 5 | + CATALOG_PATH, |
| 6 | + planArtifactCatalogUpdate, |
| 7 | + type ReleasePublication, |
| 8 | +} from "./sync-artifacts-catalog.ts"; |
| 9 | + |
| 10 | +const DIGEST_B = `sha256:${"b".repeat(64)}`; |
| 11 | +const POSTGRES_17 = `ghcr.io/supabase/cli/postgres:17.6.1.168@sha256:${"9".repeat(64)}`; |
| 12 | +const POSTGRES_15 = `ghcr.io/supabase/cli/postgres:15.14.1.168@sha256:${"f".repeat(64)}`; |
| 13 | + |
| 14 | +const fixture = `const workloadCatalog = { |
| 15 | + database: definition( |
| 16 | + "postgres", |
| 17 | + "17.6.1.168", |
| 18 | + "${POSTGRES_17}", |
| 19 | + "bin/supabase-postgres-start", |
| 20 | + ["bin/supabase-postgres-start"], |
| 21 | + { "15.14.1.168": "${POSTGRES_15}" }, |
| 22 | + ), |
| 23 | + rest: definition("postgrest", "v16.2", "ghcr.io/supabase/cli/postgrest:v16.2", "bin/postgrest"), |
| 24 | + analytics: definition( |
| 25 | + "analytics", |
| 26 | + "v1.50.9", |
| 27 | + "ghcr.io/supabase/cli/analytics:v1.50.9@sha256:${"a".repeat(64)}", |
| 28 | + "bin/logflare", |
| 29 | + ), |
| 30 | +}; |
| 31 | +`; |
| 32 | + |
| 33 | +const published = (digest?: string): ReleasePublication => ({ status: "published", digest }); |
| 34 | + |
| 35 | +describe("planArtifactCatalogUpdate", () => { |
| 36 | + test("pins Dockerfile tags that changed and leaves the other postgres line", async () => { |
| 37 | + const plan = await planArtifactCatalogUpdate({ |
| 38 | + baseDockerfile: `FROM supabase/postgres:17.6.1.168 AS pg |
| 39 | +FROM postgrest/postgrest:v16.2 AS postgrest |
| 40 | +FROM supabase/logflare:1.50.9 AS logflare |
| 41 | +`, |
| 42 | + dockerfile: `FROM supabase/postgres:17.6.1.171 AS pg |
| 43 | +FROM library/kong:2.8.1 AS kong |
| 44 | +FROM postgrest/postgrest:v16.3 AS postgrest |
| 45 | +FROM supabase/logflare:1.50.9 AS logflare |
| 46 | +`, |
| 47 | + catalog: fixture, |
| 48 | + publication: async (service) => published(service === "postgres" ? DIGEST_B : undefined), |
| 49 | + }); |
| 50 | + |
| 51 | + expect(plan.updates.map((update) => `${update.service} ${update.version}`)).toEqual([ |
| 52 | + "postgres 17.6.1.171", |
| 53 | + "postgrest v16.3", |
| 54 | + ]); |
| 55 | + expect(plan.source).toContain(`"ghcr.io/supabase/cli/postgres:17.6.1.171@${DIGEST_B}"`); |
| 56 | + expect(plan.source).toContain(`"${POSTGRES_15}"`); |
| 57 | + expect(plan.source).toContain(`"ghcr.io/supabase/cli/postgrest:v16.3"`); |
| 58 | + expect(plan.source).toContain(`"v1.50.9"`); |
| 59 | + expect(plan.skipped).toEqual([]); |
| 60 | + }); |
| 61 | + |
| 62 | + test("a missing release blocks the commit and OrioleDB does not", async () => { |
| 63 | + const movesPostgres = await planArtifactCatalogUpdate({ |
| 64 | + baseDockerfile: "FROM supabase/postgres:17.6.1.168 AS pg\n", |
| 65 | + dockerfile: `FROM supabase/postgres:17.6.1.171 AS pg |
| 66 | +FROM postgrest/postgrest:v16.3 AS postgrest |
| 67 | +`, |
| 68 | + catalog: fixture, |
| 69 | + publication: async () => ({ status: "missing" }), |
| 70 | + }); |
| 71 | + expect(movesPostgres.updates).toEqual([]); |
| 72 | + expect(movesPostgres.source).toBe(fixture); |
| 73 | + expect(movesPostgres.skipped.every((skip) => skip.blocking)).toBe(true); |
| 74 | + |
| 75 | + const oriole = await planArtifactCatalogUpdate({ |
| 76 | + baseDockerfile: |
| 77 | + "FROM supabase/postgres:17.6.1.168 AS pg\nFROM postgrest/postgrest:v16.2 AS postgrest\n", |
| 78 | + dockerfile: `FROM supabase/postgres:16.0.0.1-orioledb AS pg |
| 79 | +FROM postgrest/postgrest:v16.3 AS postgrest |
| 80 | +`, |
| 81 | + catalog: fixture, |
| 82 | + publication: async () => published(), |
| 83 | + }); |
| 84 | + expect(oriole.updates.map((update) => update.service)).toEqual(["postgrest"]); |
| 85 | + expect(oriole.skipped).toEqual([ |
| 86 | + { |
| 87 | + alias: "pg", |
| 88 | + reason: "pg supabase/postgres:16.0.0.1-orioledb has no slim image.", |
| 89 | + blocking: false, |
| 90 | + }, |
| 91 | + ]); |
| 92 | + expect(oriole.source).toContain(`"${POSTGRES_17}"`); |
| 93 | + }); |
| 94 | + |
| 95 | + test("refuses a backward pin and a tag that would escape the catalog string", async () => { |
| 96 | + const backward = await planArtifactCatalogUpdate({ |
| 97 | + baseDockerfile: "FROM supabase/postgres:17.6.1.170 AS pg\n", |
| 98 | + dockerfile: "FROM supabase/postgres:17.6.1.171 AS pg\n", |
| 99 | + catalog: fixture.replaceAll("17.6.1.168", "17.6.1.173"), |
| 100 | + publication: async () => { |
| 101 | + throw new Error("publication lookup"); |
| 102 | + }, |
| 103 | + }); |
| 104 | + expect(backward.updates).toEqual([]); |
| 105 | + expect(backward.skipped.map((skip) => skip.blocking)).toEqual([true]); |
| 106 | + expect(backward.source).toContain(`"17.6.1.173"`); |
| 107 | + |
| 108 | + await expect( |
| 109 | + planArtifactCatalogUpdate({ |
| 110 | + dockerfile: 'FROM supabase/gotrue:v1" AS gotrue\n', |
| 111 | + catalog: fixture, |
| 112 | + publication: async () => published(), |
| 113 | + }), |
| 114 | + ).rejects.toThrow(InvalidPayloadError); |
| 115 | + }); |
| 116 | +}); |
| 117 | + |
| 118 | +describe("against the real catalog", () => { |
| 119 | + test("every slim Dockerfile alias is a catalog entry", async () => { |
| 120 | + const dockerfile = await Bun.file("apps/cli/src/shared/services/Dockerfile").text(); |
| 121 | + const catalog = await Bun.file(CATALOG_PATH).text(); |
| 122 | + const plan = await planArtifactCatalogUpdate({ |
| 123 | + dockerfile, |
| 124 | + catalog, |
| 125 | + publication: async () => published(`sha256:${"a".repeat(64)}`), |
| 126 | + }); |
| 127 | + |
| 128 | + expect( |
| 129 | + plan.skipped.filter((skip) => skip.blocking && !skip.reason.includes("older than")), |
| 130 | + ).toEqual([]); |
| 131 | + }); |
| 132 | +}); |
0 commit comments