also looking at this
Gate releases on shipped artifact findings
#316
11 files
+454
-25
| @@ -1,5 +1,9 @@ | ||
| 1 | 1 | import { expect, test } from 'bun:test' |
| 2 | import { manifestTargets, verifyArchiveTargets } from './npm-packages' | |
| 2 | import { createHash } from 'node:crypto' | |
| 3 | import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs' | |
| 4 | import { tmpdir } from 'node:os' | |
| 5 | import { join } from 'node:path' | |
| 6 | import { manifestTargets, verifyArchiveTargets, verifyNpmPackages } from './npm-packages' | |
| 3 | 7 | |
| 4 | 8 | test('rejects absent built entries even when the manifest advertises them', () => { |
| 5 | 9 | const pkg = { name: '@craft-native/react', main: 'dist/index.js', exports: { '.': { import: './dist/index.mjs', types: './dist/index.d.ts' } } } |
| @@ -31,3 +35,19 @@ test('fails closed for targets that escape the package or need wildcard handling | ||
| 31 | 35 | for (const target of ['../outside.js', '/outside.js', './dist/../outside.js', '.\\outside.js', './dist/*.js']) |
| 32 | 36 | expect(() => manifestTargets({ name: 'fixture', exports: target })).toThrow() |
| 33 | 37 | }) |
| 38 | ||
| 39 | test('exports every verified npm archive with its exact digest', async () => { | |
| 40 | const root = mkdtempSync(join(tmpdir(), 'craft-npm-archive-test-')) | |
| 41 | const output = join(root, 'archives') | |
| 42 | try { | |
| 43 | await verifyNpmPackages(false, output) | |
| 44 | const manifest = JSON.parse(readFileSync(join(output, 'manifest.json'), 'utf8')) as { packages: { name: string, file: string, sha256: string }[] } | |
| 45 | expect(manifest.packages).toHaveLength(8) | |
| 46 | for (const archive of manifest.packages) { | |
| 47 | const path = join(output, archive.file) | |
| 48 | expect(existsSync(path)).toBe(true) | |
| 49 | expect(createHash('sha256').update(readFileSync(path)).digest('hex')).toBe(archive.sha256) | |
| 50 | } | |
| 51 | } | |
| 52 | finally { rmSync(root, { recursive: true, force: true }) } | |
| 53 | }, 120_000) | |