Tools live under tools/<role>/<domain> (checks, generate, release, ci, dev), every tool is a workspace named @open-pencil/<domain>-tools, a shared tools/tsconfig.json backs the new check:tools gate that fixed 55 latent type errors, test:tools runs through bun --filter, the placement check is its own checks/test-homes package, and every tool resolves the repository through resolveWorkspaceRoot. Bun, Node, and mdast types live in a tools-root workspace so they never reach the app program.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { expect, test } from 'bun:test'
|
|
|
|
import { parsePackageManifest } from '#package-artifacts/manifest/read'
|
|
import { parseNpmPack } from '#package-artifacts/npm/pack'
|
|
|
|
test('npm pack parser validates archive names and paths', () => {
|
|
expect(
|
|
parseNpmPack(JSON.stringify([{ filename: 'pkg.tgz', files: [{ path: 'src/index.ts' }] }]))
|
|
).toEqual({ filename: 'pkg.tgz', files: ['src/index.ts'] })
|
|
for (const value of [
|
|
null,
|
|
[],
|
|
[
|
|
{ filename: 'a.tgz', files: [] },
|
|
{ filename: 'b.tgz', files: [] }
|
|
],
|
|
[{ filename: 42, files: [] }],
|
|
[{ filename: 'pkg.tgz', files: [{ path: '' }] }],
|
|
[{ filename: 'pkg.tgz', files: [{ path: '/absolute' }] }],
|
|
[{ filename: 'pkg.tgz', files: [{ path: 'src\\\\index.ts' }] }],
|
|
[{ filename: '../pkg.tgz', files: [] }],
|
|
[{ filename: 'pkg.tgz', files: [{ path: '../outside' }] }]
|
|
]) {
|
|
expect(() => parseNpmPack(JSON.stringify(value))).toThrow('npm pack:')
|
|
}
|
|
})
|
|
|
|
test('npm pack parser ignores unrelated npm fields', () => {
|
|
expect(
|
|
parseNpmPack(
|
|
JSON.stringify([
|
|
{
|
|
filename: 'pkg.tgz',
|
|
size: 123,
|
|
integrity: 'sha512-example',
|
|
files: [{ path: 'src/value.ts', size: 10, mode: 420 }]
|
|
}
|
|
])
|
|
)
|
|
).toEqual({ filename: 'pkg.tgz', files: ['src/value.ts'] })
|
|
})
|
|
|
|
test('tarball manifest identity errors include archive context', () => {
|
|
expect(() => parsePackageManifest('{', 'archive.tgz')).toThrow('archive.tgz: invalid JSON')
|
|
expect(() => parsePackageManifest('{"name":3}', 'archive.tgz')).toThrow(
|
|
'archive.tgz: invalid package manifest'
|
|
)
|
|
})
|