import { describe, expect, it } from 'vitest'

import { buildFallbackReleaseManifest } from '../release-manifest'

describe('buildFallbackReleaseManifest', () => {
  it('carries the current Windows packaged-validation summary into the fallback release lane', () => {
    const manifest = buildFallbackReleaseManifest({
      downloadTargets: [
        {
          platformKey: 'windows',
          platform: 'Windows',
          subtitle: 'Primary shipping lane',
          configured: false,
          details: 'Current packaged validation is strongest on the Windows Unreal lane.',
        },
      ],
      publicDocsUrl: 'https://hypertwist.app/resources',
      releaseNotesUrl: 'https://hypertwist.app/changelog',
      correspondingSourceUrl: 'https://git.scriptoriumai.io/scriptoriumadmin/hypertwist',
      openSourceRepoUrl: 'https://git.scriptoriumai.io/scriptoriumadmin/hypertwist',
      supportEmail: 'hello@hypertwist.app',
    })

    expect(manifest.platforms[0]).toMatchObject({
      platform_key: 'windows',
      configured: false,
      validation_summary: {
        lane: 'Windows Unreal packaged validation',
        result: 'passed',
        smoke_map_count: 2,
      },
    })
  })

  it('keeps fallback release metadata while withholding raw download delivery authority', () => {
    const manifest = buildFallbackReleaseManifest({
      downloadTargets: [
        {
          platformKey: 'windows',
          platform: 'Windows',
          subtitle: 'Primary shipping lane',
          configured: true,
          details: 'Current packaged validation is strongest on the Windows Unreal lane.',
        },
      ],
      publicDocsUrl: 'https://hypertwist.app/resources',
      releaseNotesUrl: 'https://hypertwist.app/changelog',
      correspondingSourceUrl: 'https://git.scriptoriumai.io/scriptoriumadmin/hypertwist',
      openSourceRepoUrl: 'https://git.scriptoriumai.io/scriptoriumadmin/hypertwist',
      supportEmail: 'hello@hypertwist.app',
    })

    expect(manifest.platforms[0]).toMatchObject({
      platform_key: 'windows',
      configured: true,
      download_available: false,
      download_url: null,
    })
  })

  it('can keep protected viewer posture in fallback metadata without exposing download authority', () => {
    const manifest = buildFallbackReleaseManifest({
      downloadTargets: [
        {
          platformKey: 'windows',
          platform: 'Windows',
          subtitle: 'Primary shipping lane',
          configured: true,
          details: 'Current packaged validation is strongest on the Windows Unreal lane.',
        },
      ],
      publicDocsUrl: 'https://hypertwist.app/resources',
      releaseNotesUrl: 'https://hypertwist.app/changelog',
      correspondingSourceUrl: 'https://git.scriptoriumai.io/scriptoriumadmin/hypertwist',
      openSourceRepoUrl: 'https://git.scriptoriumai.io/scriptoriumadmin/hypertwist',
      supportEmail: 'operator@hypertwist.app',
      viewer: {
        authenticated: true,
        canDownload: true,
        plan: 'operator',
        role: 'operator',
        accessStatus: 'active',
      },
    })

    expect(manifest.viewer).toMatchObject({
      authenticated: true,
      canDownload: true,
      plan: 'operator',
      role: 'operator',
      accessStatus: 'active',
    })
    expect(manifest.platforms[0]).toMatchObject({
      platform_key: 'windows',
      configured: true,
      download_available: false,
      download_url: null,
    })
  })
})
