const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');

describe('scan command', () => {
  test('command file exists with correct name and description', () => {
    const p = path.join(__dirname, '..', 'commands', 'gsd', 'scan.md');
    assert.ok(fs.existsSync(p), 'commands/gsd/scan.md should exist');
    const content = fs.readFileSync(p, 'utf-8');
    assert.ok(content.includes('name: gsd:scan'), 'Command must have name: gsd:scan');
    assert.ok(content.includes('description:'), 'Command must have description frontmatter');
    assert.ok(content.includes('Rapid codebase assessment') || content.includes('lightweight alternative'),
      'Description should mention rapid/lightweight assessment');
  });

  test('workflow file exists', () => {
    const p = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'scan.md');
    assert.ok(fs.existsSync(p), 'get-shit-done/workflows/scan.md should exist');
  });

  test('workflow has focus-to-document mapping table', () => {
    const p = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'scan.md');
    const content = fs.readFileSync(p, 'utf-8');
    assert.ok(content.includes('Focus-to-Document Mapping') || content.includes('Focus | Documents'),
      'Workflow should contain a focus-to-document mapping table');
  });

  test('all 5 focus areas are documented', () => {
    const p = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'scan.md');
    const content = fs.readFileSync(p, 'utf-8');
    const focusAreas = ['tech', 'arch', 'quality', 'concerns', 'tech+arch'];
    for (const area of focusAreas) {
      assert.ok(content.includes(`\`${area}\``),
        `Workflow should document the "${area}" focus area`);
    }
  });

  test('overwrite prompt is mentioned', () => {
    const p = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'scan.md');
    const content = fs.readFileSync(p, 'utf-8');
    assert.ok(content.includes('Overwrite') || content.includes('overwrite'),
      'Workflow should mention overwrite prompt for existing documents');
  });

  test('workflow references gsd-codebase-mapper', () => {
    const p = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'scan.md');
    const content = fs.readFileSync(p, 'utf-8');
    assert.ok(content.includes('gsd-codebase-mapper'),
      'Workflow should reference the gsd-codebase-mapper agent');
  });
});
