// Explicit private local-development exceptions, not a general permission to track secrets. const localDevelopmentEnvironmentFiles = new Set(['.env', 'apps/stock/web-app/.env']); /** Refuse unexpected tracked environment files without printing contents or values. */ export function unexpectedTrackedEnvironmentFiles(paths: readonly string[]): string[] { return paths.filter(path => { if (path.startsWith('apps/wcag-ada/') || localDevelopmentEnvironmentFiles.has(path)) return false; const name = path.split('/').at(-1) ?? ''; return ( (name === '.env' || name.startsWith('.env.')) && name !== '.env.example' && !name.endsWith('.example') ); }); } if (import.meta.main) { const result = Bun.spawnSync(['git', 'ls-files', '-z']); if (result.exitCode !== 0) throw new Error('Cannot inspect tracked files for the secret audit'); const files = unexpectedTrackedEnvironmentFiles( new TextDecoder().decode(result.stdout).split('\0') ); if (files.length) { process.stderr.write(`Unexpected tracked environment files: ${files.join(', ')}\n`); process.exitCode = 1; } else { process.stdout.write( 'Tracked environment-file audit passed (two local-development exceptions; WCAG excluded).\n' ); } }