سامانه صدور فاکتور و حسابداری

Fix cancel after immediately rejected recovery links

davoodmehraban89 committed Oct 26, 2026 at 02:48 UTC 102c0c67e1b2d5e3a9976a88b478df92bd1a8673
4 files changed +41 -3
PROJECT_STATE.md
+13
@@ -106,3 +106,16 @@
106 - **Bounded real-browser integration attempt:** TinyFish run f55d8aa1-0688-4690-b1fc-28042fa5864c completed32s/5steps on the previously confirmed Finora test/work profile. It reported authenticated UI access but could not evaluate native page JavaScript, so the intentionally invalid-UUID SDK probe was NOT EXECUTED (no HTTP status/error evidence). Emails/password/preference changes0. Do not equate reported workspace access with proven JWT/endpoint integration or real settings persistence; no repeated run is warranted for the same tool limitation.
107 - **Auth settings completed:** after the owner requested secure Supabase login, Default profile provider sessions were freshly saved; actual dashboard/project access was then observed in TinyFish run c398c3ed-313d-4c3d-8273-df01b61e05cf, completed91s/14steps. Before redirects were https://factoreasy.ir and https://factoreasy.ir/*; added ONLY https://factoreasy.ir/?finora_recovery=1 and saved/reopened to verify all three, preserving both originals. Reset Password template already used {{ .ConfirmationURL }} and was left unchanged. SMTP UI reported configured; credentials/provider settings were not inspected or changed. This establishes the exact configuration, not email delivery. Nonsecret before/after evidence is saved outside git at /tmp/finora-auth-recovery-settings-20261025.json. No blocker remains in backend/visible Auth configuration; previous access prerequisites above are historical checkpoints, not a remaining permission request.
108 - **Release handoff:** complete final required checks on the newest documentation-only PR head, then mark179 ready and merge through the active strict ruleset with expected head (no bypass). Verify the resulting main's Quality/Security, all three disposable DB jobs, exact release gate, gated Pages and public assets/login/recovery controls. Latest exact PR/main/deployment SHA and run evidence are maintained in PR179's description because the merge/deployment SHA is created after this committed checkpoint. Read that description before repeating any activation or release step. Actual recipient email delivery/password acceptance and old settings/owner-ISP acceptance remain NOT VERIFIED; no unapproved real email/password operation is implied by this approval.
109 +
110 +### 2026-10-26 — Recovery release and controlled email acceptance
111 +- Owner said «ادامه بده»; prior explicit production activation/merge approval persists. Fresh preflight confirmed maince32, exact PR179 headc09632490cc9607a0a78f38e4f65b1316c6e5517 and all required exact-head checks SUCCESS (Quality40217977236 incl3DB, Security40217977332); deployed backend remains ACTIVE v4. Marked PR ready and merged normally with expected head, creating main **b39f60dc415de6f9ff1f0a34f60192ed9de04561**. Provider tree46444c81e0960caacbfa0127a9f62d7de654217a matches the tested release tree exactly. No ruleset bypass was used.
112 +- Main Quality40260533519/Security40260533520, exact Release Gate/Pages and public readback are being verified; final evidence is maintained in PR179 description. Do not redo the v4 deployment or the exact Auth callback addition merely because previous dated checkpoints say pending.
113 +- For actual email acceptance, the owner supplied a test recipient under their control after being asked which account to use. The address is intentionally omitted from git/logs. This authorizes ONE public Forgot Password request after the new page is deployed and independently checked, not a password mutation, inbox access, guessed credentials, repeated resend, new account creation or mail to anyone else. Recipient confirms receipt; no password, OTP or complete recovery link is requested in chat.
114 +
115 +- **Post-release discovery before any real email:** exact main b39f60dc... passed Quality40260533519 (175 browser/45 server/Golden/all3DB) and Security40260533520; successful gate40260907634/job121372937191 and Pages40260939146/job121372976991 deployed that exact SHA. Earlier gate40260681237 was cancelled by normal concurrency and is not release evidence. Canonical public readback matches12/12 HTML/required-script resources; anonymous login/forgot readiness, blank-email validation and marker-only rejection passed with no page/CSP/local-script errors or Supabase request. The final marker-only Cancel assertion FAILED: button click did not return to login within5s. No real email request has been initiated. Evidence /tmp/finora-recovery-public-browser-evidence.json and ...-assets-evidence.json.
116 +
117 +### 2026-10-26 — Invalid recovery cancellation repair (authorized regression fix)
118 +- Continue the owner's approved complete recovery/release goal; this is a small client repair for an actually observed failure, not a new financial phase or a request to repeat Auth deployment/configuration. Isolated branch fix/password-recovery-invalid-cancel-20261026, base live main b39f60dc415de6f9ff1f0a34f60192ed9de04561.
119 +- Hypothesis from actual source: resume() assigns state.resolving to an async IIFE; marker-only/missing-token rejection returns before any await, so finally clears resolving before the outer assignment re-stores its already-resolved Promise. cancel() then silently rejects because resolving remains truthy. Verify with a meaningful failing browser test, apply the smallest promise-lifetime fix and helper cache version, preserve all other Auth/financial behavior. Run source/generated recovery tests and existing full checks; publish a separate repair PR, protected merge and exact gated Pages/public validation before sending the single owner-authorized test request. Never claim real email/password acceptance from CI alone.
120 +- **Repair verified:** observed3/3 RED with the expected hidden login form after Cancel (cached unrelated account, marker-only without session, missing refresh token). Confirmed the JavaScript assignment/finally ordering cause; the shared promise body now starts in a microtask after the assignment. Existing proof, identity/session, pending, epoch and token-bound logout guards were not removed or changed. Only recovery helper, its cache URL20261026-recovery-cancel-v2, browser spec and this continuity file change. No backend/Auth-setting redeployment is needed.
121 +- **Actually executed on the repair tree:** focused recovery19/19 source and19/19 generated strict-CSP Pages PASS; independent reviewer reran3/3 source and3/3 generated regressions PASS, no remaining blocker. Complete existing workflow browser command **177/177 PASS (3.4m)**; all51 static/behavioral/backup/server/release-safety commands PASS, including45/45 server cases and Golden; diff check PASS. No test expectation was relaxed, no dependency added and no financial/SQL/RLS/role/grant data changed. Cloud font workaround remains process-only. Exact remote head/tree/CI and subsequent merged-main/Pages/public results belong in the repair PR description before completion; the controlled real email request stays uninitiated until public repair passes.
index.html
+1 -1
@@ -902,7 +902,7 @@ body{background:#f6f9fc}
902 <!-- The credential-free connectivity action must be loaded before core declares
903 login actions interactive. Hardened Pages binds static handlers just before core. -->
904 <script src="js/login-connectivity.js?v=20261024-independent-probes-v4"></script>
905 -<script src="js/password-recovery.js?v=20261025-password-recovery-v1"></script>
905 +<script src="js/password-recovery.js?v=20261026-recovery-cancel-v2"></script>
906 <script src="js/core.js?v=20261025-password-recovery-v1"></script>
907 <script src="js/admin.js?v=20261025-password-recovery-v1"></script>
908 <script src="js/sync.js?v=20261012-login-read-cancel-v1"></script>
js/password-recovery.js
+3 -2
@@ -45,7 +45,8 @@
45 state.client=client;if(!state.active||state.completed)return false;
46 if(state.resolving)return state.resolving;
47 const epoch=state.epoch;
48 - state.resolving=(async()=>{
48 + // Assign the shared promise before an invalid callback can finish without awaiting.
49 + state.resolving=Promise.resolve().then(async()=>{
50 try{
51 render();let verified=state.session;
52 if(incoming){
@@ -70,7 +71,7 @@
71 message('پیوند تأیید شد. رمز عبور جدید و تکرار آن را وارد کنید.','ready');return true;
72 }catch(_){if(epoch===state.epoch)invalid();return false;}
73 finally{state.resolving=null;}
73 - })();
74 + });
75 return state.resolving;
76 }
77 function handleEvent(event,session){
scripts/password-recovery.spec.js
+24
@@ -106,6 +106,30 @@ test('Recovery marker alone cannot turn a cached session into a password reset',
106 await expect(page.locator('#auth-recovery-status')).toContainText('معتبر نیست');
107 await expect(page.locator('#auth-recovery-submit')).toBeDisabled();
108 expect(calls.profiles).toBe(0);expect(calls.updates).toHaveLength(0);
109 + await page.locator('#auth-recovery-cancel').click();
110 + await expect(page.locator('#auth-form-container')).toBeVisible();
111 + expect(new URL(page.url()).searchParams.has('finora_recovery')).toBe(false);
112 + expect(await page.evaluate(()=>JSON.parse(localStorage.getItem('sb-hcsixhqbyuhpshfwqpjx-auth-token')).user.id)).toBe(ALICE);
113 + expect(calls.logouts).toHaveLength(0);expect(calls.records).toBe(0);expect(calls.writes).toBe(0);
114 +});
115 +
116 +for(const invalid of [
117 + {name:'marker without a session',suffix:'?finora_recovery=1'},
118 + {name:'recovery callback without a refresh token',suffix:'?finora_recovery=1#type=recovery&access_token='+encodeURIComponent(token(BOB))}
119 +])test('Invalid recovery can return to login: '+invalid.name,async({page})=>{
120 + const calls=await fixture(page);
121 + await page.goto(BASE+invalid.suffix,{waitUntil:'domcontentloaded'});
122 + await expect(page.locator('#auth-recovery-status')).toContainText('معتبر نیست');
123 + await expect(page.locator('#auth-recovery-submit')).toBeDisabled();
124 + await expect(page.locator('#auth-recovery-cancel')).toBeEnabled();
125 + await page.locator('#auth-recovery-cancel').click();
126 + await expect(page.locator('#auth-form-container')).toBeVisible();
127 + await expect(page.locator('#auth-recovery-container')).toBeHidden();
128 + expect(new URL(page.url()).searchParams.has('finora_recovery')).toBe(false);
129 + expect(new URL(page.url()).hash).toBe('');
130 + expect(await page.evaluate(()=>localStorage.getItem('sb-hcsixhqbyuhpshfwqpjx-auth-token'))).toBeNull();
131 + expect(calls.logouts).toHaveLength(0);expect(calls.updates).toHaveLength(0);
132 + expect(calls.profiles).toBe(0);expect(calls.records).toBe(0);expect(calls.writes).toBe(0);
133 });
134
135 test('Verified recovery survives reload only for the same validated account',async({page})=>{