/**
 * Tests for Setup Rules Generation
 *
 * @module cli/setup-rules.test
 */

import { describe, it, expect } from 'vitest';
import { generateRulesContent, getRulesFilePath } from './setup-rules.js';

// ============================================================================
// generateRulesContent
// ============================================================================

describe('generateRulesContent', () => {
  it('contains project name', () => {
    const content = generateRulesContent();
    expect(content).toContain('Nexus-Agents Integration');
  });

  it('contains MCP tools table', () => {
    const content = generateRulesContent();
    expect(content).toContain('orchestrate');
    expect(content).toContain('create_expert');
    expect(content).toContain('delegate_to_model');
    expect(content).toContain('list_experts');
    expect(content).toContain('list_workflows');
  });

  it('contains quick commands section', () => {
    const content = generateRulesContent();
    expect(content).toContain('nexus-agents orchestrate');
    expect(content).toContain('nexus-agents doctor');
    expect(content).toContain('nexus-agents config init');
  });

  it('contains usage examples', () => {
    const content = generateRulesContent();
    expect(content).toContain('Usage Examples');
    expect(content).toContain('code review');
    expect(content).toContain('security expert');
  });

  it('contains configuration section', () => {
    const content = generateRulesContent();
    expect(content).toContain('nexus-agents.yaml');
  });

  it('includes version in generated footer', () => {
    const content = generateRulesContent();
    expect(content).toContain('Generated by nexus-agents setup v');
  });

  it('is valid markdown', () => {
    const content = generateRulesContent();
    // Should have at least one heading
    expect(content).toMatch(/^# /m);
    // Should have table syntax
    expect(content).toContain('| ---- |');
  });
});

// ============================================================================
// getRulesFilePath
// ============================================================================

describe('getRulesFilePath', () => {
  it('returns path under .rules/', () => {
    const path = getRulesFilePath('/home/user/project');
    expect(path).toBe('/home/user/project/.rules/nexus-agents.md');
  });

  it('works with trailing slash', () => {
    const path = getRulesFilePath('/home/user/project/');
    expect(path).toContain('.rules/nexus-agents.md');
  });

  it('works with relative path', () => {
    const path = getRulesFilePath('.');
    expect(path).toContain('.rules/nexus-agents.md');
  });
});
