فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(A03): normalize incomplete v6 audit metadata before strict restore validation

davoodmehraban89 committed Oct 20, 2026 at 08:51 UTC 9563296884b7131a97a265a296d99977d7522fce
3 files changed +10 -3
STATUS.md
+5
@@ -60,3 +60,8 @@ Review CI on latest A03 PR head, fix failing fixtures and ensure restore authori
60 ## A03 CI request 2026-10-20
61 - Implementation commit 293239951b6c15df766e891fd386b54c6f99ec51 adds anchored full backups, strict company backup order verification, deterministic v6 replay compatibility, and end-to-end tampering tests. No pass claim before CI.
62 - PR #116 temporarily targets main to activate the existing pull_request quality workflow; remains draft and unmerged. Remote Desktop excluded.
63 +
64 +## A03 CI evidence: 2026-10-20, run 39374384074
65 +- SHA 46f5dd613b543778e27c498a54c664f9edf01845; completed failure, npm test: 257 tests, 251 passed, 6 failed, exit 1.
66 +- Failures: A02 audit rollback; A03 full restore rejects modified event (error message mismatch, integrity rejection correctly occurs); A03 v6 migration; A03 company scope; A03 append-only direct protection; A03 clear rollback.
67 +- Root cause of five fixture failures: restoreHistorical validated legacy actorId/sourceId/commandKey before deterministic migration defaults were applied. Fix permits missing legacy metadata but rejects present invalid values. Sixth test now accepts earlier chain integrity rejection rather than requiring a later immutable-overwrite error. The rejection and rollback assertion remain mandatory.
src/core/AuditService.js
+4 -2
@@ -79,8 +79,10 @@ class AuditServiceImpl {
79 }
80 if (!row || typeof row !== 'object' || Array.isArray(row) ||
81 !validId(row.id) || !validId(row.companyId) ||
82 - !validId(row.actorId) || !VALID_TYPES.has(row.eventType) ||
83 - !validId(row.commandKey) || !validId(row.sourceId) ||
82 + !VALID_TYPES.has(row.eventType) ||
83 + (row.actorId !== undefined && !validId(row.actorId)) ||
84 + (row.commandKey !== undefined && !validId(row.commandKey)) ||
85 + (row.sourceId !== undefined && !validId(row.sourceId)) ||
86 (row.businessDate !== undefined && !validBusinessDate(row.businessDate)) ||
87 (row.occurredAtUtc !== undefined && !validUtc(row.occurredAtUtc))) {
88 throw new Error('رکورد تاریخچه ممیزی نامعتبر است');
tests/a03-append-only-full-restore.test.mjs
+1 -1
@@ -26,7 +26,7 @@ test('A03: full restore refuses to mutate prior audit events and rolls back earl
26 products: [{ id: 'new-product', companyId: 'c1', name: 'must roll back' }],
27 audit_events: [{ ...before, eventType: 'period_closed' }]
28 }
29 - }), /بازنویسی سابقه/);
29 + }), /بازنویسی سابقه|زنجیره ممیزی/);
30 assert.equal(await StorageService.get('products', 'new-product'), undefined);
31 assert.deepEqual(await StorageService.get('audit_events', audit.id), before);
32