سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 18:15 UTC
test: add failing Slice D1 request workflow contract
davoodmehraban89 committed
Oct 1, 2026 at 22:12 UTC
82227d6d2b3daf5889cf77b56578e209a6213aed
1 file changed
+25
scripts/request-workflow-d1-check.mjs
new
+25
@@ -0,0 +1,25 @@
1
+import fs from 'node:fs';
2
+import assert from 'node:assert/strict';
3
+
4
+const migrationPath='supabase/migrations/20261001204500_request_workflow_d1_foundation.sql';
5
+assert.ok(fs.existsSync(migrationPath),'Slice D1 migration must exist');
6
+const sql=fs.readFileSync(migrationPath,'utf8');
7
+for(const token of [
8
+ 'request_type_definitions',
9
+ 'request_type_versions',
10
+ 'request_workflow_versions',
11
+ 'request_publish_type_version',
12
+ 'request_create_instance',
13
+ 'request_transition_instance',
14
+ 'expected_revision',
15
+ 'idempotency_key',
16
+ 'requests_workflow',
17
+ "'configure'",
18
+ 'for update'
19
+]) assert.ok(sql.toLowerCase().includes(token.toLowerCase()),`missing Slice D1 contract token: ${token}`);
20
+assert.match(sql,/unique\s*\([^)]*organization_id[^)]*code[^)]*\)/i,'request type code must be tenant-unique');
21
+assert.match(sql,/unique\s*\([^)]*organization_id[^)]*idempotency_key[^)]*\)/i,'instance creation must be idempotent per tenant');
22
+assert.match(sql,/raise exception[^;]*(stale|revision)/i,'transition RPC must reject stale revisions');
23
+assert.match(sql,/private\.has_org_capability\([^;]*requests_workflow[^;]*configure/i,'publishing must require requests_workflow.configure');
24
+assert.match(sql,/private\.has_org_capability\([^;]*requests_workflow[^;]*(create|approve|edit)/i,'runtime mutation must enforce workflow capability');
25
+console.log('Slice D1 request workflow foundation invariants: OK');