@davoodmehraban89 / Aram-2 Mirror · read-only / commits / f2ac58c
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 15:30 UTC

R5: C-01 exception registry (docs/c01_exceptions.json)

Record the six fiscal-1404 source rows that fail C-01 (opening + debit - credit - closing != 0): 121669/121670/121671/121672/157241/207127, three offsetting pairs of direct-to-closing adjustments, each netting to zero. Values derived from the real 131,280-row import and cross-checked against the XLSX Source cells; source SHA-256 anchored. status=UNAPPROVABLE; C-01 stays ERROR (no tolerance/bypass); resolution is an owner accounting decision. tests/test_c01_exceptions_r5.py: 6 integrity tests. Reviewed secret-baseline update for the registry's 3 integrity hashes (22 findings, 0 new); test tree-hashes escaped inline. Authored 253/1500 excl tests/data. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

davoodmehraban89 committed Dec 4, 2026 at 15:29 UTC f2ac58c62a7042de902e2e049d4496f984269e35
5 files changed +349 -2
.secrets.baseline
+24 -1
@@ -255,6 +255,29 @@
255 "line_number": 25
256 }
257 ],
258 + "docs/c01_exceptions.json": [
259 + {
260 + "type": "Hex High Entropy String",
261 + "filename": "docs/c01_exceptions.json",
262 + "hashed_secret": "49428be58f5d1c763e3dda4d850cc5fff8227e16",
263 + "is_verified": false,
264 + "line_number": 14
265 + },
266 + {
267 + "type": "Hex High Entropy String",
268 + "filename": "docs/c01_exceptions.json",
269 + "hashed_secret": "c14638f8d681fccab3e5a5c79edab2f05eff9914",
270 + "is_verified": false,
271 + "line_number": 201
272 + },
273 + {
274 + "type": "Hex High Entropy String",
275 + "filename": "docs/c01_exceptions.json",
276 + "hashed_secret": "df19dd21047ea9ef431df29d65592cb9b7f42452",
277 + "is_verified": false,
278 + "line_number": 202
279 + }
280 + ],
281 "docs/discrepancies.json": [
282 {
283 "type": "Hex High Entropy String",
@@ -281,5 +304,5 @@
304 }
305 ]
306 },
284 - "generated_at": "2026-12-04T14:05:45Z"
307 + "generated_at": "2026-12-04T15:24:27Z"
308 }
PROJECT_STATUS.md
+12 -1
@@ -97,7 +97,7 @@ Booklet 2 v2.0 («اصلاح مسیر و معماری نهایی Aram», [`docs/
97 | R2 | Controls C-05..C-15 wired into `run_controls` + approval | **MET** — PR #100 squash-merged 2026-12-04T10:40:42Z → `a8ba20c1` |
98 | R3 | `build_statements` vs official; (statement, note) aggregation; IS 6/8/9 root cause; EQ/CF parsing | **PARTIAL** (this PR) — BS 16/16 met; IS 6/6 **not met**, blocked by source data (evidence below) |
99 | R4 | Remove `create_all` from the production path; backup → `alembic upgrade head` → trigger check | **MET** (this PR) — Alembic-only init + restore flow; ADR-035; 20 tests |
100 -| R5 | `docs/c01_exceptions.json` — the six C-01 source rows, unapprovable until resolved | NOT_STARTED |
100 +| R5 | `docs/c01_exceptions.json` — the six C-01 source rows, unapprovable until resolved | **MET** (this PR) — registry of 6 rows / 3 offsetting pairs, status UNAPPROVABLE; 6 integrity tests |
101 | R6 | Propose marking the `v1.0.0` Release as pre-release; `experiment/browser-edition` = owner action | NOT_STARTED |
102
103 ### R1 acceptance ← evidence
@@ -161,6 +161,17 @@ non-statement rows (BS 6/16 → 16/16), and per-row note assignment was lost (mi
161
162 `backend/tests/test_schema_r4.py` **20 passed**; desktop/auth/admin regression **55 passed**; ruff check + format, mypy (domain strict + services) clean. Decisions in **ADR-035**. No new runtime dependency; protected data untouched.
163
164 +### R5 acceptance ← evidence
165 +
166 +| معیار پذیرش | شاهد | وضعیت |
167 +| --- | --- | --- |
168 +| The six C-01 source rows recorded with real values | `docs/c01_exceptions.json` — source_row 121669/121670/121671/121672/157241/207127; opening=debit=credit=0, residual=−closing; cross-checked against the XLSX cells | MET |
169 +| No invented financial value | generated from the real import + independent XLSX read; `test_source_sha256_anchors_to_committed_workbook` | MET |
170 +| C-01 still blocks; year unapprovable until resolved | `summary.status=UNAPPROVABLE`, `control.blocks_approval=true`; `test_check_c01_flags_exactly_the_recorded_rows` | MET |
171 +| Three offsetting pairs net to zero | `test_offsetting_pairs_net_to_zero` (±4,697,329,586,452 / ±20,909,528,168,795 / ±10,000,000,000,000 rial) | MET |
172 +
173 +`backend/tests/test_c01_exceptions_r5.py` **6 passed**. The registry is documentation/data only — no control code, tolerance, or bypass changed; resolution is an owner accounting decision (decompose into real movements, or record an explicit approved exception). Source SHA-256 + protected-tree hashes baselined as reviewed false positives (secret gate 22 findings, 0 new).
174 +
175 ## Known gaps feeding the C-phases (honest residual risks)
176
177 - **Authorization forgeability — CLOSED in R1 (2026-12-04, ADR-030).** Was: roles derived from a client-supplied `actor` body string; `"actor":"admin"` granted admin to anyone; most endpoints unguarded; approval open when no users existed; `pilot_api.py` exposed 17 unauthenticated routes. Now: `actor` removed from every request model; identity comes only from `current_user` resolving a 256-bit bearer token whose SHA-256 is stored server-side (8-hour absolute TTL, logout, 5-attempt lockout for 15 minutes, PBKDF2 600,000); every route except `/health`, `/auth/login`, `/auth/launch` and the one-time first-admin bootstrap requires a session, reads included; approval without users is impossible; the pilot router and the legacy `/` UI are out of the app; backup `dest` is confined to the data folder; the desktop launcher gates the local API with a one-time token. Evidence: `backend/tests/test_auth_r1.py` (33 tests). Remaining C8 scope: DPAPI vault, encrypted backup, plugin allowlist, row/field-level access layers.
backend/tests/test_c01_exceptions_r5.py new
+98
@@ -0,0 +1,98 @@
1 +"""R5 (booklet 2.1): the C-01 exception registry is internally consistent and
2 +anchored to the real committed source — no invented values.
3 +
4 +The registry ``docs/c01_exceptions.json`` records the six source rows that fail
5 +C-01 (opening + debit - credit - closing = 0) for fiscal 1404. These tests prove
6 +the recorded arithmetic is exactly what ``check_c01`` computes, the three
7 +offsetting pairs net to zero, the year is unapprovable until the owner resolves
8 +them, and the source SHA-256 matches the committed workbook.
9 +"""
10 +
11 +from __future__ import annotations
12 +
13 +import hashlib
14 +import json
15 +from decimal import Decimal
16 +from pathlib import Path
17 +
18 +from aram_backend.domain.controls import BalanceRow, check_c01
19 +
20 +ROOT = Path(__file__).resolve().parents[2]
21 +REGISTRY = ROOT / "docs" / "c01_exceptions.json"
22 +
23 +
24 +def _doc() -> dict:
25 + return json.loads(REGISTRY.read_text(encoding="utf-8"))
26 +
27 +
28 +def test_registry_structure():
29 + d = _doc()
30 + assert d["schema"] == "aram-c01-exceptions-1"
31 + assert d["control"]["code"] == "C-01"
32 + assert d["control"]["severity"] == "ERROR"
33 + assert d["control"]["blocks_approval"] is True
34 + assert d["source"]["year"] == 1404
35 + assert d["source"]["sheet"] == "Source"
36 + assert len(d["exceptions"]) == 6
37 + assert len(d["pairs"]) == 3
38 + assert d["summary"]["violating_rows"] == 6
39 + assert d["summary"]["status"] == "UNAPPROVABLE"
40 +
41 +
42 +def test_recorded_residuals_equal_the_equation():
43 + for e in _doc()["exceptions"]:
44 + resid = e["opening"] + e["debit"] - e["credit"] - e["closing"]
45 + assert resid == e["residual"], e["source_row"]
46 + # Direct-to-closing adjustments: no movement, residual = -closing.
47 + assert e["opening"] == 0 and e["debit"] == 0 and e["credit"] == 0
48 + assert e["residual"] == -e["closing"]
49 + assert e["statement_balance"] == e["closing"]
50 + assert e["raw_xlsx_cells"]["CLOSING"] == e["closing"]
51 +
52 +
53 +def test_check_c01_flags_exactly_the_recorded_rows():
54 + """Reconstruct BalanceRows from the registry; C-01 must flag exactly these six."""
55 + d = _doc()
56 + rows = [
57 + BalanceRow(
58 + row_number=e["source_row"],
59 + account_code=e["account_full_code"],
60 + opening=Decimal(e["opening"]),
61 + debit=Decimal(e["debit"]),
62 + credit=Decimal(e["credit"]),
63 + closing=Decimal(e["closing"]),
64 + statement_balance=Decimal(e["statement_balance"]),
65 + source_note=e["source_note"],
66 + )
67 + for e in d["exceptions"]
68 + ]
69 + result = check_c01(rows)
70 + assert result.passed is False
71 + assert result.severity == "ERROR"
72 + recorded = {str(e["source_row"]) for e in d["exceptions"]}
73 + assert set(result.affected) == recorded
74 +
75 +
76 +def test_offsetting_pairs_net_to_zero():
77 + d = _doc()
78 + resid = {e["source_row"]: e["residual"] for e in d["exceptions"]}
79 + for pair in d["pairs"]:
80 + assert sum(resid[r] for r in pair["rows"]) == 0
81 + assert pair["net_rial"] == 0
82 + assert d["summary"]["net_residual_across_pairs_rial"] == 0
83 +
84 +
85 +def test_source_sha256_anchors_to_committed_workbook():
86 + d = _doc()
87 + src = ROOT / d["source"]["file"]
88 + assert src.exists(), "protected source workbook must be present"
89 + digest = hashlib.sha256(src.read_bytes()).hexdigest()
90 + assert digest == d["source"]["sha256"]
91 + assert src.stat().st_size == d["source"]["bytes"]
92 +
93 +
94 +def test_protected_data_recorded_unchanged():
95 + d = _doc()
96 + assert d["protected_data"]["changed"] is False
97 + assert d["protected_data"]["data_tree"] == "2ef8a512523f62f0cf84c5009f141be2f8a9cb5f" # pragma: allowlist secret
98 + assert d["protected_data"]["samples_tree"] == "00aba54b1dc30485ba9b164c8036a7b4bbe9020e" # pragma: allowlist secret
docs/PROJECT_LOG.md
+10
@@ -517,3 +517,13 @@ Each new entry must record: UTC timestamp, actor, task/phase, base branch and SH
517 - **Why upgrade head is universally safe (evidence before code):** migration 01 is checkfirst `create_all`; 02–09 are all guarded. Verified: populated copy 08→09 (131,280 rows + 28 triggers preserved); legacy full-schema create_all (no version) → 09; legacy v1.0.0-era (auth_sessions/source_note/password_rounds absent) → 09 with all re-added. No stamping ladder needed.
518 - Gates: `tests/test_schema_r4.py` **20 passed**; desktop+auth_r1+phase7_admin regression **55 passed**; `ruff check src tests` clean; `ruff format --check` (domain/services/migrations) 36 files clean; mypy domain-strict (6) + services (20) clean. Full suite + coverage floors recorded in the PR.
519 - Protected data: `data/` `2ef8a512…` / `samples/` `00aba54b…` unchanged; no financial value touched; no new runtime dependency (Alembic already required). Tag `v1.0.0` untouched.
520 +
521 +### 2026-12-04T15:28:36Z — R5: C-01 exception registry (docs/c01_exceptions.json)
522 +
523 +- Actor: Arena agent (A1 forensics → B1 registry+tests → T1 gate → M0 integrate, ADR-034). Base: `bf25724106b4d94d923afefc765485d90c4f0591` (R4/#117 squash, verified live; branch tree-identical before starting).
524 +- **The six C-01 rows for fiscal 1404** (opening + debit − credit − closing ≠ 0), derived from the real 131,280-row import and independently cross-checked against the XLSX `Source` sheet cells: source_row **121669** (388519, note 13, closing −4,697,329,586,452), **121670** (568491, note --, +4,697,329,586,452), **121671** (818331, note 6, +20,909,528,168,795), **121672** (368199, note 20, −20,909,528,168,795), **157241** (328512, note 19-1, −10,000,000,000,000), **207127** (578490, note 9, +10,000,000,000,000). All have OPENING/Debit/Credit empty-or-zero → residual = −CLOSING.
525 +- They form **three offsetting pairs** (tax provision ↔ prior-year P&L; employee benefits ↔ early-retirement provision; misc tax ↔ current-year P&L), each netting to zero across the ledger, but each row individually fails C-01. `docs/c01_exceptions.json` records them with `status=UNAPPROVABLE`, the source SHA-256 (`5b4790dc…`), raw XLSX cells, and the resolution path (owner accounting decision: decompose into real movements or record an explicit approved exception). No tolerance/bypass added; C-01 stays ERROR.
526 +- Cross-reference: pair A (±4,697,329,586,452 rial) is the magnitude of official IS note 20-3 (−4,697,329 million rial); in the source it posts to BS note 13 + prior-year P&L, not IS 20-3 — hence IS 20-3 has no source rows in the build (R3 finding).
527 +- `tests/test_c01_exceptions_r5.py` **6 passed**: structure, residual arithmetic, `check_c01` flags exactly the six recorded rows, pairs net to zero, source SHA-256 anchors to the committed workbook, protected trees unchanged.
528 +- Secret gate: the source SHA-256 + the two protected-tree hashes in the registry are reviewed false positives (recomputable from committed data; JSON cannot carry inline pragmas). Reviewed baseline update via the documented `detect-secrets scan --exclude-files '^\.secrets\.baseline$'` → diff added **only** the 3 `docs/c01_exceptions.json` findings, removed none → gate **22 baselined, 0 new**.
529 +- Protected data: `data/` `2ef8a512…` / `samples/` `00aba54b…` unchanged; no financial value altered; documentation/data task only. Tag `v1.0.0` untouched.
docs/c01_exceptions.json new
+205
@@ -0,0 +1,205 @@
1 +{
2 + "schema": "aram-c01-exceptions-1",
3 + "generated_at": "2026-12-04T15:22:54Z",
4 + "control": {
5 + "code": "C-01",
6 + "severity": "ERROR",
7 + "blocks_approval": true,
8 + "equation": "opening + debit - credit - closing = 0",
9 + "message_fa": "همهٔ ردیف‌ها: ابتدای دوره + بدهکار − بستانکار − پایان دوره = ۰",
10 + "implementation": "backend/src/aram_backend/domain/controls.py::check_c01"
11 + },
12 + "source": {
13 + "file": "data/source_ledgers/source_1404.xlsx",
14 + "sha256": "5b4790dce6e9ea169d61c68751bc6fd5dc390012bc14473b0298ba5aac30d044",
15 + "sheet": "Source",
16 + "year": 1404,
17 + "bytes": 32062394,
18 + "row_number_basis": "1-based XLSX row index (rows 1-2 are headers; data starts at row 3); equals LedgerBalance.source_row",
19 + "movement_columns": {
20 + "OPENING": 19,
21 + "Debit": 20,
22 + "Credit": 21,
23 + "CLOSING": 23
24 + }
25 + },
26 + "summary": {
27 + "rows_checked": 131280,
28 + "violating_rows": 6,
29 + "offsetting_pairs": 3,
30 + "net_residual_across_pairs_rial": 0,
31 + "status": "UNAPPROVABLE",
32 + "resolution_owner": "Davood — Project Owner / accounting authority"
33 + },
34 + "exceptions": [
35 + {
36 + "source_row": 121669,
37 + "account_full_code": "388519",
38 + "kol_code": "38",
39 + "subsidiary_code": "8519",
40 + "account_name": "ذخیره مالیات بردرامدشرکت",
41 + "source_note": "13",
42 + "opening": 0,
43 + "debit": 0,
44 + "credit": 0,
45 + "closing": -4697329586452,
46 + "statement_balance": -4697329586452,
47 + "residual": 4697329586452,
48 + "raw_xlsx_cells": {
49 + "OPENING": null,
50 + "Debit": null,
51 + "Credit": null,
52 + "CLOSING": -4697329586452
53 + },
54 + "unit": "rial"
55 + },
56 + {
57 + "source_row": 121670,
58 + "account_full_code": "568491",
59 + "kol_code": "56",
60 + "subsidiary_code": "8491",
61 + "account_name": "سودوزیان سنواتی",
62 + "source_note": "--",
63 + "opening": 0,
64 + "debit": 0,
65 + "credit": 0,
66 + "closing": 4697329586452,
67 + "statement_balance": 4697329586452,
68 + "residual": -4697329586452,
69 + "raw_xlsx_cells": {
70 + "OPENING": 0,
71 + "Debit": null,
72 + "Credit": 0,
73 + "CLOSING": 4697329586452
74 + },
75 + "unit": "rial"
76 + },
77 + {
78 + "source_row": 121671,
79 + "account_full_code": "818331",
80 + "kol_code": "81",
81 + "subsidiary_code": "8331",
82 + "account_name": "مزایای کارمندان",
83 + "source_note": "6",
84 + "opening": 0,
85 + "debit": 0,
86 + "credit": 0,
87 + "closing": 20909528168795,
88 + "statement_balance": 20909528168795,
89 + "residual": -20909528168795,
90 + "raw_xlsx_cells": {
91 + "OPENING": 0,
92 + "Debit": 0,
93 + "Credit": 0,
94 + "CLOSING": 20909528168795
95 + },
96 + "unit": "rial"
97 + },
98 + {
99 + "source_row": 121672,
100 + "account_full_code": "368199",
101 + "kol_code": "36",
102 + "subsidiary_code": "8199",
103 + "account_name": "ذخیره تعهدات مالی کارمندان بازنشسته قبل از موعد (کد23)",
104 + "source_note": "20",
105 + "opening": 0,
106 + "debit": 0,
107 + "credit": 0,
108 + "closing": -20909528168795,
109 + "statement_balance": -20909528168795,
110 + "residual": 20909528168795,
111 + "raw_xlsx_cells": {
112 + "OPENING": 0,
113 + "Debit": 0,
114 + "Credit": 0,
115 + "CLOSING": -20909528168795
116 + },
117 + "unit": "rial"
118 + },
119 + {
120 + "source_row": 157241,
121 + "account_full_code": "328512",
122 + "kol_code": "32",
123 + "subsidiary_code": "8512",
124 + "account_name": "مالیات متفرقه",
125 + "source_note": "19-1",
126 + "opening": 0,
127 + "debit": 0,
128 + "credit": 0,
129 + "closing": -10000000000000,
130 + "statement_balance": -10000000000000,
131 + "residual": 10000000000000,
132 + "raw_xlsx_cells": {
133 + "OPENING": null,
134 + "Debit": null,
135 + "Credit": null,
136 + "CLOSING": -10000000000000
137 + },
138 + "unit": "rial"
139 + },
140 + {
141 + "source_row": 207127,
142 + "account_full_code": "578490",
143 + "kol_code": "57",
144 + "subsidiary_code": "8490",
145 + "account_name": "سودوزیان سال جاری",
146 + "source_note": "9",
147 + "opening": 0,
148 + "debit": 0,
149 + "credit": 0,
150 + "closing": 10000000000000,
151 + "statement_balance": 10000000000000,
152 + "residual": -10000000000000,
153 + "raw_xlsx_cells": {
154 + "OPENING": 0,
155 + "Debit": null,
156 + "Credit": 0,
157 + "CLOSING": 10000000000000
158 + },
159 + "unit": "rial"
160 + }
161 + ],
162 + "pairs": [
163 + {
164 + "pair": "A",
165 + "theme_fa": "ذخیره مالیات بردرامد شرکت ↔ سودوزیان سنواتی",
166 + "rows": [
167 + 121669,
168 + 121670
169 + ],
170 + "magnitude_rial": 4697329586452,
171 + "net_rial": 0
172 + },
173 + {
174 + "pair": "B",
175 + "theme_fa": "مزایای کارمندان ↔ ذخیره تعهدات مالی کارمندان بازنشسته قبل از موعد",
176 + "rows": [
177 + 121671,
178 + 121672
179 + ],
180 + "magnitude_rial": 20909528168795,
181 + "net_rial": 0
182 + },
183 + {
184 + "pair": "C",
185 + "theme_fa": "مالیات متفرقه ↔ سودوزیان سال جاری",
186 + "rows": [
187 + 157241,
188 + 207127
189 + ],
190 + "magnitude_rial": 10000000000000,
191 + "net_rial": 0
192 + }
193 + ],
194 + "analysis_fa": "هر شش ردیف تنها «مانده صورت مالی» (CLOSING) دارند و OPENING/Debit/Credit آن‌ها تهی یا صفر است؛ بنابراین معادلهٔ C-01 (ابتدای دوره + بدهکار − بستانکار − پایان دوره = ۰) برای هر ردیف نقض می‌شود (باقی‌مانده = −CLOSING). این ردیف‌ها سه جفت تعدیلِ مستقیم به مانده پایانی‌اند که جمع هر جفت صفر است، اما هر ردیف به‌تنهایی C-01 را رد می‌کند. مقادیر از ایمپورت واقعی و سلول‌های XLSX به‌طور مستقل تأیید شده‌اند؛ هیچ عددی ساخته یا اصلاح نشده است.",
195 + "resolution_required_fa": "تا زمانی که مالکِ حسابداری این شش ردیف را تعیین تکلیف نکند، سال ۱۴۰۴ قابل تأیید (approve) نیست. گزینه‌ها: (الف) تجزیهٔ هر تعدیل به حرکت‌های OPENING/Debit/Credit واقعی در دفتر منبع، یا (ب) ثبت یک استثنای صریح و مصوب با دلیل حسابداری در همین رجیستری. کنترل C-01 همچنان ERROR و مسدودکننده باقی می‌ماند؛ هیچ tolerance یا bypass در کد ساخته نمی‌شود (booklet 2.1).",
196 + "cross_references": {
197 + "discrepancies_registry": "docs/discrepancies.json",
198 + "note": "جفت A (±4,697,329,586,452 ریال) هم‌اندازه با یادداشت رسمی 20-3 (−4,697,329 میلیون ریال) است؛ در منبع، این تعدیل به یادداشت 13 (ترازنامه) و سودوزیان سنواتی ثبت شده، نه به یادداشت IS 20-3 — از این رو IS 20-3 در ساخت صورت مالی ردیف منبع ندارد (R3)."
199 + },
200 + "protected_data": {
201 + "data_tree": "2ef8a512523f62f0cf84c5009f141be2f8a9cb5f",
202 + "samples_tree": "00aba54b1dc30485ba9b164c8036a7b4bbe9020e",
203 + "changed": false
204 + }
205 +}