import { test } from 'node:test'; import assert from 'node:assert/strict'; import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { execFileSync } from 'node:child_process'; import { dirname, join } from 'node:path'; import { tmpdir } from 'node:os'; import { packagePcb } from './package-pcb.mjs'; test('PCB releases extract directly into pcb/ and exclude local configuration', t => { const root = mkdtempSync(join(tmpdir(), 'vibemake-pcb-package-')); t.after(() => rmSync(root, { recursive: true, force: true })); const put = (file, value) => { mkdirSync(dirname(join(root, file)), { recursive: true }); writeFileSync(join(root, file), value); }; put('source/index.html', ''); put('source/assets/app.js', 'console.log("PCB");'); put('source/pcb-service-config.json', '{"base":"/pcb/"}'); put('source/.env.local', 'PRIVATE_BUILD_VALUE=example'); const output = join(root, 'output'); put('output/vibemake-pcb/pcb/stale.html', 'old nested package'); put('output/vibemake-pcb/stale.html', 'old package file'); const result = packagePcb({ source: join(root, 'source'), output }); const entries = execFileSync('unzip', ['-Z1', result.archive], { encoding: 'utf8' }).trim().split('\n'); assert.ok(entries.includes('index.html')); assert.ok(entries.includes('assets/app.js')); assert.ok(entries.includes('build-info.json')); assert.ok(!entries.some(path => path.startsWith('pcb/') || path.startsWith('vibemake-pcb/'))); assert.ok(!entries.some(path => path.includes('.env'))); assert.ok(existsSync(join(result.directory, 'index.html'))); assert.ok(existsSync(join(result.directory, 'assets/app.js'))); assert.equal(existsSync(join(result.directory, 'pcb')), false); assert.equal(existsSync(join(result.directory, 'stale.html')), false); const website = join(root, 'website'); const protectedFiles = ['index.html', 'cad/index.html', 'js/cad/app.js', 'css/cad.css', 'pcb/assets/previous.js']; for (const file of protectedFiles) put(`website/${file}`, `published:${file}`); execFileSync('unzip', ['-oq', result.archive, '-d', join(website, 'pcb')]); for (const file of protectedFiles) assert.equal(readFileSync(join(website, file), 'utf8'), `published:${file}`); assert.equal(readFileSync(join(website, 'pcb/index.html'), 'utf8'), readFileSync(join(root, 'source/index.html'), 'utf8')); assert.equal(existsSync(join(website, 'pcb/pcb')), false); assert.equal(JSON.parse(readFileSync(join(website, 'pcb/build-info.json'))).scope, 'pcb'); assert.match(readFileSync(join(website, 'pcb/DEPLOY.md'), 'utf8'), /directly into \/pcb\//); const previous = readFileSync(result.archive); put('source/pcb-service-config.json', '{"base":"/"}'); assert.throws(() => packagePcb({ source: join(root, 'source'), output }), /\/pcb\//); assert.deepEqual(readFileSync(result.archive), previous); assert.equal(existsSync(join(result.directory, '.env.local')), false); });