// tests/mockup-conformance-report.test.ts
//
// F62-a：audit:mockup-conformance --report 落盘的结构化 JSON 由纯函数 buildReport 构造，
// 供 handoff gate 校验（见 mockup-handoff-evidence.test.ts）。测纯函数，不碰 fs / Figma。
import { describe, it, expect } from 'vitest'
import { buildReport } from '../scripts/audit-mockup-conformance.mjs'

const TS = '2026-07-10T12:00:00.000Z'

describe('buildReport', () => {
  it('maps sub-audit results to {key, exitCode} and marks ok when all passed', () => {
    const report = buildReport('abc123', ['456:789'], [
      { key: 'integrity', code: 0 },
      { key: 'overlap', code: 0 },
    ], TS)
    expect(report.fileKey).toBe('abc123')
    expect(report.nodeIds).toEqual(['456:789'])
    expect(report.subAudits).toEqual([
      { key: 'integrity', exitCode: 0 },
      { key: 'overlap', exitCode: 0 },
    ])
    expect(report.timestamp).toBe(TS)
    expect(report.figmaLastModified).toBe(null)
    expect(report.ok).toBe(true)
  })

  it('marks ok=false when any sub-audit has a non-zero exit code', () => {
    const report = buildReport('abc123', [], [
      { key: 'integrity', code: 0 },
      { key: 'overlap', code: 1 },
    ], TS)
    expect(report.ok).toBe(false)
  })

  it('marks ok=false when a sub-audit errored (code 2 = could not run)', () => {
    const report = buildReport('abc123', [], [
      { key: 'integrity', code: 2 },
    ], TS)
    expect(report.ok).toBe(false)
  })
})
