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

fix: distinguish explicit server reload from successful write confirmation

davoodmehraban89 committed Nov 24, 2026 at 11:35 UTC 8d05ff60b64b9e6d21d5afd242bedcf5350d3c73
5 files changed +9 -7
PROJECT_STATE.md
+2
@@ -721,3 +721,5 @@ Next action: run and inspect Quality on the latest PR212 head. If any browser te
721
722
723 - FIN-B03 candidate implementation: explicit conflict-review button, ordinary pull refuses a paused context even if edits are undone; no queued write on paused save. Stage bounded scoped snapshot, verify authenticated identity and active membership before read and again after explicit discard consent; strict row scope, duplicate and version checks, local graph/CAS/fingerprint and context rechecks; publication invalidates old context and clears pause. Cancel, denied/read error, changed tenant or local edits preserve state (confirmed membership revocation still purges). No server writes and no original receipt claim. UI warns about unsaved forms and prior unknown commit. Targeted VM and browser keyboard/cancel/confirm tests added, exact CI pending. Field-level merge not implemented; no DB change. Parent B02-R1 ACK atomicity PASS on Quality 45352284249, WP2/Security PASS, browser/WP1 pending at observation.
724 +
725 +- B03 review follow-up: distinct neutral server-loaded status (not acknowledgement/readback equivalence), explicit abandonment of pending records, explicit CSS hiding of review control even under button display rules. Added status assertion. No change to the financial write path. Final exact CI pending.
index.html
+1 -1
@@ -293,7 +293,7 @@ body{background:#f6f9fc}
293 </div>
294
295 <div id="sync-badge" role="status" aria-live="polite" style="display:none;position:fixed;bottom:80px;left:12px;z-index:9999;color:#fff;padding:6px 12px;border-radius:999px;font-size:12px;box-shadow:0 2px 8px rgba(0,0,0,.25)"></div>
296 -<button id="sync-conflict-review" type="button" class="btn btn-secondary" hidden style="position:fixed;bottom:36px;left:12px;z-index:9999;background:#fff;color:#8b1d1d;border:1px solid #b91c1c;max-width:calc(100vw - 24px)">بررسی تعارض ذخیره</button>
296 +<button id="sync-conflict-review" type="button" class="btn btn-secondary" hidden style="display:none;position:fixed;bottom:36px;left:12px;z-index:9999;background:#fff;color:#8b1d1d;border:1px solid #b91c1c;max-width:calc(100vw - 24px)">بررسی تعارض ذخیره</button>
297 <div class="app-root">
298 <aside class="sidebar app-shell-nav no-print" aria-label="ناوبری اصلی">
299 <div class="brand-box">
js/organization-rbac.js
+2 -2
@@ -161,13 +161,13 @@ window.finoraReviewSyncConflict=async function(){
161 const snapshot=await finoraReadOrganizationSnapshot(context.org,context.uid,controller.signal,true);
162 check();
163 const {up,del}=computeDiff();
164 - if(!confirm('بازخوانی سرور آماده است. با تأیید، تمام تغییرات محلی ذخیره‌نشده ('+up.length+' ثبت یا ویرایش و '+del.length+' حذف) و ورودی‌های ذخیره‌نشده فرم‌ها ممکن است از بین بروند. عملیات قبلی ممکن است در سرور ثبت شده باشد؛ پیش از ثبت دوباره، سوابق را بررسی کنید. از تغییرات محلی صرف‌نظر و نسخه سرور را بارگذاری می‌کنید؟'))return false;
164 + if(!confirm('بازخوانی سرور آماده است. با تأیید، تمام تغییرات محلی ذخیره‌نشده ('+up.length+' ثبت یا ویرایش و '+del.length+' حذف) کنار گذاشته می‌شوند؛ ورودی‌های ذخیره‌نشده فرم‌ها نیز ممکن است از بین بروند. عملیات قبلی ممکن است در سرور ثبت شده باشد؛ پیش از ثبت دوباره، سوابق را بررسی کنید. از تغییرات محلی صرف‌نظر و نسخه سرور را بارگذاری می‌کنید؟'))return false;
165 await verify();
166 check();
167 clearTimeout(syncTimer);syncTimer=null;syncAgain=false;
168 finoraInvalidateSyncContext();
169 finoraPublishOrganizationSnapshot(snapshot,finoraSyncContext());
170 - setSyncBadge('reconciled');
170 + setSyncBadge('serverLoaded');
171 try{refreshAllSurfaces();}catch(error){console.error('conflict review surface refresh failed',error);alert('نسخه سرور بارگذاری شد؛ بازخوانی نما کامل نشد.');}
172 return true;
173 }catch(error){
js/sync.js
+3 -3
@@ -56,7 +56,7 @@ function keyOfRecord(coll,item){return coll==='settings'?'main':String(item&&ite
56 function stripOwner(item){const c=Object.assign({},item);delete c.ownerUserId;delete c._serverVersion;delete c.accountingPostingPending;delete c.accountingPostingPendingAt;return c;}
57 function finoraShowConflictReview(show){
58 const button=document.getElementById('sync-conflict-review');
59 - if(button)button.hidden=!show;
59 + if(button){button.hidden=!show;if(button.style)button.style.display=show?'inline-flex':'none';}
60 }
61 document.addEventListener('click',event=>{
62 if(event.target?.id==='sync-conflict-review'&&typeof window.finoraReviewSyncConflict==='function')void window.finoraReviewSyncConflict();
@@ -64,11 +64,11 @@ document.addEventListener('click',event=>{
64 function setSyncBadge(state){
65 finoraShowConflictReview(state==='conflict'&&!!currentUser?.organizationId&&finoraSyncIsPaused());
66 const el=document.getElementById('sync-badge');if(!el)return;
67 - const map={saved:['✔ ذخیره شد','#059669'],saving:['⏳ در حال ذخیره…','#d97706'],error:['⚠️ ذخیره نشد؛ تلاش مجدد…','#dc2626'],conflict:['⚠️ ذخیره تأیید نشد؛ تغییرات محفوظ است','#dc2626'],reconciled:['✔ تطابق داده با سرور تأیید شد','#059669']};
67 + const map={saved:['✔ ذخیره شد','#059669'],saving:['⏳ در حال ذخیره…','#d97706'],error:['⚠️ ذخیره نشد؛ تلاش مجدد…','#dc2626'],conflict:['⚠️ ذخیره تأیید نشد؛ تغییرات محفوظ است','#dc2626'],reconciled:['✔ تطابق داده با سرور تأیید شد','#059669'],serverLoaded:['نسخه سرور بارگذاری شد؛ عملیات قبلی را بررسی کنید','#475569']};
68 const m=map[state];if(!m)return;
69 el.textContent=m[0];el.style.background=m[1];el.style.display='block';
70 clearTimeout(setSyncBadge._t);
71 - if(state==='saved'||state==='reconciled')setSyncBadge._t=setTimeout(()=>{el.style.display='none';},2000);
71 + if(state==='saved'||state==='reconciled'||state==='serverLoaded')setSyncBadge._t=setTimeout(()=>{el.style.display='none';},2000);
72 }
73 async function pullAll({signal}={}){
74 const capture=finoraCaptureRead(),uid=capture.context.uid;
scripts/pending-sync-preservation.test.mjs
+1 -1
@@ -194,7 +194,7 @@ test('tenant change during read-back cannot publish or replay the old request',a
194
195 async function conflictFixture(){const h=await harness();h.c.window.revalidateFinoraMembership=async()=>true;h.c.confirm=()=>true;h.evaluate("datastore.contacts[0].name='unsaved';syncPending=true");await h.c.handleSyncError({code:'40001'});return h;}
196 test('paused even with undone edits cannot be cleared by ordinary pull',async()=>{const h=await conflictFixture();h.evaluate("datastore.contacts[0].name='server-before'");const before=h.state();await assert.rejects(h.c.pullAll(),/FINORA_READ_PAUSED_CONFLICT/);assert.deepEqual(h.state(),before);assert.equal(h.review.hidden,false);});
197 -test('conflict review explicitly accepts a staged server snapshot with zero writes',async()=>{const h=await conflictFixture();let checks=0;h.c.window.revalidateFinoraMembership=async()=>{checks++;return true};h.setRead(async()=>({data:[row('server-new',9)],error:null}));assert.equal(await h.c.window.finoraReviewSyncConflict(),true);assert.equal(checks,2);assert.equal(h.requests.length,0);assert.equal(h.state().row.name,'server-new');assert.equal(h.state().versions[0][1],9);assert.equal(h.state().pending,false);assert.equal(h.review.hidden,true);assert.equal(h.evaluate('finoraSyncIsPaused()'),false);});
197 +test('conflict review explicitly accepts a staged server snapshot with zero writes',async()=>{const h=await conflictFixture();let checks=0;h.c.window.revalidateFinoraMembership=async()=>{checks++;return true};h.setRead(async()=>({data:[row('server-new',9)],error:null}));assert.equal(await h.c.window.finoraReviewSyncConflict(),true);assert.equal(checks,2);assert.equal(h.requests.length,0);assert.equal(h.state().row.name,'server-new');assert.equal(h.state().versions[0][1],9);assert.equal(h.state().pending,false);assert.equal(h.review.hidden,true);assert.equal(h.evaluate('finoraSyncIsPaused()'),false);assert.match(h.badge.textContent,/نسخه سرور بارگذاری شد/);});
198 for(const mode of ['cancel','read-error','wrong-tenant','denied','wrong-user','duplicate'])test('conflict review preserves full graph on '+mode,async()=>{const h=await conflictFixture();h.setRead(async()=>({data:[row('server-new',9)],error:null}));if(mode==='cancel')h.c.confirm=()=>false;if(mode==='read-error')h.setRead(async()=>({data:null,error:{message:'failed'}}));if(mode==='wrong-tenant')h.setRead(async()=>({data:[{...row(),organization_id:'ORG_B'}],error:null}));if(mode==='denied')h.c.window.revalidateFinoraMembership=async()=>false;if(mode==='wrong-user')h.c.sb.auth.getUser=async()=>({data:{user:{id:'U2'}}});if(mode==='duplicate')h.setRead(async()=>({data:[row(),row()],error:null}));const before=h.state();assert.equal(await h.c.window.finoraReviewSyncConflict(),false);assert.deepEqual(h.state(),before);assert.equal(h.requests.length,0);assert.equal(h.review.hidden,false);assert.equal(h.review.disabled,false);});
199 test('edits made during staged conflict read survive and suppress confirmation',async()=>{const h=await conflictFixture(),d=deferred();let confirms=0;h.c.confirm=()=>{confirms++;return true};h.setRead(()=>d.promise);const work=h.c.window.finoraReviewSyncConflict();await tick();h.evaluate("datastore.contacts[0].name='newer'");d.resolve({data:[row('server-new',9)],error:null});assert.equal(await work,false);assert.equal(confirms,0);assert.equal(h.state().row.name,'newer');assert.equal(h.requests.length,0);});
200 test('concurrent review blocked; stale tenant response cannot publish',async()=>{const h=await conflictFixture(),d=deferred();h.setRead(()=>d.promise);const work=h.c.window.finoraReviewSyncConflict();await tick();assert.equal(await h.c.window.finoraReviewSyncConflict(),false);h.evaluate("finoraInvalidateSyncContext();currentUser={...currentUser,organizationId:'ORG_B'}");h.setRead(async()=>({data:[{...row('B',3),organization_id:'ORG_B'}],error:null}));await h.c.pullAll();d.resolve({data:[row('old',8)],error:null});assert.equal(await work,false);assert.equal(h.state().row.name,'B');assert.equal(h.state().versions[0][1],3);assert.equal(h.requests.length,0);});