import { readFileSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'

const SRC = join(import.meta.dirname, '..')

function sourceFiles(dir: string): string[] {
  return readdirSync(dir).flatMap((name) => {
    const path = join(dir, name)
    if (statSync(path).isDirectory()) return sourceFiles(path)
    if (!/\.(ts|tsx|astro)$/.test(name)) return []
    if (/\.test\.tsx?$/.test(name)) return []
    return [path]
  })
}

describe('session fixtures never reach a real user', () => {
  it('is imported by no shipped source file', () => {
    const offenders = sourceFiles(SRC).filter((path) =>
      readFileSync(path, 'utf8').includes('sessions-fixtures'),
    )
    expect(offenders).toEqual([])
  })
})
