/**
 * A6 regression: TaskAttempt failure_signature column mapping
 * Bug: guard checked patch.failure_signature but wrote failure_summary column.
 * Fix: correctly maps failure_signature AND adds separate failure_summary handling.
 */

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

describe('A6: TaskAttempt column mapping', () => {
  const src = readFileSync(
    join(import.meta.dir, '..', '..', 'src', 'storage', 'repositories', 'TaskAttemptRepository.ts'),
    'utf-8'
  )

  it('maps failure_signature guard to failure_signature column', () => {
    const sig_block = src.match(/patch\.failure_signature !== undefined[^}]+}/s)
    expect(sig_block).not.toBeNull()
    expect(sig_block![0]).toContain("failure_signature = ?")
    expect(sig_block![0]).toContain('patch.failure_signature')
  })

  it('has separate failure_summary handling block', () => {
    const summary_block = src.match(/patch\.failure_summary !== undefined[^}]+}/s)
    expect(summary_block).not.toBeNull()
    expect(summary_block![0]).toContain("failure_summary = ?")
    expect(summary_block![0]).toContain('patch.failure_summary')
  })
})
