{{ message }}
Repository navigation
Expand file tree
/
Copy pathmirror-slim-image.test.ts
More file actions
700 lines (655 loc) · 22.4 KB
/
Copy pathmirror-slim-image.test.ts
File metadata and controls
700 lines (655 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
import { describe, expect, test } from "bun:test";
import {
copyImage,
copyNatives,
ensureEcrPublicRepo,
fetchNatives,
main,
nativesFromEvent,
uploadNativesS3,
verifyDigest,
type CommandResult,
type RunCommand,
} from "./mirror-slim-image.ts";
import {
InvalidPayloadError,
checksumFor,
digestReference,
nativeFileNames,
nativeObjectUrl,
nativeTagPattern,
nativeTripletDigests,
parseNatives,
validateMirrorDispatch,
} from "./slim-mirror-payload.ts";
const DIGEST = `sha256:${"a".repeat(64)}`;
const OTHER = `sha256:${"b".repeat(64)}`;
const ok = (stdout = ""): CommandResult => ({ ok: true, stdout, stderr: "" });
const fail = (stderr = "", stdout = ""): CommandResult => ({ ok: false, stdout, stderr });
describe("validateMirrorDispatch", () => {
test("derives source and destination on workflow_dispatch", () => {
expect(
validateMirrorDispatch({
eventName: "workflow_dispatch",
service: "postgrest",
version: "v16.2",
digest: DIGEST,
payloadSource: undefined,
payloadDestination: undefined,
}),
).toEqual({
service: "postgrest",
version: "v16.2",
digest: DIGEST,
source: "ghcr.io/supabase/cli/postgrest:v16.2",
destination: "public.ecr.aws/supabase/cli/postgrest:v16.2",
});
});
test("requires payload URLs to match derived refs on repository_dispatch", () => {
expect(() =>
validateMirrorDispatch({
eventName: "repository_dispatch",
service: "postgrest",
version: "v16.2",
digest: DIGEST,
payloadSource: "ghcr.io/evil/cli/postgrest:v16.2",
payloadDestination: "public.ecr.aws/supabase/cli/postgrest:v16.2",
}),
).toThrow(InvalidPayloadError);
});
test("rejects a digest that is not sha256", () => {
expect(() =>
validateMirrorDispatch({
eventName: "workflow_dispatch",
service: "postgrest",
version: "v16.2",
digest: "sha256:nope",
payloadSource: undefined,
payloadDestination: undefined,
}),
).toThrow(InvalidPayloadError);
});
});
describe("parseNatives", () => {
test("accepts an empty or missing list", () => {
expect(parseNatives(undefined, "v16.2")).toEqual([]);
expect(parseNatives(null, "v16.2")).toEqual([]);
expect(parseNatives([], "v16.2")).toEqual([]);
});
test("rejects a platform image tag", () => {
expect(() => parseNatives([{ tag: "v16.2-linux-arm64", digest: DIGEST }], "v16.2")).toThrow(
InvalidPayloadError,
);
});
test("keeps a matching native tag", () => {
expect(parseNatives([{ tag: "v16.2-native-linux-arm64", digest: DIGEST }], "v16.2")).toEqual([
{ tag: "v16.2-native-linux-arm64", digest: DIGEST },
]);
expect(nativeTagPattern("v16.2").test("v16.2-native-darwin-arm64")).toBe(true);
});
});
describe("verifyDigest", () => {
test("accepts a matching head", async () => {
const run: RunCommand = async () => ok(`${DIGEST}\n`);
await verifyDigest({
reference: "ghcr.io/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
log: () => undefined,
});
});
test("rejects a mismatch", async () => {
const run: RunCommand = async () => ok(`${OTHER}\n`);
await expect(
verifyDigest({
reference: "ghcr.io/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
log: () => undefined,
}),
).rejects.toThrow(InvalidPayloadError);
});
test("re-reads a stale tag until it converges", async () => {
const heads = [fail("not found [http 404]"), ok(`${OTHER}\n`), ok(`${DIGEST}\n`)];
let reads = 0;
const run: RunCommand = async () => heads[reads++] ?? fail("unexpected read");
await verifyDigest({
reference: "public.ecr.aws/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
attempts: 5,
sleep: async () => undefined,
log: () => undefined,
});
expect(reads).toBe(3);
});
test("reports the last mismatch once attempts are exhausted", async () => {
let reads = 0;
const run: RunCommand = async () => {
reads++;
return ok(`${OTHER}\n`);
};
await expect(
verifyDigest({
reference: "public.ecr.aws/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
attempts: 3,
sleep: async () => undefined,
log: () => undefined,
}),
).rejects.toThrow(`resolves to ${OTHER}, expected ${DIGEST}`);
expect(reads).toBe(3);
});
test("fails on the first read when the head errors for another reason", async () => {
let reads = 0;
const run: RunCommand = async () => {
reads++;
return fail("unauthorized [http 401]");
};
await expect(
verifyDigest({
reference: "public.ecr.aws/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
attempts: 5,
sleep: async () => undefined,
log: () => undefined,
}),
).rejects.toThrow("unauthorized [http 401]");
expect(reads).toBe(1);
});
test("rejects a non-integer attempt count before reading", async () => {
let reads = 0;
const run: RunCommand = async () => {
reads++;
return ok(`${OTHER}\n`);
};
await expect(
verifyDigest({
reference: "public.ecr.aws/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
attempts: Number.NaN,
log: () => undefined,
}),
).rejects.toThrow(InvalidPayloadError);
expect(reads).toBe(0);
});
});
describe("ensureEcrPublicRepo", () => {
test("no-ops when the repository exists", async () => {
const run: RunCommand = async () => ok();
const logs: string[] = [];
await ensureEcrPublicRepo({
service: "postgrest",
run,
log: (message) => logs.push(message),
});
expect(logs).toEqual(["ECR Public repository cli/postgrest exists"]);
});
test("creates a missing repository", async () => {
const run: RunCommand = async (argv) =>
argv.includes("describe-repositories") ? fail("not found") : ok();
const logs: string[] = [];
await ensureEcrPublicRepo({
service: "postgrest",
run,
log: (message) => logs.push(message),
});
expect(logs).toEqual(["created ECR Public repository cli/postgrest"]);
});
test("treats a create race as success", async () => {
const run: RunCommand = async () => fail("RepositoryAlreadyExistsException");
const logs: string[] = [];
await ensureEcrPublicRepo({
service: "auth",
run,
log: (message) => logs.push(message),
});
expect(logs).toEqual(["ECR Public repository cli/auth was created concurrently"]);
});
test("fails when create is denied", async () => {
const run: RunCommand = async () => fail("AccessDenied");
await expect(
ensureEcrPublicRepo({ service: "postgrest", run, log: () => undefined }),
).rejects.toThrow(/CreateRepository/);
});
});
describe("copyImage", () => {
test("copies by digest with referrers", async () => {
const calls: string[][] = [];
const run: RunCommand = async (argv) => {
calls.push([...argv]);
return ok();
};
await copyImage({
source: "ghcr.io/supabase/cli/postgrest:v16.2",
destination: "public.ecr.aws/supabase/cli/postgrest:v16.2",
digest: DIGEST,
run,
});
expect(calls).toEqual([
[
"regctl",
"image",
"copy",
"--referrers",
"--digest-tags",
digestReference("ghcr.io/supabase/cli/postgrest:v16.2", DIGEST),
"public.ecr.aws/supabase/cli/postgrest:v16.2",
],
]);
});
});
describe("copyNatives", () => {
test("copies each matching source and continues after a missing tag", async () => {
const calls: string[][] = [];
const run: RunCommand = async (argv) => {
calls.push([...argv]);
if (argv[1] === "manifest" && String(argv[3]).includes("linux-amd64")) return fail("missing");
if (argv[1] === "manifest") return ok(`${DIGEST}\n`);
return ok();
};
const warnings: string[] = [];
const failed = await copyNatives({
service: "postgrest",
natives: [
{ tag: "v16.2-native-linux-arm64", digest: DIGEST },
{ tag: "v16.2-native-linux-amd64", digest: DIGEST },
],
run,
log: (message) => {
warnings.push(message);
},
});
expect(failed).toBe(1);
expect(calls).toEqual([
["regctl", "manifest", "head", "ghcr.io/supabase/cli/postgrest:v16.2-native-linux-arm64"],
[
"regctl",
"image",
"copy",
`ghcr.io/supabase/cli/postgrest@${DIGEST}`,
"public.ecr.aws/supabase/cli/postgrest:v16.2-native-linux-arm64",
],
["regctl", "manifest", "head", "ghcr.io/supabase/cli/postgrest:v16.2-native-linux-amd64"],
]);
expect(warnings.some((line) => line.includes("linux-amd64 is missing"))).toBe(true);
});
test("skips a digest mismatch without copying", async () => {
const calls: string[][] = [];
const run: RunCommand = async (argv) => {
calls.push([...argv]);
return argv[1] === "manifest" ? ok(`${OTHER}\n`) : fail("should not copy");
};
const failed = await copyNatives({
service: "postgrest",
natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }],
run,
log: () => undefined,
});
expect(failed).toBe(1);
expect(calls).toEqual([
["regctl", "manifest", "head", "ghcr.io/supabase/cli/postgrest:v16.2-native-linux-arm64"],
]);
});
});
describe("main", () => {
test("validate writes GitHub outputs", async () => {
const fields: Record<string, string> = {};
const code = await main(["validate"], {
env: {
EVENT_NAME: "workflow_dispatch",
SERVICE: "postgrest",
VERSION: "v16.2",
DIGEST,
},
run: async () => fail("unused"),
writeOutput: (next) => {
Object.assign(fields, next);
},
});
expect(code).toBe(0);
expect(fields["destination"]).toBe("public.ecr.aws/supabase/cli/postgrest:v16.2");
});
test("verify-digest re-reads up to ATTEMPTS times", async () => {
const heads = [ok(`${OTHER}\n`), ok(`${DIGEST}\n`)];
let reads = 0;
const code = await main(["verify-digest"], {
env: {
REFERENCE: "public.ecr.aws/supabase/cli/postgrest:v16.2",
DIGEST,
ATTEMPTS: "2",
},
run: async () => heads[reads++] ?? fail("unexpected read"),
sleep: async () => undefined,
log: () => undefined,
});
expect(code).toBe(0);
expect(reads).toBe(2);
});
test("copy-natives no-ops without a dispatch payload", async () => {
const logs: string[] = [];
const code = await main(["copy-natives"], {
env: { EVENT_NAME: "workflow_dispatch", SERVICE: "postgrest", VERSION: "v16.2" },
run: async () => fail("unused"),
log: (message) => logs.push(message),
});
expect(code).toBe(0);
expect(logs).toEqual(["no native artifacts in payload"]);
});
test("copy-natives reads natives from the dispatch event", async () => {
const natives = await nativesFromEvent(
{ EVENT_NAME: "repository_dispatch", GITHUB_EVENT_PATH: "event.json" },
"v16.2",
async () =>
JSON.stringify({
client_payload: { natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }] },
}),
);
expect(natives).toEqual([{ tag: "v16.2-native-linux-arm64", digest: DIGEST }]);
});
});
const ARCHIVE_BLOB = `sha256:${"1".repeat(64)}`;
const MANIFEST_BLOB = `sha256:${"2".repeat(64)}`;
const CHECKSUM_BLOB = `sha256:${"3".repeat(64)}`;
const ARCHIVE_SHA = "d".repeat(64);
const ociManifest = JSON.stringify({
layers: [
{ mediaType: "application/vnd.supabase.slim.archive.v1.tar+zstd", digest: ARCHIVE_BLOB },
{ mediaType: "application/vnd.supabase.slim.manifest.v1+json", digest: MANIFEST_BLOB },
{ mediaType: "application/vnd.supabase.slim.checksum.v1", digest: CHECKSUM_BLOB },
],
});
describe("native triplet helpers", () => {
test("keeps release asset names as object keys", () => {
expect(nativeFileNames("postgrest", "v16.2", "linux-arm64")).toEqual({
archive: "postgrest-v16.2-linux-arm64.tar.zst",
manifest: "postgrest-v16.2-linux-arm64.manifest.json",
checksum: "postgrest-v16.2-linux-arm64.SHA256SUMS",
});
expect(nativeObjectUrl("postgrest", "v16.2", "postgrest-v16.2-linux-arm64.tar.zst")).toBe(
"https://supabase-cli-artifacts.s3.us-east-1.amazonaws.com/postgrest/v16.2/postgrest-v16.2-linux-arm64.tar.zst",
);
});
test("selects triplet blobs by media type and rejects incomplete artifacts", () => {
expect(nativeTripletDigests(ociManifest)).toEqual({
archive: ARCHIVE_BLOB,
manifest: MANIFEST_BLOB,
checksum: CHECKSUM_BLOB,
});
expect(
nativeTripletDigests(JSON.stringify({ layers: [{ mediaType: "x", digest: ARCHIVE_BLOB }] })),
).toBeUndefined();
});
test("matches sums lines by archive name", () => {
const sums = `${ARCHIVE_SHA.toUpperCase()} postgrest-v16.2-linux-arm64.tar.zst\n`;
expect(checksumFor(sums, "postgrest-v16.2-linux-arm64.tar.zst")).toBe(ARCHIVE_SHA);
expect(checksumFor(sums, "postgrest-v16.2-linux-amd64.tar.zst")).toBeUndefined();
});
});
describe("fetchNatives", () => {
const io = (
overrides: { readonly sha?: string; readonly manifest?: string; readonly head?: string } = {},
) => {
const files: Record<string, string> = {};
const calls: string[][] = [];
const run: RunCommand = async (argv) => {
calls.push([...argv]);
if (argv[1] === "manifest" && argv[2] === "head") return ok(`${overrides.head ?? DIGEST}\n`);
return argv[1] === "manifest" ? ok(ociManifest) : fail("unexpected");
};
return {
calls,
run,
runToFile: async (argv: ReadonlyArray<string>, outputPath: string) => {
calls.push([...argv, `> ${outputPath}`]);
const digest = argv[4];
files[outputPath] =
digest === MANIFEST_BLOB
? (overrides.manifest ??
JSON.stringify({ service: "postgrest", version: "v16.2", target: "linux-arm64" }))
: digest === CHECKSUM_BLOB
? `${ARCHIVE_SHA} postgrest-v16.2-linux-arm64.tar.zst\n`
: "archive-bytes";
return ok();
},
readText: async (path: string) => files[path] ?? "",
sha256File: async () => overrides.sha ?? ARCHIVE_SHA,
mkdir: () => undefined,
log: () => undefined,
};
};
test("downloads the triplet under release asset names and verifies it", async () => {
const deps = io();
const fetched = await fetchNatives({
service: "postgrest",
version: "v16.2",
natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }],
outputDir: "/tmp/natives",
...deps,
});
expect(fetched).toEqual([
{ target: "linux-arm64", files: nativeFileNames("postgrest", "v16.2", "linux-arm64") },
]);
expect(deps.calls[0]).toEqual([
"regctl",
"manifest",
"head",
"ghcr.io/supabase/cli/postgrest:v16.2-native-linux-arm64",
]);
expect(deps.calls[1]).toEqual([
"regctl",
"manifest",
"get",
`ghcr.io/supabase/cli/postgrest@${DIGEST}`,
"--format",
"raw-body",
]);
expect(deps.calls[2]).toEqual([
"regctl",
"blob",
"get",
"ghcr.io/supabase/cli/postgrest",
ARCHIVE_BLOB,
"> /tmp/natives/linux-arm64/postgrest-v16.2-linux-arm64.tar.zst",
]);
});
test("skips a native whose tag no longer resolves to the dispatched digest", async () => {
const deps = io({ head: OTHER });
const fetched = await fetchNatives({
service: "postgrest",
version: "v16.2",
natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }],
outputDir: "/tmp/natives",
...deps,
});
expect(fetched).toEqual([]);
expect(deps.calls).toHaveLength(1);
});
test("keeps the first entry for a repeated target and never refetches it", async () => {
const deps = io();
const fetched = await fetchNatives({
service: "postgrest",
version: "v16.2",
natives: [
{ tag: "v16.2-native-linux-arm64", digest: DIGEST },
{ tag: "v16.2-native-linux-arm64", digest: OTHER },
],
outputDir: "/tmp/natives",
...deps,
});
expect(fetched.map((item) => item.target)).toEqual(["linux-arm64"]);
expect(deps.calls.filter((argv) => argv[1] === "manifest" && argv[2] === "head")).toHaveLength(
1,
);
});
test("drops a target whose manifest is not JSON", async () => {
const fetched = await fetchNatives({
service: "postgrest",
version: "v16.2",
natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }],
outputDir: "/tmp/natives",
...io({ manifest: "{not json" }),
});
expect(fetched).toEqual([]);
expect(nativeTripletDigests("<html>")).toBeUndefined();
});
test("drops a target whose archive does not match its sums file", async () => {
const fetched = await fetchNatives({
service: "postgrest",
version: "v16.2",
natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }],
outputDir: "/tmp/natives",
...io({ sha: "e".repeat(64) }),
});
expect(fetched).toEqual([]);
});
test("drops a target whose manifest names another release", async () => {
const fetched = await fetchNatives({
service: "postgrest",
version: "v16.2",
natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }],
outputDir: "/tmp/natives",
...io({
manifest: JSON.stringify({ service: "postgrest", version: "v16.1", target: "linux-arm64" }),
}),
});
expect(fetched).toEqual([]);
});
});
describe("uploadNativesS3", () => {
const fetched = [
{ target: "linux-arm64", files: nativeFileNames("postgrest", "v16.2", "linux-arm64") },
];
test("copies archive, manifest, then sums and verifies anonymous reads", async () => {
const calls: string[][] = [];
const checked: string[] = [];
await uploadNativesS3({
service: "postgrest",
version: "v16.2",
inputDir: "/tmp/natives",
fetched,
run: async (argv) => {
calls.push([...argv]);
return ok();
},
httpStatus: async (url, method) => {
checked.push(`${method} ${url}`);
return url.endsWith("/") ? 403 : 200;
},
log: () => undefined,
});
expect(calls.map((argv) => argv.at(-1))).toEqual([
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-linux-arm64.tar.zst",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-linux-arm64.manifest.json",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-linux-arm64.SHA256SUMS",
]);
expect(calls[0]).toContain("/tmp/natives/linux-arm64/postgrest-v16.2-linux-arm64.tar.zst");
expect(calls.every((argv) => argv[1] === "s3" && argv[2] === "cp")).toBe(true);
expect(checked).toEqual([
"HEAD https://supabase-cli-artifacts.s3.us-east-1.amazonaws.com/postgrest/v16.2/postgrest-v16.2-linux-arm64.tar.zst",
"HEAD https://supabase-cli-artifacts.s3.us-east-1.amazonaws.com/postgrest/v16.2/postgrest-v16.2-linux-arm64.manifest.json",
"HEAD https://supabase-cli-artifacts.s3.us-east-1.amazonaws.com/postgrest/v16.2/postgrest-v16.2-linux-arm64.SHA256SUMS",
"GET https://supabase-cli-artifacts.s3.us-east-1.amazonaws.com/",
]);
});
test("fails when an object is not publicly readable", async () => {
await expect(
uploadNativesS3({
service: "postgrest",
version: "v16.2",
inputDir: "/tmp/natives",
fetched,
run: async () => ok(),
httpStatus: async () => 403,
log: () => undefined,
}),
).rejects.toThrow(/not publicly readable/);
});
test("fails when the bucket starts listing", async () => {
await expect(
uploadNativesS3({
service: "postgrest",
version: "v16.2",
inputDir: "/tmp/natives",
fetched,
run: async () => ok(),
httpStatus: async () => 200,
log: () => undefined,
}),
).rejects.toThrow(/listing must stay closed/);
});
});
describe("main fetch-natives", () => {
test("writes count=0 without a dispatch payload", async () => {
const fields: Record<string, string> = {};
const code = await main(["fetch-natives"], {
env: {
EVENT_NAME: "workflow_dispatch",
SERVICE: "postgrest",
VERSION: "v16.2",
OUTPUT_DIR: "/tmp/natives",
},
run: async () => fail("unused"),
log: () => undefined,
writeOutput: (next) => {
Object.assign(fields, next);
},
});
expect(code).toBe(0);
expect(fields).toEqual({ count: "0", targets: "" });
});
test("exits 1 when the payload names natives but none can be verified", async () => {
const fields: Record<string, string> = {};
const event = JSON.stringify({
client_payload: { natives: [{ tag: "v16.2-native-linux-arm64", digest: DIGEST }] },
});
const code = await main(["fetch-natives"], {
env: {
EVENT_NAME: "repository_dispatch",
GITHUB_EVENT_PATH: "/tmp/event.json",
SERVICE: "postgrest",
VERSION: "v16.2",
OUTPUT_DIR: "/tmp/natives",
},
run: async () => fail("manifest unknown"),
readText: async () => event,
log: () => undefined,
writeOutput: (next) => {
Object.assign(fields, next);
},
});
expect(code).toBe(1);
expect(fields).toEqual({ count: "0", targets: "" });
});
});
describe("main upload-natives-s3", () => {
test("uploads every target listed in TARGETS", async () => {
const uploaded: string[] = [];
const code = await main(["upload-natives-s3"], {
env: {
SERVICE: "postgrest",
VERSION: "v16.2",
INPUT_DIR: "/tmp/natives",
TARGETS: "linux-arm64, darwin-arm64",
},
run: async (argv) => {
uploaded.push(String(argv.at(-1)));
return ok();
},
httpStatus: async (url) => (url.endsWith("/") ? 403 : 200),
log: () => undefined,
});
expect(code).toBe(0);
expect(uploaded).toEqual([
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-linux-arm64.tar.zst",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-linux-arm64.manifest.json",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-linux-arm64.SHA256SUMS",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-darwin-arm64.tar.zst",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-darwin-arm64.manifest.json",
"s3://supabase-cli-artifacts/postgrest/v16.2/postgrest-v16.2-darwin-arm64.SHA256SUMS",
]);
});
});
You can’t perform that action at this time.
