import assert from 'node:assert/strict';
import test from 'node:test';
import { BOOTSTRAP_VERSION, workerBootstrap } from '../src/bootstrap.js';

test('bootstrap v2 is owner-readable and carries lifecycle/output contract without executor mechanics', () => {
  const workerId = `wrk_${crypto.randomUUID()}`;
  const runId = `run_${crypto.randomUUID()}`;
  const assignmentId = `asg_${crypto.randomUUID()}`;
  const timestamp = new Date().toISOString();
  const text = workerBootstrap({
    run: { runId, title: 'Execution Continuity dogfood', taskName: 'Execution Continuity', rootConversationName: 'Execution Continuity Root', rootWorkerId: workerId, state: 'active', createdAt: timestamp, updatedAt: timestamp },
    worker: { workerId, runId, name: '/root/a', displayName: 'Execution Continuity Lane A', taskSummary: 'Implement continuity domain and persistence.', parentWorkerId: workerId, executor: 'chatgpt-web', state: 'launch_requested', assignmentId, executionId: null, createdAt: timestamp, updatedAt: timestamp },
    assignment: { assignmentId, objective: 'Implement continuity domain and persistence.', constraints: [], acceptanceCriteria: ['Tests pass'], dependencies: [], allowedScope: ['packages/core/**'], forbiddenScope: ['apps/extension/**'], artifacts: [] },
  });
  assert.equal(BOOTSTRAP_VERSION, 2);
  assert.match(text.split('\n')[0]!, /^TASK: Execution Continuity Lane A \| ROOT CONVERSATION: Execution Continuity Root \| SUMMARY:/);
  assert.match(text, new RegExp(workerId));
  assert.match(text, /OWNER-VISIBLE ASSIGNMENT/);
  assert.match(text, /Allowed scope: packages\/core/);
  assert.match(text, /Forbidden scope: apps\/extension/);
  assert.match(text, /worker\.complete/);
  assert.match(text, /worker\.fail/);
  assert.match(text, /worker\.await_human/);
  assert.match(text, /worker\.await_dependency/);
  assert.match(text, /<continuation-state>/);
  assert.match(text, /status: working \| complete \| blocked/);
  assert.doesNotMatch(text, /token|secret|websocket|click Retry|send `?continue`?|auto.?resume|schedule itself/i);
});
