/**
 * Regression test: ContextAssembler L6-L9 stub layers
 *
 * Verifies that L6-L9 layers are implemented as actual stub layer pushes,
 * not just TODO comments.
 */

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

const SOURCE_PATH = join(
  import.meta.dir,
  '..',
  '..',
  'src',
  'context',
  'ContextAssembler.ts'
)

const source = readFileSync(SOURCE_PATH, 'utf-8')

describe('ContextAssembler L6-L9 stub layers', () => {
  test('source has L6 evidence layer (not just TODO comment)', () => {
    // TODO(P3): L6 should be gone
    expect(source).not.toContain("TODO(P3): L6")
    // 'evidence' level should exist as a pushed layer
    expect(source).toContain("level: 'evidence'")
  })

  test('source has L7 conversation layer', () => {
    expect(source).not.toContain("TODO(P3): L7")
    expect(source).toContain("level: 'conversation'")
  })

  test('source has L8 tool_output layer', () => {
    expect(source).not.toContain("TODO(P3): L8")
    expect(source).toContain("level: 'tool_output'")
  })

  test('source has L9 user_override layer', () => {
    expect(source).not.toContain("TODO(P3): L9")
    expect(source).toContain("level: 'user_override'")
  })

  test('stub layers have priority values 6-9', () => {
    expect(source).toContain('priority: 6')
    expect(source).toContain('priority: 7')
    expect(source).toContain('priority: 8')
    expect(source).toContain('priority: 9')
  })

  test('L6-L9 layers have positive token_estimate (B26: populated stubs)', () => {
    // B26: L6-L9 now have structured placeholder content with token_estimate > 0
    // Verify by finding each layer's token_estimate line and checking it's not 0
    const layerLevels = ["evidence", "conversation", "tool_output", "user_override"]
    for (const level of layerLevels) {
      // Find the token_estimate value for this layer by finding it after the level marker
      const section = source.split(`level: '${level}'`)[1] || ''
      const tokenMatch = section.match(/token_estimate:\s*(\d+)/)
      expect(tokenMatch).not.toBeNull()
      expect(parseInt(tokenMatch![1], 10)).toBeGreaterThan(0)
    }
  })
})
