import { execFileSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); function git(args) { return execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim(); } function isIgnored(file) { try { execFileSync('git', ['check-ignore', '--no-index', '-q', file], { cwd: root, stdio: 'ignore', }); return true; } catch (error) { if (error.status === 1) return false; throw error; } } function assert(condition, message) { if (!condition) throw new Error(message); } const trackedDatabases = git([ 'ls-files', '--', 'dev.db', 'dev.db-*', 'prisma/*.db', 'prisma/*.db-*', ]) .split('\n') .filter(Boolean); assert( trackedDatabases.length === 0, `Runtime SQLite files in supported locations must not be tracked; found: ${trackedDatabases.join(', ')}`, ); for (const file of [ 'dev.db', 'dev.db-wal', 'dev.db-shm', 'prisma/dev.db', 'prisma/dev.db-wal', 'prisma/dev.db-shm', ]) { assert(isIgnored(file), `Runtime SQLite file must be ignored: ${file}`); } assert( !isIgnored('test/fixtures/reference.db'), 'Intentional fixture must remain versionable', ); console.log('Backend repository hygiene verified');