سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 22:00 UTC
test: cover stale membership revocation and trigger JWT gate for tenant changes
davoodmehraban89 committed
Nov 24, 2026 at 11:14 UTC
3fd33525ad83408e55a78842c7a8663d9a51b436
4 files changed
+28
.github/workflows/free-supabase-local-e2e.yml
+4
@@ -11,6 +11,10 @@ on:
11
- "js/purchases.js"
12
- "js/products.js"
13
- "js/journal-ui.js"
14
+ # Tenant context, generic CAS writes and their behavioral contracts.
15
+ - "js/organization-rbac.js"
16
+ - "js/sync.js"
17
+ - "scripts/pending-sync-preservation.test.mjs"
18
# Browser accounting contract changes must run real-JWT WP2 checks.
19
- "scripts/accounting-document-workflow.spec.js"
20
- "scripts/journal-rpc-adapter.test.mjs"
PROJECT_STATE.md
+2
@@ -693,3 +693,5 @@ Next action: run and inspect Quality on the latest PR212 head. If any browser te
693
### 2026-11-24 — FIN-B01 — candidate implementation checkpoint (not accepted)
694
- Stage target membership and snapshot without changing active identity, local selection or graph; prohibit switching with dirty/pending/paused/in-flight state and recheck context/fingerprint after every await; publish target and snapshots only together. Stale membership reply ignored. Rejected/failed switch restores selector, no automatic destructive recovery. Forced revocation still purges memory. Source-backed tests now distinguish voluntary blocked switch from forced A→B→A stale ACK.
695
- Files: js/organization-rbac.js, js/bootstrap.js, scripts/pending-sync-preservation.test.mjs, cache assertion if present; docs. Targeted tests cover clean switch, four dirty/inflight states, edits during awaits, read/identity failure, concurrent switch and retained stale completion. Exact-head CI not yet observed; not accepted. No SQL or Production. B02 deliberate recovery from paused/ambiguous writes is open, separate; next inspect all A01/B01 gates and then B02. No new implementation of same engine.
696
+
697
+- B01 gate follow-up: initial candidate 7f20ad848785da04a051bbaf3ce993444c6aa3fc on Draft PR252. Quality 45350300174, WP1 45350300134 and Security 45350300148 triggered; WP2 absent because prior path filter omitted organization/sync. Expand filter (no gate removed) and test actual membership-revalidation source for stale tenant response and authoritative current revocation purge. Exact final SHA and run evidence in PR252; not accepted until actual pass.
docs/EXECUTION_STATUS.md
+2
@@ -195,3 +195,5 @@
195
196
### 2026-11-24 — FIN-B01 safe organization switching (candidate)
197
- Base PR251 99fb2d4; staged identity/read + atomic local publication and pending-state block. No DB change. Exact candidate CI and review pending; forced membership revocation remains authoritative. B02 recovery unresolved. A01/B01 not accepted.
198
+
199
+- PR252 candidate 7f20ad8 initially did not trigger WP2. Path coverage expanded to organization-rbac/sync/pending-sync behavioral test, with membership stale-response and real purge tests; check new exact-head CI.
scripts/pending-sync-preservation.test.mjs
+20
@@ -7,6 +7,8 @@ const syncSource=readFileSync(new URL('../js/sync.js',import.meta.url),'utf8');
7
const orgSource=readFileSync(new URL('../js/organization-rbac.js',import.meta.url),'utf8');
8
const orgReader=orgSource.slice(orgSource.indexOf('const legacyPullAll=pullAll;'),orgSource.indexOf('// Keep the version-aware'));
9
const switcher=orgSource.slice(orgSource.indexOf('window.switchFinoraOrganization=async function'),orgSource.indexOf('window.finoraOrganizationSwitcherHtml'));
10
+const membership=orgSource.slice(orgSource.indexOf('window.revalidateFinoraMembership=async function'),orgSource.indexOf('window.requireFreshFinoraMembership='));
11
+const purge=orgSource.slice(orgSource.indexOf('function clearFinoraTenantMemory('),orgSource.indexOf('function showFinoraMembershipLock('));
12
function deferred(){let resolve;const promise=new Promise(r=>resolve=r);return {promise,resolve};}
13
const tick=()=>new Promise(r=>setImmediate(r));
14
function row(name='server-before',version=7){return {collection:'contacts',id:'C1',owner_id:'U1',organization_id:'ORG_A',version,data:{name}};}
@@ -140,3 +142,21 @@ test('all pending collections survive permission rejection without a full reload
142
h.c.sb.rpc=async()=>({data:null,error:{code:'42501',message:'permission denied'}});await h.c.runSync();
143
assert.equal(h.state().row.name,'contact-edit');assert.equal(h.evaluate('datastore.settings[0].theme'),'theme-edit');assert.equal(h.state().pending,true);
144
});
145
+
146
+async function installMembershipHarness(h){
147
+ h.c.document.querySelectorAll=()=>[];h.c.localStorage.removeItem=()=>{};h.c.STORAGE_KEY='test-only';
148
+ h.c.lockCalls=[];h.c.signOutCalls=0;h.c.sb.auth.signOut=async()=>{h.c.signOutCalls++;};
149
+ h.evaluate("let finoraMembershipRevalidationBusy=false;function showFinoraMembershipLock(hasAlternative){lockCalls.push(hasAlternative);}");
150
+ vm.runInContext(purge+'\n'+membership,h.c);
151
+}
152
+test('stale membership reply cannot revoke a newly hydrated tenant',async()=>{
153
+ const h=await harness(),d=deferred();await installMembershipHarness(h);
154
+ h.setRead(()=>d.promise);const old=h.c.window.revalidateFinoraMembership({sensitive:true});await tick();
155
+ h.evaluate("finoraInvalidateSyncContext();currentUser={...currentUser,organizationId:'ORG_B'}");h.setRead(async()=>({data:[row('B-safe',3)],error:null}));await h.c.pullAll();
156
+ d.resolve({data:[],error:null});assert.equal(await old,false);assert.equal(h.c.currentUser.organizationId,'ORG_B');assert.equal(h.state().row.name,'B-safe');assert.equal(h.state().versions[0][1],3);assert.equal(h.c.signOutCalls,0);assert.equal(h.c.lockCalls.length,0);
157
+});
158
+test('current membership revocation still purges pending memory and signs out',async()=>{
159
+ const h=await harness();await installMembershipHarness(h);h.evaluate("datastore.contacts[0].name='A-private';syncPending=true");
160
+ h.setRead(async()=>({data:[],error:null}));assert.equal(await h.c.window.revalidateFinoraMembership({sensitive:true}),false);
161
+ assert.equal(h.c.currentUser,null);assert.equal(h.evaluate('datastore.contacts.length'),0);assert.equal(h.evaluate('syncSnap.size'),0);assert.equal(h.evaluate('syncVersionSnap.size'),0);assert.equal(h.evaluate('syncPending'),false);assert.equal(h.c.signOutCalls,1);assert.deepEqual(h.c.lockCalls,[false]);
162
+});