import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const app = fs.readFileSync('src/server/app.mjs', 'utf8'); const catalogStart = app.indexOf('const research = ['); const catalogEnd = app.indexOf('\n];', catalogStart); assert.ok(catalogStart > 0 && catalogEnd > catalogStart); const reports = [...app.slice(catalogStart, catalogEnd).matchAll(/file: '([^']+)'/g)].map(match => { const file = 'docs/' + match[1], bytes = fs.readFileSync(file); return { path: file, bytes: bytes.length, sha256: hash(bytes) }; }); assert.equal(reports.length, 4); const latest = JSON.parse(fs.readFileSync('releases/latest.json')); const manifestFile = path.join(latest.portableRoot, 'MANIFEST.json'), bytes = fs.readFileSync(manifestFile), manifest = JSON.parse(bytes); const categories = new Map(); for (const row of manifest.files) { const parts = row.path.replaceAll('\\', '/').split('/'); const key = parts[0] === 'docs' ? parts.slice(0, 2).join('/') : parts[0]; const current = categories.get(key) ?? { path: key, files: 0, bytes: 0 }; current.files++; current.bytes += row.bytes; categories.set(key, current); } const sum = rows => ({ files: rows.length, bytes: rows.reduce((total, row) => total + row.bytes, 0) }); const result = { success: true, observedAt: new Date().toISOString(), sourceCommit: JSON.parse(fs.readFileSync('.qa/embedded-browser-b-code-baseline.json')).codeCommit, observedPayload: { manifestFile, manifestSha256: hash(bytes), version: manifest.version, note: 'Inventory only; this does not mean this candidate passed acceptance.' }, all: sum(manifest.files), docs: sum(manifest.files.filter(row => row.path.startsWith('docs/'))), directlyServedResearchReports: reports, largestCategories: [...categories.values()].sort((a,b) => b.bytes-a.bytes).slice(0,18), findings: [ 'scripts/package.mjs currently copies the entire docs directory into both source and portable payloads.', 'src/server/app.mjs directly serves four fixed research reports; this static lookup alone is insufficient to prove every other document can be omitted.', 'src/core/initial-example-project.mjs reads examples/starter-project at initialization; keep the initial project and required build files.', 'Installation validation enumerates and hashes every file declared in MANIFEST.json; preserve the full declared-file validation contract after splitting documentation.' ], scope: 'Read-only planning inventory for PLAN-1.23. No runtime file omitted, cached verification enabled, source modified, formal credential read, or performance improvement claimed.' }; fs.writeFileSync('.qa/embedded-browser-b-payload-analysis.json', JSON.stringify(result, null, 2) + '\n', { flag: 'wx' }); console.log(JSON.stringify(result, null, 2));