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

import { contentLoader } from './ContentLoader.js';
import { questEngine } from './QuestEngine.js';
import { saveState } from './SaveState.js';
import { sageService } from './SageService.js';

async function bootstrapActiveQ001() {
  process.env.CONTENT_DIR = '../content';
  await contentLoader.load();
  saveState._state = {
    world_flags: [],
    progression: {
      unlocked_access: [],
      unlocked_vms: [],
      unlocked_docs: ['onboarding']
    },
    quests: {
      Q001: {
        state: 'active',
        started_at: '2026-04-25T12:00:00.000Z'
      }
    },
    tickets: {},
    mail: [],
    certifications: [],
    pressure: {},
    incidents: {},
    sage: {
      hint_counts: {}
    }
  };
  questEngine.initialize(saveState.get());
}

test('SageService returns intro context for active quest', async () => {
  await bootstrapActiveQ001();
  const result = sageService.reply('summary');
  assert.match(result.response, /onboarding doc/i);
  assert.ok(result.followUps.length > 0);
});

test('SageService advances through authored hints for active quest', async () => {
  await bootstrapActiveQ001();
  const first = sageService.reply('help');
  const second = sageService.reply('another hint');

  assert.match(first.response, /\.ssh folder/i);
  assert.match(second.response, /permissions matter/i);
});
