import fs from 'node:fs'
import process from 'node:process'

const exists=p=>fs.existsSync(p)
const pkg=JSON.parse(fs.readFileSync('package.json','utf8'))
const result={
  generatedAt:new Date().toISOString(),
  node:process.version,
  packageManager:pkg.packageManager,
  lockfile:exists('pnpm-lock.yaml'),
  nodeModules:exists('node_modules'),
  playwrightConfig:exists('playwright.config.ts'),
  playwrightInstalled:exists('node_modules/@playwright/test'),
  vitestInstalled:exists('node_modules/vitest'),
  demoRuntimeScript:Boolean(pkg.scripts?.['dev:web:demo']),
  e2eScript:Boolean(pkg.scripts?.['test:e2e']),
}
result.status=result.lockfile&&result.playwrightInstalled&&result.vitestInstalled?'ready':'blocked'
result.blockers=[]
if(!result.lockfile)result.blockers.push('pnpm-lock.yaml is absent; reproducible dependency install evidence is not available.')
if(!result.nodeModules)result.blockers.push('node_modules is absent in this artifact environment.')
if(!result.playwrightInstalled)result.blockers.push('@playwright/test is declared but not installed in this artifact environment.')
if(!result.vitestInstalled)result.blockers.push('vitest is declared but not installed in this artifact environment.')
console.log(JSON.stringify(result,null,2))
