import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';

const HOME23_ROOT = process.cwd();

test('live-problems panel exposes an operator readout, not only raw verifier rows', () => {
  const js = fs.readFileSync(path.join(HOME23_ROOT, 'engine/src/dashboard/home23-dashboard.js'), 'utf8');
  const css = fs.readFileSync(path.join(HOME23_ROOT, 'engine/src/dashboard/home23-dashboard.css'), 'utf8');
  const html = fs.readFileSync(path.join(HOME23_ROOT, 'engine/src/dashboard/home23-dashboard.html'), 'utf8');

  assert.match(html, /h23-problems-overlay-panel/);
  assert.match(js, /renderProblemsOperatorSummary/);
  assert.match(js, /Operator Status/);
  assert.match(js, /Needed From You/);
  assert.match(js, /problemRepairText/);
  assert.match(js, /renderProblemUserAction/);
  assert.match(js, /Action Needed/);
  assert.match(js, /Inspect Plan/);
  assert.match(js, /Mark Handled \+ Re-check/);
  assert.match(js, /recordProblemUserIntervention/);
  assert.match(js, /recordGoodLifeUserIntervention/);
  assert.match(js, /user-intervention/);
  assert.match(js, /Verifier remains the source of truth/);
  assert.match(js, /Re-check/);
  assert.match(js, /manual review needed; autonomous remediation has escalated this issue/);
  assert.match(js, /problem\.escalated === true/);
  assert.match(js, /nothing; this issue is resolved/);
  assert.match(js, /brief\.status === 'Paused'/);
  assert.match(js, /paused by budget/);
  assert.match(js, /brief\.status === 'Resting'/);
  assert.match(js, /resting autonomously/);
  assert.match(js, /goodLifePausedFleetText/);
  assert.match(js, /budget \$\{reset\}/);
  assert.match(js, /renderGoodLifeHostPressure/);
  assert.match(js, /renderGoodLifePm2Changes/);
  assert.match(js, /Runtime Changes/);
  assert.match(js, /renderGoodLifeWorkerReceiptDetail/);
  assert.match(js, /renderGoodLifeIssueWorkerReceipt/);
  assert.match(js, /Latest Worker Receipt/);
  assert.match(js, /renderGoodLifeIssueInterventionConsole/);
  assert.match(js, /Operator Intervention/);
  assert.match(js, /Recommended next step/);
  assert.match(js, /Projection Provenance/);
  assert.match(js, /provenance\.projection\?\.authority/);
  assert.match(js, /From The Inside arc/);
  assert.match(js, /provenance\.curriculumArc\.issuesRead/);
  assert.match(js, /provenance\.conflicts/);
  assert.match(js, /Ask \$\{escapeHtml\(workerName\)\} Worker/);
  assert.match(js, /openGoodLifeWorkers/);
  assert.match(js, /Run Engine Check/);
  assert.match(js, /h23-goodlife-primary-action/);
  assert.match(js, /Next Action/);
  assert.match(js, /Work Manifest/);
  assert.match(js, /manifest\.allowedTransition/);
  assert.match(js, /manifest\.sourceSurface/);
  assert.match(js, /Correction Tombstones/);
  assert.match(js, /correctionTombstones/);
  assert.match(js, /do_not_inherit_old_projection/);
  assert.match(js, /Restraint Receipts/);
  assert.match(js, /restraintReceipts/);
  assert.match(js, /Scheduler Sovereignty/);
  assert.match(js, /renderGoodLifeScheduler/);
  assert.match(js, /Doctrine Adoption/);
  assert.match(js, /doctrineAdoption\.reusable/);
  assert.match(js, /doctrineAdoption\.blocked/);
  assert.match(js, /renderGoodLifeRings/);
  assert.match(js, /Good Life three-ring status/);
  assert.match(js, /operatorRings/);
  assert.match(js, /formatGoodLifeWorkerResult/);
  assert.match(js, /Worker check complete: \$\{formatGoodLifeWorkerResult/);
  assert.match(js, /last change/);
  assert.match(js, /currently not online/);
  assert.match(js, /repair signal/);
  assert.match(js, /compactGoodLifeHostDetail/);
  assert.match(js, /Host Pressure/);
  assert.match(js, /CPU Load/);
  assert.match(js, /Top Process/);
  assert.match(js, /goodLifeHostPressureStatus/);
  assert.match(js, /drives rest/);
  assert.match(js, /informational/);
  assert.match(css, /\.h23-problems-operator/);
  assert.match(css, /\.h23-problem-operator-grid/);
  assert.match(css, /\.h23-problem-user-action/);
  assert.match(css, /\.h23-goodlife-fleet-row\.paused/);
  assert.match(css, /\.h23-goodlife-fleet-row\.resting/);
  assert.match(css, /\.h23-goodlife-evidence-row\.watch/);
  assert.match(css, /\.h23-goodlife-evidence-row\.info/);
  assert.match(css, /\.h23-goodlife-intervention-console/);
  assert.match(css, /\.h23-goodlife-intervention-grid/);
  assert.match(css, /\.h23-goodlife-primary-action/);
  assert.match(css, /\.h23-goodlife-primary-action \.h23-goodlife-mini-actions[\s\S]*flex:\s*0 0 auto/);
  assert.match(css, /\.h23-goodlife-rings/);
  assert.match(css, /\.h23-goodlife-ring\.needs-user/);
  assert.match(css, /\.h23-goodlife-overlay-body[\s\S]*grid-template-rows:\s*minmax\(180px,\s*0\.82fr\)\s*auto\s*minmax\(260px,\s*1\.18fr\)\s*auto/);
  assert.match(css, /\.h23-goodlife-overlay-top[\s\S]*overflow-y:\s*auto/);
  assert.match(css, /\.h23-goodlife-overlay-workspace[\s\S]*overflow:\s*hidden/);
  assert.match(css, /\.h23-goodlife-overlay-list,\s*\n\.h23-goodlife-overlay-detail[\s\S]*overflow-y:\s*auto/);
  assert.match(css, /\.h23-goodlife-overlay-action-status[\s\S]*pointer-events:\s*none/);
});

test('Good Life issue detail shows user-facing repair context before raw JSON', () => {
  const js = fs.readFileSync(path.join(HOME23_ROOT, 'engine/src/dashboard/home23-dashboard.js'), 'utf8');
  const css = fs.readFileSync(path.join(HOME23_ROOT, 'engine/src/dashboard/home23-dashboard.css'), 'utf8');

  assert.match(js, /h23-goodlife-issue-brief/);
  assert.match(js, /What is wrong/);
  assert.match(js, /What is happening/);
  assert.match(js, /Needed from jtr/);
  assert.match(js, /Stop condition/);
  assert.match(css, /\.h23-goodlife-issue-brief/);
});
