Elffuss BraidHub

utopia-ia/elffuss-code public

main · 1.9 KiBRawPermalink
1// Los ficheros de texto del repo son texto para git: ninguno lleva un byte NUL
2// literal. Con uno dentro, git trata el fichero entero como binario: `git diff`
3// solo dice «Binary files differ» y `git grep -I` se lo salta, así que nada de lo
4// que cambia en él se ve al revisar ni al barrer el diff antes de publicar. Pasó
5// con md.js y arch.js (un centinela '\0' escrito tal cual); dentro de una cadena
6// se escribe '\u0000', que es lo mismo para JavaScript.
7//
8// node tests/texto-plano.mjs
9import { readdirSync, readFileSync, statSync } from 'node:fs';
10import { join, relative, extname } from 'node:path';
11import { fileURLToPath } from 'node:url';
12
13const RAIZ = fileURLToPath(new URL('..', import.meta.url));
14const TEXTO = new Set(['.js', '.mjs', '.cjs', '.css', '.html', '.json', '.md', '.py', '.sh', '.go', '.txt', '.svg', '.webmanifest', '.yml', '.yaml']);
15const FUERA = new Set(['node_modules', '.git']);
16
17let fallos = 0, vistos = 0;
18const ok = (n, c, e = '') => { console.log(`${c ? '✅' : '❌'} ${n}${e ? ' — ' + e : ''}`); if (!c) fallos++; };
19
20const conNul = [];
21function recorre(dir) {
22 for (const nombre of readdirSync(dir)) {
23 if (FUERA.has(nombre)) continue;
24 const ruta = join(dir, nombre);
25 const st = statSync(ruta, { throwIfNoEntry: false });
26 if (!st) continue;
27 if (st.isDirectory()) { recorre(ruta); continue; }
28 if (!TEXTO.has(extname(nombre).toLowerCase())) continue;
29 vistos++;
30 if (readFileSync(ruta).includes(0)) conNul.push(relative(RAIZ, ruta));
31 }
32}
33recorre(RAIZ);
34
35ok(`se revisan los ficheros de texto del repo (${vistos})`, vistos > 50, `${vistos} ficheros`);
36ok('ninguno lleva un byte NUL literal (git lo trataría como binario)', conNul.length === 0, conNul.join(', '));
37console.log(fallos ? `\n❌ ${fallos} FALLO(S)` : '\n✅ TEXTO PLANO: git ve todos los ficheros de texto como texto');
38process.exit(fallos ? 1 : 0);