|
1 | | -import { execFileSync } from "node:child_process"; |
| 1 | +import { execFileSync, spawnSync } from "node:child_process"; |
2 | 2 | import { createHash } from "node:crypto"; |
3 | 3 | import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
4 | 4 | import { tmpdir } from "node:os"; |
@@ -33,6 +33,7 @@ import { |
33 | 33 |
|
34 | 34 | const SCRIPT = "scripts/release-ci-summary.mjs"; |
35 | 35 | const MANIFEST_ARTIFACT_ENTRY = "full-release-validation-manifest.json"; |
| 36 | +const hasUnzip = spawnSync("unzip", ["-v"], { stdio: "ignore" }).status === 0; |
36 | 37 |
|
37 | 38 | function crc32(input: Buffer): number { |
38 | 39 | let crc = 0xffffffff; |
@@ -524,50 +525,53 @@ describe("release CI summary child correlation", () => { |
524 | 525 | ); |
525 | 526 | }); |
526 | 527 |
|
527 | | - it("hashes and safely streams one bounded manifest entry from the exact artifact ZIP", () => { |
528 | | - const root = mkdtempSync(join(tmpdir(), "release-manifest-artifact-")); |
529 | | - try { |
530 | | - const archivePath = join(root, "manifest.zip"); |
531 | | - const manifest = { runAttempt: 1, runId: "29071366025" }; |
532 | | - const archive = makeStoredZip({ |
533 | | - [MANIFEST_ARTIFACT_ENTRY]: JSON.stringify(manifest), |
534 | | - }); |
535 | | - writeFileSync(archivePath, archive); |
536 | | - expect(readManifestArtifactArchive(archivePath, artifactDigest(archive))).toEqual(manifest); |
537 | | - expect(() => readManifestArtifactArchive(archivePath, `sha256:${"0".repeat(64)}`)).toThrow( |
538 | | - "artifact digest mismatch", |
539 | | - ); |
| 528 | + it.skipIf(!hasUnzip)( |
| 529 | + "hashes and safely streams one bounded manifest entry from the exact artifact ZIP", |
| 530 | + () => { |
| 531 | + const root = mkdtempSync(join(tmpdir(), "release-manifest-artifact-")); |
| 532 | + try { |
| 533 | + const archivePath = join(root, "manifest.zip"); |
| 534 | + const manifest = { runAttempt: 1, runId: "29071366025" }; |
| 535 | + const archive = makeStoredZip({ |
| 536 | + [MANIFEST_ARTIFACT_ENTRY]: JSON.stringify(manifest), |
| 537 | + }); |
| 538 | + writeFileSync(archivePath, archive); |
| 539 | + expect(readManifestArtifactArchive(archivePath, artifactDigest(archive))).toEqual(manifest); |
| 540 | + expect(() => readManifestArtifactArchive(archivePath, `sha256:${"0".repeat(64)}`)).toThrow( |
| 541 | + "artifact digest mismatch", |
| 542 | + ); |
| 543 | + |
| 544 | + const extraEntryArchive = makeStoredZip({ |
| 545 | + [MANIFEST_ARTIFACT_ENTRY]: JSON.stringify(manifest), |
| 546 | + "unexpected.json": "{}", |
| 547 | + }); |
| 548 | + writeFileSync(archivePath, extraEntryArchive); |
| 549 | + expect(() => |
| 550 | + readManifestArtifactArchive(archivePath, artifactDigest(extraEntryArchive)), |
| 551 | + ).toThrow(`must contain only ${MANIFEST_ARTIFACT_ENTRY}`); |
540 | 552 |
|
541 | | - const extraEntryArchive = makeStoredZip({ |
542 | | - [MANIFEST_ARTIFACT_ENTRY]: JSON.stringify(manifest), |
543 | | - "unexpected.json": "{}", |
544 | | - }); |
545 | | - writeFileSync(archivePath, extraEntryArchive); |
546 | | - expect(() => |
547 | | - readManifestArtifactArchive(archivePath, artifactDigest(extraEntryArchive)), |
548 | | - ).toThrow(`must contain only ${MANIFEST_ARTIFACT_ENTRY}`); |
| 553 | + const oversizedManifestArchive = makeStoredZip({ |
| 554 | + [MANIFEST_ARTIFACT_ENTRY]: "x".repeat(128 * 1024 + 1), |
| 555 | + }); |
| 556 | + writeFileSync(archivePath, oversizedManifestArchive); |
| 557 | + expect(() => |
| 558 | + readManifestArtifactArchive(archivePath, artifactDigest(oversizedManifestArchive)), |
| 559 | + ).toThrow("artifact entry size is invalid"); |
549 | 560 |
|
550 | | - const oversizedManifestArchive = makeStoredZip({ |
551 | | - [MANIFEST_ARTIFACT_ENTRY]: "x".repeat(128 * 1024 + 1), |
552 | | - }); |
553 | | - writeFileSync(archivePath, oversizedManifestArchive); |
554 | | - expect(() => |
555 | | - readManifestArtifactArchive(archivePath, artifactDigest(oversizedManifestArchive)), |
556 | | - ).toThrow("artifact entry size is invalid"); |
557 | | - |
558 | | - const oversizedArchive = Buffer.alloc(256 * 1024 + 1); |
559 | | - writeFileSync(archivePath, oversizedArchive); |
560 | | - expect(() => |
561 | | - readManifestArtifactArchive(archivePath, artifactDigest(oversizedArchive)), |
562 | | - ).toThrow("artifact compressed size is invalid"); |
563 | | - |
564 | | - const source = readFileSync(SCRIPT, "utf8"); |
565 | | - expect(source).toContain('execFileSync("unzip", ["-p", archivePath'); |
566 | | - expect(source).not.toContain('execFileSync("unzip", ["-q", archivePath, "-d"'); |
567 | | - } finally { |
568 | | - rmSync(root, { force: true, recursive: true }); |
569 | | - } |
570 | | - }); |
| 561 | + const oversizedArchive = Buffer.alloc(256 * 1024 + 1); |
| 562 | + writeFileSync(archivePath, oversizedArchive); |
| 563 | + expect(() => |
| 564 | + readManifestArtifactArchive(archivePath, artifactDigest(oversizedArchive)), |
| 565 | + ).toThrow("artifact compressed size is invalid"); |
| 566 | + |
| 567 | + const source = readFileSync(SCRIPT, "utf8"); |
| 568 | + expect(source).toContain('execFileSync("unzip", ["-p", archivePath'); |
| 569 | + expect(source).not.toContain('execFileSync("unzip", ["-q", archivePath, "-d"'); |
| 570 | + } finally { |
| 571 | + rmSync(root, { force: true, recursive: true }); |
| 572 | + } |
| 573 | + }, |
| 574 | + ); |
571 | 575 |
|
572 | 576 | it("bridges only attempt-one manifest v2 artifacts with the legacy stable name", () => { |
573 | 577 | const legacyV2 = trustedMainPackageFixture(); |
|
0 commit comments