import-boundary.test.ts
1 import assert from 'node:assert/strict' 2 import fs from 'node:fs' 3 import path from 'node:path' 4 import { describe, it } from 'node:test' 5 6 const repoRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '../../../..') 7 const srcRoot = path.join(repoRoot, 'src') 8 9 const ALLOWED_IMPORTERS = new Set([ 10 path.join(srcRoot, 'lib/server/chat-execution/chat-execution.ts'), 11 path.join(srcRoot, 'lib/server/execution-engine/chat-turn.ts'), 12 ]) 13 14 function walk(dir: string): string[] { 15 const results: string[] = [] 16 for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { 17 const fullPath = path.join(dir, entry.name) 18 if (entry.isDirectory()) { 19 results.push(...walk(fullPath)) 20 continue 21 } 22 if (!/\.(?:ts|tsx|js|mjs)$/.test(entry.name)) continue 23 if (entry.name.includes('.test.')) continue 24 results.push(fullPath) 25 } 26 return results 27 } 28 29 describe('executeSessionChatTurn import boundary', () => { 30 it('is only imported through the execution-engine chat-turn wrapper', () => { 31 const offenders: string[] = [] 32 const importPattern = /import\s*\{[^}]*\bexecuteSessionChatTurn\b[^}]*\}\s*from\s*['"][^'"]+['"]/m 33 34 for (const filePath of walk(srcRoot)) { 35 if (ALLOWED_IMPORTERS.has(filePath)) continue 36 const contents = fs.readFileSync(filePath, 'utf8') 37 if (importPattern.test(contents)) { 38 offenders.push(path.relative(repoRoot, filePath)) 39 } 40 } 41 42 assert.deepEqual(offenders, []) 43 }) 44 })