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

function sourceFiles(root: string): string[] {
  return readdirSync(root, { withFileTypes: true }).flatMap(entry => {
    const path = join(root, entry.name)
    if (entry.isDirectory()) return sourceFiles(path)
    return /\.(ts|vue)$/.test(entry.name) ? [path] : []
  })
}

describe('UI vendor boundary', () => {
  it('keeps PrimeVue and AG Grid imports inside the shared adapter', () => {
    const featureRoot = join(process.cwd(), 'src', 'features')
    const forbiddenImport = /(?:from|import\s*\()\s*["'](?:primevue|ag-grid)/
    const violations = sourceFiles(featureRoot).filter(path => forbiddenImport.test(readFileSync(path, 'utf8')))

    expect(violations).toEqual([])
  })
})
