import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';

const decisionPath = new URL('../docs/PRODUCT-DECISIONS.md', import.meta.url);
const policyPath = new URL('../docs/TIMMY-AGENT-POLICY.md', import.meta.url);
const readmePath = new URL('../README.md', import.meta.url);

test('product decision record fixes the AI boundary and release authority', async () => {
  const decision = await readFile(decisionPath, 'utf8');

  assert.match(decision, /Observable AI fields[\s\S]*Bristol form[\s\S]*broad color[\s\S]*image quality/i);
  assert.match(decision, /Prohibited inferences[\s\S]*disease[\s\S]*bleeding[\s\S]*pain[\s\S]*urgency[\s\S]*fever[\s\S]*vomiting[\s\S]*food/i);
  assert.match(decision, /release authority/i);
  assert.match(decision, /tool-capable Hermes Agent/i);
  assert.match(decision, /browser never receives provider credentials or Hermes session IDs/i);
  assert.match(decision, /deterministic urgent-symptom guidance runs before chat/i);
  assert.match(decision, /Human gates[\s\S]*clinical and privacy review[\s\S]*beta consent[\s\S]*RC approval/i);
  assert.match(decision, /\.\.\/PRODUCT\.md/);
  assert.match(decision, /\.\.\/AI-EVIDENCE\.md/);
  assert.match(decision, /\.\.\/research\/SELF-HOSTED-STOOL-VISION\.md/);
});

test('Hermes deployment installs a checked-in non-diagnostic workspace policy', async () => {
  const [policy, readme] = await Promise.all([readFile(policyPath, 'utf8'), readFile(readmePath, 'utf8')]);
  assert.match(policy, /never diagnose/i);
  assert.match(policy, /urgent symptoms/i);
  assert.match(policy, /explicit user intent and confirmation/i);
  assert.match(readme, /install -m 600 docs\/TIMMY-AGENT-POLICY\.md/);
});
