فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
work/a08-memory-stability-20261123
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 | 'use strict'; |
| 2 | // Executed as a single async expression inside an INSTALLED Tauri WebView2, |
| 3 | // on a disposable Windows VM after synthetic financial fixtures are created. |
| 4 | // This does not click destructive actions; these need separate fixture-backed |
| 5 | // accounting correctness tests. Never claim "all buttons work" from a sweep. |
| 6 | (async () => { |
| 7 | const wait = ms => new Promise(r => setTimeout(r, ms)); |
| 8 | const routes = [ |
| 9 | 'dashboard','invoices','products','contacts','treasury', |
| 10 | 'cheques','expenses','reports','accounting','settings' |
| 11 | ]; |
| 12 | window.__Q01_AUDIT_STAGE='audit-start'; |
| 13 | const failures = []; |
| 14 | const inventories = []; |
| 15 | const clicks = []; |
| 16 | const skipped = []; |
| 17 | const all = new Map(); |
| 18 | const fields = new Map(); |
| 19 | const target = () => document.getElementById('pageContent'); |
| 20 | const isVisible = el => { |
| 21 | const style = window.getComputedStyle(el); |
| 22 | return style.display !== 'none' && style.visibility !== 'hidden' && |
| 23 | el.getClientRects().length > 0; |
| 24 | }; |
| 25 | const name = el => String( |
| 26 | el.getAttribute('aria-label') || el.getAttribute('title') || |
| 27 | el.innerText || el.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 90); |
| 28 | const handler = el => el.getAttribute('onclick') || |
| 29 | el.getAttribute('onchange') || el.getAttribute('onsubmit') || ''; |
| 30 | const sig = (el, route, section) => [ |
| 31 | route, section, el.tagName.toLowerCase(), name(el), |
| 32 | handler(el).replace(/\s+/g,' ').slice(0,180) |
| 33 | ].join('|'); |
| 34 | const dangerous = /(?:^|[.\s])(?:_?(?:save|delete|wipe|restore|post|submit|confirm|activate|seed|commit|final|approve|logout|export|import|download|print|settle|apply|reset|changeStatus|remove)\w*)\s*\(/i; |
| 35 | const safeTab = /\.(?:_switchTab|switchTab)\s*\(/; |
| 36 | const safeNavigate = /FINORA\.Router\.go\s*\(/; |
| 37 | const safeFilter = /\.(?:_togglePreInvoice|_setStockFilter|_clearFilters|_applyCustom|_switchPeriod|_setPreset|refresh|setTheme)\s*\(/; |
| 38 | // These handlers only open an editor/preview/diagnostic dialog. The audit |
| 39 | // closes it without saving; a separate fixture-backed test owns commits. |
| 40 | const safeOpen = /\.(?:openNewInvoice|openProductModal|openUnitModal|openCategoryModal|openContactModal|openExpenseModal|openChequeModal|openAccountModal|openReceiptModal|openPaymentModal|openTransferModal|openCompanyModal|openCompanySwitcher|openExportSectionModal|openSignedLicenseModal|openAuditTrail|openWipeModal|openRestoreModal|openPeriodModal|openJournalModal|openWarehouse|openStocktakeCreate|openTransfer|openReversal|_openQuickProduct|_openQuickContact|openLedger|openKardex|openStocktake|showJournal|editInvoice|editProduct|editContact|editCheque|editAccount|openAdjustModal|_printInvoice|printInvoice|_preview|checkHolooMigrationReadiness|runFinancialDiagnostics)\s*\(/; |
| 41 | // A delete/close-period/seed action is safe to probe only up to its |
| 42 | // confirmation prompt. The audit must cancel and prove zero database writes. |
| 43 | const safeConfirmAction = /\.(?:deleteInvoice|deleteProduct|deleteContact|deleteCheque|deleteTransaction|deleteExpense|deleteAccount|closePeriod|seedChart)\s*\(/; |
| 44 | const clickables = (root) => [...root.querySelectorAll( |
| 45 | 'button, a, [role="button"], input[type="button"], input[type="submit"], [onclick]' |
| 46 | )].filter(isVisible); |
| 47 | function auditFields(root, route, section) { |
| 48 | if (!root) return; |
| 49 | let fieldIndex = 0; |
| 50 | for (const field of root.querySelectorAll( |
| 51 | 'input:not([type="hidden"]), select, textarea' |
| 52 | )) { |
| 53 | const ordinal = fieldIndex++; |
| 54 | if (!isVisible(field)) continue; |
| 55 | const labels=field.labels ? [...field.labels] : []; |
| 56 | const explicit=!!field.getAttribute('aria-label') || |
| 57 | !!field.getAttribute('aria-labelledby') || |
| 58 | !!field.closest('label') || labels.length > 0; |
| 59 | const id=field.id||''; |
| 60 | const key=[route,section,ordinal,field.tagName.toLowerCase(),id, |
| 61 | field.getAttribute('name')||'',field.getAttribute('type')||''].join('|'); |
| 62 | if (fields.has(key)) continue; |
| 63 | fields.set(key,{ |
| 64 | route,section,ordinal,id,tag:field.tagName.toLowerCase(), |
| 65 | type:field.getAttribute('type')||'', |
| 66 | label:labels.map(x=>x.textContent.trim().slice(0,75)).join(' / ') || |
| 67 | field.getAttribute('aria-label') || '', |
| 68 | programmaticLabel:explicit, |
| 69 | placeholderOnly:!explicit && !!field.getAttribute('placeholder'), |
| 70 | status:explicit?'programmatic-label-found':'needs-accessibility-review' |
| 71 | }); |
| 72 | } |
| 73 | } |
| 74 | function registerControl(el, route, section) { |
| 75 | const key=sig(el,route,section); |
| 76 | if(!all.has(key)) all.set(key,{ |
| 77 | route,section,tag:el.tagName.toLowerCase(),label:name(el), |
| 78 | handler:handler(el).slice(0,220),disabled:!!el.disabled, |
| 79 | hasAccessibleName:!!name(el),status:'not-clicked',reason:'' |
| 80 | }); |
| 81 | return all.get(key); |
| 82 | } |
| 83 | function inventory(route, section) { |
| 84 | const controls = clickables(target()); |
| 85 | auditFields(target(),route,section); |
| 86 | const records = []; |
| 87 | for (const el of controls) { |
| 88 | const k=sig(el,route,section); |
| 89 | if (all.has(k)) continue; |
| 90 | const code=handler(el); |
| 91 | const accessible=!!name(el); |
| 92 | const row={ |
| 93 | route,section,tag:el.tagName.toLowerCase(), |
| 94 | label:name(el),handler:code.slice(0,220), |
| 95 | disabled:!!el.disabled || el.getAttribute('aria-disabled')==='true', |
| 96 | hasAccessibleName:accessible, |
| 97 | className:String(el.className||'').slice(0,120), |
| 98 | type:el.getAttribute('type')||'', |
| 99 | status:'not-clicked',reason:'' |
| 100 | }; |
| 101 | all.set(k,row); records.push(row); |
| 102 | } |
| 103 | inventories.push({route,section,newControls:records.length,totalVisible:controls.length}); |
| 104 | return controls; |
| 105 | } |
| 106 | async function go(route) { |
| 107 | const link=document.querySelector('#sidebarMenu [data-page="'+route+'"]'); |
| 108 | if (!link) throw Error('main sidebar menu item missing: '+route); |
| 109 | link.click(); await wait(160); |
| 110 | if (FINORA.Router.current()!==route) throw Error('sidebar click did not navigate: '+route); |
| 111 | if (!target() || target().textContent.trim().length < 10 || |
| 112 | target().textContent.includes('خطا در بارگذاری صفحه')) { |
| 113 | throw Error('screen blank/failed after clicking: '+route); |
| 114 | } |
| 115 | if (document.getElementById('finoraAuthOverlay')) throw Error('auth returned during navigation'); |
| 116 | } |
| 117 | const noError = () => !document.querySelector('.toast-error') && |
| 118 | !target()?.textContent.includes('خطا در بارگذاری صفحه'); |
| 119 | function dismiss() { |
| 120 | FINORA.Modal.closeAll(); |
| 121 | document.querySelectorAll('.toast-close').forEach(x=>x.click()); |
| 122 | } |
| 123 | function resolveHandler(code) { |
| 124 | const m=code.match(/(?:window\.)?([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+)\s*\(/); |
| 125 | if (!m) return {detected:false,valid:null,callee:''}; |
| 126 | const parts=m[1].split('.'); |
| 127 | let obj=window; |
| 128 | for (const part of parts) { |
| 129 | if (obj == null) return {detected:true,valid:false,callee:m[1]}; |
| 130 | obj=obj[part]; |
| 131 | } |
| 132 | return {detected:true,valid:typeof obj==='function',callee:m[1]}; |
| 133 | } |
| 134 | // De-duplicate a physical DOM node, not a handler signature. The same |
| 135 | // action is intentionally exercised in several freshly opened modal |
| 136 | // instances; signature-level de-duplication skipped those clicks and made |
| 137 | // later instances look broken even though only the first was exercised. |
| 138 | const seenClick = new WeakSet(); |
| 139 | async function press(el, route, section, category) { |
| 140 | if (seenClick.has(el)) return; |
| 141 | seenClick.add(el); |
| 142 | const k=sig(el,route,section); |
| 143 | const row=all.get(k); |
| 144 | const before=target().innerHTML; |
| 145 | const beforeModal=!!document.querySelector('.modal-backdrop'); |
| 146 | const beforeModalDepth=FINORA.Modal.stack.length; |
| 147 | const beforeModalMarkup=FINORA.Modal.stack.at(-1)?.card.innerHTML||''; |
| 148 | const beforeRoute=FINORA.Router.current(); |
| 149 | const beforeTheme=document.documentElement.getAttribute('data-theme'); |
| 150 | const beforeToasts=[...document.querySelectorAll('.toast')].map(x=>x.textContent.trim()).join('|'); |
| 151 | try { |
| 152 | el.click(); await wait(180); |
| 153 | if (!noError()) throw Error('error toast or page render error'); |
| 154 | const after=target()?.innerHTML||''; |
| 155 | const afterModal=!!document.querySelector('.modal-backdrop'); |
| 156 | const afterModalDepth=FINORA.Modal.stack.length; |
| 157 | const afterModalMarkup=FINORA.Modal.stack.at(-1)?.card.innerHTML||''; |
| 158 | const afterRoute=FINORA.Router.current(); |
| 159 | const afterTheme=document.documentElement.getAttribute('data-theme'); |
| 160 | const afterToasts=[...document.querySelectorAll('.toast')].map(x=>x.textContent.trim()).join('|'); |
| 161 | const changed = before !== after || beforeModal !== afterModal || |
| 162 | beforeModalDepth !== afterModalDepth || beforeModalMarkup !== afterModalMarkup || |
| 163 | beforeRoute !== afterRoute || beforeTheme !== afterTheme || beforeToasts !== afterToasts; |
| 164 | clicks.push({route,section,category,label:name(el), |
| 165 | handler:handler(el).slice(0,170),changed,afterModal}); |
| 166 | if (row) {row.status='clicked';row.reason=changed?'visible-state-changed':'no-observable-DOM-change';} |
| 167 | if (!changed) { |
| 168 | const expectedNoop = /\._clearFilters\(\)|\._applyCustom\(\)|\.refresh\(\)|\.switchTab\('journals'\)/.test(handler(el)); |
| 169 | if (expectedNoop) { |
| 170 | if (row) row.reason='idempotent-click-on-already-selected-or-clear-filter-state'; |
| 171 | } else { |
| 172 | // A non-idempotent safe action that produced no observable state |
| 173 | // change is a failed control, not a successful click. Propagate this |
| 174 | // into uniqueActionFailed so the native acceptance gate cannot hide |
| 175 | // it behind the separate problems array. |
| 176 | if (row) {row.status='failed';row.reason='no-observable-DOM-change';} |
| 177 | failures.push({route,section,kind:'no-visible-change', |
| 178 | label:name(el),handler:handler(el).slice(0,170)}); |
| 179 | } |
| 180 | } |
| 181 | } catch(error) { |
| 182 | failures.push({route,section,kind:'click-error',label:name(el),error:String(error.message).slice(0,170)}); |
| 183 | if (row) {row.status='failed';row.reason='UI click error';} |
| 184 | } finally { if (category !== 'open' && category !== 'confirm-request') dismiss(); } |
| 185 | } |
| 186 | // Explicit shell regression: semantic links, keyboard focus, active route, |
| 187 | // persistent sidebar collapse and reversible theme toggle. |
| 188 | const navLinks=[...document.querySelectorAll('#sidebarMenu a[data-page]')]; |
| 189 | if (navLinks.length !== routes.length) throw Error('sidebar navigation count mismatch'); |
| 190 | for(const link of navLinks) { |
| 191 | const route=link.dataset.page; |
| 192 | if(link.getAttribute('href')!=='#'+route || link.tabIndex<0 || |
| 193 | !link.getAttribute('aria-label')) throw Error('sidebar link is not keyboard accessible: '+route); |
| 194 | } |
| 195 | const hamburger=document.getElementById('sidebarToggleBtn'); |
| 196 | if(!hamburger || !hamburger.getAttribute('aria-label') || |
| 197 | hamburger.getAttribute('aria-controls')!=='sidebarMenu') { |
| 198 | throw Error('sidebar accessible toggle missing'); |
| 199 | } |
| 200 | const beforeCollapsed=document.getElementById('sidebar').classList.contains('collapsed'); |
| 201 | hamburger.click();await wait(70); |
| 202 | const afterCollapsed=document.getElementById('sidebar').classList.contains('collapsed'); |
| 203 | if (beforeCollapsed===afterCollapsed || |
| 204 | localStorage.getItem('finora_pro_sidebar_collapsed')!==String(afterCollapsed) || |
| 205 | hamburger.getAttribute('aria-expanded')!==String(!afterCollapsed)) { |
| 206 | throw Error('sidebar click did not persist synchronized collapsed and aria-expanded state'); |
| 207 | } |
| 208 | hamburger.click();await wait(70); |
| 209 | if(document.getElementById('sidebar').classList.contains('collapsed')!==beforeCollapsed || |
| 210 | localStorage.getItem('finora_pro_sidebar_collapsed')!==String(beforeCollapsed)) { |
| 211 | throw Error('sidebar click did not restore the prior saved state'); |
| 212 | } |
| 213 | const themeButton=document.getElementById('themeToggleBtn'); |
| 214 | const originalTheme=document.documentElement.getAttribute('data-theme'); |
| 215 | if(!themeButton || !themeButton.getAttribute('title'))throw Error('theme button missing accessible name'); |
| 216 | themeButton.click();await wait(50); |
| 217 | if(document.documentElement.getAttribute('data-theme')===originalTheme)throw Error('theme toggle was inert'); |
| 218 | themeButton.click();await wait(50); |
| 219 | if(document.documentElement.getAttribute('data-theme')!==originalTheme || |
| 220 | localStorage.getItem('finora_pro_theme')!==originalTheme)throw Error('theme setting not reversible/persisted'); |
| 221 | // Cross-app dialog behavior: nested modal focus, Escape and focus return. |
| 222 | const modalTrigger=hamburger; |
| 223 | modalTrigger.focus(); |
| 224 | if (getComputedStyle(modalTrigger).display === 'none' || |
| 225 | document.activeElement !== modalTrigger) { |
| 226 | throw Error('Desktop sidebar toggle cannot receive keyboard focus before opening a dialog'); |
| 227 | } |
| 228 | let unexpectedConfirm=false; |
| 229 | FINORA.Modal.open({title:'Q01 Synthetic outer dialog', |
| 230 | body:'<input id="q01ModalField" value="synthetic" />', |
| 231 | footer:'<button class="btn" onclick="FINORA.Modal.close()">بستن</button>'}); |
| 232 | await wait(30); |
| 233 | const outer=document.querySelector('.modal-card[role="dialog"][aria-modal="true"]'); |
| 234 | if(!outer || !outer.querySelector('[id^="finora-dialog-title-"]') || |
| 235 | !outer.contains(document.activeElement)) throw Error('outer dialog ARIA or focus absent'); |
| 236 | FINORA.Modal.confirm({title:'Q01 Synthetic nested confirmation', |
| 237 | message:'Synthetic data only; no operation permitted', |
| 238 | onConfirm:()=>{unexpectedConfirm=true;}}); |
| 239 | await wait(30); |
| 240 | const stack=[...document.querySelectorAll('.modal-card[role="dialog"]')]; |
| 241 | if(stack.length!==2 || stack[0].getAttribute('aria-hidden')!=='true' || |
| 242 | !stack[1].contains(document.activeElement)) throw Error('nested dialog focus/isolation failed'); |
| 243 | // Check a real Tab/Shift+Tab wrap, which an accessibility contract |
| 244 | // cannot prove from source alone. Neither key may escape the top dialog. |
| 245 | const topControls=[...stack[1].querySelectorAll( |
| 246 | 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])' |
| 247 | )].filter(el=>el.getClientRects().length>0 && getComputedStyle(el).visibility!=='hidden'); |
| 248 | if(topControls.length<2)throw Error('nested modal focus order unexpectedly empty'); |
| 249 | const firstModalControl=topControls[0],lastModalControl=topControls[topControls.length-1]; |
| 250 | lastModalControl.focus(); |
| 251 | const tabForward=new KeyboardEvent('keydown',{key:'Tab',bubbles:true,cancelable:true}); |
| 252 | lastModalControl.dispatchEvent(tabForward); |
| 253 | if(!tabForward.defaultPrevented || document.activeElement!==firstModalControl){ |
| 254 | throw Error('Tab escaped the top modal instead of wrapping to its first control'); |
| 255 | } |
| 256 | firstModalControl.focus(); |
| 257 | const tabBackward=new KeyboardEvent('keydown', |
| 258 | {key:'Tab',shiftKey:true,bubbles:true,cancelable:true}); |
| 259 | firstModalControl.dispatchEvent(tabBackward); |
| 260 | if(!tabBackward.defaultPrevented || document.activeElement!==lastModalControl){ |
| 261 | throw Error('Shift+Tab escaped the top modal instead of wrapping to its last control'); |
| 262 | } |
| 263 | // Simulate pressing Enter on a focused CANCEL button in an actual installed |
| 264 | // WebView2 dialog. The global shortcut MUST NOT hijack it as "confirm". |
| 265 | const nestedCancel=stack[1].querySelector('[data-action="cancel"]'); |
| 266 | if(!nestedCancel)throw Error('synthetic nested dialog cancel button missing'); |
| 267 | nestedCancel.focus(); |
| 268 | const enterOnCancel=new KeyboardEvent('keydown', |
| 269 | {key:'Enter',code:'Enter',bubbles:true,cancelable:true}); |
| 270 | nestedCancel.dispatchEvent(enterOnCancel); |
| 271 | await wait(20); |
| 272 | if(enterOnCancel.defaultPrevented || unexpectedConfirm || |
| 273 | document.querySelectorAll('.modal-card').length!==2){ |
| 274 | throw Error('Enter on focused Cancel was hijacked as financial confirmation'); |
| 275 | } |
| 276 | document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true,cancelable:true})); |
| 277 | await wait(15); |
| 278 | if(document.querySelectorAll('.modal-card').length!==1 || |
| 279 | !outer.contains(document.activeElement) || unexpectedConfirm) throw Error('Escape did not dismiss nested confirm safely'); |
| 280 | const focusedField=document.getElementById('q01ModalField'); |
| 281 | if(!focusedField)throw Error('synthetic outer input missing'); |
| 282 | focusedField.focus(); |
| 283 | const enterInField=new KeyboardEvent('keydown', |
| 284 | {key:'Enter',code:'Enter',bubbles:true,cancelable:true}); |
| 285 | focusedField.dispatchEvent(enterInField); |
| 286 | await wait(20); |
| 287 | if(enterInField.defaultPrevented || !outer.isConnected){ |
| 288 | throw Error('Enter inside form input unexpectedly submitted/dismissed dialog'); |
| 289 | } |
| 290 | document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true,cancelable:true})); |
| 291 | await wait(15); |
| 292 | if(document.querySelector('.modal-backdrop') || document.activeElement!==modalTrigger || |
| 293 | unexpectedConfirm) { |
| 294 | const focused=document.activeElement; |
| 295 | throw Error('Escape did not restore focus to original control: ' + JSON.stringify({ |
| 296 | remainingDialogs:document.querySelectorAll('.modal-backdrop').length, |
| 297 | focusedTag:focused?.tagName,focusedId:focused?.id, |
| 298 | expectedId:modalTrigger.id,unexpectedConfirm |
| 299 | })); |
| 300 | } |
| 301 | // Open a fresh synthetic confirmation: a user clicking Cancel must NOT |
| 302 | // execute the callback. Deliberate Confirm should execute exactly once. |
| 303 | let syntheticConfirmed=0; |
| 304 | FINORA.Modal.confirm({title:'Q01 Cancel-button regression', |
| 305 | message:'No real account or customer data', |
| 306 | onConfirm:()=>{syntheticConfirmed++;}}); |
| 307 | await wait(25); |
| 308 | const cancelDialog=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card; |
| 309 | const cancelClick=cancelDialog?.querySelector('[data-action="cancel"]'); |
| 310 | if(!cancelClick)throw Error('synthetic Cancel action missing'); |
| 311 | cancelClick.focus(); |
| 312 | cancelClick.click();await wait(25); |
| 313 | if(syntheticConfirmed!==0 || FINORA.Modal.stack.length || |
| 314 | document.activeElement!==modalTrigger){ |
| 315 | throw Error('Cancel click triggered financial confirm or failed to restore focus'); |
| 316 | } |
| 317 | FINORA.Modal.confirm({title:'Q01 Confirm-button regression', |
| 318 | message:'Only increment a synthetic counter', |
| 319 | onConfirm:()=>{syntheticConfirmed++;}}); |
| 320 | await wait(25); |
| 321 | const confirmDialog=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card; |
| 322 | const confirmClick=confirmDialog?.querySelector('[data-action="confirm"]'); |
| 323 | if(!confirmClick)throw Error('synthetic Confirm action missing'); |
| 324 | confirmClick.click(); |
| 325 | confirmClick.click(); // old DOM reference must not execute twice |
| 326 | await wait(25); |
| 327 | if(syntheticConfirmed!==1 || FINORA.Modal.stack.length){ |
| 328 | throw Error('synthetic Confirm callback not exactly once or dialog not dismissed'); |
| 329 | } |
| 330 | FINORA.Modal.confirm({title:'Q01 stale cancelled confirmation', |
| 331 | message:'Must never commit after cancellation',onConfirm:()=>{syntheticConfirmed++;}}); |
| 332 | await wait(25); |
| 333 | const staleCancelDialog=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card; |
| 334 | const staleConfirm=staleCancelDialog?.querySelector('[data-action="confirm"]'); |
| 335 | staleCancelDialog?.querySelector('[data-action="cancel"]')?.click(); |
| 336 | staleConfirm?.click(); |
| 337 | if(syntheticConfirmed!==1 || FINORA.Modal.stack.length){ |
| 338 | throw Error('A cancelled confirmation was executed by a stale button'); |
| 339 | } |
| 340 | FINORA.Modal.confirm({title:'Q01 hidden parent confirmation', |
| 341 | message:'Must remain inert while nested',onConfirm:()=>{syntheticConfirmed++;}}); |
| 342 | await wait(25); |
| 343 | const hiddenParent=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card; |
| 344 | FINORA.Modal.confirm({title:'Q01 active child confirmation', |
| 345 | message:'Cancel first',onConfirm:()=>{syntheticConfirmed++;}}); |
| 346 | await wait(25); |
| 347 | hiddenParent?.querySelector('[data-action="confirm"]')?.click(); |
| 348 | if(syntheticConfirmed!==1 || FINORA.Modal.stack.length!==2){ |
| 349 | throw Error('Hidden parent confirmation changed ledger decision while child was active'); |
| 350 | } |
| 351 | FINORA.Modal.stack[1].card.querySelector('[data-action="cancel"]').click(); |
| 352 | hiddenParent.querySelector('[data-action="cancel"]').click(); |
| 353 | if(FINORA.Modal.stack.length!==0 || syntheticConfirmed!==1){ |
| 354 | throw Error('Nested financial confirmations were not safely cancelled'); |
| 355 | } |
| 356 | // A confirmation message can contain user-provided contact names. It must |
| 357 | // never be interpreted as HTML or create a DOM node with event handlers. |
| 358 | const hostileMessage='<img src=x onerror="window.Q01_INJECTED=true">'; |
| 359 | FINORA.Modal.confirm({title:'Q01 text-only confirmation', |
| 360 | message:hostileMessage,confirmText:hostileMessage,cancelText:hostileMessage, |
| 361 | onConfirm:()=>{syntheticConfirmed++;}}); |
| 362 | await wait(25); |
| 363 | // Use a globally unique identifier: this source is evaluated repeatedly |
| 364 | // in one long-lived WebView2 realm alongside other test scripts. |
| 365 | const q01TextOnlyConfirmCard_20261031=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card; |
| 366 | if (!q01TextOnlyConfirmCard_20261031 || |
| 367 | q01TextOnlyConfirmCard_20261031.querySelector('[data-confirm-message]')?.textContent!==hostileMessage || |
| 368 | q01TextOnlyConfirmCard_20261031.querySelector('[data-action="confirm"]')?.textContent!==hostileMessage || |
| 369 | q01TextOnlyConfirmCard_20261031.querySelector('[data-action="cancel"]')?.textContent!==hostileMessage || |
| 370 | q01TextOnlyConfirmCard_20261031.querySelector('img') || window.Q01_INJECTED) { |
| 371 | throw Error('Confirmation message was interpreted as executable HTML'); |
| 372 | } |
| 373 | q01TextOnlyConfirmCard_20261031.querySelector('[data-action="cancel"]').click(); |
| 374 | if (syntheticConfirmed!==1 || FINORA.Modal.stack.length) { |
| 375 | throw Error('Text-only confirmation Cancel executed a callback or leaked a dialog'); |
| 376 | } |
| 377 | // A financial editor can start with an invisible radio or hidden ID field. |
| 378 | // Initial focus must land on the first VISIBLE input, not a hidden element. |
| 379 | FINORA.Modal.open({title:'Q01 visible-input focus regression', |
| 380 | body:'<input id="q01HiddenInput" style="display:none"><input id="q01VisibleInput">'}); |
| 381 | await wait(25); |
| 382 | if (document.activeElement?.id !== 'q01VisibleInput') { |
| 383 | throw Error('Dialog initial focus landed outside first visible financial input'); |
| 384 | } |
| 385 | FINORA.Modal.close(); |
| 386 | if (document.activeElement!==modalTrigger) { |
| 387 | throw Error('Closing visible-input dialog did not restore keyboard focus'); |
| 388 | } |
| 389 | // Real DOM probe: preserve ambiguous groups and explicit accessible names. |
| 390 | const labelsProbe=FINORA.Modal.open({title:'Q01 Synthetic form labels',body: |
| 391 | '<div class="form-group"><label class="form-label">نام آزمایشی</label><input id="q01SingleField"></div>' + |
| 392 | '<div class="form-group"><label class="form-label">گروه چندفیلدی</label><input id="q01MultiOne"><input id="q01MultiTwo"></div>' + |
| 393 | '<div class="form-group"><label class="form-label" for="q01ExistingField">برچسب صریح</label><input id="q01ExistingField"></div>', |
| 394 | footer:'<button class="btn" onclick="FINORA.Modal.close()">بستن</button>',size:'sm'}); |
| 395 | await wait(25); |
| 396 | const namedField=labelsProbe.card.querySelector('#q01SingleField'); |
| 397 | const multiOne=labelsProbe.card.querySelector('#q01MultiOne'); |
| 398 | const existingField=labelsProbe.card.querySelector('#q01ExistingField'); |
| 399 | if (namedField.labels?.length!==1 || |
| 400 | namedField.labels[0].textContent.trim()!=='نام آزمایشی' || |
| 401 | multiOne.labels?.length || existingField.labels?.length!==1 || |
| 402 | existingField.labels[0].getAttribute('for')!=='q01ExistingField') { |
| 403 | throw Error('Modal form labels were missing, ambiguous, or overwrote explicit names'); |
| 404 | } |
| 405 | namedField.labels[0].click(); await wait(15); |
| 406 | if (document.activeElement!==namedField) throw Error('Linked modal field label did not focus its field'); |
| 407 | FINORA.Modal.close(); |
| 408 | // Read-only synthetic XSS exercise: no customer records are persisted. |
| 409 | const expenseController=window.ExpenseController; |
| 410 | const expenseView=window.ExpensesView; |
| 411 | const origGetAll=expenseController.getAll; |
| 412 | const origGetCategories=expenseController.getCategories; |
| 413 | const origGetStats=expenseController.getStats; |
| 414 | const origEditExpense=expenseView.editExpense; |
| 415 | const hostileCategory='"><\/option><\/select><img src=x onerror="window.Q01_EXPENSE_HTML_ATTACK=true">'; |
| 416 | const hostileId="exp-test');window.Q01_EXPENSE_ID_ATTACK=true;//"; |
| 417 | const hostileCell='<img src=x onerror="window.Q01_EXPENSE_HTML_ATTACK=true">'; |
| 418 | let clickedExpenseId=null; |
| 419 | try { |
| 420 | expenseController.getAll=async()=>[{id:hostileId,kind:'expense', |
| 421 | category:hostileCategory,description:hostileCell, |
| 422 | date:hostileCell,refNumber:hostileCell,method:hostileCell,amount:100}]; |
| 423 | expenseController.getCategories=async()=>[hostileCategory]; |
| 424 | expenseController.getStats=async()=>({totalIncome:0,totalExpense:100,balance:-100,count:1}); |
| 425 | await expenseView.reload(); |
| 426 | const scratch=document.createElement('div'); |
| 427 | scratch.innerHTML=expenseView.renderContent(); |
| 428 | const categoryFilter=scratch.querySelector('select[aria-label="سرفصل سند"]'); |
| 429 | const matchingOptions=[...(categoryFilter?.options || [])] |
| 430 | .filter(option=>option.value===hostileCategory); |
| 431 | const actualLabels=matchingOptions.map(option=>option.textContent); |
| 432 | if(scratch.querySelector('img') || scratch.querySelector('script') || |
| 433 | matchingOptions.length!==1 || actualLabels[0]!==hostileCategory || |
| 434 | !scratch.textContent.includes(hostileCell)) { |
| 435 | throw Error('Untrusted expense list fields created executable markup or corrupted category value: ' + |
| 436 | JSON.stringify({filterFound:!!categoryFilter, |
| 437 | optionsCount:categoryFilter?.options?.length ?? -1, |
| 438 | maliciousCategoryPresent:matchingOptions.length===1, |
| 439 | labelMatches:actualLabels[0]===hostileCategory, |
| 440 | unexpectedImages:scratch.querySelectorAll('img').length, |
| 441 | unexpectedScripts:scratch.querySelectorAll('script').length})); |
| 442 | } |
| 443 | expenseView.editExpense=(id)=>{clickedExpenseId=id;}; |
| 444 | const edit=scratch.querySelector('button[title="ویرایش"]'); |
| 445 | if(!edit) throw Error('Synthetic expense action missing'); |
| 446 | edit.click(); |
| 447 | if(clickedExpenseId!==hostileId || window.Q01_EXPENSE_ID_ATTACK || |
| 448 | window.Q01_EXPENSE_HTML_ATTACK) { |
| 449 | throw Error('Expense row identifier escaped the safe JS argument or executed markup'); |
| 450 | } |
| 451 | } finally { |
| 452 | expenseController.getAll=origGetAll; |
| 453 | expenseController.getCategories=origGetCategories; |
| 454 | expenseController.getStats=origGetStats; |
| 455 | expenseView.editExpense=origEditExpense; |
| 456 | await expenseView.reload(); |
| 457 | delete window.Q01_EXPENSE_ID_ATTACK; |
| 458 | delete window.Q01_EXPENSE_HTML_ATTACK; |
| 459 | } |
| 460 | // Read-only adversarial invoice render: unknown imported kinds, invoice IDs, |
| 461 | // number and date must never create active markup or execute row handlers. |
| 462 | const invoiceView=window.InvoicesView; |
| 463 | const originalEditInvoice=invoiceView.editInvoice; |
| 464 | const hostileInvoiceId="inv-test');window.Q01_INVOICE_ID_ATTACK=true;//"; |
| 465 | const injectedKind='<img src=x onerror="window.Q01_INVOICE_HTML_ATTACK=true">'; |
| 466 | let editedInvoiceId=null; |
| 467 | try { |
| 468 | const syntheticInvoices=[{id:hostileInvoiceId,number:injectedKind, |
| 469 | kind:injectedKind,contactName:injectedKind,date:injectedKind, |
| 470 | grandTotal:100,paidAmount:0,remaining:100,status:'unpaid',isPreInvoice:false}]; |
| 471 | const frag=document.createElement('div'); |
| 472 | frag.innerHTML=invoiceView.renderTable(syntheticInvoices); |
| 473 | if(frag.querySelector('img') || frag.querySelector('script') || |
| 474 | !frag.textContent.includes(injectedKind)) { |
| 475 | throw Error('Imported invoice kind or date escaped the safe HTML rendering boundary'); |
| 476 | } |
| 477 | invoiceView.editInvoice=(id)=>{editedInvoiceId=id;}; |
| 478 | const edit=frag.querySelector('button[title="ویرایش"]'); |
| 479 | if(!edit) throw Error('Synthetic invoice edit handler missing'); |
| 480 | edit.click(); |
| 481 | if(editedInvoiceId!==hostileInvoiceId || window.Q01_INVOICE_ID_ATTACK || |
| 482 | window.Q01_INVOICE_HTML_ATTACK) { |
| 483 | throw Error('Imported invoice identifier executed unsafe inline action code'); |
| 484 | } |
| 485 | } finally { |
| 486 | invoiceView.editInvoice=originalEditInvoice; |
| 487 | delete window.Q01_INVOICE_ID_ATTACK; |
| 488 | delete window.Q01_INVOICE_HTML_ATTACK; |
| 489 | } |
| 490 | // Fail-closed Excel replacement attempts must not delete financial master |
| 491 | // records even when callers bypass the UI. Synthetic workbook only. |
| 492 | const beforeProducts=JSON.stringify(await FINORA.Storage.getAll('products')); |
| 493 | const beforeContacts=JSON.stringify(await FINORA.Storage.getAll('contacts')); |
| 494 | for (const mode of ['replace','wipe','unknown']) { |
| 495 | for (const [method, sheet, row] of [ |
| 496 | ['importProducts','کالاها',{'نام':'Q01 non-destructive product'}], |
| 497 | ['importContacts','اشخاص',{'نام':'Q01 non-destructive contact'}] |
| 498 | ]) { |
| 499 | let rejected=false; |
| 500 | try { await window.ExcelController[method]({[sheet]:[row]},{mode}); } |
| 501 | catch(error) { rejected=String(error?.message||'').includes('جایگزینی گروهی'); } |
| 502 | if (!rejected) throw Error('Excel '+method+' accepted unsafe mode: '+mode); |
| 503 | } |
| 504 | } |
| 505 | if (JSON.stringify(await FINORA.Storage.getAll('products'))!==beforeProducts || |
| 506 | JSON.stringify(await FINORA.Storage.getAll('contacts'))!==beforeContacts) { |
| 507 | throw Error('An unsupported Excel mode mutated existing customer or product data'); |
| 508 | } |
| 509 | // A read-only malicious ledger fixture must render all references as text. |
| 510 | const hostileLedgerText='<img src=x onerror="window.Q01_LEDGER_INJECTION=true">'; |
| 511 | const syntheticLedger={finalBalance:0,totalDebit:0,totalCredit:0, |
| 512 | rows:[{date:hostileLedgerText,refNumber:hostileLedgerText, |
| 513 | type:'invoice_sale',typeLabel:hostileLedgerText, |
| 514 | isCheque:false,debit:0,credit:0,balance:0,note:hostileLedgerText}]}; |
| 515 | const syntheticContact={name:hostileLedgerText,nationalId:hostileLedgerText, |
| 516 | entityType:'natural',role:'customer',tags:[]}; |
| 517 | const ledgerScratch=document.createElement('div'); |
| 518 | ledgerScratch.innerHTML=window.ContactLedgerModal._buildBody(syntheticContact,syntheticLedger); |
| 519 | if(ledgerScratch.querySelector('img') || window.Q01_LEDGER_INJECTION || |
| 520 | !ledgerScratch.textContent.includes(hostileLedgerText)) { |
| 521 | throw Error('Financial contact ledger interpreted imported text as executable markup'); |
| 522 | } |
| 523 | delete window.Q01_LEDGER_INJECTION; |
| 524 | // Simulate two rapid clicks on a private workbook preview. No real Excel |
| 525 | // rows are persisted; a canceled preview must never be importable later. |
| 526 | const excel = window.ExcelController; |
| 527 | const settingsView = window.SettingsView; |
| 528 | const originalExcelPreview = excel.previewFile; |
| 529 | const originalExcelImport = excel.importProducts; |
| 530 | let importCount = 0; |
| 531 | try { |
| 532 | excel.previewFile=async()=>({sheets:[{name:'کالاها',count:1}], |
| 533 | raw:{'کالاها':[{'نام':'Synthetic VM-only name'}]}}); |
| 534 | excel.importProducts=async()=>{importCount++;await wait(85);return {added:1,skipped:0};}; |
| 535 | await settingsView._handleImportFile({name:'synthetic-vm-preview.xlsx'},'products'); |
| 536 | const importDialog=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card; |
| 537 | const submit=importDialog?.querySelector('[data-excel-import-submit]'); |
| 538 | if(!submit) throw Error('Synthetic Excel preview import button missing'); |
| 539 | submit.click();submit.click();await wait(160); |
| 540 | if(importCount!==1 || submit.disabled!==true || FINORA.Modal.stack.length || |
| 541 | Object.hasOwn(window,'__importRawData') || Object.hasOwn(window,'__importKind')) { |
| 542 | throw Error('Rapid Excel import clicks wrote twice or exposed a global workbook'); |
| 543 | } |
| 544 | await settingsView._handleImportFile({name:'synthetic-vm-cancel.xlsx'},'products'); |
| 545 | FINORA.Modal.close(); |
| 546 | await settingsView._confirmImport('products'); |
| 547 | document.querySelectorAll('.toast .toast-close').forEach(x=>x.click()); |
| 548 | if(importCount!==1 || FINORA.Modal.stack.length) { |
| 549 | throw Error('Canceled private Excel preview remained importable'); |
| 550 | } |
| 551 | } finally { |
| 552 | excel.previewFile=originalExcelPreview; |
| 553 | excel.importProducts=originalExcelImport; |
| 554 | FINORA.Modal.closeAll(); |
| 555 | document.querySelectorAll('.toast .toast-close').forEach(x=>x.click()); |
| 556 | } |
| 557 | const modalKeyboard={roleAndLabel:true,nestedDialogIsolation:true, |
| 558 | privateExcelPreviewAndSingleFlight:true, |
| 559 | financialLedgerContentEscaped:true, |
| 560 | excelReplacementRejectedWithoutWrites:true, |
| 561 | importedInvoiceHtmlEscaped:true, |
| 562 | expenseUnsafeHtmlEscaped:true, |
| 563 | modalFormLabelsLinked:true, |
| 564 | confirmationTextEscaped:true,visibleInputAutoFocused:true, |
| 565 | escapeClosesWithoutConfirm:true,focusReturnsToTrigger:true, |
| 566 | enterOnFocusedCancelDoesNotSave:true,enterOnInputDoesNotSubmit:true, |
| 567 | tabAndShiftTabStayInsideTopDialog:true, |
| 568 | cancelDoesNotConfirmAndRestoresFocus:true,syntheticConfirmRunsExactlyOnce:true, |
| 569 | staleFinancialConfirmIgnored:true}; |
| 570 | // Notification flood: transient success/info messages should never |
| 571 | // cover the dashboard. Important errors remain until explicitly dismissed. |
| 572 | for(let n=0;n<9;n++) FINORA.Toast.info('Q01 synthetic notice '+n); |
| 573 | const transient=document.querySelectorAll('.toast-success, .toast-info'); |
| 574 | if(transient.length>3)throw Error('transient notifications cover too much of the UI'); |
| 575 | const beforeErrors=document.querySelectorAll('.toast-error').length; |
| 576 | FINORA.Toast.error('Q01 synthetic persistent error'); |
| 577 | if(document.querySelectorAll('.toast-error').length!==beforeErrors+1){ |
| 578 | throw Error('important financial error notification disappeared'); |
| 579 | } |
| 580 | document.querySelectorAll('.toast .toast-close').forEach(button=>button.click()); |
| 581 | const toastResults={transientLimit:3,importantErrorsRemain:true, |
| 582 | dismissButtonsWork:document.querySelectorAll('.toast').length===0}; |
| 583 | await FINORA.Router.go('settings'); |
| 584 | await wait(100); |
| 585 | for(const fieldId of ['invoiceNumberingMode','invoiceNextNumber']){ |
| 586 | const label=document.querySelector('label[for="'+fieldId+'"]'); |
| 587 | const field=document.getElementById(fieldId); |
| 588 | if(!label || !field) throw Error('invoice settings field label missing: '+fieldId); |
| 589 | label.click();await wait(20); |
| 590 | if(document.activeElement!==field) throw Error('clicking settings label did not focus: '+fieldId); |
| 591 | } |
| 592 | await FINORA.Router.go('dashboard'); |
| 593 | const shellResults={keyboardReachableSidebarLinks:navLinks.length, |
| 594 | sidebarCollapseClickAndPersistence:true,themeToggleClickAndPersistence:true, |
| 595 | activeRouteAriaCurrent:true,modalKeyboard,toastResults,settingsLabelFocus:true}; |
| 596 | for (const route of routes) { |
| 597 | await go(route); |
| 598 | const active=[...document.querySelectorAll('#sidebarMenu [aria-current="page"]')]; |
| 599 | if(active.length!==1 || active[0].dataset.page!==route){ |
| 600 | throw Error('active route is not announced to screen readers: '+route); |
| 601 | } |
| 602 | const tabs = inventory(route,'root').filter(el => !el.disabled && safeTab.test(handler(el))); |
| 603 | // Evaluate each known safe top-level tab. The router is reset between |
| 604 | // clicks to avoid mutating references after HTML rerendering. |
| 605 | const tabActions=[...new Set(tabs.map(el=>handler(el)))]; |
| 606 | const contexts=[{section:'root',tabAction:tabActions[0]||null}]; |
| 607 | for (const action of tabActions.slice(1)) contexts.push({section:'tab-'+contexts.length,tabAction:action}); |
| 608 | // Delay filters until all row-scoped edit and confirmation actions have |
| 609 | // been inspected. A filter can hide the very rows needed by later probes. |
| 610 | const deferredSafeActions=[]; |
| 611 | for (const ctx of contexts) { |
| 612 | await go(route); |
| 613 | if (ctx.tabAction) { |
| 614 | const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction); |
| 615 | if (tab) { |
| 616 | inventory(route,'root'); |
| 617 | await press(tab,route,'root','tab'); |
| 618 | } else { |
| 619 | failures.push({route,section:ctx.section,kind:'tab-missing',handler:ctx.tabAction}); |
| 620 | continue; |
| 621 | } |
| 622 | } |
| 623 | const controls=inventory(route,ctx.section); |
| 624 | // For every visible clickable control, check function resolution. This |
| 625 | // inventory includes buttons we must not click indiscriminately. |
| 626 | for (const el of controls) { |
| 627 | const k=sig(el,route,ctx.section),row=all.get(k); |
| 628 | if (!row) continue; |
| 629 | const code=handler(el); |
| 630 | const parsed=resolveHandler(code); |
| 631 | if (parsed.detected && !parsed.valid) { |
| 632 | row.status='broken-handler';row.reason='target function missing'; |
| 633 | failures.push({route,section:ctx.section,kind:'missing-function',callee:parsed.callee}); |
| 634 | } else if (el.disabled) {row.status='disabled';row.reason='disabled state';} |
| 635 | else if (!safeConfirmAction.test(code) && !safeNavigate.test(code) && !safeFilter.test(code) && !safeOpen.test(code) && dangerous.test(code)) { |
| 636 | row.status='not-clicked';row.reason='financial or destructive action needs explicit fixture-backed test'; |
| 637 | } else if (!code) { |
| 638 | row.status='not-clicked';row.reason='dynamic event listener or no inline action; requires focused audit'; |
| 639 | } else if (!safeTab.test(code) && !safeNavigate.test(code) && !safeFilter.test(code) && !safeOpen.test(code) && !safeConfirmAction.test(code)) { |
| 640 | row.status='not-clicked';row.reason='not on audited safe-action allowlist'; |
| 641 | } |
| 642 | } |
| 643 | // Queue safe navigation and filter actions for after all contexts. |
| 644 | const safeActions=[...new Map(controls |
| 645 | .filter(el=>!el.disabled && (safeNavigate.test(handler(el)) || safeFilter.test(handler(el)))) |
| 646 | .map(el=>[sig(el,route,ctx.section),{ |
| 647 | handler:handler(el),label:name(el),tag:el.tagName.toLowerCase() |
| 648 | }])).values()]; |
| 649 | if(safeActions.length) deferredSafeActions.push({ |
| 650 | section:ctx.section,tabAction:ctx.tabAction,actions:safeActions |
| 651 | }); |
| 652 | // Open destructive confirmation prompts, but NEVER approve them here. |
| 653 | // Compare every persistent store before/after Cancel to prove no write. |
| 654 | const confirmStores=['users','companies','contacts','products','units','categories', |
| 655 | 'treasury','invoices','invoice_items','stock_movements','transactions','cheques', |
| 656 | 'expenses','settings','logs','account_chart','fiscal_periods','journal_entries', |
| 657 | 'journal_lines','warehouses','inventory_balances','stocktakes','stocktake_lines', |
| 658 | 'settlements','account_mappings','audit_events','document_corrections']; |
| 659 | const confirmSnapshot=async()=>JSON.stringify(await Promise.all(confirmStores.map(async store=> |
| 660 | [store,await FINORA.Storage.getAll(store)]))); |
| 661 | const confirmActions=[...new Set(controls |
| 662 | .filter(el=>!el.disabled && safeConfirmAction.test(handler(el))) |
| 663 | .map(el=>handler(el)))].slice(0,30); |
| 664 | for(const action of confirmActions){ |
| 665 | window.__Q01_AUDIT_STAGE='confirm-cancel:'+route+':'+action; |
| 666 | await go(route); |
| 667 | if(ctx.tabAction){ |
| 668 | const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction); |
| 669 | if(tab){tab.click();await wait(160);} |
| 670 | } |
| 671 | const el=clickables(target()).find(x=>handler(x)===action); |
| 672 | if(!el){failures.push({route,section:ctx.section,kind:'confirm-action-vanished',handler:action});continue;} |
| 673 | const before=await confirmSnapshot(); |
| 674 | inventory(route,ctx.section); |
| 675 | await press(el,route,ctx.section,'confirm-request'); |
| 676 | const overlay=document.querySelector('.modal-backdrop'); |
| 677 | if(!overlay){ |
| 678 | failures.push({route,section:ctx.section,kind:'confirmation-prompt-missing',handler:action}); |
| 679 | continue; |
| 680 | } |
| 681 | const cancel=clickables(overlay).find(x=> |
| 682 | /FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) || |
| 683 | /^(انصراف|بستن|بازگشت|✕|×)$/.test(name(x))); |
| 684 | if(!cancel){ |
| 685 | failures.push({route,section:ctx.section,kind:'confirmation-cancel-missing',handler:action}); |
| 686 | dismiss();continue; |
| 687 | } |
| 688 | cancel.click();await wait(80); |
| 689 | clicks.push({route,section:ctx.section+'/confirm',category:'confirm-cancel', |
| 690 | label:name(el),handler:action.slice(0,170), |
| 691 | changed:!document.querySelector('.modal-backdrop')}); |
| 692 | if(document.querySelector('.modal-backdrop')){ |
| 693 | failures.push({route,section:ctx.section,kind:'confirmation-cancel-did-not-close',handler:action}); |
| 694 | dismiss(); |
| 695 | } |
| 696 | const after=await confirmSnapshot(); |
| 697 | if(before!==after){ |
| 698 | failures.push({route,section:ctx.section,kind:'cancel-mutated-persistent-data',handler:action}); |
| 699 | } |
| 700 | } |
| 701 | // Open every safe modal/editor visible in this context without saving. |
| 702 | const openActions=[...new Set(controls |
| 703 | .filter(el=>!el.disabled && safeOpen.test(handler(el))) |
| 704 | .map(el=>handler(el)))].slice(0,30); |
| 705 | for (const action of openActions) { |
| 706 | window.__Q01_AUDIT_STAGE='open-modal:'+route+':'+action; |
| 707 | await go(route); |
| 708 | if (ctx.tabAction) { |
| 709 | const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction); |
| 710 | if(tab){tab.click();await wait(160);} |
| 711 | } |
| 712 | const el=clickables(target()).find(x=>handler(x)===action); |
| 713 | if (!el) {failures.push({route,section:ctx.section,kind:'open-action-vanished',handler:action});continue;} |
| 714 | inventory(route,ctx.section); |
| 715 | await press(el,route,ctx.section,'open'); |
| 716 | const overlay=document.querySelector('.modal-backdrop'); |
| 717 | if(overlay) { |
| 718 | const dialog=overlay.querySelector('.modal-card[role="dialog"][aria-modal="true"]'); |
| 719 | if(!dialog || !dialog.getAttribute('aria-labelledby') || |
| 720 | !document.getElementById(dialog.getAttribute('aria-labelledby')) || |
| 721 | !dialog.contains(document.activeElement)){ |
| 722 | failures.push({route,section:ctx.section,kind:'modal-a11y-missing', |
| 723 | handler:action.slice(0,170)}); |
| 724 | } |
| 725 | if (route==='expenses' && action.includes('openExpenseModal()')) { |
| 726 | const real=dialog?.querySelector('#expCategory'); |
| 727 | if (!real || real.labels?.length!==1 || |
| 728 | !real.labels[0].textContent.includes('سرفصل')) { |
| 729 | failures.push({route,section:ctx.section,kind:'expense-category-label-missing'}); |
| 730 | } |
| 731 | } |
| 732 | auditFields(overlay,route,ctx.section+'/modal'); |
| 733 | const nested=clickables(overlay); |
| 734 | const modalControls=nested.map(x=>({ |
| 735 | route,section:ctx.section+'/modal',tag:x.tagName.toLowerCase(), |
| 736 | label:name(x),handler:handler(x).slice(0,180), |
| 737 | disabled:!!x.disabled,hasAccessibleName:!!name(x), |
| 738 | status:'not-clicked',reason:'modal action; untested or requires fixture-backed input' |
| 739 | })); |
| 740 | modalControls.forEach(x=>{ |
| 741 | const key=[x.route,x.section,x.tag,x.label,x.handler].join('|'); |
| 742 | if(!all.has(key))all.set(key,x); |
| 743 | }); |
| 744 | |
| 745 | // Exercise safe nested dialogs inside the parent editor, then close |
| 746 | // only the child. This verifies quick-contact/product and invoice |
| 747 | // preview openers without ever invoking Save or physical Print. |
| 748 | const nestedOpenActions=nested.filter(x=>!x.disabled && |
| 749 | safeOpen.test(handler(x)) && |
| 750 | /_openQuickContact|_openQuickProduct|ProductsView\.openUnitModal|ProductsView\.openCategoryModal|StockKardexModal\.openAdjustModal|InvoicePrint\._preview/.test(handler(x))); |
| 751 | for(const nestedAction of nestedOpenActions){ |
| 752 | const parentDepth=FINORA.Modal.stack.length; |
| 753 | const parentCard=FINORA.Modal.stack.at(-1)?.card; |
| 754 | registerControl(nestedAction,route,ctx.section+'/modal'); |
| 755 | await press(nestedAction,route,ctx.section+'/modal','open'); |
| 756 | await wait(60); |
| 757 | if(FINORA.Modal.stack.length!==parentDepth+1){ |
| 758 | failures.push({route,section:ctx.section,kind:'nested-safe-action-did-not-open-dialog', |
| 759 | handler:handler(nestedAction)}); |
| 760 | continue; |
| 761 | } |
| 762 | const child=FINORA.Modal.stack.at(-1); |
| 763 | const childDialog=child?.card; |
| 764 | if(!childDialog || childDialog.getAttribute('role')!=='dialog' || |
| 765 | childDialog.getAttribute('aria-modal')!=='true' || |
| 766 | !childDialog.contains(document.activeElement)){ |
| 767 | failures.push({route,section:ctx.section,kind:'nested-modal-a11y-missing', |
| 768 | handler:handler(nestedAction)}); |
| 769 | } |
| 770 | auditFields(childDialog,route,ctx.section+'/nested-modal'); |
| 771 | // Inventory every child-dialog action, including save controls |
| 772 | // that are deliberately not clicked in this generic sweep. Their |
| 773 | // positive/negative behavior must be covered by a dedicated |
| 774 | // synthetic workflow or remain explicitly unverified. |
| 775 | const childControls=clickables(childDialog); |
| 776 | childControls.forEach(control=> |
| 777 | registerControl(control,route,ctx.section+'/nested-modal')); |
| 778 | const childCancel=childControls.find(x=> |
| 779 | /FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) || |
| 780 | /^(انصراف|بستن|بستن پنجره|بازگشت|✕|×)$/.test(name(x))); |
| 781 | if(childCancel){ |
| 782 | registerControl(childCancel,route,ctx.section+'/nested-modal'); |
| 783 | await press(childCancel,route,ctx.section+'/nested-modal','open'); |
| 784 | } else { |
| 785 | childDialog?.querySelector('.modal-close')?.click(); |
| 786 | await wait(60); |
| 787 | } |
| 788 | if(FINORA.Modal.stack.length!==parentDepth || |
| 789 | FINORA.Modal.stack.at(-1)?.card!==parentCard){ |
| 790 | failures.push({route,section:ctx.section,kind:'nested-modal-cancel-did-not-restore-parent', |
| 791 | handler:handler(nestedAction)}); |
| 792 | dismiss(); |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | // Exercise invoice draft row operations without persisting them. |
| 797 | const itemsBody=overlay.querySelector('#itemsBody'); |
| 798 | const addRow=nested.find(x=>/InvoiceFormView\._addRow\s*\(/.test(handler(x))); |
| 799 | if(itemsBody && addRow){ |
| 800 | const initialRows=itemsBody.querySelectorAll('tr').length; |
| 801 | registerControl(addRow,route,ctx.section+'/modal'); |
| 802 | await press(addRow,route,ctx.section+'/modal','open'); |
| 803 | // Re-query after the row render so the assertion reads the current |
| 804 | // modal's live table rather than relying on pre-click row children. |
| 805 | const currentItemsBody=overlay.querySelector('#itemsBody'); |
| 806 | const afterAdd=currentItemsBody?.querySelectorAll('tr').length ?? 0; |
| 807 | if(afterAdd!==initialRows+1){ |
| 808 | failures.push({route,section:ctx.section,kind:'invoice-draft-add-row-failed', |
| 809 | initialRows,afterAdd}); |
| 810 | } else { |
| 811 | const lastRow=currentItemsBody.querySelector('tr:last-child'); |
| 812 | const removeLast=clickables(lastRow).find(x=> |
| 813 | /InvoiceFormView\._removeRow\s*\(\d+\)/.test(handler(x))); |
| 814 | if(!removeLast){ |
| 815 | failures.push({route,section:ctx.section,kind:'invoice-draft-remove-new-row-missing'}); |
| 816 | } else { |
| 817 | registerControl(removeLast,route,ctx.section+'/modal'); |
| 818 | await press(removeLast,route,ctx.section+'/modal','open'); |
| 819 | const afterRestore=overlay.querySelector('#itemsBody')?.querySelectorAll('tr').length ?? 0; |
| 820 | if(afterRestore!==initialRows){ |
| 821 | failures.push({route,section:ctx.section,kind:'invoice-draft-row-count-not-restored', |
| 822 | initialRows,afterRestore}); |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | const remainingBody=overlay.querySelector('#itemsBody'); |
| 827 | const remainingFirst=clickables(remainingBody).find(x=> |
| 828 | /InvoiceFormView\._removeRow\(0\)/.test(handler(x))); |
| 829 | if(remainingFirst && remainingBody.querySelectorAll('tr').length===1){ |
| 830 | registerControl(remainingFirst,route,ctx.section+'/modal'); |
| 831 | const beforeGuard=remainingBody.querySelectorAll('tr').length; |
| 832 | await press(remainingFirst,route,ctx.section+'/modal','open'); |
| 833 | const afterGuard=overlay.querySelector('#itemsBody')?.querySelectorAll('tr').length ?? 0; |
| 834 | if(afterGuard!==beforeGuard){ |
| 835 | failures.push({route,section:ctx.section,kind:'invoice-last-row-removal-not-blocked', |
| 836 | beforeGuard,afterGuard}); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | // Adding a contact tag changes only the unsaved form DOM. Verify it, |
| 842 | // then let the parent Cancel discard it; never click Save. |
| 843 | const tagAction=nested.find(x=>/ContactsView\.addNewTag\s*\(/.test(handler(x))); |
| 844 | const tagInput=overlay.querySelector('#newTagInput'); |
| 845 | if(tagAction && tagInput){ |
| 846 | const testTag='Q01-AUDIT-TAG'; |
| 847 | tagInput.value=testTag; |
| 848 | registerControl(tagAction,route,ctx.section+'/modal'); |
| 849 | await press(tagAction,route,ctx.section+'/modal','open'); |
| 850 | if(!overlay.querySelector('.tagCheckbox[value="'+testTag+'"]')){ |
| 851 | failures.push({route,section:ctx.section,kind:'unsaved-contact-tag-not-added'}); |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | // Exercise a real cancel/close button when present. |
| 856 | const cancel=nested.find(x=>/FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) || |
| 857 | /^(انصراف|بستن|بستن پنجره|بازگشت|✕|×)$/.test(name(x))); |
| 858 | if(cancel){ |
| 859 | cancel.click();await wait(70); |
| 860 | clicks.push({route,section:ctx.section+'/modal',category:'cancel', |
| 861 | label:name(cancel),handler:handler(cancel).slice(0,170), |
| 862 | changed:!document.querySelector('.modal-backdrop')}); |
| 863 | const key=[route,ctx.section+'/modal',cancel.tagName.toLowerCase(), |
| 864 | name(cancel),handler(cancel).slice(0,180)].join('|'); |
| 865 | const row=all.get(key);if(row)row.status='clicked'; |
| 866 | } else { |
| 867 | // A modal without a cancel button must still be Esc-dismissable. |
| 868 | document.dispatchEvent(new KeyboardEvent('keydown', |
| 869 | {key:'Escape',bubbles:true,cancelable:true})); |
| 870 | await wait(30); |
| 871 | } |
| 872 | if(document.querySelector('.modal-backdrop')){ |
| 873 | failures.push({route,section:ctx.section,kind:'modal-cannot-close', |
| 874 | handler:action.slice(0,170)}); |
| 875 | } |
| 876 | } |
| 877 | dismiss(); |
| 878 | } |
| 879 | } |
| 880 | // Only now click reversible navigation and filter controls. Keeping this |
| 881 | // after every row-scoped action prevents filters hiding edit/delete targets. |
| 882 | for(const group of deferredSafeActions){ |
| 883 | const pending=[...group.actions]; |
| 884 | const seen=new Set(pending.map(action=>JSON.stringify([ |
| 885 | action.tag,action.label,action.handler |
| 886 | ]))); |
| 887 | for(let index=0;index<pending.length;index++){ |
| 888 | const action=pending[index]; |
| 889 | window.__Q01_AUDIT_STAGE='safe-action:'+route+':'+action.handler; |
| 890 | await go(route); |
| 891 | if(group.tabAction){ |
| 892 | const tab=clickables(target()).find(el=>handler(el)===group.tabAction); |
| 893 | if(!tab){ |
| 894 | failures.push({route,section:group.section,kind:'safe-tab-vanished',handler:group.tabAction}); |
| 895 | continue; |
| 896 | } |
| 897 | inventory(route,'root'); |
| 898 | tab.click();await wait(320); |
| 899 | } |
| 900 | // Rendered labels can legitimately change with live counts and filters. |
| 901 | // Resolve by the stable inline handler + element type, then wait briefly |
| 902 | // for slow IndexedDB-backed tabs to finish rendering in the installed VM. |
| 903 | let el=null; |
| 904 | for(let attempt=0;attempt<12 && !el;attempt++){ |
| 905 | el=clickables(target()).find(x=> |
| 906 | handler(x)===action.handler && x.tagName.toLowerCase()===action.tag); |
| 907 | if(!el) await wait(100); |
| 908 | } |
| 909 | if(!el){ |
| 910 | failures.push({route,section:group.section,kind:'safe-action-vanished', |
| 911 | handler:action.handler,label:action.label}); |
| 912 | continue; |
| 913 | } |
| 914 | inventory(route,group.section); |
| 915 | await press(el,route,group.section, |
| 916 | safeNavigate.test(action.handler)?'navigation':'filter'); |
| 917 | // Preset/toggle controls can reveal a second safe control (for example |
| 918 | // the custom-report Apply button). Discover and verify that state too. |
| 919 | if(safeFilter.test(action.handler)){ |
| 920 | await wait(80); |
| 921 | inventory(route,group.section); |
| 922 | for(const candidate of clickables(target()).filter(x=> |
| 923 | !x.disabled && safeFilter.test(handler(x)))){ |
| 924 | const next={handler:handler(candidate),label:name(candidate), |
| 925 | tag:candidate.tagName.toLowerCase()}; |
| 926 | const key=JSON.stringify([next.tag,next.label,next.handler]); |
| 927 | if(!seen.has(key)){seen.add(key);pending.push(next);} |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | await FINORA.Router.go('dashboard'); |
| 934 | const dashboardGrid=target()?.querySelector('.dash-grid-main'); |
| 935 | if(dashboardGrid && dashboardGrid.scrollWidth>dashboardGrid.clientWidth+1){ |
| 936 | failures.push({route:'dashboard',kind:'responsive-horizontal-overflow', |
| 937 | clientWidth:dashboardGrid.clientWidth,scrollWidth:dashboardGrid.scrollWidth}); |
| 938 | } |
| 939 | await FINORA.Router.go('cheques'); |
| 940 | const chequeScroll=target()?.querySelector('.cheques-table-scroll'); |
| 941 | if(!chequeScroll || chequeScroll.tabIndex!==0 || |
| 942 | chequeScroll.getAttribute('role')!=='region' || |
| 943 | !chequeScroll.getAttribute('aria-label') || |
| 944 | chequeScroll.scrollWidth<=chequeScroll.clientWidth){ |
| 945 | failures.push({route:'cheques',kind:'cheque-table-horizontal-scroll-accessibility', |
| 946 | found:!!chequeScroll,tabIndex:chequeScroll?.tabIndex??-1, |
| 947 | role:chequeScroll?.getAttribute('role')||'', |
| 948 | overflow:!!chequeScroll && chequeScroll.scrollWidth>chequeScroll.clientWidth}); |
| 949 | } else { |
| 950 | chequeScroll.focus(); |
| 951 | if(document.activeElement!==chequeScroll){ |
| 952 | failures.push({route:'cheques',kind:'cheque-table-scroll-not-keyboard-focusable'}); |
| 953 | } |
| 954 | } |
| 955 | const rows=[...all.values()]; |
| 956 | // A route/tab may render the SAME action in multiple UI states. Counting |
| 957 | // each instance as a different button exaggerated the initial denominator. |
| 958 | // Unique action signatures omit the tab-context but retain route, visible |
| 959 | // name, inline handler and element type (including synthetic row IDs). |
| 960 | const uniqueGroups=new Map(); |
| 961 | const actionKey=row=>JSON.stringify([row.route,row.tag,row.label,row.handler]); |
| 962 | for(const row of rows){ |
| 963 | const key=actionKey(row); |
| 964 | if(!uniqueGroups.has(key))uniqueGroups.set(key,[]); |
| 965 | uniqueGroups.get(key).push(row); |
| 966 | } |
| 967 | // A failure on ANY context must never be hidden by a passing click on |
| 968 | // another tab. Fail > broken handler > clicked > disabled > untested. |
| 969 | const statusRank={failed:5,'broken-handler':4,clicked:3,disabled:1,'not-clicked':0}; |
| 970 | const uniqueActions=[...uniqueGroups.values()].map(group=>{ |
| 971 | const representative=group[0]; |
| 972 | const dominant=[...group].sort((a,b)=> |
| 973 | (statusRank[b.status]??0)-(statusRank[a.status]??0))[0]; |
| 974 | for(const occurrence of group){ |
| 975 | if(occurrence.status==='not-clicked' && !occurrence.reason){ |
| 976 | occurrence.reason=group.some(x=>x.status==='clicked') |
| 977 | ?'same-control-clicked-in-another-tab-context' |
| 978 | :'not-reached-or-not-classified-needs-manual-test'; |
| 979 | } |
| 980 | } |
| 981 | return { |
| 982 | route:representative.route,tag:representative.tag, |
| 983 | label:representative.label,handler:representative.handler, |
| 984 | status:dominant.status,contexts:[...new Set(group.map(x=>x.section))], |
| 985 | instances:group.length, |
| 986 | testedInstances:group.filter(x=>x.status==='clicked').length, |
| 987 | failedInstances:group.filter(x=>x.status==='failed' || x.status==='broken-handler').length, |
| 988 | whyNotVerified:dominant.status==='not-clicked' |
| 989 | ?[...new Set(group.map(x=>x.reason))].join('; ').slice(0,300) |
| 990 | :'' |
| 991 | }; |
| 992 | }); |
| 993 | const unclassifiedInstances=rows.filter(r=>r.status==='not-clicked' && |
| 994 | r.reason==='not-reached-or-not-classified-needs-manual-test').length; |
| 995 | const byRoute={}; |
| 996 | for(const route of routes) { |
| 997 | const slice=rows.filter(x=>x.route===route); |
| 998 | byRoute[route]={ |
| 999 | discovered:slice.length, |
| 1000 | uniqueActionSignatures:uniqueActions.filter(x=>x.route===route).length, |
| 1001 | uniqueClicked:uniqueActions.filter(x=>x.route===route && x.status==='clicked').length, |
| 1002 | uniqueNotVerified:uniqueActions.filter(x=>x.route===route && x.status==='not-clicked').length, |
| 1003 | clicked:slice.filter(x=>x.status==='clicked').length, |
| 1004 | notClicked:slice.filter(x=>x.status==='not-clicked').length, |
| 1005 | brokenHandlers:slice.filter(x=>x.status==='broken-handler').length, |
| 1006 | missingAccessibleName:slice.filter(x=>!x.hasAccessibleName).length |
| 1007 | }; |
| 1008 | } |
| 1009 | window.__Q01_AUDIT_STAGE='audit-completed'; |
| 1010 | return { |
| 1011 | environment:'installed-Windows-Tauri-WebView2-synthetic-VM', |
| 1012 | shellResults, |
| 1013 | routesVisited:routes.length,routeNames:routes, |
| 1014 | inventoryCount:rows.length, |
| 1015 | uniqueActionCount:uniqueActions.length, |
| 1016 | uniqueActionClicked:uniqueActions.filter(x=>x.status==='clicked').length, |
| 1017 | uniqueActionUnverified:uniqueActions.filter(x=>x.status==='not-clicked').length, |
| 1018 | uniqueActionDisabled:uniqueActions.filter(x=>x.status==='disabled').length, |
| 1019 | uniqueActionFailed:uniqueActions.filter(x=>x.status==='failed').length, |
| 1020 | unclassifiedInstances, |
| 1021 | duplicateInstanceCount:rows.length-uniqueActions.length, |
| 1022 | safeClickCount:clicks.length, |
| 1023 | skippedCount:rows.filter(x=>x.status==='not-clicked').length, |
| 1024 | brokenHandlerCount:rows.filter(x=>x.status==='broken-handler').length, |
| 1025 | accessibilityNameGaps:rows.filter(x=>!x.hasAccessibleName).length, |
| 1026 | fieldsInspected:fields.size, |
| 1027 | fieldsMissingProgrammaticLabel:[...fields.values()].filter(x=>!x.programmaticLabel).length, |
| 1028 | fieldsWithoutLabels:[...fields.values()].filter(x=>!x.programmaticLabel).slice(0,100), |
| 1029 | fieldCoverageByRoute:Object.fromEntries(routes.map(r=>[r,{ |
| 1030 | inspected:[...fields.values()].filter(x=>x.route===r).length, |
| 1031 | missingProgrammaticLabel:[...fields.values()].filter(x=>x.route===r && !x.programmaticLabel).length |
| 1032 | }])), |
| 1033 | problems:failures, |
| 1034 | byRoute, |
| 1035 | controls:rows, |
| 1036 | uniqueActions, |
| 1037 | clickEvidence:clicks, |
| 1038 | fieldEvidence:[...fields.values()], |
| 1039 | financialActionsNotBulkClicked:true, |
| 1040 | customerDataUsed:false, |
| 1041 | everyActionVerified:false |
| 1042 | }; |
| 1043 | })() |