/**
 * C7 regression: Register 5 missing high-priority tools
 * Validates that BuiltInToolRegistrar registers fs.stat, cpp.build,
 * cpp.test, cpp.static.cppcheck, and debug.run stub tools.
 *
 * Uses source inspection (reading the source file as text).
 */

import { describe, it, expect } from 'bun:test'
import { readFileSync } from 'fs'
import { join } from 'path'

const source_path = join(import.meta.dir, '../../src/tools/BuiltInToolRegistrar.ts')
const source = readFileSync(source_path, 'utf-8')

describe('C7: Stub tool registrations', () => {
  const stub_tools = [
    { name: 'fs.stat', category: 'filesystem' },
    { name: 'cpp.build', category: 'build' },
    { name: 'cpp.test', category: 'test' },
    { name: 'cpp.static.cppcheck', category: 'static_analysis' },
    { name: 'debug.run', category: 'debug' },
  ]

  for (const tool of stub_tools) {
    it(`registers ${tool.name} tool`, () => {
      // Check that the tool name appears in a stub definition
      expect(source).toContain(`name: '${tool.name}'`)
      expect(source).toContain(`category: '${tool.category}'`)
    })
  }

  it('stub executors have not_implemented error type', () => {
    // Verify the stub executor returns not_implemented error
    expect(source).toContain("error_type: 'not_implemented'")
    expect(source).toContain("message: 'TODO: implement'")
  })

  it('stub executors return error type envelope', () => {
    expect(source).toContain("type: 'error'")
    expect(source).toContain("call_id: ''")
  })

  it('create_stub_definitions method exists', () => {
    expect(source).toContain('create_stub_definitions()')
  })

  it('create_stub_executor method exists', () => {
    expect(source).toContain('create_stub_executor(')
  })

  it('stub tools are registered via register_tool in register_all', () => {
    // Verify the stub registration loop exists in register_all
    expect(source).toContain('stub_definitions')
    expect(source).toContain('create_stub_executor(name)')
  })
})
