سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 19:30 UTC
qa/attachment-allocator-two-session-20261122
audit-remediation-wave3-4-20261002
audit-remediation-wave3-verify-20261002
audit-remediation-wave4-20261002
audit-remediation-wave4b-20261002
audit-remediation-wave5a-identity-20261002
audit-remediation-wave5b-offboarding-20261002
audit-remediation-wave5c-authorization-20261002
audit-security-intent-review-20261002
audit/finora-financial-core-20261115
audit/finora-master-prompt-phase0-20261016
audit/finora-stage3-legacy-source-readonly-20261023
audit/full-controls-20261030
audit/owner-live-state-reconcile-20261012
audit/owner-review-20261007
audit/phase1-live-permissions-readonly-20261013
audit/reconcile-live-state-20261006
audit/reconcile-state-20261002
audit/wp0-hardening-baseline-20261102
branding-login-favicon-20261002
c8-workflow-task1
c8-workflow-task2
c8-workflow-task3
chore/wave0-pages-gate-closeout
claude-code-plugins-setup
design/finora-c01-authoritative-source-draft-20261124
docs-wave4b-verified-20261002
docs/active-company-invoice-release-evidence-20261014
docs/agent-operating-model-20261114
docs/chart-taxpayer-release-evidence-20261004
docs/cloud-only-agent-orchestration-20261115
docs/confirm-finora-product-charter-20261115
docs/continuation-20261030
docs/d4a-verified
docs/external-work-review-20261121
docs/finora-audit-continuity-20261014
docs/finora-backup-merge-evidence-20261014
docs/finora-ci-reconciliation-20261122
docs/finora-codex-master-prompt
docs/finora-eight-phase-plan-20261011
docs/finora-f002-live-buyer-filter-verified-20261015
docs/finora-license-race-release-evidence-20261014
docs/finora-license-rollout-acceptance-20261015
docs/finora-phase0-repeat-and-pages-nav-verified-20261015
docs/finora-phase0-repeat-evidence-20261015
docs/finora-selectors-release-and-fixture-qa-20261015
docs/finora-stagea-pr240-ci-triage-20261123
docs/finora-test-license-live-pass-20261015
docs/finora-v2-m01-coverage-20261124
docs/handoff-charter-v2-20261124
docs/invoice-product-search-release-20261011
docs/invoice-workspace-release-20261007
docs/phase-status-20261031
docs/phase0-acceptance-release-evidence-20261012
docs/phase0-admin-provision-release-evidence-20261012
docs/phase0-core-bundle-owner-login-open-20261013
docs/phase0-duplicate-js-release-20261016
docs/phase0-f001-auth-rest-shared-timeout-20261013
docs/phase0-f001-owner-login-observed-20261013
docs/phase0-f001-second-device-fail-40s-20261013
docs/phase0-f003-release-verification-20261011
docs/phase0-f004-print-release-evidence-20261012
docs/phase0-f004-watermark-release-evidence-20261012
docs/phase0-f005-large-selector-release-20261012
docs/phase0-f005-release-evidence-20261012
docs/phase0-f006-dark-release-evidence-20261012
docs/phase0-f008-final-pr-closure-evidence-20261012
docs/phase0-f008-reconcile-stale-prs-20261012
docs/phase0-f107-production-evidence-20261012
docs/phase0-kavenegar-otp-preflight-release-20261012
docs/phase0-login-release-evidence-20261012
docs/phase0-login-rest-bootstrap-stage-release-20261012
docs/phase0-owner-app-assets-bundle-release-20261013
docs/phase0-owner-login-csp-release-20261012
docs/phase0-reconcile-postmerge-evidence-20261012
docs/phase0-site-probe-release-evidence-20261012
docs/phase0-startup-release-evidence-20261012
docs/phase3-treasury-release-evidence-20261014
docs/pilot-posted-correction-release-evidence-20261014
docs/pilot-purchase-correction-release-evidence-20261014
docs/print-persian-release-verification-20261011
docs/qa-ci-triage-218-20261122
docs/real-account-qa-20261030
docs/release-state-20261007
docs/seamless-amendment-release-20261014
docs/seamless-document-correction-release-20261014
docs/settings-login-release-20261025
docs/stripe-qa-deployment-evidence-20261011
docs/ux-f2-release-evidence-20261011
docs/ux-f2-release-verification-20261011
docs/wave0-closeout
docs/wave2-closeout
exec-phase1-architecture
exec-phase1-implementation
exec-phase1-qa
exec-phase1-security-release
exec-phase1-ux
feat/accounting-document-draft-approval-20261011
feat/accounting-document-release-candidate-20261011
feat/active-company-strict-isolation-20261014
feat/admin-provisioning-reconciled-20261011
feat/admin-secure-user-provisioning-20261011
feat/admin-user-provisioning-merged-20261011
feat/d4a-request-work-queue
feat/document-lifecycle-atf-20261118
feat/document-lifecycle-temp-permanent-atef
feat/draft-first-attachment-lifecycle-216
feat/finora-offline-encrypted-backup-20261014
feat/finora-phase-a-navigation-20261023
feat/finora-stripe-sandbox-edge-gate
feat/immutable-attachment-temporary-vouchers
feat/iran-accounting-design-audit
feat/journal-document-lifecycle-20261118
feat/journal-rpc-repository-adapter-20261117
feat/office-c7-fulltext-ocr-provenance
feat/password-recovery-admin-reset-20261025
feat/pilot-expense-income-inplace-amendment-20261014
feat/pilot-journal-invoice-correction-20261014
feat/pilot-purchase-correction-20261014
feat/pilot-treasury-unallocated-correction-20261014
feat/retain-document-editor-after-save-20261014
feat/seamless-financial-document-correction-20261014
feat/slice-b-tenant-rbac
feat/stripe-sandbox-invoice-probe
feature/accounting-core-p0
feature/accounting-product-guidance
feature/admin-identity-phone-auth
feature/commercial-rnd
feature/finora-phase1a-supabase-cli-20261016
feature/finora-stage2-manual-canary-20261017
feature/finora-stage3-commercial-payload-20261023
feature/finora-stage3-enforce-invoice-rpc-20261023
feature/finora-stage3-enforce-purchase-red-20261023
feature/invoice-workspace-cleanup
feature/phase0-kavenegar-otp-preflight-20261012
feature/ux-commerce-settings-r2
fix-shell-scroll-live-cache-20261002
fix-shell-scrollbar-explicit-ownership-20261002
fix-shell-scrollbar-ownership-20261002
fix-shell-scrollbar-right-edge-20261002
fix/about-bug-report-20261114
fix/active-company-invoice-scope-20261014
fix/active-company-isolation-reconcile-20261014
fix/admin-central-password-reset-20261028
fix/auth-network-diagnostics
fix/chart-taxpayer-reference-20261003
fix/combobox-enter-reliability
fix/combobox-live-search
fix/combobox-production-cache
fix/combobox-release-asset-v2
fix/company-edit-action-20261028
fix/company-edit-pilot-delete-20261014
fix/company-form-action-state-20261014
fix/company-form-action-state-rebased-20261014
fix/contact-operational-balance-20261111
fix/dark-theme-contrast
fix/financial-lifecycle-recovery-20261124
fix/finora-accounting-test-organization-readiness-20261015
fix/finora-b01-safe-org-switch-20261124
fix/finora-b02-sync-recovery-20261124
fix/finora-b03-conflict-review-20261124
fix/finora-org-license-bootstrap-race-20261014
fix/finora-stage3-posted-source-immutable-20261023
fix/finora-v2-b03-r2-qa-20261124
fix/finora-v2-b03-r3-readonly-20261124
fix/g01-asof-financial-position-20261128
fix/invoice-product-search-rehydrate-20261011
fix/invoice-search-cache-bust
fix/issue229-linked-draft-status-20261122
fix/login-assets-retry-20261014
fix/login-inert-startup-20261110
fix/login-member-access-20261101
fix/login-resilience-20261017
fix/login-short-viewport-20261028
fix/login-startup-readiness-20261024
fix/navigation-utilities-placement-20261105
fix/office-c7-source-ref-binding
fix/office-c7-source-ref-binding-v2
fix/owner-login-network-20261026
fix/password-recovery-invalid-cancel-20261026
fix/payment-amount-format-20261111
fix/phase0-admin-provision-seat-bootstrap-20261012
fix/phase0-auth-bundled-assets-for-unstable-isp-20261013
fix/phase0-auth-handler-binding-stalled-session-20261012
fix/phase0-login-context-stage-visibility-20261012
fix/phase0-login-single-local-bundle-20261013
fix/phase0-login-site-probe-clarity-20261012
fix/phase0-login-ui-ready-20261012
fix/phase0-modal-dashboard-drill-20261011
fix/phase0-pages-blocking-core-bundles-20261013
fix/phase0-print-no-draft-watermark-20261012
fix/phase0-startup-parallel-asset-load-20261012
fix/phase3-behavioral-verification
fix/preserve-pending-edits-20261121
fix/print-persian-digit-consistency-20261011
fix/recovery-login-startup-20261027
fix/report-opening-balance-release-20261130
fix/settings-checkbox-persistence-20261024
fix/taxpayer-arithmetic-20261004
fix/ux-keyboard-search-f2-20261011
fix/wave2-request-input-integrity
hardening/c01-source-draft-20261129
hardening/global-draft-conversion-20261113
hardening/wp1-ledger-integrity-20261102
integration/finora-execution-20261124
integration/issue229-ui-qa-20261122
integration/wp1-ledger-core-20261115
integration/wp2-manual-journal-rpc-20261116
main
ops-heartbeat-v2-20261002
ops-progress-heartbeat-rule-20261002
ops/wave4-production-20261003
plan/financial-core-phase1-approval-20261016
qa/attachment-allocator-two-session-20261122
qa/draft-first-save-red-evidence-20261122
qa/finora-autopost-retry-identity-red-20261122
qa/finora-identity-rpc-security-tripwire-20261122
qa/finora-issue223-manual-kardex-browser-red-20261123
qa/finora-issue223-stock-real-jwt-20261123
qa/finora-issue238-inventory-count-browser-red-20261123
qa/finora-issue238-save-browser-red-20261122
qa/finora-login-cors-header-preflight-20261025
qa/finora-phase0-saved-session-repeat-20261015
qa/finora-phase5-posted-insert-jwt-red-20261123
qa/finora-stage3-ui-jwt-autopost-20261023
qa/finora-v2-g01-report-reconciliation-20261125
qa/free-supabase-local-wp2-20261116
qa/issue229-approval-boundary-jwt-20261122
qa/issue229-sale-save-linked-draft-red-20261122
qa/phase0-acceptance-start-20261012
qa/phase0-f005-account-project-contract-stress-20261012
qa/phase0-f005-selector-stress-20261012
qa/phase0-f006-dark-contrast-20261012
qa/post-wave4-verification-20261003
qa/posted-source-immutable-jwt-20261122
qa/pr219-wp1-disposable-dburl-proof-20261123
qa/purchase-source-jwt-20261122
qa/real-settings-acceptance-20261025
qa/recovery-mail-acceptance-20261026
qa/source-autopost-jwt-atomicity-20261122
qa/wave0-negative-gate-proof
qa/wp2-auth-tenant-e2e-20261117
qa/wp2-authorized-journal-write-20261122
qa/wp2-financial-paths-reconciliation-20261122
qa/wp3-financial-tenant-isolation-20261117
remediation/wave0-liveqa-wave1
remediation/wave2-request-integrity
staging/finora-stage22-free-20261022
state-scroll-verified-20261002
state-wave4b-production-20261002
state-wave5a-production-20261002
test/finora-accounting-boot-readiness-20261015
test/finora-f0-02-production-selectors-20261015
test/finora-pages-commerce-event-wiring-20261015
test/finora-pages-invoice-selectors-readonly-20261015
test/finora-stage3-jwt-source-post-20261023
test/phase0-invoice-fixture-bootstrap-20261016
test/phase0-invoice-persistence-20261011
test/phase0-pages-delayed-dispatcher-20261016
ux-scroll-ownership-20261002
work/finora-stage3-enforce-purchase-green-20261023
work/finora-stage3-enforce-sale-green-20261023
work/finora-stage3-payload-green-20261023
| 1 | const {test,expect}=require('@playwright/test'); |
| 2 | const BASE=process.env.FINORA_LOGIN_PAGES_BASE||'http://127.0.0.1:4173/_site/index.html'; |
| 3 | |
| 4 | async function syntheticLogin(page,{restoreSession=false,holdSessionCheck=false}={}){ |
| 5 | // Patch transport before core.js calls createClient; initAuthSystem, the CSP |
| 6 | // handlers, organization hydration and records loading remain the real code. |
| 7 | await page.addInitScript(({restoreSession,holdSessionCheck})=>{ |
| 8 | const fixture=window.finoraLoginFixture={passwordCalls:0,profileReads:[],recordReads:0,writes:0}; |
| 9 | const sessionCheck=holdSessionCheck?new Promise(resolve=>{window.finoraReleaseSessionCheck=resolve;}):Promise.resolve(); |
| 10 | let sdk; |
| 11 | Object.defineProperty(window,'supabase',{ |
| 12 | configurable:true, |
| 13 | get(){return sdk;}, |
| 14 | set(value){ |
| 15 | sdk=value; |
| 16 | const create=value.createClient; |
| 17 | value.createClient=function(...args){ |
| 18 | const client=create.apply(this,args); |
| 19 | client.auth.getSession=async()=>{ |
| 20 | await sessionCheck; |
| 21 | return {data:{session:restoreSession?{user:{id:'fixture-restored'}}:null},error:null}; |
| 22 | }; |
| 23 | client.auth.signInWithPassword=async()=>{ |
| 24 | fixture.passwordCalls++; |
| 25 | return {data:{user:{id:'fixture-password'}},error:null}; |
| 26 | }; |
| 27 | client.rpc=async()=>{fixture.writes++;throw new Error('Unexpected fixture write');}; |
| 28 | client.from=table=>{ |
| 29 | const filters={}; |
| 30 | let single=false; |
| 31 | const query={ |
| 32 | select(){return this;},in(){return this;},order(){return this;},range(){return this;},abortSignal(){return this;}, |
| 33 | eq(key,value){filters[key]=value;return this;}, |
| 34 | single(){single=true;return this;}, |
| 35 | then(resolve){ |
| 36 | const uid=filters.id||filters.user_id||'fixture-password'; |
| 37 | let rows=[]; |
| 38 | if(table==='profiles'){ |
| 39 | fixture.profileReads.push(uid); |
| 40 | rows=[{id:uid,email:'fixture@example.test',full_name:'Synthetic Login',role:'accountant'}]; |
| 41 | }else if(table==='organization_members'){ |
| 42 | rows=[{id:'fixture-membership',user_id:uid,organization_id:'fixture-org',status:'active',is_owner:true}]; |
| 43 | }else if(table==='organizations'){ |
| 44 | rows=[{id:'fixture-org',name:'Synthetic Company',status:'active'}]; |
| 45 | }else if(table==='licenses'){ |
| 46 | rows=[{organization_id:'fixture-org',plan:'lifetime',status:'active',starts_at:'2026-01-01',ends_at:'2099-01-01',modules:['full_suite'],max_companies:5,max_users:5}]; |
| 47 | }else if(table==='records')fixture.recordReads++; |
| 48 | return Promise.resolve(resolve({data:single?rows[0]:rows,error:null})); |
| 49 | } |
| 50 | }; |
| 51 | return query; |
| 52 | }; |
| 53 | return client; |
| 54 | }; |
| 55 | } |
| 56 | }); |
| 57 | },{restoreSession,holdSessionCheck}); |
| 58 | // Defense in depth: a fixture must never send credentials or read a real tenant. |
| 59 | await page.route('https://*.supabase.co/**',route=>route.abort('blockedbyclient')); |
| 60 | await page.route('https://cdn.jsdelivr.net/**',route=>route.abort('blockedbyclient')); |
| 61 | await page.route('https://cdnjs.cloudflare.com/**',route=>route.abort('blockedbyclient')); |
| 62 | page.on('dialog',dialog=>dialog.dismiss()); |
| 63 | } |
| 64 | |
| 65 | async function holdBundle(page,name){ |
| 66 | let release,arrived; |
| 67 | const held=new Promise(resolve=>{release=resolve;}); |
| 68 | const requested=new Promise(resolve=>{arrived=resolve;}); |
| 69 | await page.route('**/js/finora-pages-'+name+'.js*',async route=>{ |
| 70 | arrived(); |
| 71 | await held; |
| 72 | await route.continue(); |
| 73 | }); |
| 74 | return {release,requested}; |
| 75 | } |
| 76 | |
| 77 | async function submitPassword(page){ |
| 78 | await page.locator('#auth-email').fill('fixture@example.test'); |
| 79 | await page.locator('#auth-password').fill('synthetic-password-only'); |
| 80 | await page.locator('#auth-login-button').click({noWaitAfter:true}); |
| 81 | } |
| 82 | |
| 83 | test('Pages login does not wait for a separate recovery script download',async({page})=>{ |
| 84 | await syntheticLogin(page); |
| 85 | let release; |
| 86 | const held=new Promise(resolve=>{release=resolve;}); |
| 87 | const recoveryRequests=[]; |
| 88 | await page.route('**/js/password-recovery.js*',async route=>{ |
| 89 | recoveryRequests.push(route.request().url()); |
| 90 | await held; |
| 91 | await route.continue().catch(()=>{}); |
| 92 | }); |
| 93 | try{ |
| 94 | await page.goto(BASE,{waitUntil:'commit'}); |
| 95 | await expect(page.locator('#auth-login-button')).toBeEnabled({timeout:2500}); |
| 96 | expect(await page.evaluate(()=>({ |
| 97 | bound:window.FinoraLoginActionsBound, |
| 98 | ready:window.FinoraStartupStatus?.authFormReady, |
| 99 | recovery:typeof window.finoraRequestPasswordRecovery, |
| 100 | active:window.FinoraPasswordRecovery?.active |
| 101 | }))).toEqual({bound:true,ready:true,recovery:'function',active:false}); |
| 102 | await submitPassword(page); |
| 103 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 104 | expect(await page.evaluate(()=>({user:currentUser?.id,...window.finoraLoginFixture}))) |
| 105 | .toEqual({user:'fixture-password',passwordCalls:1,profileReads:['fixture-password'],recordReads:1,writes:0}); |
| 106 | expect(recoveryRequests).toEqual([]); |
| 107 | }finally{release();} |
| 108 | }); |
| 109 | |
| 110 | test('Pages preload and execute one core URL versioned from its complete auth content',async({page,request})=>{ |
| 111 | await syntheticLogin(page); |
| 112 | const coreRequests=[]; |
| 113 | page.on('request',req=>{if(new URL(req.url()).pathname.endsWith('/core.js'))coreRequests.push(req.url());}); |
| 114 | await page.goto(BASE,{waitUntil:'domcontentloaded'}); |
| 115 | const urls=await page.evaluate(()=>({ |
| 116 | preload:document.querySelector('link[rel="preload"][href*="/core.js"]')?.href, |
| 117 | script:document.querySelector('script[src*="/core.js"]')?.src |
| 118 | })); |
| 119 | expect(urls.preload).toBe(urls.script); |
| 120 | const response=await request.get(urls.script); |
| 121 | expect(response.ok()).toBe(true); |
| 122 | const hash=require('node:crypto').createHash('sha256').update(await response.body()).digest('hex').slice(0,16); |
| 123 | expect(new URL(urls.script).searchParams.get('v')).toBe(hash); |
| 124 | expect(coreRequests).toEqual([urls.script]); |
| 125 | }); |
| 126 | |
| 127 | test('Pages static button handlers have a content version for their DOM order',async({page,request})=>{ |
| 128 | await syntheticLogin(page); |
| 129 | await page.goto(BASE,{waitUntil:'domcontentloaded'}); |
| 130 | const url=await page.locator('script[src*="generated-event-handlers.js"]').evaluate(el=>el.src); |
| 131 | const response=await request.get(url); |
| 132 | expect(response.ok()).toBe(true); |
| 133 | const hash=require('node:crypto').createHash('sha256').update(await response.body()).digest('hex').slice(0,16); |
| 134 | expect(new URL(url).searchParams.get('v')).toBe(hash); |
| 135 | await submitPassword(page); |
| 136 | await expect(page.locator('#auth-screen')).toBeHidden(); |
| 137 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(1); |
| 138 | }); |
| 139 | |
| 140 | for(const bundle of ['business','accounting']){ |
| 141 | test('early successful Pages login survives a slow '+bundle+' bundle before company-read timeout starts',async({page})=>{ |
| 142 | await syntheticLogin(page); |
| 143 | await page.clock.install(); |
| 144 | const asset=await holdBundle(page,bundle); |
| 145 | await page.goto(BASE,{waitUntil:'commit'}); |
| 146 | await asset.requested; |
| 147 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 148 | expect(await page.evaluate(()=>document.readyState)).toBe('loading'); |
| 149 | await submitPassword(page); |
| 150 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','loading'); |
| 151 | // The credentials have already succeeded. A slow local ERP download must |
| 152 | // not consume the separate 25-second account/data-read deadline. |
| 153 | await page.clock.fastForward(26000); |
| 154 | expect(await page.evaluate(()=>({ |
| 155 | status:document.getElementById('auth-login-status').dataset.state, |
| 156 | profileReads:window.finoraLoginFixture.profileReads, |
| 157 | user:currentUser |
| 158 | }))).toEqual({status:'loading',profileReads:[],user:null}); |
| 159 | await expect(page.locator('#auth-screen')).toBeVisible(); |
| 160 | asset.release(); |
| 161 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 162 | expect(await page.evaluate(()=>({ |
| 163 | user:currentUser?.id, |
| 164 | organization:currentUser?.organizationId, |
| 165 | license:currentUser?.subscription?.type, |
| 166 | ...window.finoraLoginFixture |
| 167 | }))).toEqual({user:'fixture-password',organization:'fixture-org',license:'lifetime',passwordCalls:1,profileReads:['fixture-password'],recordReads:1,writes:0}); |
| 168 | }); |
| 169 | } |
| 170 | |
| 171 | test('stalled Pages assets expire visibly without late entry and a fresh click recovers after download',async({page})=>{ |
| 172 | await syntheticLogin(page); |
| 173 | await page.clock.install(); |
| 174 | const asset=await holdBundle(page,'accounting'); |
| 175 | await page.goto(BASE,{waitUntil:'commit'}); |
| 176 | await asset.requested; |
| 177 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 178 | await submitPassword(page); |
| 179 | await page.clock.fastForward(46000); |
| 180 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','error'); |
| 181 | await expect(page.locator('#auth-login-status')).toContainText('BOOT_APP_ASSETS'); |
| 182 | expect(await page.evaluate(()=>({user:currentUser,profileReads:window.finoraLoginFixture.profileReads}))) |
| 183 | .toEqual({user:null,profileReads:[]}); |
| 184 | asset.release(); |
| 185 | await expect.poll(()=>page.evaluate(()=>window.FinoraStartupStatus?.extensionsReady),{timeout:15000}).toBe(true); |
| 186 | await expect(page.locator('#auth-screen')).toBeVisible(); |
| 187 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','error'); |
| 188 | expect(await page.evaluate(()=>window.finoraLoginFixture.profileReads)).toEqual([]); |
| 189 | await submitPassword(page); |
| 190 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 191 | expect(await page.evaluate(()=>({user:currentUser?.id,...window.finoraLoginFixture}))) |
| 192 | .toEqual({user:'fixture-password',passwordCalls:2,profileReads:['fixture-password'],recordReads:1,writes:0}); |
| 193 | }); |
| 194 | |
| 195 | test('cached-session restoration owns the login attempt while early password clicks are ignored',async({page})=>{ |
| 196 | await syntheticLogin(page,{restoreSession:true}); |
| 197 | const asset=await holdBundle(page,'accounting'); |
| 198 | await page.goto(BASE,{waitUntil:'commit'}); |
| 199 | await asset.requested; |
| 200 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 201 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','loading'); |
| 202 | await submitPassword(page); |
| 203 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(0); |
| 204 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','busy'); |
| 205 | asset.release(); |
| 206 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 207 | expect(await page.evaluate(()=>({user:currentUser?.id,...window.finoraLoginFixture}))) |
| 208 | .toEqual({user:'fixture-restored',passwordCalls:0,profileReads:['fixture-restored'],recordReads:1,writes:0}); |
| 209 | }); |
| 210 | |
| 211 | test('early password click waits for the pending initial session check then continues once without another click',async({page})=>{ |
| 212 | await syntheticLogin(page,{restoreSession:true,holdSessionCheck:true}); |
| 213 | await page.goto(BASE,{waitUntil:'domcontentloaded'}); |
| 214 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 215 | await submitPassword(page); |
| 216 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(0); |
| 217 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','loading'); |
| 218 | expect(await page.evaluate(()=>({user:currentUser,profileReads:window.finoraLoginFixture.profileReads}))) |
| 219 | .toEqual({user:null,profileReads:[]}); |
| 220 | await page.evaluate(()=>window.finoraReleaseSessionCheck()); |
| 221 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 222 | expect(await page.evaluate(()=>({user:currentUser?.id,...window.finoraLoginFixture}))) |
| 223 | .toEqual({user:'fixture-password',passwordCalls:1,profileReads:['fixture-password'],recordReads:1,writes:0}); |
| 224 | }); |
| 225 | |
| 226 | test('Pages downloads its pinned extension bundle before slow accounting finishes and executes it once',async({page})=>{ |
| 227 | await syntheticLogin(page); |
| 228 | const requested=[]; |
| 229 | page.on('request',request=>{ |
| 230 | if(new URL(request.url()).pathname.endsWith('/finora-extension-bundle.js'))requested.push(request.url()); |
| 231 | }); |
| 232 | await page.route('**/js/finora-extension-bundle.js*',async route=>{ |
| 233 | const response=await route.fetch(); |
| 234 | await route.fulfill({response,body:await response.text()+'\n;window.finoraFixtureBundleExecutions=(window.finoraFixtureBundleExecutions||0)+1;'}); |
| 235 | }); |
| 236 | const asset=await holdBundle(page,'accounting'); |
| 237 | await page.goto(BASE,{waitUntil:'commit'}); |
| 238 | await asset.requested; |
| 239 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 240 | expect(await page.evaluate(()=>document.readyState)).toBe('loading'); |
| 241 | await expect.poll(()=>requested.length,{timeout:1500}).toBe(1); |
| 242 | expect(requested[0]).toMatch(/finora-extension-bundle\.js\?v=[0-9a-f]{16}$/); |
| 243 | expect(await page.evaluate(()=>window.finoraFixtureBundleExecutions||0)).toBe(0); |
| 244 | asset.release(); |
| 245 | await expect.poll(()=>page.evaluate(()=>window.FinoraStartupStatus?.extensionsReady),{timeout:15000}).toBe(true); |
| 246 | expect(await page.evaluate(()=>({ |
| 247 | executions:window.finoraFixtureBundleExecutions, |
| 248 | failures:window.FinoraStartupStatus.failedExtensionCount, |
| 249 | scripts:document.querySelectorAll('script[src*="finora-extension-bundle.js"]').length |
| 250 | }))).toEqual({executions:1,failures:0,scripts:1}); |
| 251 | expect(requested).toHaveLength(1); |
| 252 | }); |
| 253 | |
| 254 | test('early successful credentials cannot open the workspace when a required Pages bundle fails',async({page})=>{ |
| 255 | await syntheticLogin(page); |
| 256 | let release; |
| 257 | const held=new Promise(resolve=>{release=resolve;}); |
| 258 | await page.route('**/js/finora-pages-accounting.js*',async route=>{await held;await route.abort('failed');}); |
| 259 | await page.goto(BASE,{waitUntil:'commit'}); |
| 260 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 261 | await submitPassword(page); |
| 262 | release(); |
| 263 | await expect(page.locator('#auth-login-status')).toContainText('BOOT_APP_ASSETS_FAILED',{timeout:15000}); |
| 264 | await expect(page.locator('#auth-screen')).toBeVisible(); |
| 265 | expect(await page.evaluate(()=>({user:currentUser,writes:window.finoraLoginFixture.writes}))).toEqual({user:null,writes:0}); |
| 266 | }); |
| 267 | |
| 268 | test('Pages login survives an unavailable standalone SDK asset',async({page})=>{ |
| 269 | await syntheticLogin(page); |
| 270 | await page.route('**/vendor/supabase.js*',r=>r.abort('failed')); |
| 271 | await page.goto(BASE,{waitUntil:'domcontentloaded'}); |
| 272 | await expect(page.locator('#auth-login-button')).toBeEnabled({timeout:2500}); |
| 273 | await expect(page.locator('#auth-reload-page')).toBeHidden(); |
| 274 | await submitPassword(page); |
| 275 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 276 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(1); |
| 277 | }); |
| 278 | for(const asset of ['core','generated-event-handlers'])test('Pages '+asset+' failure leaves independent diagnostics and a truthful recovery action',async({page})=>{ |
| 279 | await syntheticLogin(page); |
| 280 | await page.route('**/js/'+asset+'.js*',r=>r.abort('failed')); |
| 281 | await page.goto(BASE,{waitUntil:'domcontentloaded'}); |
| 282 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','error',{timeout:8000}); |
| 283 | await expect(page.locator('#auth-login-status')).toContainText(/LOGIN_.*(?:FAILED|TIMEOUT)/); |
| 284 | await expect(page.locator('#auth-login-button')).toBeDisabled(); |
| 285 | await expect(page.locator('#auth-connectivity-check')).toBeEnabled(); |
| 286 | await expect(page.locator('#auth-reload-page')).toBeVisible(); |
| 287 | await page.locator('#auth-connectivity-check').click(); |
| 288 | await expect(page.locator('#auth-connectivity-result')).toHaveAttribute('data-status',asset==='core'?'site-error':'auth-unreachable',{timeout:15000}); |
| 289 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(0); |
| 290 | await page.unroute('**/js/'+asset+'.js*'); |
| 291 | await Promise.all([page.waitForNavigation({waitUntil:'domcontentloaded'}),page.locator('#auth-reload-page').click()]); |
| 292 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 293 | await expect(page.locator('#auth-reload-page')).toBeHidden(); |
| 294 | await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','ready'); |
| 295 | }); |
| 296 | |
| 297 | test('delayed Auth bundle gives bounded feedback and recovers without losing typed input',async({page})=>{ |
| 298 | await syntheticLogin(page); |
| 299 | let release;const held=new Promise(resolve=>{release=resolve}); |
| 300 | await page.route('**/js/core.js*',async route=>{await held;await route.continue().catch(()=>{})}); |
| 301 | try{ |
| 302 | await page.goto(BASE,{waitUntil:'commit'}); |
| 303 | await page.locator('#auth-email').fill('fixture@example.test'); |
| 304 | await page.locator('#auth-password').fill('synthetic-password-only'); |
| 305 | await expect(page.locator('#auth-login-status')).toContainText('LOGIN_BOOTSTRAP_TIMEOUT',{timeout:9000}); |
| 306 | await expect(page.locator('#auth-connectivity-check')).toBeEnabled(); |
| 307 | await expect(page.locator('#auth-login-button')).toBeDisabled(); |
| 308 | release(); |
| 309 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 310 | await expect(page.locator('#auth-reload-page')).toBeHidden(); |
| 311 | await expect(page.locator('#auth-email')).toHaveValue('fixture@example.test'); |
| 312 | await expect(page.locator('#auth-password')).toHaveValue('synthetic-password-only'); |
| 313 | await page.locator('#auth-login-button').click(); |
| 314 | await expect(page.locator('#auth-screen')).toBeHidden({timeout:15000}); |
| 315 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(1); |
| 316 | }finally{release()} |
| 317 | }); |
| 318 | |
| 319 | for(const viewport of [{width:390,height:844},{width:1440,height:900},{width:1280,height:720}]){ |
| 320 | test('healthy login hides recovery action at '+viewport.width+'x'+viewport.height,async({page})=>{ |
| 321 | await page.setViewportSize(viewport); |
| 322 | await syntheticLogin(page); |
| 323 | await page.goto(BASE,{waitUntil:'domcontentloaded'}); |
| 324 | await expect(page.locator('#auth-login-button')).toBeEnabled(); |
| 325 | await expect(page.locator('#auth-reload-page')).toBeHidden(); |
| 326 | }); |
| 327 | } |
| 328 | |
| 329 | test('bootstrap reload preserves recovery callback until recovery code can consume it',async({page})=>{ |
| 330 | await syntheticLogin(page); |
| 331 | await page.addInitScript(()=>{window.finoraInitialCallback={hash:location.hash,search:location.search};}); |
| 332 | await page.route('**/js/core.js*',r=>r.abort('failed')); |
| 333 | const url=new URL(BASE); |
| 334 | url.search='?finora_recovery=1'; |
| 335 | url.hash='type=recovery&access_token=SYNTHETIC_ONLY&refresh_token=SYNTHETIC_ONLY'; |
| 336 | await page.goto(url.href,{waitUntil:'domcontentloaded'}); |
| 337 | await expect(page.locator('#auth-reload-page')).toBeVisible(); |
| 338 | await page.unroute('**/js/core.js*'); |
| 339 | await Promise.all([page.waitForNavigation({waitUntil:'domcontentloaded'}),page.locator('#auth-reload-page').click()]); |
| 340 | expect(await page.evaluate(()=>window.finoraInitialCallback)).toEqual({hash:url.hash,search:url.search}); |
| 341 | // The independently loaded recovery sanitizer still removes credentials. |
| 342 | expect(new URL(page.url()).hash).toBe(''); |
| 343 | expect(await page.evaluate(()=>window.finoraLoginFixture.passwordCalls)).toBe(0); |
| 344 | }); |
| 345 | |
| 346 | test('diagnostics use the versioned core preload while button handlers are pending',async({page})=>{ |
| 347 | await syntheticLogin(page); |
| 348 | let release;const held=new Promise(resolve=>{release=resolve;}); |
| 349 | await page.route('**/js/generated-event-handlers.js*',async route=>{await held;await route.continue().catch(()=>{});}); |
| 350 | const probes=[]; |
| 351 | page.on('request',req=>{const u=new URL(req.url());if(u.pathname.endsWith('/core.js')&&u.searchParams.has('finora_diag'))probes.push(u);}); |
| 352 | try{ |
| 353 | await page.goto(BASE,{waitUntil:'commit'}); |
| 354 | await expect(page.locator('#auth-connectivity-check')).toBeEnabled(); |
| 355 | expect(await page.locator('script[src*="js/core.js"]').count()).toBe(0); |
| 356 | const preload=new URL(await page.locator('link[rel="preload"][href*="js/core.js"]').getAttribute('href'),BASE); |
| 357 | await page.locator('#auth-connectivity-check').click(); |
| 358 | await expect(page.locator('#auth-connectivity-result')).toHaveAttribute('data-status','auth-unreachable'); |
| 359 | expect(probes).toHaveLength(1); |
| 360 | expect(probes[0].searchParams.get('v')).toBe(preload.searchParams.get('v')); |
| 361 | expect(preload.searchParams.get('v')).toMatch(/^[a-f0-9]{16}$/); |
| 362 | }finally{release();} |
| 363 | }); |