فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix/phase-a-pack4-stock-scope-20261101
a02/strict-export-preflight-20261018
audit/a01-readonly-invoice-metadata-20261101
ci/a06-require-trusted-issuer-for-release
ci/main-postmerge-phase-a-validation-20261020
ci/phase-a-controlled-public-release
design/issue-5-commercial-corrections-adr
docs/a01-a02-a05-oct23-verified-evidence
docs/a01-cheque-endorsement-evidence-20261022
docs/a01-cheque-event-date-evidence-20261021
docs/a01-explicit-refund-reason-evidence-20261021
docs/a01-refund-auth-status-20261020
docs/a01-refund-trace-evidence-20261020
docs/a02-102-evidence-20261018
docs/a02-pr104-evidence-20261018
docs/a02-pr106-evidence-20261019
docs/a02-pr108-ten-tests-20261019
docs/a02-private-sql-backup-evidence-20261111
docs/a03-merge-status-sync-20261020
docs/a04-software-gate-acceptance-20261020
docs/feature-matrix-20261014
docs/finora-master-execution-playbook
docs/four-phase-execution-20261014
docs/four-phase-roadmap-20261014
docs/holoo-lab-stabilization-phase1-20261111
docs/holoo-runtime-schema-audit-20261111
docs/ops-142-governance-5-1-3-20261030
docs/phase-a-a01-a02-a06-a08-verified-evidence-20261023
docs/phase-a-a01-a05-a06-evidence-20261023
docs/phase-a-independent-acceptance-evidence
docs/phase-a-pr110-evidence-20261019
docs/project-status-phase-a-20261014
feat/a01-referenced-return-corrections
feat/a01-referenced-returns-on-main
feat/a02-atomic-opening-ledger-preflight
feat/a02-holoo-compatibility-preflight
feat/a02-holoo-declared-control-totals
feat/a02-holoo-explicit-csv-gate
feat/a02-holoo-safe-zip-intake-offline-webview2-20261030
feat/a02-offline-sql-server-provisioning-20261030
feat/a02-opening-balance-dry-run
feat/a02-opening-ledger-admin-ui
feat/a02-opt-in-isolated-sql-restore-executor-20261030
feat/a02-private-holoo-zip-staging-20261030
feat/a02-safe-isolated-restore-plan-20261030
feat/a02-sql-backup-header-verifyonly-20261030
feat/a03-audit-schema-atomic-events
feat/a03-complete-manual-journal-audit
feat/a05-cheque-treasury-reconciliation
feat/a06-signed-offline-license-activation
feat/a08-synthetic-performance-baseline
feat/phase-a-accounting-benchmark-return-preview
feat/phase-a-ledger-settlement-diagnostics
feature/v2-reconciliation-20261013
fix/a01-atomic-confirm-ui-one-shot-20261031
fix/a01-cheque-clearance-explicit-account-20261023
fix/a01-cheque-contractual-due-date-validity-20261023
fix/a01-cheque-endorsement-counterparty-20261022
fix/a01-cheque-event-date-open-period-20261021
fix/a01-cumulative-return-amount-cap
fix/a01-explicit-refund-reason-approval-20261021
fix/a01-manager-authorized-customer-refunds-20261020
fix/a01-no-implicit-refund
fix/a01-one-shot-confirm-on-atomic-import-20261031
fix/a01-refund-and-overcollection-net-cash
fix/a01-refund-correction-trace-20261020
fix/a02-atomic-excel-master-merge-20261031
fix/a02-canonical-mapping-contract-20261018
fix/a02-disable-destructive-excel-replace-20261031
fix/a02-holoo-invoice-line-coverage-20261023
fix/a02-holoo-preflight-required-invoice-lines-20261023
fix/a02-mapping-contract-20261018
fix/a02-opening-preflight-unbalanced-report
fix/a02-orphan-mapping-20261018
fix/a02-private-excel-import-session-20261031
fix/a02-strict-export-input-20261019
fix/a03-append-only-full-backup-import
fix/a03-append-only-write-guard
fix/a03-block-transaction-clear-append-only-20261016
fix/a03-chain-validation-20261020
fix/a03-company-scoped-audit-data-access
fix/a03-deny-direct-audit-write-20261019
fix/a03-escaped-expense-list-20261031
fix/a03-escaped-financial-record-ids-20261031
fix/a03-financial-ledger-actions-and-print-20261031
fix/a04-backup-checksum-preflight
fix/a04-company-audit-replay-stable-compare
fix/a04-company-backup-source-isolation-20261020
fix/a04-full-restore-posted-financial-integrity
fix/a04-reject-mixed-company-backup-20261019
fix/a04-replace-immutable-posted-ledger
fix/a04-restore-financial-journal-references
fix/a04-service-source-company-boundary-20261020
fix/a05-block-inactive-treasury-settlements
fix/a05-cheque-cash-evidence-reconciliation-20261023
fix/a05-cheque-ledger-and-bank-reconciliation-20261023
fix/a05-fiscal-close-invariant-gates
fix/a06-backup-restore-user-privileges
fix/a06-license-user-company-quota-20261023
fix/a06-malformed-trial-state-fail-closed
fix/a06-offline-clock-fail-closed-20261019
fix/a07-indexeddb-blocked-startup
fix/a07-offline-bundled-assets
fix/a07-version-and-startup-banner
fix/issue-7-company-backup-isolation
fix/p0-deterministic-fractional-invoice-money-20261031
fix/p0-fractional-quantity-input-20261031
fix/p0-fractional-quantity-integrated-20261031
fix/p0-invoice-posting-invariants-20261031
fix/p0-legacy-stock-and-product-inputs-20261031
fix/p0-reports-immutable-cogs-20261101
fix/p0-verified-financial-percent-20261031
fix/p0-zero-discount-report-revenue-20261101
fix/phase-a-backup-app-version
fix/phase-a-backup-integrity-checksum
fix/phase-a-backup-record-id-validation-20261014
fix/phase-a-backup-version-validation-20261014
fix/phase-a-closure-pack3-20261101
fix/phase-a-entitlement-payload-validation
fix/phase-a-gate-exact-evidence-20261019
fix/phase-a-pack4-stock-scope-20261101
fix/phase-a-pack5-integrated-evidence-20261101
fix/phase-a-pack6-atomic-legacy-20261101
fix/phase-a-restore-envelope-and-rollback
fix/phase-a-settings-admin-gate
fix/print-browser-header-footer-20261014
fix/q01-expense-security-probe-exact-option-20261031
fix/q01-financial-grid-labels-20261031
fix/q01-form-label-association-20261031
fix/q01-native-evidence-integrity-20261030
fix/q01-number-input-persian-decimal-20261031
fix/q01-responsive-dashboard-and-cheque-table-20261031
fix/q01-safe-ui-action-audit-coverage-20261031
fix/q01-visible-desktop-sidebar-and-safe-confirm-20261030
fix/roadmap-metadata-sync-20261014
gate/a03-audit-metadata-validation-20261019
integration/a02-windows-holoo-setup-candidate-20261030
license-server
main
perf/a07-lazy-load-excel
perf/a08-cheque-reconciliation-account-index-20261023
perf/a08-paginated-reports-20261101
phase1-restore-hardening
planning/holoo-execution-20261013
planning/roadmap-project-management-20261014
qa/native-click-coverage-audit-20261030
release/v2.0.0
test/a01-native-endorsement-mandatory-20261023
test/a01-native-purchase-return-guardrails
test/a01-native-sale-return-financial-guardrails
test/a01-safe-integer-boundary-20261019
test/a02-native-opening-dry-run-rejections
test/a02-native-positive-opening-ledger
test/a04-native-corrupt-fbackup-20261016
test/a04-native-encrypted-company-backup
test/a04-native-encrypted-company-backup-main
test/a04-native-late-transaction-rollback
test/a04-native-windows-backup-recovery
test/a04-real-edge-v6-v7-migration
test/a04-real-native-interrupted-restore
test/a05-native-draft-ledger-and-repeat-close-20261016
test/a05-native-fiscal-close-guardrails
test/a07-native-multipage-print-engine
test/a07-native-origin-provenance
test/a07-native-webview2-offline-routes
test/a07-windows-offline-startup-smoke
test/a08-installed-webview2-60k-baseline
test/a08-native-webview2-heap-metrics
test/a08-windows-synthetic-performance-baseline
test/github-write-access-20261009
test/native-win-ui-routes-after-finance-backup
test/phase-a-combined-a01-a05-a08-final-evidence
test/phase-a-combined-native-acceptance-matrix
test/phase-a-ledger-invariants-20261014
test/phase-a-native-all-routes-on-merged-lab
test/phase-a-native-encrypted-backup
test/phase-a-native-finance-backup-matrix
test/phase-a-native-ui-and-backup-smoke
test/phase-a-windows-native-installer-lab
work/a08-dispatch-activation-20261123
work/a08-memory-stability-20261123
work/finance-curated-20261123
| 1 | import test from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import fs from 'node:fs'; |
| 4 | import os from 'node:os'; |
| 5 | import { createRequire } from 'node:module'; |
| 6 | import { execFileSync } from 'node:child_process'; |
| 7 | import path from 'node:path'; |
| 8 | import { fileURLToPath } from 'node:url'; |
| 9 | |
| 10 | const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); |
| 11 | const folder = path.join(root, 'src', 'views'); |
| 12 | const viewFiles = fs.readdirSync(folder).filter(n => n.endsWith('.js')); |
| 13 | const views = new Map(viewFiles.map(filename => [ |
| 14 | path.basename(filename, '.js'), |
| 15 | fs.readFileSync(path.join(folder, filename), 'utf8') |
| 16 | ])); |
| 17 | |
| 18 | test('Q01: every named inline view handler has an actual declared view method', () => { |
| 19 | const missing = []; |
| 20 | const refs = []; |
| 21 | for (const [sourceName, source] of views) { |
| 22 | // Find only declarations in the HTML/template markup, not arbitrary test |
| 23 | // or controller calls that do not become user-facing controls. |
| 24 | const actions = [...source.matchAll(/on(?:click|change|input|submit|mousedown|blur|focus|keyup|keydown)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)]; |
| 25 | for (const action of actions) { |
| 26 | const handler = (action[1] || action[2] || '').replace(/\\(["'])/g, '$1'); |
| 27 | for (const call of handler.matchAll(/(?:window\.)?([A-Za-z_$][\w$]*(?:View|Modal))\.([A-Za-z_$][\w$]*)\s*\(/g)) { |
| 28 | const viewName = call[1], method = call[2]; |
| 29 | refs.push({sourceName, viewName, method}); |
| 30 | const src = views.get(viewName); |
| 31 | if (!src) { |
| 32 | missing.push({sourceName, viewName, method, reason:'source-not-found'}); |
| 33 | continue; |
| 34 | } |
| 35 | const declaration = new RegExp('^\\s*(?:async\\s+)?' + method + '\\s*\\(', 'm'); |
| 36 | if (!declaration.test(src)) missing.push({sourceName, viewName, method, reason:'method-not-declared'}); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | assert.ok(viewFiles.length >= 10, 'unexpectedly few view files in UI inventory'); |
| 41 | assert.ok(refs.length >= 80, 'inline view events not sufficiently inventoried'); |
| 42 | assert.deepEqual(missing, [], 'declared on* handlers must resolve to real view methods'); |
| 43 | }); |
| 44 | |
| 45 | test('Q01: the actual sidebar has one entry for each registered route', () => { |
| 46 | const shell = fs.readFileSync(path.join(root, 'index.html'), 'utf8'); |
| 47 | const main = fs.readFileSync(path.join(root, 'src', 'main.js'), 'utf8'); |
| 48 | const sidebar = [...shell.matchAll(/data-page="([a-z]+)"/g)].map(x=>x[1]); |
| 49 | const registered = [...main.matchAll(/\{ name: '([a-z]+)',\s*title:/g)].map(x=>x[1]); |
| 50 | assert.equal(new Set(sidebar).size, sidebar.length, 'sidebar has duplicated navigation controls'); |
| 51 | assert.equal(new Set(registered).size, registered.length, 'router has duplicate route definitions'); |
| 52 | assert.equal(sidebar.length, 10, 'navigation coverage baseline changed; update native click audit'); |
| 53 | assert.deepEqual(sidebar.sort(), registered.sort(), 'sidebar has missing, orphan or dead routes'); |
| 54 | }); |
| 55 | |
| 56 | test('Q01: the native UI coverage runner must report unclicked controls explicitly', () => { |
| 57 | const source = fs.readFileSync(path.join(root, 'tests', 'windows-vm-ui-interaction-audit-browser.js'), 'utf8'); |
| 58 | for (const required of [ |
| 59 | 'routesVisited','safeClickCount','not-clicked', |
| 60 | 'financialActionsNotBulkClicked:true','everyActionVerified:false', |
| 61 | 'accessibilityNameGaps','missing-function' |
| 62 | ]) { |
| 63 | assert.ok(source.includes(required), 'coverage reporter missing mandatory field: '+required); |
| 64 | } |
| 65 | assert.ok(!source.includes('localStorage.clear()') && !source.includes('wipeAll('), |
| 66 | 'interaction audit must never clear the database in the installed VM'); |
| 67 | }); |
| 68 | |
| 69 | test('Q01: menu controls remain keyboard-reachable with synchronized screen-reader state', () => { |
| 70 | const shell = fs.readFileSync(path.join(root, 'index.html'), 'utf8'); |
| 71 | const main = fs.readFileSync(path.join(root, 'src','main.js'), 'utf8'); |
| 72 | const router = fs.readFileSync(path.join(root, 'src','core','Router.js'), 'utf8'); |
| 73 | const styles = fs.readFileSync(path.join(root, 'src','styles','main.css'), 'utf8'); |
| 74 | const navLinks = [...shell.matchAll(/<a href="#([a-z]+)" data-page="([a-z]+)"/g)]; |
| 75 | assert.equal(navLinks.length, 10); |
| 76 | for(const match of navLinks) assert.equal(match[1], match[2]); |
| 77 | assert.match(shell, /id="sidebarToggleBtn"[^>]*aria-label="[^"]+"[^>]*aria-expanded="true"[^>]*aria-controls="sidebarMenu"/); |
| 78 | assert.match(main, /localStorage\.setItem\(SIDEBAR_COLLAPSED_KEY,/); |
| 79 | assert.match(main, /aria-expanded/); |
| 80 | assert.match(router, /aria-current/); |
| 81 | assert.match(styles, /:focus-visible/); |
| 82 | const desktopToggle = styles.match(/\.hamburger\s*\{([^}]*)\}/)?.[1]; |
| 83 | assert.ok(desktopToggle, 'desktop sidebar toggle styles not found'); |
| 84 | assert.match(desktopToggle, /display:\s*inline-flex\s*;/, |
| 85 | 'the sidebar toggle must be visible/focusable on desktop as well as mobile'); |
| 86 | assert.doesNotMatch(desktopToggle, /display:\s*none\s*;/); |
| 87 | const nativeAudit = fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 88 | assert.match(nativeAudit, /Desktop sidebar toggle cannot receive keyboard focus/); |
| 89 | }); |
| 90 | |
| 91 | test('Q01: shared dialogs have ARIA naming, keyboard dismissal and focus restoration contracts', () => { |
| 92 | const code = fs.readFileSync(path.join(root, 'src','core','Modal.js'),'utf8'); |
| 93 | assert.match(code, /setAttribute\('role', 'dialog'\)/); |
| 94 | assert.match(code, /setAttribute\('aria-modal', 'true'\)/); |
| 95 | assert.match(code, /setAttribute\('aria-labelledby', titleId\)/); |
| 96 | assert.match(code, /event\.key === 'Escape'/); |
| 97 | assert.match(code, /event\.key !== 'Tab'/); |
| 98 | assert.match(code, /previousFocus\.focus/); |
| 99 | assert.match(code, /const focusables = this\._focusable\(modal\.card\)/, |
| 100 | 'initial focus must skip hidden financial inputs'); |
| 101 | assert.match(code, /focusables\.find\(el => el\.matches\('input, select, textarea'\)\)/); |
| 102 | assert.match(code, /\[data-confirm-message\]'\)\.textContent = String\(message \?\? ''\)/, |
| 103 | 'untrusted confirmation messages must be assigned as text, not HTML'); |
| 104 | assert.doesNotMatch(code, /\$\{message\}<\/p>/, |
| 105 | 'financial confirmation message must never be interpolated into innerHTML'); |
| 106 | assert.match(code, /cancelButton\.textContent = String\(cancelText \?\? ''\)/); |
| 107 | assert.match(code, /confirmButton\.textContent = String\(confirmText \?\? ''\)/); |
| 108 | assert.doesNotMatch(code, /\$\{(?:cancelText|confirmText)\}<\/button>/, |
| 109 | 'confirmation button labels must never become executable markup'); |
| 110 | assert.match(code, /addEventListener\('keydown'/); |
| 111 | assert.match(code, /removeEventListener\('keydown'/); |
| 112 | }); |
| 113 | |
| 114 | test('A01: financial confirm never executes twice after Confirm/Cancel or while hidden', () => { |
| 115 | const modal=fs.readFileSync(path.join(root,'src','core','Modal.js'),'utf8'); |
| 116 | const native=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 117 | const runner=fs.readFileSync(path.join(root,'tests','windows-vm-installed-tauri-cdp.cjs'),'utf8'); |
| 118 | assert.ok(modal.includes('let settled = false')); |
| 119 | assert.ok(modal.includes('this.stack[this.stack.length - 1] === modal')); |
| 120 | assert.equal(modal.split('if (settled || !isActive()) return;').length-1, 2); |
| 121 | for(const token of ['confirmClick.click();','staleConfirm?.click()', |
| 122 | "hiddenParent?.querySelector('[data-action=\"confirm\"]')?.click()", |
| 123 | 'staleFinancialConfirmIgnored:true']) { |
| 124 | assert.ok(native.includes(token),'missing one-shot UI probe: '+token); |
| 125 | } |
| 126 | assert.ok(runner.includes('modalKeyboard.staleFinancialConfirmIgnored')); |
| 127 | }); |
| 128 | |
| 129 | test('Q01: native CDP diagnostics preserve the failing audit action and exception stack', () => { |
| 130 | const cdp=fs.readFileSync(path.join(root,'tests','windows-vm-installed-tauri-cdp.cjs'),'utf8'); |
| 131 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 132 | assert.match(cdp,/exception\.description/); |
| 133 | assert.match(cdp,/detail\.stackTrace\?\.callFrames/); |
| 134 | assert.match(cdp,/window\.__Q01_AUDIT_STAGE/); |
| 135 | for(const token of ['safe-action:','confirm-cancel:','open-modal:','audit-completed']) { |
| 136 | assert.ok(audit.includes(token),'native UI audit missing stage marker '+token); |
| 137 | } |
| 138 | }); |
| 139 | |
| 140 | test('Q01: repeated WebView2 audit evaluation avoids generic global lexical names', () => { |
| 141 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 142 | assert.match(audit,/const q01TextOnlyConfirmCard_20261031=/); |
| 143 | assert.doesNotMatch(audit,/const safeConfirm\s*=/); |
| 144 | assert.ok(audit.includes('one long-lived WebView2 realm')); |
| 145 | }); |
| 146 | |
| 147 | test('Q01: dashboard and cheque tables remain usable in the installed narrow content pane', () => { |
| 148 | const styles=fs.readFileSync(path.join(root,'src','styles','main.css'),'utf8'); |
| 149 | const cheques=fs.readFileSync(path.join(root,'src','views','ChequesView.js'),'utf8'); |
| 150 | const native=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 151 | assert.match(styles,/\.table-wrap\s*\{[^}]*overflow-x:\s*auto/s); |
| 152 | assert.match(styles,/@media\s*\(max-width:\s*1200px\)/); |
| 153 | assert.match(styles,/\.dash-grid-main,\s*\.dash-grid-main\s*>\s*\*/); |
| 154 | assert.match(styles,/\.table-wrap\[tabindex="0"\]:focus-visible/); |
| 155 | assert.match(cheques,/class="table-wrap cheques-table-scroll" tabindex="0" role="region"/); |
| 156 | assert.match(cheques,/aria-label="جدول چکها/); |
| 157 | assert.match(native,/responsive-horizontal-overflow/); |
| 158 | assert.match(native,/cheque-table-horizontal-scroll-accessibility/); |
| 159 | }); |
| 160 | |
| 161 | test('Q01: deferred safe actions survive live label changes and slow tab rendering', () => { |
| 162 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 163 | assert.match(audit,/for\(let attempt=0;attempt<12 && !el;attempt\+\+\)/); |
| 164 | assert.match(audit,/handler\(x\)===action\.handler && x\.tagName\.toLowerCase\(\)===action\.tag/); |
| 165 | assert.doesNotMatch(audit,/handler\(x\)===action\.handler && name\(x\)===action\.label/); |
| 166 | }); |
| 167 | |
| 168 | test('Q01: native UI audit opens and cancels safe nested editors and restores invoice draft rows', () => { |
| 169 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 170 | for(const token of ['_printInvoice','InvoicePrint\\._preview','nested-safe-action-did-not-open-dialog', |
| 171 | 'nested-modal-cancel-did-not-restore-parent','invoice-draft-add-row-failed', |
| 172 | 'invoice-draft-row-count-not-restored','invoice-last-row-removal-not-blocked', |
| 173 | 'unsaved-contact-tag-not-added','beforeModalDepth','afterModalDepth']) { |
| 174 | assert.ok(audit.includes(token),'native nested-modal audit missing: '+token); |
| 175 | } |
| 176 | assert.doesNotMatch(audit,/safeOpen\s*=.*_printReport|safeOpen\s*=.*_printKardex|safeOpen\s*=.*_printLedger/); |
| 177 | }); |
| 178 | |
| 179 | test('Q01: native audit verifies safe routes, filters, edit previews and cancel-only destructive prompts', () => { |
| 180 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 181 | for(const token of ['safeNavigate','safeFilter','safeOpen','safeConfirmAction', |
| 182 | 'confirm-request','confirm-cancel','confirmation-prompt-missing', |
| 183 | 'cancel-mutated-persistent-data','FINORA.Storage.getAll(store)', |
| 184 | 'safe-action-vanished','editInvoice','editProduct','editContact', |
| 185 | 'editCheque','runFinancialDiagnostics','checkHolooMigrationReadiness']) { |
| 186 | assert.ok(audit.includes(token),'native action audit missing coverage contract: '+token); |
| 187 | } |
| 188 | assert.match(audit,/const confirmStores=\['users','companies','contacts','products'/); |
| 189 | assert.match(audit,/category !== 'open' && category !== 'confirm-request'/); |
| 190 | assert.match(audit,/_togglePreInvoice\|_setStockFilter\|_clearFilters/); |
| 191 | }); |
| 192 | |
| 193 | test('Q01: form labels are only associated within unambiguous modal groups', () => { |
| 194 | const modal=fs.readFileSync(path.join(root,'src','core','Modal.js'),'utf8'); |
| 195 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 196 | assert.match(modal, /_associateFormLabels\(card\)/); |
| 197 | assert.match(modal, /fields\.length !== 1/); |
| 198 | assert.match(modal, /labels\.length !== 1/); |
| 199 | assert.match(modal, /field\.labels\?\.length/); |
| 200 | assert.match(audit, /Modal form labels were missing, ambiguous, or overwrote explicit names/); |
| 201 | assert.match(audit, /expense-category-label-missing/); |
| 202 | }); |
| 203 | |
| 204 | test('Q01: primary search and filter controls have explicit accessible names', () => { |
| 205 | for (const [name, count] of [ |
| 206 | ['InvoicesView',3],['ProductsView',2],['ContactsView',4],['ExpensesView',5] |
| 207 | ]) { |
| 208 | const source=fs.readFileSync(path.join(root,'src','views',name+'.js'),'utf8'); |
| 209 | const names=[...source.matchAll(/aria-label="[^"]+"/g)]; |
| 210 | assert.ok(names.length>=count, name+' lost search/filter accessibility labels'); |
| 211 | } |
| 212 | }); |
| 213 | |
| 214 | test('A03: expense table escapes imported values in HTML and inline action arguments', () => { |
| 215 | const src=fs.readFileSync(path.join(root,'src','views','ExpensesView.js'),'utf8'); |
| 216 | const native=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 217 | for(const fragment of [ |
| 218 | 'this._esc(Formatters.toPersianDigits(e.date', |
| 219 | 'this._esc(ExpenseController.getMethodLabel(e.method))', |
| 220 | 'this._esc(e.refNumber ? Formatters.toPersianDigits(e.refNumber)', |
| 221 | 'this._esc(JSON.stringify(String(e.id ??', |
| 222 | '<option value="${this._esc(c)}"' |
| 223 | ]) assert.ok(src.includes(fragment), 'unescaped expense HTML found: '+fragment); |
| 224 | assert.ok(native.includes('expenseUnsafeHtmlEscaped:true')); |
| 225 | assert.ok(native.includes('Untrusted expense list fields created executable markup')); |
| 226 | // The first category option is the legitimate 'all' filter, never the injected row. |
| 227 | assert.match(native, /filter\(option=>option\.value===hostileCategory\)/); |
| 228 | assert.match(native, /matchingOptions\.length!==1/); |
| 229 | assert.doesNotMatch(native, /select\[aria-label="سرفصل سند"\] option'\)\?\.value!==hostileCategory/); |
| 230 | assert.ok(native.includes('Expense row identifier escaped the safe JS argument')); |
| 231 | }); |
| 232 | |
| 233 | test('A03: financial list views encode imported record IDs and textual values', () => { |
| 234 | const sources=['InvoicesView','ProductsView','ContactsView','TreasuryView','ChequesView']; |
| 235 | for(const name of sources){ |
| 236 | const source=fs.readFileSync(path.join(root,'src','views',name+'.js'),'utf8'); |
| 237 | assert.ok(source.includes('this._esc(JSON.stringify(String('), |
| 238 | name+' lacks HTML-safe JSON encoding for inline record arguments'); |
| 239 | assert.doesNotMatch(source,/onclick="[^"]*\('\$\{[^}]+\.id\}'\)/, |
| 240 | name+' still interpolates raw IDs into JavaScript event handlers'); |
| 241 | assert.doesNotMatch(source,/<option value="\$\{(?:[a-zA-Z]+)\.id\}"/, |
| 242 | name+' still interpolates raw IDs into option attributes'); |
| 243 | } |
| 244 | const invoice=fs.readFileSync(path.join(root,'src','views','InvoicesView.js'),'utf8'); |
| 245 | assert.ok(invoice.includes('${this._esc(k.label)}'), 'unknown imported invoice kind is not HTML escaped'); |
| 246 | assert.ok(invoice.includes('renderTable(invoices = cache.invoices)'), |
| 247 | 'native adversarial test needs an isolated read-only invoice render fixture'); |
| 248 | const expenses=fs.readFileSync(path.join(root,'src','views','ExpensesView.js'),'utf8'); |
| 249 | assert.ok(expenses.includes('this._esc(JSON.stringify(String(e.id ??')); |
| 250 | }); |
| 251 | |
| 252 | test('Q01: remaining financial grid, reporting and settings inputs announce their function', () => { |
| 253 | const read=name=>fs.readFileSync(path.join(root,'src','views',name+'.js'),'utf8'); |
| 254 | const cases=[ |
| 255 | ['ReportsView',['aria-label="از تاریخ گزارش"','aria-label="تا تاریخ گزارش"']], |
| 256 | ['InvoiceFormView',['aria-label="جستجوی کالای ردیف فاکتور"','aria-label="نوع تخفیف ردیف"','aria-label="وضعیت پرداخت فاکتور"','aria-label="مبلغ پرداختشده"']], |
| 257 | ['AccountingView',['aria-label="حساب ردیف سند"','aria-label="مبلغ بدهکار ردیف"','aria-label="مبلغ بستانکار ردیف"','aria-label="شرح ردیف سند"','for="acStWarehouse"']], |
| 258 | ['TreasuryView',['aria-label="جستجوی تراکنشهای خزانه"']], |
| 259 | ['ChequesView',['aria-label="جستجوی چک"','aria-label="نوع چک"','aria-label="وضعیت چک"']], |
| 260 | ['SettingsView',['aria-label="تعداد صفرهای میانبر مثبت"','aria-label="متن تایید پاک کردن دادهها"']] |
| 261 | ]; |
| 262 | for(const [name,labels] of cases){ |
| 263 | const source=read(name); |
| 264 | for(const label of labels)assert.ok(source.includes(label),name+' missing programmatic name: '+label); |
| 265 | } |
| 266 | const runner=fs.readFileSync(path.join(root,'tests','windows-vm-installed-tauri-cdp.cjs'),'utf8'); |
| 267 | assert.ok(runner.includes('audit.fieldsMissingProgrammaticLabel, 0'), |
| 268 | 'installed WebView2 audit must require zero visible inputs without programmatic labels'); |
| 269 | }); |
| 270 | |
| 271 | test('A02: Excel imports reject destructive replacement before touching master data', () => { |
| 272 | const controller=fs.readFileSync(path.join(root,'src','controllers','ExcelController.js'),'utf8'); |
| 273 | const settings=fs.readFileSync(path.join(root,'src','views','SettingsView.js'),'utf8'); |
| 274 | assert.equal((controller.match(/if \(mode !== 'merge'\)/g)||[]).length,2, |
| 275 | 'both contact and product imports must fail closed'); |
| 276 | assert.doesNotMatch(controller,/if \(mode === 'replace'\)/, |
| 277 | 'nontransactional delete-then-import must never be reachable'); |
| 278 | const importModeSelect=settings.split('id="importMode">')[1]?.split('</select>')[0]; |
| 279 | assert.ok(importModeSelect, 'Excel import mode selector missing'); |
| 280 | assert.doesNotMatch(importModeSelect,/<option value="replace"/, |
| 281 | 'destructive Excel option must not be offered; the backup restore option is separate'); |
| 282 | assert.match(settings,/pending\?\.kind !== kind/); |
| 283 | assert.match(settings,/data-excel-import-submit/); |
| 284 | assert.doesNotMatch(settings,/_confirmImport\(\$\{JSON\.stringify\(kind\)/, |
| 285 | 'untrusted filenames must never be embedded as executable inline HTML'); |
| 286 | }); |
| 287 | |
| 288 | test('A03: company switch, posted journals and printable ledger encode untrusted IDs', () => { |
| 289 | const settings=fs.readFileSync(path.join(root,'src','views','SettingsView.js'),'utf8'); |
| 290 | const accounting=fs.readFileSync(path.join(root,'src','views','AccountingView.js'),'utf8'); |
| 291 | const ledger=fs.readFileSync(path.join(root,'src','views','ContactLedgerModal.js'),'utf8'); |
| 292 | assert.ok(settings.includes('this._esc(JSON.stringify(String(c.id ??')); |
| 293 | assert.ok(accounting.includes('const actionArg = value => html(JSON.stringify(String(value ??')); |
| 294 | assert.ok(!accounting.includes("'${html(j.id)}'")); |
| 295 | assert.ok(!accounting.includes("'${html(p.id)}'")); |
| 296 | assert.ok(!accounting.includes("'${html(s.id)}'")); |
| 297 | assert.ok(ledger.includes('this._esc(JSON.stringify(String(contactId ??')); |
| 298 | assert.ok(ledger.includes('<title>صورتحساب ${this._esc(contact.name)}</title>')); |
| 299 | assert.doesNotMatch(ledger,/cdn\.jsdelivr\.net/); |
| 300 | assert.ok(ledger.split('this._esc(Formatters.toPersianDigits(r.date').length>=3); |
| 301 | }); |
| 302 | |
| 303 | test('A02: private Excel preview releases data on cancel and blocks concurrent import', () => { |
| 304 | const settings=fs.readFileSync(path.join(root,'src','views','SettingsView.js'),'utf8'); |
| 305 | assert.ok(settings.includes('let pendingExcelImport = null')); |
| 306 | assert.ok(settings.includes('let excelImportBusy = false')); |
| 307 | assert.ok(settings.includes('if (excelImportBusy) return;')); |
| 308 | assert.ok(settings.includes('if (pendingExcelImport === pending) pendingExcelImport = null;')); |
| 309 | assert.ok(settings.includes('submitButton.disabled = true')); |
| 310 | assert.ok(settings.includes('onClose: () =>')); |
| 311 | assert.doesNotMatch(settings,/window\.__import(?:RawData|Kind)/, |
| 312 | 'private workbook contents must never be exposed as global window properties'); |
| 313 | }); |
| 314 | |
| 315 | test('Q01: Escape is handled once for nested financial dialogs and shortcut target is topmost', () => { |
| 316 | const shortcuts = fs.readFileSync(path.join(root,'src','core','KeyboardShortcuts.js'),'utf8'); |
| 317 | const modal = fs.readFileSync(path.join(root,'src','core','Modal.js'),'utf8'); |
| 318 | assert.match(shortcuts, /window\.FINORA\?\.Modal\?\.stack\?\.length/); |
| 319 | assert.match(shortcuts, /backdrops\[backdrops\.length - 1\]/); |
| 320 | assert.match(modal, /shortcuts\.escapeCloses === false/); |
| 321 | assert.match(modal, /this\.close\(\)/); |
| 322 | }); |
| 323 | |
| 324 | test('Q01: pressing plain Enter on focused Cancel, buttons or inputs must not invoke global save', () => { |
| 325 | const shortcuts = fs.readFileSync(path.join(root, 'src','core','KeyboardShortcuts.js'), 'utf8'); |
| 326 | const nativeAudit = fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'), 'utf8'); |
| 327 | assert.match(shortcuts, /active !== modal\.querySelector\('\.modal-card'\)/, |
| 328 | 'plain Enter must only target the dialog surface, never its focused controls'); |
| 329 | assert.match(shortcuts, /e\.key === 'Enter' && !e\.shiftKey && this\.settings\.enterConfirms && modal/); |
| 330 | assert.match(nativeAudit, /enterOnFocusedCancelDoesNotSave:true/); |
| 331 | assert.match(nativeAudit, /enterOnInputDoesNotSubmit:true/); |
| 332 | assert.match(nativeAudit, /'Enter on focused Cancel was hijacked as financial confirmation'/); |
| 333 | }); |
| 334 | |
| 335 | test('Q01: installed WebView2 must click synthetic modal Cancel/Confirm and trap Tab both directions', () => { |
| 336 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 337 | const native=fs.readFileSync(path.join(root,'tests','windows-vm-installed-tauri-cdp.cjs'),'utf8'); |
| 338 | for (const check of [ |
| 339 | 'tabAndShiftTabStayInsideTopDialog:true', |
| 340 | 'cancelDoesNotConfirmAndRestoresFocus:true', |
| 341 | 'syntheticConfirmRunsExactlyOnce:true', |
| 342 | 'syntheticConfirmed!==0','syntheticConfirmed!==1', |
| 343 | 'confirmationTextEscaped:true', |
| 344 | 'visibleInputAutoFocused:true', |
| 345 | 'Dialog initial focus landed outside first visible financial input', |
| 346 | 'Confirmation message was interpreted as executable HTML', |
| 347 | 'tabForward.defaultPrevented','tabBackward.defaultPrevented' |
| 348 | ]) assert.ok(audit.includes(check),'native modal control evidence missing: '+check); |
| 349 | for(const check of [ |
| 350 | 'modalKeyboard.tabAndShiftTabStayInsideTopDialog', |
| 351 | 'modalKeyboard.cancelDoesNotConfirmAndRestoresFocus', |
| 352 | 'modalKeyboard.syntheticConfirmRunsExactlyOnce' |
| 353 | ]) assert.ok(native.includes(check),'installed native runner must assert: '+check); |
| 354 | }); |
| 355 | |
| 356 | test('Q01: financial mutations are not mislabeled safe by the static control catalog', () => { |
| 357 | const dir=fs.mkdtempSync(path.join(os.tmpdir(),'q01-source-catalog-')); |
| 358 | try { |
| 359 | const output=path.join(dir,'catalog.json'); |
| 360 | execFileSync(process.execPath,[path.join(root,'scripts','q01-ui-control-catalog.cjs'),output],{ |
| 361 | cwd:root,encoding:'utf8',timeout:20000,stdio:['ignore','pipe','pipe'] |
| 362 | }); |
| 363 | const catalog=JSON.parse(fs.readFileSync(output,'utf8')); |
| 364 | assert.ok(catalog.eventBindings>=200,'unexpectedly few view event bindings'); |
| 365 | assert.ok(catalog.sensitiveBindings>=40, |
| 366 | 'financial actions were not classified conservatively; check verb+suffix matcher'); |
| 367 | assert.equal(catalog.allButtonsClicked,false); |
| 368 | for (const name of ['saveJournal','postDraft','deleteDraft', |
| 369 | 'confirmOpeningPosting','saveCheque','saveProduct','restoreBackup','confirmWipe']) { |
| 370 | const matches=catalog.controls.filter(x=>x.action.includes('.'+name+'(')); |
| 371 | assert.ok(matches.length>0,'sensitive action not discovered: '+name); |
| 372 | assert.ok(matches.every(x=>x.category==='sensitive-write-or-export'), |
| 373 | 'sensitive action incorrectly marked navigation: '+name); |
| 374 | assert.ok(matches.every(x=>x.runtimeClicked===false), |
| 375 | 'source catalog must not claim runtime interaction: '+name); |
| 376 | } |
| 377 | const safe=catalog.controls.filter(x=>/\.(?:switchTab|_switchTab)\s*\(/.test(x.action)); |
| 378 | assert.ok(safe.length>0,'navigation controls not discovered'); |
| 379 | assert.ok(safe.some(x=>x.category==='navigation-or-other'), |
| 380 | 'all menu actions incorrectly categorized as financial writes'); |
| 381 | } finally { |
| 382 | fs.rmSync(dir,{recursive:true,force:true}); |
| 383 | } |
| 384 | }); |
| 385 | |
| 386 | test('Q01: filter clicks are deferred until row-scoped confirmation and editor probes finish', () => { |
| 387 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 388 | const queue=audit.indexOf('const deferredSafeActions=[]'); |
| 389 | const confirm=audit.indexOf('const confirmActions='); |
| 390 | const open=audit.indexOf('const openActions='); |
| 391 | const deferred=audit.indexOf('for(const group of deferredSafeActions)'); |
| 392 | assert.ok(queue>=0 && confirm>queue && open>confirm && deferred>open, |
| 393 | 'filters must not hide row targets before edit/delete confirmation probes'); |
| 394 | assert.ok(audit.includes('safe-tab-vanished')); |
| 395 | assert.ok(audit.includes('safe-action-vanished')); |
| 396 | assert.ok(audit.includes("const safeTab = /\\.(?:_switchTab|switchTab)")); |
| 397 | assert.ok(audit.includes("_switchPeriod|_setPreset")); |
| 398 | assert.ok(audit.includes("tabAction:tabActions[0]||null")); |
| 399 | assert.ok(audit.includes("const pending=[...group.actions]")); |
| 400 | assert.ok(audit.includes("for(const candidate of clickables(target()).filter(x=>")); |
| 401 | assert.doesNotMatch(audit,/safeOpen = .*changeStatus|safeOpen = .*_printReport|safeOpen = .*_printKardex|safeOpen = .*_printLedger/); |
| 402 | assert.match(audit,/safeOpen = .*_printInvoice/); |
| 403 | }); |
| 404 | |
| 405 | test('Q01: safe navigation audit re-resolves same-handler controls by stable tag', () => { |
| 406 | const audit=fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 407 | assert.ok(audit.includes('handler:handler(el),label:name(el),tag:el.tagName.toLowerCase()')); |
| 408 | assert.ok(audit.includes('handler(x)===action.handler && x.tagName.toLowerCase()===action.tag')); |
| 409 | assert.ok(audit.includes('for(let attempt=0;attempt<12 && !el;attempt++)')); |
| 410 | assert.ok(audit.includes('tab.click();await wait(160);')); |
| 411 | assert.ok(audit.includes("safeNavigate.test(action.handler)?'navigation':'filter'")); |
| 412 | }); |
| 413 | |
| 414 | test('Q01: partial-payment amount field has an explicit associated label', () => { |
| 415 | const view=fs.readFileSync(path.join(root,'src','views','InvoiceFormView.js'),'utf8'); |
| 416 | assert.match(view,/label for="invPaidAmount"/); |
| 417 | assert.match(view,/id="invPaidAmount"/); |
| 418 | assert.match(view,/مبلغ پرداختشده/); |
| 419 | }); |
| 420 | |
| 421 | test('Q01: native click audit separates unique action signatures from repeated tab instances', () => { |
| 422 | const audit = fs.readFileSync(path.join(root,'tests','windows-vm-ui-interaction-audit-browser.js'),'utf8'); |
| 423 | const native = fs.readFileSync(path.join(root,'tests','windows-vm-installed-tauri-cdp.cjs'),'utf8'); |
| 424 | for(const key of ['uniqueActionCount','uniqueActionClicked','uniqueActionUnverified', |
| 425 | 'duplicateInstanceCount','unclassifiedInstances','uniqueActions', |
| 426 | 'same-control-clicked-in-another-tab-context', |
| 427 | 'not-reached-or-not-classified-needs-manual-test']){ |
| 428 | assert.ok(audit.includes(key),'missing unique action audit evidence: '+key); |
| 429 | } |
| 430 | assert.ok(native.includes('audit.uniqueActionCount <= audit.inventoryCount'), |
| 431 | 'native runner must not confuse 470 UI instances with unique buttons'); |
| 432 | assert.ok(native.includes("x.status!=='not-clicked' || !!x.reason"), |
| 433 | 'every unclicked action occurrence must have a reason'); |
| 434 | }); |
| 435 | |
| 436 | test('Q01: unverified-action Markdown respects deduplicated click evidence and fails closed', () => { |
| 437 | const require=createRequire(import.meta.url); |
| 438 | const { buildReport }=require(path.join(root,'scripts','q01-native-action-gap-report.cjs')); |
| 439 | const synthetic={ |
| 440 | environment:'installed-Windows-Tauri-WebView2-synthetic-VM', |
| 441 | everyActionVerified:false,customerDataUsed:false, |
| 442 | uniqueActionCount:2,uniqueActionClicked:1,uniqueActionUnverified:1, |
| 443 | uniqueActionDisabled:0,uniqueActionFailed:0, |
| 444 | duplicateInstanceCount:1,inventoryCount:3, |
| 445 | controls:[{},{},{}], |
| 446 | uniqueActions:[ |
| 447 | {route:'invoices',tag:'button',label:'ثبت نهایی',handler:'InvoiceForm.save()', |
| 448 | status:'not-clicked',whyNotVerified:'requires synthetic financial fixture'}, |
| 449 | {route:'invoices',tag:'button',label:'لغو',handler:'Modal.close()', |
| 450 | status:'clicked',whyNotVerified:''} |
| 451 | ], |
| 452 | problems:[{route:'invoices',kind:'manual-review',label:'fixture needed'}] |
| 453 | }; |
| 454 | const md=buildReport(synthetic); |
| 455 | assert.match(md,/ثبت نهایی/); |
| 456 | assert.match(md,/requires synthetic financial fixture/); |
| 457 | assert.match(md,/امضاهای کنترلی متمایز \| 2/); |
| 458 | assert.doesNotMatch(md,/\| لغو \| clicked/,'clicked actions do not belong in gap list'); |
| 459 | assert.throws(()=>buildReport({...synthetic,everyActionVerified:true}),/UNVERIFIED_INPUT/); |
| 460 | assert.throws(()=>buildReport({...synthetic,inventoryCount:500}),/COUNT_MISMATCH/); |
| 461 | }); |