سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 18:15 UTC
Add C8 policy UI contract and mocked DOM tests
davoodmehraban89 committed
Oct 1, 2026 at 20:16 UTC
083745ce19e4a2e93b00d2c8ad0317acbcd631c9
5 files changed
+198
-1
.github/workflows/quality.yml
+3
-1
@@ -64,6 +64,8 @@ jobs:
64
run: node scripts/office-slice-c6-check.mjs
65
- name: Office Slice C7 invariants
66
run: node scripts/office-slice-c7-check.mjs
67
+ - name: Office Slice C8 policy UI invariants
68
+ run: node scripts/office-slice-c8-check.mjs
69
- name: Install browser smoke-test runtime
70
run: |
71
npm install --no-save @playwright/test@1.55.0 pdf-lib@1.17.1
@@ -71,4 +73,4 @@ jobs:
73
- name: Real DOM smoke
74
run: |
75
python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 &
74
- npx playwright test scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js --reporter=line --workers=1
76
+ npx playwright test scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js --reporter=line --workers=1
PROJECT_STATE.md
+7
@@ -101,6 +101,13 @@ Authenticated two-real-user production browser E2E with a persistent legitimate
101
- Proposed design self-reviewed for scope, authorization, immutable evidence, concurrency, idempotency, expired-license read-only behavior and non-interference with C1/C5/accounting.
102
- C8 implementation, migrations, real-DOM, accounting rerun and database adversarial/concurrency tests: NOT VERIFIED / NOT RUN. This commit changes documentation only.
103
104
+## C8 task-1 implementation checkpoint — 2026-10-01
105
+- Baseline before C8 code: main `43680ac03434ed1d6f7f18a0177c7be59c87f1d1`; immediately preceding reconciled baseline `f64249a6c84b3c2e12d41eb14ff1c9c92a0c3dbf` had Quality `36843788152` PASS with accounting/Golden checks and real-DOM `16 passed (8.9s)`, Security `36843788218` PASS, Pages `36843787512` PASS.
106
+- Live database review confirmed current RBAC helpers, composite records identity, and C1 canonical correspondence statuses `draft / registered / submitted / closed`; persistent production currently contains no correspondence rows. C8 must therefore treat only `registered` and `submitted` as transitionable and `closed` as terminal.
107
+- Added the pre-deployment C8 policy editor/catalog module plus behavior-level Playwright and static contract tests. The module is intentionally NOT loaded by `js/bootstrap.js` until the approved database RPCs are deployed and verified, preventing a broken production control surface.
108
+- Quality workflow now includes the C8 static contract and mocked real-DOM policy publication test while preserving all prior accounting/Golden/ELI/C1-C7 gates.
109
+- Database migration, SQL behavioral tests, concurrency test, attach/transition/read RPCs and production C8 E2E remain NOT IMPLEMENTED / NOT VERIFIED. Supabase has no development branch. A development branch would cost $0.01344/hour and is an external-cost boundary requiring explicit cost confirmation before creation.
110
+
111
## C8 implementation-plan checkpoint — 2026-10-01
112
- Baseline main `53cd24eabdfed3bae162bbc217753824a8cfb3bb`; Quality `36824644380`, Security `36824644419`, Pages `36824643831` observed success. These are prior documentation-head statuses, not C8 verification.
113
- Read actual runtime loader `js/bootstrap.js`, office modules and C7 tests; plan uses focused `js/office-workflow.js` and behavior-level DOM assertions instead of presence-only checks.
js/office-workflow.js
new
+125
@@ -0,0 +1,125 @@
1
+/* Finora Office Slice C8 — workflow policy editor/catalog (pre-deployment UI module). */
2
+(function(){
3
+'use strict';
4
+const CAPABILITIES=['edit','refer','approve'];
5
+function node(tag,attrs={},text){
6
+ const el=document.createElement(tag);
7
+ Object.entries(attrs).forEach(([k,v])=>{
8
+ if(k==='class')el.className=v;
9
+ else if(k==='type')el.type=v;
10
+ else if(k==='value')el.value=v;
11
+ else if(k==='checked')el.checked=Boolean(v);
12
+ else if(k==='disabled')el.disabled=Boolean(v);
13
+ else el.setAttribute(k,String(v));
14
+ });
15
+ if(text!==undefined&&text!==null)el.textContent=String(text);
16
+ return el;
17
+}
18
+function orgId(){
19
+ if(window.currentUser&&window.currentUser.organizationId)return window.currentUser.organizationId;
20
+ try{if(typeof currentUser!=='undefined'&¤tUser&¤tUser.organizationId)return currentUser.organizationId}catch(_){}
21
+ return null;
22
+}
23
+function canConfigure(){
24
+ if(typeof window.hasFinoraCapability==='function')return Boolean(window.hasFinoraCapability('office_automation','configure'));
25
+ try{if(typeof hasFinoraCapability==='function')return Boolean(hasFinoraCapability('office_automation','configure'))}catch(_){}
26
+ return false;
27
+}
28
+function rpc(){if(!window.sb||typeof window.sb.rpc!=='function')throw new Error('Supabase client unavailable');return window.sb}
29
+window.officeWorkflowPolicies=async function(){
30
+ const organizationId=orgId(); if(!organizationId)throw new Error('organization required');
31
+ const {data,error}=await rpc().rpc('office_workflow_catalog',{p_organization_id:organizationId});
32
+ if(error)throw error;
33
+ return Array.isArray(data)?data:[];
34
+};
35
+function stageRow(){
36
+ const row=node('div',{'class':'office-workflow-stage-row'});
37
+ const id=node('input',{'type':'text','data-field':'stage-id','maxlength':'64','aria-label':'شناسه مرحله'});
38
+ const label=node('input',{'type':'text','data-field':'stage-label','maxlength':'160','aria-label':'عنوان مرحله'});
39
+ const start=node('input',{'type':'checkbox','data-field':'stage-start','aria-label':'مرحله شروع'});
40
+ const terminal=node('input',{'type':'checkbox','data-field':'stage-terminal','aria-label':'مرحله پایان'});
41
+ const remove=node('button',{'type':'button','class':'btn btn-secondary btn-inline'},'حذف مرحله');
42
+ remove.addEventListener('click',()=>row.remove());
43
+ row.append(id,label,start,terminal,remove); return row;
44
+}
45
+function edgeRow(){
46
+ const row=node('div',{'class':'office-workflow-edge-row'});
47
+ const id=node('input',{'type':'text','data-field':'edge-id','maxlength':'64','aria-label':'شناسه انتقال'});
48
+ const from=node('input',{'type':'text','data-field':'edge-from','maxlength':'64','aria-label':'از مرحله'});
49
+ const to=node('input',{'type':'text','data-field':'edge-to','maxlength':'64','aria-label':'به مرحله'});
50
+ const label=node('input',{'type':'text','data-field':'edge-label','maxlength':'160','aria-label':'عنوان انتقال'});
51
+ const cap=node('select',{'data-field':'edge-capability','aria-label':'مجوز لازم'});
52
+ CAPABILITIES.forEach(x=>cap.append(node('option',{'value':x},x)));
53
+ const remove=node('button',{'type':'button','class':'btn btn-secondary btn-inline'},'حذف انتقال');
54
+ remove.addEventListener('click',()=>row.remove());
55
+ row.append(id,from,to,label,cap,remove); return row;
56
+}
57
+function definitionFrom(root){
58
+ const stages=[...root.querySelectorAll('.office-workflow-stage-row')].map(r=>({
59
+ id:String(r.querySelector('[data-field="stage-id"]').value||'').trim(),
60
+ label:String(r.querySelector('[data-field="stage-label"]').value||'').trim(),
61
+ start:Boolean(r.querySelector('[data-field="stage-start"]').checked),
62
+ terminal:Boolean(r.querySelector('[data-field="stage-terminal"]').checked)
63
+ }));
64
+ const edges=[...root.querySelectorAll('.office-workflow-edge-row')].map(r=>({
65
+ id:String(r.querySelector('[data-field="edge-id"]').value||'').trim(),
66
+ from:String(r.querySelector('[data-field="edge-from"]').value||'').trim(),
67
+ to:String(r.querySelector('[data-field="edge-to"]').value||'').trim(),
68
+ label:String(r.querySelector('[data-field="edge-label"]').value||'').trim(),
69
+ capability:String(r.querySelector('[data-field="edge-capability"]').value||'')
70
+ }));
71
+ return {stages,edges};
72
+}
73
+window.officeWorkflowPublish=async function(payload){
74
+ const organizationId=orgId(); if(!organizationId)throw new Error('organization required');
75
+ if(!canConfigure())throw new Error('configure permission required');
76
+ const {data,error}=await rpc().rpc('office_workflow_publish',{
77
+ p_organization_id:organizationId,p_policy_key:payload.policyKey,p_title:payload.title,p_definition:payload.definition
78
+ });
79
+ if(error)throw error;
80
+ return Number(data);
81
+};
82
+function renderCatalog(root,rows){
83
+ root.replaceChildren();
84
+ if(!rows.length){root.append(node('p',{'class':'af-empty'},'سیاست گردشی منتشر نشده است.'));return}
85
+ rows.forEach(p=>{
86
+ const card=node('div',{'class':'card office-workflow-policy-card'});
87
+ card.append(node('strong',{},p.title||p.policy_key||'—'));
88
+ card.append(node('span',{'class':'office-workflow-policy-meta'},' · '+String(p.policy_key||'')+' · نسخه '+String(p.version||'')));
89
+ root.append(card);
90
+ });
91
+}
92
+window.officeWorkflowMountAdmin=function(root){
93
+ if(!root)throw new Error('root required');
94
+ root.replaceChildren();
95
+ const wrap=node('section',{'class':'office-workflow-admin','aria-label':'سیاست گردش مکاتبات'});
96
+ wrap.append(node('h2',{},'سیاست گردش مکاتبات'));
97
+ wrap.append(node('p',{},'مرحله گردش، جایگزین ثبت دبیرخانه یا تأیید داخلی نامه نیست.'));
98
+ const form=node('div',{'class':'card'});
99
+ const policyKey=node('input',{'type':'text','maxlength':'64','data-field':'policy-key','aria-label':'کلید سیاست'});
100
+ const title=node('input',{'type':'text','maxlength':'160','data-field':'policy-title','aria-label':'عنوان سیاست'});
101
+ const stages=node('div',{'data-role':'stages'}),edges=node('div',{'data-role':'edges'});
102
+ const addStage=node('button',{'type':'button','class':'btn btn-secondary btn-inline'},'افزودن مرحله');
103
+ const addEdge=node('button',{'type':'button','class':'btn btn-secondary btn-inline'},'افزودن انتقال');
104
+ const publish=node('button',{'type':'button','class':'btn btn-primary btn-inline'},'انتشار نسخه');
105
+ const status=node('div',{'role':'status','aria-live':'polite'});
106
+ addStage.addEventListener('click',()=>stages.append(stageRow()));
107
+ addEdge.addEventListener('click',()=>edges.append(edgeRow()));
108
+ publish.disabled=!canConfigure();
109
+ const catalog=node('div',{'data-role':'catalog'});
110
+ publish.addEventListener('click',async()=>{
111
+ publish.disabled=true; status.textContent='در حال انتشار…';
112
+ try{
113
+ const version=await window.officeWorkflowPublish({policyKey:String(policyKey.value||'').trim(),title:String(title.value||'').trim(),definition:definitionFrom(wrap)});
114
+ status.textContent='نسخه '+String(version)+' منتشر شد.';
115
+ renderCatalog(catalog,await window.officeWorkflowPolicies());
116
+ }catch(e){status.textContent='انتشار ناموفق: '+String(e&&e.message||e)}
117
+ finally{publish.disabled=!canConfigure()}
118
+ });
119
+ form.append(node('label',{},'کلید سیاست'),policyKey,node('label',{},'عنوان سیاست'),title,addStage,stages,addEdge,edges,publish,status);
120
+ wrap.append(form,node('h3',{},'نسخههای فعال'),catalog); root.append(wrap);
121
+ window.officeWorkflowPolicies().then(rows=>renderCatalog(catalog,rows)).catch(e=>catalog.replaceChildren(node('p',{'class':'af-empty'},'دریافت سیاستها ناموفق بود: '+String(e&&e.message||e))));
122
+ return wrap;
123
+};
124
+window.FINORA_OFFICE_WORKFLOW_C8_UI_VERSION='c8-task1-v1';
125
+})();
\ No newline at end of file
scripts/office-slice-c8-check.mjs
new
+8
@@ -0,0 +1,8 @@
1
+import fs from 'node:fs';
2
+const src=fs.readFileSync('js/office-workflow.js','utf8');
3
+const required=['officeWorkflowPolicies','officeWorkflowPublish','officeWorkflowMountAdmin','office_workflow_catalog','office_workflow_publish','textContent','replaceChildren'];
4
+for(const token of required){if(!src.includes(token))throw new Error('C8 UI contract missing: '+token)}
5
+if(/\.innerHTML\s*=/.test(src))throw new Error('C8 UI must not render workflow content through innerHTML');
6
+if(!src.includes("['edit','refer','approve']"))throw new Error('C8 capability allowlist drift');
7
+if(!src.includes('مرحله گردش، جایگزین ثبت دبیرخانه یا تأیید داخلی نامه نیست.'))throw new Error('C8 status/workflow separation notice missing');
8
+console.log('Office Slice C8 policy UI contract: PASS');
\ No newline at end of file
scripts/office-slice-c8.spec.js
new
+55
@@ -0,0 +1,55 @@
1
+const {test,expect}=require('@playwright/test');
2
+test('Office C8 policy editor publishes a two-stage policy',async({page})=>{
3
+ await page.goto('http://127.0.0.1:4173/index.html',{waitUntil:'domcontentloaded'});
4
+ await page.evaluate(()=>{
5
+ window.currentUser={organizationId:'11111111-1111-1111-1111-111111111111'};
6
+ window.hasFinoraCapability=(moduleKey,capability)=>moduleKey==='office_automation'&&capability==='configure';
7
+ window.__c8Calls=[];
8
+ window.sb={rpc:async(name,args)=>{
9
+ window.__c8Calls.push({name,args});
10
+ if(name==='office_workflow_publish')return {data:2,error:null};
11
+ if(name==='office_workflow_catalog')return {data:[{policy_key:'main_flow',version:2,title:'عنوان نسخه دوم',definition:{stages:[],edges:[]}}],error:null};
12
+ return {data:null,error:{message:'unexpected rpc'}};
13
+ }};
14
+ });
15
+ await page.addScriptTag({url:'http://127.0.0.1:4173/js/office-workflow.js'});
16
+ await page.evaluate(()=>{const root=document.createElement('div');root.id='c8-root';document.body.append(root);window.officeWorkflowMountAdmin(root)});
17
+ await page.getByLabel('کلید سیاست').fill('main_flow');
18
+ await page.getByLabel('عنوان سیاست').fill('گردش اصلی');
19
+ await page.getByRole('button',{name:'افزودن مرحله'}).click();
20
+ await page.getByRole('button',{name:'افزودن مرحله'}).click();
21
+ const rows=page.locator('.office-workflow-stage-row');
22
+ await rows.nth(0).getByLabel('شناسه مرحله').fill('start');
23
+ await rows.nth(0).getByLabel('عنوان مرحله').fill('شروع');
24
+ await rows.nth(0).getByLabel('مرحله شروع').check();
25
+ await rows.nth(1).getByLabel('شناسه مرحله').fill('done');
26
+ await rows.nth(1).getByLabel('عنوان مرحله').fill('پایان');
27
+ await rows.nth(1).getByLabel('مرحله پایان').check();
28
+ await page.getByRole('button',{name:'افزودن انتقال'}).click();
29
+ const edge=page.locator('.office-workflow-edge-row').first();
30
+ await edge.getByLabel('شناسه انتقال').fill('submit');
31
+ await edge.getByLabel('از مرحله').fill('start');
32
+ await edge.getByLabel('به مرحله').fill('done');
33
+ await edge.getByLabel('عنوان انتقال').fill('ارسال');
34
+ await edge.getByLabel('مجوز لازم').selectOption('refer');
35
+ await page.getByRole('button',{name:'انتشار نسخه'}).click();
36
+ await expect(page.getByRole('status')).toContainText('نسخه 2 منتشر شد.');
37
+ const rpcCalls=await page.evaluate(()=>window.__c8Calls);
38
+ const publish=rpcCalls.find(x=>x.name==='office_workflow_publish');
39
+ expect(publish.args.p_policy_key).toBe('main_flow');
40
+ expect(publish.args.p_definition.stages).toHaveLength(2);
41
+ expect(publish.args.p_definition.edges).toEqual([{id:'submit',from:'start',to:'done',label:'ارسال',capability:'refer'}]);
42
+ await expect(page.locator('[data-role="catalog"]')).toContainText('عنوان نسخه دوم');
43
+});
44
+test('Office C8 policy publish control is authority-safe',async({page})=>{
45
+ await page.goto('http://127.0.0.1:4173/index.html',{waitUntil:'domcontentloaded'});
46
+ await page.evaluate(()=>{
47
+ window.currentUser={organizationId:'22222222-2222-2222-2222-222222222222'};
48
+ window.hasFinoraCapability=()=>false;
49
+ window.sb={rpc:async()=>({data:[],error:null})};
50
+ });
51
+ await page.addScriptTag({url:'http://127.0.0.1:4173/js/office-workflow.js'});
52
+ await page.evaluate(()=>{const root=document.createElement('div');root.id='c8-root';document.body.append(root);window.officeWorkflowMountAdmin(root)});
53
+ await expect(page.getByRole('button',{name:'انتشار نسخه'})).toBeDisabled();
54
+ await expect(page.locator('#c8-root')).toContainText('مرحله گردش، جایگزین ثبت دبیرخانه یا تأیید داخلی نامه نیست.');
55
+});
\ No newline at end of file