فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(holoo): add allowlisted read-only query boundary
Davood Mehraban committed
Nov 22, 2026 at 21:38 UTC
49a69ce74837c94b6e98b7d2f775f25ee2369f3b
2 files changed
+39
src/holoo-query-boundary.cjs
new
+16
@@ -0,0 +1,16 @@
1
+'use strict';
2
+const { evaluateHolooWrite } = require('./holoo-write-policy.cjs');
3
+// Explicit SQL boundary for future adapters. Never accepts arbitrary SQL from callers.
4
+const QUERIES = Object.freeze({
5
+ invoiceCount: 'SELECT COUNT_BIG(*) AS count FROM dbo.FACTURE',
6
+ lineCount: 'SELECT COUNT_BIG(*) AS count FROM dbo.FACTART',
7
+ documentCount: 'SELECT COUNT_BIG(*) AS count FROM dbo.SANAD'
8
+});
9
+async function executeHolooLabRead({ database, audit, queryId, executor } = {}) {
10
+ const decision = evaluateHolooWrite({ operation: 'read', database, audit });
11
+ if (!decision.allowed) throw new Error(decision.reason);
12
+ if (!Object.hasOwn(QUERIES, queryId)) throw new Error('Unapproved Holoo read query');
13
+ if (typeof executor !== 'function') throw new Error('Read executor is required');
14
+ return executor({ database, sql: QUERIES[queryId], readOnly: true });
15
+}
16
+module.exports = { executeHolooLabRead };
tests/holoo-query-boundary.test.mjs
new
+23
@@ -0,0 +1,23 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { createRequire } from 'node:module';
4
+const require = createRequire(import.meta.url);
5
+const { executeHolooLabRead } = require('../src/holoo-query-boundary.cjs');
6
+const database = 'HolooBackup_050808_LAB_20261110';
7
+const audit = { database, schemaVersion: 1, tables: ['FACTART','FACTURE','SANAD'].map(table => ({table,primaryKeys:1})), procedureConcurrencySignals: ['InsertInFacture','InsertInFactureCode'].map(name => ({name,allocatesNumberWithoutVisibleLock:true})), readOnlyAudit: true, complete: true, productionWriteGate: { status:'NO-GO',productionWritesAuthorized:false } };
8
+test('approved read calls executor with fixed SELECT only', async () => {
9
+ const calls=[];
10
+ const result=await executeHolooLabRead({database,audit,queryId:'invoiceCount',executor: async x => {calls.push(x);return 42;}});
11
+ assert.equal(result,42);
12
+ assert.deepEqual(calls,[{database,sql:'SELECT COUNT_BIG(*) AS count FROM dbo.FACTURE',readOnly:true}]);
13
+});
14
+test('arbitrary SQL cannot reach executor', async () => {
15
+ let calls=0;
16
+ for(const queryId of ['DELETE FROM dbo.FACTURE','invoiceCount; DROP TABLE dbo.FACTURE','__proto__',undefined]) await assert.rejects(executeHolooLabRead({database,audit,queryId,executor:async()=>{calls++;}}));
17
+ assert.equal(calls,0);
18
+});
19
+test('invalid audit or production target never reaches executor', async () => {
20
+ let calls=0;
21
+ for(const params of [{database:'Holoo1',audit},{database,audit:null},{database,audit:{...audit,productionWriteGate:{status:'GO',productionWritesAuthorized:true}}}]) await assert.rejects(executeHolooLabRead({...params,queryId:'invoiceCount',executor:async()=>{calls++;}}));
22
+ assert.equal(calls,0);
23
+});