Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
Apply additive privately tracked view-only SQL client, require TypeScript and six unit tests, then exercise actual adapter on synthetic real SQL Server
davoodmehraban89 committed
Oct 18, 2026 at 22:21 UTC
1cffcf8cca2e04d66acda8d523abb4e89e6cbd93
1 file changed
+48
-84
.github/workflows/v6-real-sql-adapter-synthetic-once.yml
+48
-84
@@ -28,47 +28,27 @@ jobs:
28
mkdir -p "$RUNNER_TEMP/tf-stage"
29
unzip -q "$f" -d "$RUNNER_TEMP/tf-stage"
30
echo "TF_ROOT=$RUNNER_TEMP/tf-stage" >> "$GITHUB_ENV"
31
+ gh api 'repos/davoodmehraban89/TreasuryFlow-Validation-Private/contents/qa/patches/v6-add-readonly-sqlserver-adapter.mjs?ref=1ee794c1cce62e64b97c32769e5b6aca0f2fa58c' --jq .content 2>/dev/null | base64 -d > "$RUNNER_TEMP/v6-private-sql-additive-patch.mjs"
32
+ test -s "$RUNNER_TEMP/v6-private-sql-additive-patch.mjs"
33
+ echo "TF_SQL_PATCH=$RUNNER_TEMP/v6-private-sql-additive-patch.mjs" >> "$GITHUB_ENV"
34
echo 'GATE_PASS_PINNED_V6_SOURCE_SHA256'
35
- name: Setup Node 22
36
uses: actions/setup-node@v4
37
with:
38
node-version: '22'
36
- - name: Install original locked private V6 adapter dependencies
39
+ - name: Apply guarded private read-only adapter implementation and test code
40
shell: bash
41
run: |
42
set -euo pipefail
43
cd "$TF_ROOT"
41
- npm ci --no-audit --no-fund > "$RUNNER_TEMP/private-npm-install.log" 2>&1
42
- node -e 'console.log("SQL_MSSQL_DEPENDENCY="+!!require.resolve("mssql"));console.log("SQL_TS_COMPILER="+!!require.resolve("typescript"));'
43
- cat > "$RUNNER_TEMP/private-path-inventory.mjs" <<'NODE'
44
- import fs from 'node:fs';
45
- import path from 'node:path';
46
- const root=process.env.TF_ROOT;
47
- const all=[];
48
- function walk(p,depth=0){
49
- if(depth>8||!fs.existsSync(p))return;
50
- for(const d of fs.readdirSync(p,{withFileTypes:true})){
51
- if(['node_modules','.next','release','.git'].includes(d.name))continue;
52
- const f=path.join(p,d.name);
53
- if(d.isDirectory())walk(f,depth+1);
54
- else if(/[.]tsx?$/.test(d.name)&&fs.statSync(f).size<150000)all.push(f);
55
- }
56
- }
57
- walk(path.join(root,'src'));
58
- const client=all.filter(f=>{
59
- const src=fs.readFileSync(f,'utf8');
60
- return src.includes('SqlServerAccountingAdapter')&&src.includes('testConnection')&&src.includes('inspectSchema');
61
- });
62
- const readonly=all.filter(f=>fs.readFileSync(f,'utf8').includes('prepareReadOnlySql'));
63
- const mayan=all.filter(f=>fs.readFileSync(f,'utf8').includes('MayanInterop'));
64
- console.log('SQL_ADAPTER_TESTABLE_IMPLEMENTATION_FOUND='+(client.length===1));
65
- console.log('SQL_READONLY_GUARD_SOURCE_FOUND='+Boolean(readonly.length));
66
- console.log('SQL_MAYAN_INTEROP_SOURCE_REFERENCED='+Boolean(mayan.length));
67
- if(client.length===1)fs.appendFileSync(process.env.GITHUB_ENV,'TF_SQL_CLIENT_SOURCE='+client[0]+'\n');
68
- if(readonly.length>0)fs.appendFileSync(process.env.GITHUB_ENV,'TF_SQL_GUARD_SOURCE='+readonly[0]+'\n');
69
- NODE
70
- node "$RUNNER_TEMP/private-path-inventory.mjs"
71
- echo 'GATE_PASS_V6_SQL_SOURCE_CAPABILITY_DIAGNOSIS'
44
+ node --check "$TF_SQL_PATCH" >/dev/null 2> "$RUNNER_TEMP/private-sql-patch-syntax.log" || { echo 'V6_PRIVATE_SQL_PATCH_SYNTAX_ERROR'; exit 1; }
45
+ node "$TF_SQL_PATCH" "$TF_ROOT" > "$RUNNER_TEMP/private-sql-patch-applied.log" 2>&1 || { echo 'V6_PRIVATE_SQL_PATCH_APPLY_FAILED'; exit 1; }
46
+ grep '^GATE_PASS_' "$RUNNER_TEMP/private-sql-patch-applied.log"
47
+ npm ci --no-audit --no-fund > "$RUNNER_TEMP/private-npm-install.log" 2>&1 || { echo 'PRIVATE_NPM_CI_FAILED'; exit 1; }
48
+ npx --no-install vitest run src/platform/integration/v6-readonly-mayan-sql-client.test.ts --reporter=dot > "$RUNNER_TEMP/private-v6-sql-unit.log" 2>&1 || { echo 'V6_SQL_ADAPTER_UNIT_TESTS_FAILED'; exit 1; }
49
+ echo 'GATE_PASS_V6_SQL_ADAPTER_UNIT_SECURITY_TESTS'
50
+ npm run typecheck > "$RUNNER_TEMP/private-v6-sql-typecheck.log" 2>&1 || { echo 'V6_SQL_ADAPTER_TYPESCRIPT_TYPECHECK_FAILED'; exit 1; }
51
+ echo 'GATE_PASS_V6_SQL_ADAPTER_TYPESCRIPT_TYPECHECK'
52
- name: Launch real SQL Server 2022 Developer with synthetic-only view-only login
53
shell: bash
54
run: |
@@ -115,71 +95,55 @@ jobs:
95
docker exec tf-synthetic-sql /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$sa" -C -b -Q "CREATE LOGIN [tf_synthetic_reader] WITH PASSWORD = N'$ro';" > "$RUNNER_TEMP/private-sql-login.log" 2>&1 || { echo 'SQL_LOGIN_SETUP_FAILED'; exit 1; }
96
docker exec tf-synthetic-sql /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$sa" -C -b -d TreasuryFlowSyntheticCI -Q "CREATE USER tf_synthetic_reader FOR LOGIN tf_synthetic_reader; GRANT SELECT ON OBJECT::dbo.vw_SyntheticTransfers TO tf_synthetic_reader;" > "$RUNNER_TEMP/private-sql-grants.log" 2>&1 || { echo 'SQL_VIEW_GRANT_FAILED'; exit 1; }
97
echo 'GATE_PASS_REAL_SQL2022_SYNTHETIC_VIEW_ONLY_PRINCIPAL'
118
- - name: Execute actual private 1.0.1 SQL Server adapter against live engine and verify write denial
98
+ - name: Execute new protected V6 SQL view-only adapter against real SQL Server 2022
99
shell: bash
100
run: |
101
set -euo pipefail
122
- test -n "${TF_SQL_CLIENT_SOURCE:-}" || { echo 'SQL_ADAPTER_TESTABLE_IMPLEMENTATION_UNAVAILABLE_IN_PRIVATE_V6_STAGE'; exit 1; }
123
- test -n "${TF_SQL_GUARD_SOURCE:-}" || { echo 'SQL_SQL_GUARD_SOURCE_UNAVAILABLE_IN_PRIVATE_V6_STAGE'; exit 1; }
124
- cat > "$TF_ROOT/temporary-v6-adapter-sql-smoke.cjs" <<'NODE'
125
- const fs=require('fs'),path=require('path'),assert=require('assert').strict;
126
- const ts=require('typescript');
127
- function importTS(relative){
128
- const file=path.join(process.cwd(),relative),raw=fs.readFileSync(file,'utf8');
129
- const compiled=ts.transpileModule(raw,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,esModuleInterop:true}}).outputText;
130
- const out=path.join(process.cwd(),'temporary-'+path.basename(relative)+'.cjs');
131
- fs.writeFileSync(out,compiled,'utf8');
132
- return require(out);
133
- }
102
+ cat > "$TF_ROOT/temporary-private-v6-actual-sql-smoke.cjs" <<'NODE'
103
+ const fs=require('fs'),path=require('path'),assert=require('node:assert/strict');
104
+ const ts=require('typescript'),sql=require('mssql');
105
+ const p=path.join(process.cwd(),'src/platform/integration/v6-readonly-mayan-sql-client.ts');
106
+ const compiled=ts.transpileModule(fs.readFileSync(p,'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,esModuleInterop:true}}).outputText;
107
+ const mod=path.join(process.cwd(),'temporary-private-v6-sql-driver.cjs');
108
+ fs.writeFileSync(mod,compiled);
109
+ const {V6SqlServerReadOnlyClient}=require(mod);
110
(async()=>{
135
- const {SqlServerAccountingAdapter}=importTS(process.env.TF_SQL_CLIENT_SOURCE);
136
- const {prepareReadOnlySql}=importTS(process.env.TF_SQL_GUARD_SOURCE);
137
- assert.equal(typeof SqlServerAccountingAdapter,'function');
138
- const x=new SqlServerAccountingAdapter({server:'127.0.0.1',database:'TreasuryFlowSyntheticCI',auth:'sql',user:'tf_synthetic_reader',password:process.env.TF_SYNTH_SQL_RO,encrypt:false,trustServerCertificate:true});
139
- const connected=await x.testConnection();
140
- assert.equal(connected.ok,true);
141
- console.log('GATE_PASS_PRIVATE_V6_ACTUAL_SQL_ADAPTER_CONNECT');
142
- const columns=await x.inspectSchema();
143
- assert(Array.isArray(columns));
144
- const known=columns.filter(x=>x.table_name==='vw_SyntheticTransfers');
145
- assert(known.length>=7);
146
- console.log('GATE_PASS_PRIVATE_V6_ACTUAL_SQL_ADAPTER_SCHEMA_METADATA');
147
- await assert.rejects(x.executeApprovedWrite('INSERT',{}),/approved write contract/);
148
- console.log('GATE_PASS_PRIVATE_V6_DENY_UNAPPROVED_WRITE_CONTRACT');
149
- const sql=require('mssql');
150
- const conf={server:'127.0.0.1',database:'TreasuryFlowSyntheticCI',user:'tf_synthetic_reader',password:process.env.TF_SYNTH_SQL_RO,options:{encrypt:false,trustServerCertificate:true},connectionTimeout:15000};
151
- const conn=await new sql.ConnectionPool(conf).connect();
111
+ assert.equal(typeof V6SqlServerReadOnlyClient,'function');
112
+ const user='tf_synthetic_reader',password=process.env.TF_SYNTH_SQL_RO,db='TreasuryFlowSyntheticCI';
113
+ const c=new V6SqlServerReadOnlyClient({server:'127.0.0.1',database:db,user,password,approvedViews:['dbo.vw_SyntheticTransfers'],localSyntheticLab:true});
114
+ assert.equal(await c.testConnection(),true);
115
+ console.log('GATE_PASS_REAL_SQL_V6_ADAPTER_CONNECT');
116
+ const schema=await c.inspectApprovedView('dbo.vw_SyntheticTransfers');
117
+ assert(schema.length>=7);
118
+ console.log('GATE_PASS_REAL_SQL_V6_APPROVED_VIEW_SCHEMA');
119
+ const rows=await c.readApprovedView('dbo.vw_SyntheticTransfers',2);
120
+ assert.equal(rows.length,2);
121
+ assert.equal(rows[0].Amount_IRR,'1250000');
122
+ assert.equal(rows[1].Amount_IRR,'3250000');
123
+ console.log('GATE_PASS_REAL_SQL_V6_VIEW_READ_AND_INTEGER_IRR');
124
+ await assert.rejects(c.readApprovedView('dbo.SyntheticTransfers',2));
125
+ await assert.rejects(c.readApprovedView('dbo.vw_SyntheticTransfers',101));
126
+ console.log('GATE_PASS_REAL_SQL_V6_VIEW_ALLOWLIST_AND_ROW_LIMIT');
127
+ const pool=await new sql.ConnectionPool({server:'127.0.0.1',database:db,user,password,options:{encrypt:false,trustServerCertificate:true}}).connect();
128
try{
153
- const query=prepareReadOnlySql('SELECT Row_ID,Amount_IRR,Client_Reference FROM dbo.vw_SyntheticTransfers ORDER BY Row_ID');
154
- const rows=await conn.request().query(query);
155
- assert.equal(rows.recordset.length,2);
156
- assert.equal(Number(rows.recordset[0].Amount_IRR),1250000);
157
- assert.equal(Number(rows.recordset[1].Amount_IRR),3250000);
158
- console.log('GATE_PASS_REAL_SQL_SERVER_V6_READ_ONLY_VIEW_QUERY_TWO_SYNTHETIC_ROWS');
159
- for(const forbidden of [
129
+ const ops=[
130
'UPDATE dbo.SyntheticTransfers SET Amount_IRR=1 WHERE Row_ID=1',
161
- 'INSERT dbo.SyntheticTransfers (Row_ID,Destination_IBAN,Beneficiary_Name,Amount_IRR,Client_Reference) VALUES (9,\'BAD\',N\'FAIL\',1,\'DENIED\')',
131
'DELETE FROM dbo.SyntheticTransfers WHERE Row_ID=1',
132
'DROP VIEW dbo.vw_SyntheticTransfers',
133
'SELECT COUNT(*) FROM dbo.SyntheticTransfers'
165
- ]){
166
- await assert.rejects(conn.request().query(forbidden));
167
- }
168
- console.log('GATE_PASS_REAL_SQL_SERVER_NO_TABLE_READ_AND_ALL_WRITE_DENIALS');
169
- for(const bad of ['DELETE FROM dbo.vw_SyntheticTransfers','SELECT 1; DELETE FROM dbo.vw_SyntheticTransfers','SELECT * INTO dbo.Hacked FROM dbo.vw_SyntheticTransfers']){
170
- assert.throws(()=>prepareReadOnlySql(bad));
171
- }
172
- console.log('GATE_PASS_V6_READ_ONLY_SQL_GUARD_NEGATIVE_CASES');
173
- }finally{await conn.close()}
174
- })().catch(e=>{console.error('PRIVATE_SQL_ADAPTER_FAILURE_CLASS='+String(e?.name||'OtherError').replace(/[^A-Za-z]/g,''));process.exitCode=1});
134
+ ];
135
+ for(const q of ops)await assert.rejects(pool.request().query(q));
136
+ console.log('GATE_PASS_REAL_SQL_V6_PRINCIPAL_DENIES_WRITE_AND_BASE_TABLE_READ');
137
+ }finally{await pool.close()}
138
+ })().catch(e=>{console.log('PRIVATE_SQL_REAL_ENGINE_FAILURE_CLASS='+String(e?.name||'OTHER').replace(/[^A-Za-z]/g,''));process.exitCode=1});
139
NODE
140
cd "$TF_ROOT"
177
- node temporary-v6-adapter-sql-smoke.cjs > "$RUNNER_TEMP/private-v6-sql-adapter-results.log" 2>&1 || {
178
- grep -E '^PRIVATE_SQL_ADAPTER_FAILURE_CLASS=' "$RUNNER_TEMP/private-v6-sql-adapter-results.log" || true
179
- echo 'REAL_SQL_SERVER_PRIVATE_V6_ADAPTER_GATE_FAILED'
141
+ node temporary-private-v6-actual-sql-smoke.cjs > "$RUNNER_TEMP/private-v6-real-sql-results.log" 2>&1 || {
142
+ grep '^PRIVATE_SQL_REAL_ENGINE_FAILURE_CLASS=' "$RUNNER_TEMP/private-v6-real-sql-results.log" || true
143
+ echo 'REAL_SQL_SERVER_V6_ADAPTER_INTEGRATION_FAILED'
144
exit 1
145
}
182
- grep '^GATE_PASS_' "$RUNNER_TEMP/private-v6-sql-adapter-results.log"
146
+ grep '^GATE_PASS_' "$RUNNER_TEMP/private-v6-real-sql-results.log"
147
- name: Constrain public disclosure
148
if: always()
149
shell: bash