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

function sourceFiles(dir: string): string[] {
  return readdirSync(dir).flatMap((entry) => {
    const path = join(dir, entry);
    return statSync(path).isDirectory() ? sourceFiles(path) : path.endsWith('.ts') ? [path] : [];
  });
}

describe('reviews persistence boundary', () => {
  it('does not own other module tables', () => {
    const dir = new URL('..', import.meta.url);
    for (const file of sourceFiles(dir.pathname)) {
      if (!file.endsWith('.ts') || file.endsWith('boundary.test.ts')) continue;
      const source = readFileSync(file, 'utf8');
      expect(source).not.toMatch(
        /catalog_|inventory_|pricing_|shipping_|promotions_|cart_|users_addresses/,
      );
    }
  });
});
