/**
 * A8 regression: CommandRiskAnalyzer `in` operator bug
 * 'sudo_likely' in string was always false (checks String prototype).
 * Fixed to use string.includes('sudo').
 */

import { describe, it, expect } from 'bun:test'
import { CommandRiskAnalyzer } from '../../src/security/CommandRiskAnalyzer.js'

describe('A8: CommandRiskAnalyzer sudo detection', () => {
  const analyzer = new CommandRiskAnalyzer('/tmp/test-project')

  it('detects sudo in system modification commands', () => {
    const result = analyzer.analyze('sudo apt install vim')
    expect(result.flags).toContain('intent_sudo')
    expect(result.flags).not.toContain('system_command')
  })

  it('flags non-sudo system commands as system_command', () => {
    const result = analyzer.analyze('apt install vim')
    expect(result.flags).toContain('system_command')
  })

  it('detects sudo in standalone usage', () => {
    const result = analyzer.analyze('sudo ls /etc')
    expect(result.flags).toContain('intent_sudo')
  })

  it('does not falsely flag commands without sudo', () => {
    const result = analyzer.analyze('ls -la')
    expect(result.flags).not.toContain('intent_sudo')
  })
})
