سامانه صدور فاکتور و حسابداری
test: lock public QA remediation invariants
davoodmehraban89 committed
Oct 2, 2026 at 01:09 UTC
e0deb86b8233e76829e5c093b669de28e7307c45
1 file changed
+26
scripts/public-qa-regression-check.mjs
new
+26
@@ -0,0 +1,26 @@
1
+import fs from 'node:fs';
2
+import vm from 'node:vm';
3
+import {spawnSync} from 'node:child_process';
4
+import './build-pages.mjs';
5
+
6
+function must(condition,message){if(!condition)throw new Error('Public QA regression: '+message);}
7
+
8
+const money=fs.readFileSync('js/money-format.js','utf8');
9
+const sandbox={};
10
+vm.runInNewContext(money+'\n;globalThis.__parseFormattedNumber=parseFormattedNumber;',sandbox,{filename:'js/money-format.js'});
11
+for(const [input,expected] of [['۱۲٫۵',12.5],['۱٬۲۳۴٫۵۶',1234.56],['١٢٫٥',12.5],['12.5',12.5],['1,234.56',1234.56]]){
12
+ const actual=sandbox.__parseFormattedNumber(input);
13
+ must(Object.is(actual,expected),`parseFormattedNumber(${JSON.stringify(input)}) expected ${expected}, got ${actual}`);
14
+}
15
+
16
+const built=fs.readFileSync('_site/index.html','utf8');
17
+must(!fs.existsSync('_site/diag.html'),'diag.html must never be present in the deployable artifact');
18
+must(!/script-src[^;]*'unsafe-inline'/i.test(built),'deployable CSP must not allow unsafe-inline scripts');
19
+must(!/\son[a-z]+=/i.test(built),'deployable HTML must not contain inline event handlers');
20
+must(!/<script(?![^>]*\ssrc=)[^>]*>/i.test(built),'deployable HTML must not contain inline script blocks');
21
+for(const tag of [...built.matchAll(/<script[^>]+src="https:\/\/[^\"]+"[^>]*>/gi)].map(m=>m[0]))must(/integrity=/i.test(tag),'external scripts must carry SRI');
22
+const generatedCheck=spawnSync(process.execPath,['--check','_site/js/generated-event-handlers.js'],{encoding:'utf8'});
23
+must(generatedCheck.status===0,'generated event-handler bundle must parse: '+(generatedCheck.stderr||generatedCheck.stdout));
24
+const selfcheck=fs.readFileSync('js/selfcheck.js','utf8');
25
+must(/version:'1\.0'/.test(selfcheck)&&/\{version:'1\.0',run\}/.test(selfcheck),'FinoraHealth version must remain 1.0');
26
+console.log('Public QA regression invariants: PASS');