@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 86913c7
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 17:00 UTC

fix(phase0): independently diagnose login JS, manifest, and Auth health (#112)

* docs(state): record owner SITE_UNREACHABLE screenshot, false-positive manifest-only probe, and no remote quota * fix(login): independently probe executable asset, manifest, and GoTrue health * fix(cache): load updated three-way auth connectivity diagnostic on production * test(login): require independent executable asset and manifest checks * test(login): independent manifest, critical JS, Auth outage regressions

davoodmehraban89 committed Oct 12, 2026 at 23:16 UTC 86913c74a1abc88a2912f5ba393ef3fb01dcde49
5 files changed +100 -26
PROJECT_STATE.md
+6
@@ -82,6 +82,12 @@ The latest user message is the sole source of new instructions. Read AGENTS.md t
82 - **Independent Supabase deployment inspection:** `list_edge_functions` still returned only `admin-user-management` and `finora-stripe-qa-read`, neither the new SMS hook nor phone Auth settings activated or modified. No SMS sent, no new Auth users created, no financial DB writes/RLS/schema changes. Existing email/password/Google login remains untouched. User's Desktop Commander device available; checkout `C:\Temp\Factor-easy` is stale with 2189 untracked files and was not edited.
83 - **Remaining independent activation authorization:** vendor approval, secure server secrets, hook deployment + verify_jwt=false, enabling Supabase phone Auth and signed Send SMS hook, validated existing-user phone linking (never duplicate `auth.users.id`), SMS delivery costs/test number, CAPTCHA/rate limiting/replay dedupe plan, staged mobile UI and affected owner ISP acceptance. **No next step may infer any of these authorized. F0-01 and Phase 0 OPEN.**
84
85 +### 2026-10-12 Phase 0 F0-01 affected network: screenshot SITE_UNREACHABLE and account timeout — DIAGNOSIS OPEN
86 +- **Owner evidence:** real Chrome screenshot of Finora email/password login shows `دریافت اطلاعات حساب بیش از حد طول کشید...` and `SITE_UNREACHABLE` from the built-in connectivity diagnostic. The screenshot contains private login address: NEVER copy user email/credential into tickets, public logs or code. It does not prove password invalid, that all ERP assets are inaccessible or which tenant/network fetch failed. Earlier owner video/photo documented blank/inert handlers, separately addressed in PR #107; this observation is AFTER that deployment.
87 +- **Confirmed code-level limitation:** `js/login-connectivity.js` currently runs two probes: same-origin `manifest.json` and Supabase GoTrue `/auth/v1/health`, then **returns SITE_UNREACHABLE whenever ONLY manifest fetch fails**, masking the Auth outcome and without testing any executable JS. The `manifest.json` exists in GitHub and is copied by `scripts/build-pages.mjs`, but owner ISP actual asset HTTP result remains unknown. `enterApp()` read-only account bootstrap/profile/org membership/paginated records has a 25s timeout and shows the independent account timeout message. These two strings do not prove one shared cause.
88 +- **Diagnostic remediation scope:** test one same-origin critical local JS file **and** manifest independently alongside Supabase Auth health, preserve truthful independent codes and avoid false blanket unreachable from manifest alone. Add deterministic Chromium tests for manifest-only HTTP failure, actual script failure, Auth failure and combined failures. Do not log personal identifiers, passwords, JWTs, API keys or HTTP response bodies. No Supabase/Auth/RLS/roles/schema, financial posting or real account modifications. Preserve exact legacy login behavior pending actual owner ISP result. Rollback narrow UI-only PR.
89 +- **Availability limitation:** Desktop Commander device `DESKTOP-71SJ63M` reports ONLINE, but **monthly tool quota is exhausted** (explicit tool error); do not retry/reconnect/circumvent. Public external fetch of owner domain was also inaccessible in current external inspection context. Therefore real owner-ISP CDN/site/GoTrue HTTP status and precise 25s timeout stage are **NOT VERIFIED**; F0-01 and overall Phase 0 OPEN. Next owner validation: same browser and alternate network comparing independent probe codes without sharing login secrets.
90 +
91 ## Current change ledger
92 | 2026-10-07 | Owner requested accounting/product usability refinement from live screenshots: automatic non-user-entered floating-detail codes, contextual in-product guides (especially accounting/chart/dimensions), remove duplicate product internal tax ID and use product code as internal item ID, strengthen in-control product/person search, introduce hierarchical product group/subgroup coding with deterministic 6-digit product codes, and keep sale/purchase commercial-document workspace layout stable while only semantic fields change. | **IMPLEMENTED / LOCAL VERIFICATION PASSED / CI PENDING** | Baseline main = `7e58c75f7d754f378d94ca3f356c1ae580aa7ee3`. Automatic dimension type/value codes, contextual guides, product-code-as-internal-ID, normalized multi-token search, and additive six-digit product coding implemented. Existing historical codes preserved. Commercial sale/purchase workspaces now share a stable `صدور سند تجاری` header/actions layout; duplicate purchase sidebar injection removed; the public selector is the single document-type selector and the legacy internal invoice-kind control is hidden. Local syntax/static/commerce/UX/accounting phases 2–6/Golden checks passed; protected-branch CI remains pending. |
93
index.html
+2 -2
@@ -14,7 +14,7 @@
14 <meta name="apple-mobile-web-app-capable" content="yes" />
15 <meta name="theme-color" content="#071a48" />
16 <link rel="preload" as="script" href="js/core.js?v=20261012-login-wiring-v3" />
17 -<link rel="preload" as="script" href="js/login-connectivity.js?v=20261011-login-triage-v1" />
17 +<link rel="preload" as="script" href="js/login-connectivity.js?v=20261012-site-probe-v2" />
18 <script src="vendor/supabase.js"></script>
19 <script async src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
20 <link id="finora-optional-font" rel="stylesheet" media="print" href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/misc/Farsi-Digits/Vazirmatn-FD-font-face.css" />
@@ -892,7 +892,7 @@ body{background:#f6f9fc}
892
893 <!-- The credential-free connectivity action must be loaded before core declares
894 login actions interactive. Hardened Pages binds static handlers just before core. -->
895 -<script src="js/login-connectivity.js?v=20261011-login-triage-v1"></script>
895 +<script src="js/login-connectivity.js?v=20261012-site-probe-v2"></script>
896 <script src="js/core.js?v=20261012-login-wiring-v3"></script>
897 <script src="js/admin.js?v=20261012-provision-error-v1"></script>
898 <script src="js/sync.js?v=20261012-login-read-cancel-v1"></script>
js/login-connectivity.js
+39 -22
@@ -1,42 +1,59 @@
1 -// Read-only, credential-free connection diagnostics for the Finora login screen.
2 -// Never logs usernames, passwords, sessions, API responses, or access tokens.
1 +// Read-only, credential-free diagnostics. A missing manifest is NOT proof
2 +// that core JS or the Supabase Auth service is unreachable.
3 async function checkAuthConnectivity(){
4 const out=document.getElementById('auth-connectivity-result');
5 const button=document.getElementById('auth-connectivity-check');
6 - if(!out)return;
7 - if(button?.disabled)return;
6 + if(!out||button?.disabled)return;
7 if(button)button.disabled=true;
9 - out.textContent='در حال بررسی اتصال به سایت و سرویس ورود...';
8 + out.textContent='در حال بررسی مستقل فایل برنامه و سرور ورود...';
9 out.dataset.status='checking';
10 const controller=new AbortController();
11 const timer=setTimeout(()=>controller.abort(),12000);
12 try{
13 if(navigator.onLine===false){
15 - out.textContent='اتصال اینترنت این دستگاه قطع است (OFFLINE). پس از وصل‌شدن اینترنت دوباره تلاش کنید.';
14 + out.textContent='اتصال اینترنت دستگاه قطع است (OFFLINE). اتصال را برقرار کنید و دوباره بررسی کنید.';
15 out.dataset.status='offline';
16 return;
17 }
19 - const [site,auth]=await Promise.allSettled([
18 + // Execute three independent checks so a failed PWA manifest cannot mask
19 + // a healthy executable file or a healthy GoTrue endpoint. Both are GET;
20 + // neither accesses user identity, session, password or private records.
21 + const requests=[
22 + fetch(new URL('js/login-connectivity.js?v=20261012-site-probe-v2',document.baseURI).href,{cache:'no-store',signal:controller.signal}),
23 fetch(new URL('manifest.json',document.baseURI).href,{cache:'no-store',signal:controller.signal}),
24 fetch(SUPABASE_URL+'/auth/v1/health',{method:'GET',headers:{apikey:SUPABASE_KEY},cache:'no-store',signal:controller.signal})
22 - ]);
23 - const siteOk=site.status==='fulfilled'&&site.value.ok;
24 - if(!siteOk){
25 - out.textContent='فایل‌های نرم‌افزار از این شبکه به‌درستی دریافت نمی‌شوند (SITE_UNREACHABLE). با اینترنت دیگری امتحان کنید.';
25 + ];
26 + const [script,manifest,auth]=await Promise.allSettled(requests);
27 + const describe=(r,name)=>{
28 + if(r.status==='rejected')return name+(controller.signal.aborted?'_TIMEOUT':'_NETWORK_ERROR');
29 + return name+(r.value.ok?'_OK':'_HTTP_'+r.value.status);
30 + };
31 + const scriptOk=script.status==='fulfilled'&&script.value.ok;
32 + const manifestOk=manifest.status==='fulfilled'&&manifest.value.ok;
33 + const authOk=auth.status==='fulfilled'&&auth.value.status===200;
34 + const siteCode=describe(script,'SITE_JS');
35 + const manifestCode=describe(manifest,'MANIFEST');
36 + const authCode=auth.status==='rejected'?(controller.signal.aborted?'AUTH_TIMEOUT':'AUTH_UNREACHABLE'):
37 + (auth.value.status===200?'AUTH_OK':'AUTH_HTTP_'+auth.value.status);
38 + const codes=[siteCode,manifestCode,authCode].join(' | ');
39 + if(!scriptOk&&!manifestOk){
40 out.dataset.status='site-error';
27 - }else if(auth.status==='rejected'){
28 - const code=controller.signal.aborted?'AUTH_TIMEOUT':'AUTH_UNREACHABLE';
29 - out.textContent='سایت باز می‌شود، اما مرورگر به سرور ورود فینورا دسترسی ندارد ('+code+'). با اینترنت دیگری آزمایش کنید؛ اگر مشکل باقی بود، همین کد را برای پشتیبانی بفرستید.';
30 - out.dataset.status='auth-unreachable';
31 - }else if(auth.value.status===200){
32 - out.textContent='اتصال به سایت و سرور ورود برقرار است (AUTH_OK). اگر ورود انجام نمی‌شود، متن دقیق خطای ورود را بررسی کنید.';
33 - out.dataset.status='ok';
41 + out.textContent='دو فایل بررسی‌شده از این شبکه دریافت نشدند ('+codes+'). با اینترنت دیگری امتحان کنید؛ این آزمون علت قطعی مشکل ورود را مشخص نمی‌کند.';
42 + }else if(!scriptOk){
43 + out.dataset.status='site-error';
44 + out.textContent='فایل اصلی اجرای ورود در این شبکه قابل دریافت نیست، هرچند فایل تنظیمات سایت پاسخ داده است ('+codes+').';
45 + }else if(!authOk){
46 + out.dataset.status=auth.status==='rejected'?'auth-unreachable':'auth-http';
47 + out.textContent='فایل اصلی سایت دریافت می‌شود، اما بررسی سرور ورود موفق نبود ('+codes+'). نتیجه را بدون اطلاعات حساب برای پشتیبانی بفرستید.';
48 + }else if(!manifestOk){
49 + out.dataset.status='site-warning';
50 + out.textContent='فایل اجرایی و سرور ورود در دسترس‌اند، اما فایل تنظیمات سایت دریافت نشد ('+codes+'). این مورد به‌تنهایی مانع ورود را ثابت نمی‌کند.';
51 }else{
35 - out.textContent='سرویس ورود پاسخ داده، اما پاسخ آن غیرمنتظره است (AUTH_HTTP_'+auth.value.status+'). این کد را برای پشتیبانی بفرستید.';
36 - out.dataset.status='auth-http';
52 + out.dataset.status='ok';
53 + out.textContent='فایل اصلی و سرور ورود پاسخ داده‌اند ('+codes+'). این نتیجه موفقیت رمز عبور یا بارگذاری اطلاعات شرکت را تأیید نمی‌کند.';
54 }
38 - }catch(err){
39 - out.textContent='آزمایش اتصال کامل نشد (DIAGNOSTIC_FAILED). با اینترنت دیگری دوباره امتحان کنید.';
55 + }catch{
56 + out.textContent='بررسی مستقل اتصال کامل نشد (DIAGNOSTIC_FAILED). بدون ارسال رمز یا اطلاعات حساب دوباره امتحان کنید.';
57 out.dataset.status='error';
58 }finally{
59 clearTimeout(timer);
scripts/login-connectivity-check.mjs
+6 -2
@@ -6,9 +6,9 @@ const diagnostic=fs.readFileSync('js/login-connectivity.js','utf8');
6 assert(html.includes('id="auth-connectivity-check"'),'Missing diagnostic action');
7 assert(html.includes('id="auth-connectivity-result"'),'Missing accessible result');
8 assert(html.includes('id="auth-connectivity-result" aria-live="polite"'),'Diagnostic must announce updates without adding a conflicting global role=status');
9 -assert(html.includes('js/login-connectivity.js?v=20261011-login-triage-v1'),'Missing versioned script');
9 +assert(html.includes('js/login-connectivity.js?v=20261012-site-probe-v2'),'Missing versioned script');
10 assert(html.includes('js/core.js?v=20261012-login-wiring-v3'),'Production login controls must use new cache version');
11 -assert(html.indexOf('<script src="js/login-connectivity.js?v=20261011-login-triage-v1"')<html.indexOf('<script src="js/core.js?v=20261012-login-wiring-v3"'),'Connectivity handler script must execute before core (not just preload)');
11 +assert(html.indexOf('<script src="js/login-connectivity.js?v=20261012-site-probe-v2"')<html.indexOf('<script src="js/core.js?v=20261012-login-wiring-v3"'),'Connectivity handler script must execute before core (not just preload)');
12 assert(html.includes('js/bootstrap.js?v=20261012-login-ready-v2'),'Parallel bootstrap must also be cache-busted');
13 assert(html.includes('id="auth-login-button"')&&html.includes('id="auth-login-status"'),'Login control requires real readiness/progress feedback');
14 assert(core.includes('window.FinoraAppAssetsReady'),'Authenticated workspace must remain gated until all module scripts settle');
@@ -19,6 +19,10 @@ assert(!core.includes('اتصال اینترنت/VPN را بررسی کنید'),
19 assert(diagnostic.includes("'/auth/v1/health'"),'Must test the real GoTrue health path');
20 assert(diagnostic.includes('apikey:SUPABASE_KEY'),'Health check requires public API key');
21 assert(diagnostic.includes("new URL('manifest.json',document.baseURI)"),'Missing same-origin site baseline');
22 +assert(diagnostic.includes("new URL('js/login-connectivity.js?v=20261012-site-probe-v2',document.baseURI)"),'Missing same-origin executable asset probe');
23 +assert(diagnostic.includes("SITE_JS")&&diagnostic.includes("MANIFEST"),'Must diagnose executable asset and manifest independently');
24 +assert(diagnostic.includes("site-warning"),'Manifest-only error must not be misreported as total site failure');
25 +assert(!diagnostic.includes("if(!siteOk)"),'Legacy manifest-only SITE_UNREACHABLE classifier must be removed');
26 assert(!diagnostic.includes('signInWithPassword')&&!diagnostic.includes('auth-password'),'Diagnostic must not touch credentials');
27 assert(diagnostic.includes('new AbortController()'),'Probe timeout must be bounded');
28 console.log('PASS: login connectivity diagnostics are read-only, cache-versioned and credential-free');
scripts/login-connectivity.spec.js
+47
@@ -28,3 +28,50 @@ test('Login diagnostics label HTTP server failures, not bad passwords', async ({
28 await expect(page.locator('#auth-connectivity-result')).toHaveAttribute('data-status','auth-http',{timeout:15000});
29 await expect(page.locator('#auth-connectivity-result')).toContainText('AUTH_HTTP_503');
30 });
31 +
32 +test('A failing manifest cannot falsely classify working login JS and Auth as SITE_UNREACHABLE',async({page})=>{
33 + await page.goto(base,{waitUntil:'domcontentloaded'});
34 + await page.route('**/manifest.json*',route=>route.fulfill({status:404,body:'missing'}));
35 + await page.route('**/auth/v1/health',route=>route.fulfill({
36 + status:200,contentType:'application/json',
37 + headers:{'access-control-allow-origin':'*'},
38 + body:'{"name":"GoTrue"}'
39 + }));
40 + await page.locator('#auth-connectivity-check').click();
41 + const output=page.locator('#auth-connectivity-result');
42 + await expect(output).toHaveAttribute('data-status','site-warning',{timeout:15000});
43 + await expect(output).toContainText('SITE_JS_OK');
44 + await expect(output).toContainText('MANIFEST_HTTP_404');
45 + await expect(output).toContainText('AUTH_OK');
46 + await expect(output).not.toContainText('SITE_UNREACHABLE');
47 +});
48 +
49 +test('Critical JS read fails but manifest and Auth are healthy: report failed asset precisely',async({page})=>{
50 + await page.goto(base,{waitUntil:'domcontentloaded'});
51 + await page.route('**/js/login-connectivity.js*',route=>route.abort('failed'));
52 + await page.route('**/auth/v1/health',route=>route.fulfill({
53 + status:200,contentType:'application/json',
54 + headers:{'access-control-allow-origin':'*'},
55 + body:'{"name":"GoTrue"}'
56 + }));
57 + await page.locator('#auth-connectivity-check').click();
58 + const output=page.locator('#auth-connectivity-result');
59 + await expect(output).toHaveAttribute('data-status','site-error',{timeout:15000});
60 + await expect(output).toContainText('SITE_JS_NETWORK_ERROR');
61 + await expect(output).toContainText('MANIFEST_OK');
62 + await expect(output).toContainText('AUTH_OK');
63 +});
64 +
65 +test('Both site resources and Auth unreachable: report independent failures without exposing user data',async({page})=>{
66 + await page.goto(base,{waitUntil:'domcontentloaded'});
67 + await page.route('**/js/login-connectivity.js*',route=>route.abort('failed'));
68 + await page.route('**/manifest.json*',route=>route.abort('failed'));
69 + await page.route('**/auth/v1/health',route=>route.abort('failed'));
70 + await page.locator('#auth-connectivity-check').click();
71 + const output=page.locator('#auth-connectivity-result');
72 + await expect(output).toHaveAttribute('data-status','site-error',{timeout:15000});
73 + await expect(output).toContainText('SITE_JS_NETWORK_ERROR');
74 + await expect(output).toContainText('MANIFEST_NETWORK_ERROR');
75 + await expect(output).toContainText('AUTH_UNREACHABLE');
76 + expect(await output.textContent()).not.toMatch(/Bearer |password|access_token|apiKey/i);
77 +});