/**
 * Architecture review fixture E2E test — P7 gate
 * Test: ArchitectureDesigner assesses changes → emits impact → gate check.
 *
 * @module packages/runtime/test/e2e/architecture-review-fixture.test
 */

import { describe, it, expect } from 'bun:test'
import { ArchitectureDesigner } from '../../src/agents/architecture/ArchitectureDesigner.js'

describe('Architecture Review Gate (P7 gate)', () => {
  const arch = new ArchitectureDesigner()

  it('should identify affected components from file paths', () => {
    const impact = arch.assess_impact({
      description: 'Refactor storage layer',
      files: [
        'packages/contracts/src/ids.ts',
        'packages/runtime/src/storage/DatabaseManager.ts',
        'packages/workers/src/roles/ExecutorRole.ts'
      ]
    })

    expect(impact.affected_components).toContain('contracts')
    expect(impact.affected_components).toContain('runtime')
    expect(impact.affected_components).toContain('workers')
  })

  it('should flag risks for large changes', () => {
    const files = Array.from({ length: 15 }, (_, i) => `packages/runtime/src/module${i}.ts`)
    const impact = arch.assess_impact({
      description: 'Massive refactor',
      files
    })

    expect(impact.risks.length).toBeGreaterThan(0)
    expect(impact.requires_replan).toBe(true)
  })

  it('should require user confirmation for moderate-impact changes', () => {
    const impact = arch.assess_impact({
      description: 'Change event schema',
      files: ['packages/contracts/src/event.ts']
    })

    // Contract change should trigger elevated review
    expect(['requires_user_confirmation', 'reject_or_escalate']).toContain(impact.result)
  })

  it('should silent_continue for safe changes', () => {
    const impact = arch.assess_impact({
      description: 'Fix typo in comment',
      files: ['packages/runtime/src/utils/helpers.ts']
    })

    expect(impact.result).toBe('silent_continue')
  })
})
