سامانه صدور فاکتور و حسابداری

test: classify function drift by raw body hash, whitespace candidate and security metadata

davoodmehraban89 committed Oct 16, 2026 at 14:07 UTC 252423669b95a117f72e2ab770963435eaad36b2
1 file changed +23
scripts/phase1a-classify-function-drift.mjs new
+23
@@ -0,0 +1,23 @@
1 +#!/usr/bin/env node
2 +// Additional, non-authoritative analysis of raw pg_proc.prosrc. Do not mistake
3 +// whitespace-stripped hashes for a proof of SQL semantic equivalence.
4 +import fs from 'node:fs';
5 +const prod=JSON.parse(fs.readFileSync(process.argv[2],'utf8')).functions;
6 +const raw=JSON.parse(fs.readFileSync(process.argv[3],'utf8'));
7 +const local=Array.isArray(raw)?raw:raw.functions;
8 +const byKey=new Map(local.map(x=>[x.key,x]));
9 +const classes={exact:[],whitespaceOnlyCandidate:[],bodyChanged:[],metadataChanged:[],missing:[]};
10 +for(const p of prod){
11 + const l=byKey.get(p.key);
12 + if(!l){classes.missing.push(p.key);continue}
13 + const meta=['config','secdef','volatile','arguments','return'].filter(x=>JSON.stringify(p[x])!==JSON.stringify(l[x]));
14 + if(meta.length){classes.metadataChanged.push({key:p.key,attributes:meta});continue}
15 + if(p.exact===l.exact){classes.exact.push(p.key);continue}
16 + if(p.compact===l.compact){classes.whitespaceOnlyCandidate.push(p.key);continue}
17 + classes.bodyChanged.push(p.key);
18 +}
19 +const localOnly=local.filter(x=>!prod.some(p=>p.key===x.key)).map(x=>x.key);
20 +const result={counts:{production:prod.length,local:local.length,exact:classes.exact.length,whitespaceOnlyCandidate:classes.whitespaceOnlyCandidate.length,bodyChanged:classes.bodyChanged.length,metadataChanged:classes.metadataChanged.length,missing:classes.missing.length,localOnly:localOnly.length},findings:{whitespaceOnlyCandidate:classes.whitespaceOnlyCandidate,bodyChanged:classes.bodyChanged,metadataChanged:classes.metadataChanged,productionOnly:classes.missing,repositoryOnly:localOnly},warning:'Whitespace removal can conceal differences inside SQL string literals. Candidate means needs contextual review, not parity proven.'};
21 +fs.writeFileSync('phase1a-function-classification.json',JSON.stringify(result,null,2)+'\n');
22 +console.log(JSON.stringify(result,null,2));
23 +if(classes.bodyChanged.length||classes.metadataChanged.length||classes.missing.length||localOnly.length)process.exitCode=1;