ReviewOS

also looking at this

craft-native/craft

Gate releases on shipped artifact findings

#316
Merged glennmichael123 wants to merge codex/gate-shipped-artifacts into main
11 files +454 -25
scripts/npm-packages.test.tsmodified+21-1
Changes to scripts/npm-packages.test.ts
@@ -1,5 +1,9 @@
11import { expect, test } from 'bun:test'
2import { manifestTargets, verifyArchiveTargets } from './npm-packages'
2import { createHash } from 'node:crypto'
3import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
4import { tmpdir } from 'node:os'
5import { join } from 'node:path'
6import { manifestTargets, verifyArchiveTargets, verifyNpmPackages } from './npm-packages'
37
48test('rejects absent built entries even when the manifest advertises them', () => {
59 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
3135 for (const target of ['../outside.js', '/outside.js', './dist/../outside.js', '.\\outside.js', './dist/*.js'])
3236 expect(() => manifestTargets({ name: 'fixture', exports: target })).toThrow()
3337})
38
39test('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)