codex/aram-mapping-source-parser-20261101
add-index-html-10623938925177053894 arena/094f314c-aram chatgpt-phase1b2-autopilot codex/adr-future-connectors-pi-v1 codex/aram-account-note-source-trace-20261031 codex/aram-actions-node24-maintenance-20261031 codex/aram-analyst-review-workbook-20261031 codex/aram-bs-candidate-statement-20261031 codex/aram-cash-flow-direct-candidate-20261031 codex/aram-clean-reference-year-integrity-20261030 codex/aram-cross-statement-controls-20261031 codex/aram-equity-changes-candidate-20261031 codex/aram-five-statement-cli-20261031 codex/aram-five-statement-integration-20261031 codex/aram-five-statement-orchestrator-20261031 codex/aram-gate3-coverage-target-guard-20261030 codex/aram-gate3-hidden-xlsx-guard-20261030 codex/aram-gate3-integration-validation-20261030 codex/aram-gate3-mapping-change-preview-20261030 codex/aram-gate3-stale-note-guard-20261030 codex/aram-income-statement-candidate-20261031 codex/aram-manifest-referential-integrity-20261031 codex/aram-mapping-source-parser-20261101 codex/aram-multidimensional-mapping-20261101 codex/aram-multistatement-mapping-20261031 codex/aram-pipeline-manifest-schema-20261031 codex/aram-readonly-mapping-coverage-20261031 codex/aram-reconciliation-review-gate-20261031 codex/aram-same-flush-fiscal-lock-20261030 codex/aram-synthetic-windows-demo-20261031 codex/aram-trial-balance-diagnostic-20261031 codex/aram-windows-background-detail-search-20261031 codex/aram-windows-detail-review-20261031 codex/aram-windows-five-statement-pilot-20261031 codex/aram-windows-statement-figures-20261031 codex/gate-2a-pilot-workbook codex/gate-2a-pilot-workbook-6864754244772568979 codex/gate3-authenticated-principal-boundary-20261030 codex/gate3-authored-draft-staging-20261030 codex/gate3-carry-forward-preview-20261023 codex/gate3-draft-staging-audit-20261030 codex/gate3-mapping-batch-freshness-20261030 codex/gate3-mapping-batch-review-20261030 codex/gate3-mapping-core codex/gate3-mapping-coverage-20261023 codex/gate3-mapping-excel-20261023 codex/gate3-note-mapping-review-20261023 codex/gate3-signed-year-scope-20261030 codex/gate3-unapproved-proposal-storage-20261030 codex/payvast-mapping-discovery-20261023 codex/phase-2a-backend-foundation codex/phase-2b-post-merge-record codex/phase-2b-source-registration codex/phase-2b-source-registration-12955190277775369594 codex/post-gate2a-control-reconciliation codex/post-pr18-acceptance-record codex/project-control-foundation codex/t1-repo-hygiene-20261023 codex/t2-ci-hardening-20261023 codex/t3-explicit-migrations-20261023 codex/t6a-readonly-diagnostics-20261023 codex/v1-01-safety-gate-hardening codex/v1-year-isolation-followup-20261023 codex/windows-native-pilot-shell-20261030 docs/aram-master-control-plan-20261111 docs/aram-roadmap-dashboard-20261030 docs/financial-statement-reconciliation-1402-1404-20261110 feat/gate3-governed-mapping-20261101 feat/gate3-package9-1-security-20261103 feat/gate3-package9-isolated-20261103 fix/password-unicode-validation-20261111 governance/aram-5-1-3-controls-20261030 governance/role-based-operating-model jules-1168663913887856558-73b8a885 jules-gate-2b-mapping-workflow-foundation-4137724387867065330 phase-1b1-audit-report-7365389436990903239 phase-2a-backend-foundation-10237597358138521261 phase1b2-postmerge-metadata-fix refactor/drg-parent-year-id-15088443704684163304 source-data-cleanup
py 271 lines 11.2 KB
Raw
1 """Clearly synthetic demo data; NEVER company data or an official report.
2
3 This is intentionally shared with integration tests to prevent fixture drift.
4 Writing to disk is opt-in, exclusively inside a brand-new user-specified
5 directory; no existing files are overwritten.
6 """
7 from __future__ import annotations
8
9 import argparse
10 from dataclasses import asdict
11 from io import BytesIO
12 import json
13 from pathlib import Path
14
15 from openpyxl import Workbook
16
17 from aram_backend.cash_flow_direct_candidate import CashFlowEntry
18 from aram_backend.pilot_workbook import SHEET_HEADERS
19 from aram_backend.reconciliation_review import NoteReference
20
21 COMPANY = "001"
22 YEAR = 1404
23 DEMO_WORKBOOK = "ARAM-SYNTHETIC-ONLY.xlsx"
24 DEMO_MANIFEST = "ARAM-SYNTHETIC-ONLY.json"
25 DEMO_NOTICE = "READ-ME-SYNTHETIC-ONLY.txt"
26
27
28 def source_workbook() -> bytes:
29 """One debit-net balanced ledger shared by every candidate builder."""
30 book = Workbook()
31 book.remove(book.active)
32 for name, headers in SHEET_HEADERS.items():
33 book.create_sheet(name).append(list(headers))
34
35 def add(sheet: str, **values: object) -> None:
36 book[sheet].append([values.get(column) for column in SHEET_HEADERS[sheet]])
37
38 add(
39 "Company", company_code=COMPANY, company_name="Synthetic integration only",
40 fiscal_year=YEAR, currency="IRR", unit="Rial", prepared_by="Test fixture",
41 status="Draft",
42 )
43 ledger = (
44 # code, name, opening, debit, credit, closing
45 ("CASH", "Cash", "40", "30", "20", "50"),
46 ("AR", "Receivables", "50", "0", "0", "50"),
47 ("AP", "Payables", "-20", "10", "0", "-10"),
48 ("CAP", "Share capital", "-70", "0", "0", "-70"),
49 ("REV", "Revenue", "0", "0", "40", "-40"),
50 ("EXP", "Cost of revenue", "0", "20", "0", "20"),
51 )
52 for index, (code, name, opening, debit, credit, closing) in enumerate(ledger, 101):
53 add(
54 "Accounts", company_code=COMPANY, fiscal_year=YEAR,
55 general_code=code, general_name=name, account_full_code=code,
56 account_name=name, opening=opening, debit=debit, credit=credit,
57 closing=closing, source_row=index, row_status="Draft",
58 closing_delta="0",
59 )
60
61 notes = (
62 ("BS", "Current assets", "C01", "Cash"),
63 ("BS", "Current assets", "A01", "Receivables"),
64 ("BS", "Current liabilities", "L01", "Payables"),
65 ("BS", "Equity", "E01", "Equity"),
66 ("IS", "Revenue", "R01", "Revenue"),
67 ("IS", "Cost of revenue", "X01", "Cost of revenue"),
68 ("EQ", "Share capital", "E01", "Share capital"),
69 ("EQ", "Current year result", "P01", "Current year result"),
70 )
71 for statement, section, note, title in notes:
72 add(
73 "Notes", company_code=COMPANY, fiscal_year=YEAR,
74 statement=statement, statement_section=section,
75 note_number=note, note_title=title, subnote_code="",
76 subnote_title="",
77 )
78
79 mappings = (
80 ("CASH", "BS", "Current assets", "C01"),
81 ("AR", "BS", "Current assets", "A01"),
82 ("AP", "BS", "Current liabilities", "L01"),
83 ("CAP", "BS", "Equity", "E01"),
84 ("CAP", "EQ", "Share capital", "E01"),
85 ("REV", "IS", "Revenue", "R01"),
86 ("REV", "BS", "Equity", "E01"),
87 ("REV", "EQ", "Current year result", "P01"),
88 ("EXP", "IS", "Cost of revenue", "X01"),
89 ("EXP", "BS", "Equity", "E01"),
90 ("EXP", "EQ", "Current year result", "P01"),
91 )
92 for index, (account, statement, section, note) in enumerate(mappings, 1):
93 add(
94 "Mapping", mapping_id=f"SYNTH-M-{index:02d}",
95 company_code=COMPANY, fiscal_year=YEAR,
96 account_full_code=account, account_level="General",
97 general_code=account, target_statement=statement,
98 statement_section=section, note_number=note, subnote_code="",
99 mapping_version=1, approval_status="Approved",
100 reviewer="Synthetic fixture only", review_date="2026-10-31",
101 source="Synthetic test", notes="Not an authenticated approval",
102 validation_status="Valid",
103 )
104
105 output = BytesIO()
106 book.save(output)
107 book.close()
108 return output.getvalue()
109
110
111 def references() -> tuple[NoteReference, ...]:
112 return (
113 NoteReference("BS", "Current assets", "C01", "", "50", "SYNTH-BS-CASH"),
114 NoteReference("BS", "Current assets", "A01", "", "50", "SYNTH-BS-AR"),
115 NoteReference("BS", "Current liabilities", "L01", "", "-10", "SYNTH-BS-AP"),
116 NoteReference("BS", "Equity", "E01", "", "-90", "SYNTH-BS-EQ"),
117 NoteReference("IS", "Revenue", "R01", "", "-40", "SYNTH-IS-REV"),
118 NoteReference("IS", "Cost of revenue", "X01", "", "20", "SYNTH-IS-COST"),
119 NoteReference("EQ", "Share capital", "E01", "", "-70", "SYNTH-EQ-CAP"),
120 NoteReference("EQ", "Current year result", "P01", "", "-20", "SYNTH-EQ-PROFIT"),
121 )
122
123
124 def cash_transactions() -> tuple[CashFlowEntry, ...]:
125 return (
126 CashFlowEntry(
127 company_code=COMPANY, fiscal_year=YEAR, line_id="CF-L1",
128 transaction_id="CF-V1", posting_date="1404-01-01",
129 cash_account_code="CASH", counterpart_account_code="REV",
130 cash_debit="30", cash_credit="0", counterpart_debit="0",
131 counterpart_credit="30", evidence_ref="SYNTH-TXN-1",
132 ),
133 CashFlowEntry(
134 company_code=COMPANY, fiscal_year=YEAR, line_id="CF-L2",
135 transaction_id="CF-V2", posting_date="1404-01-02",
136 cash_account_code="CASH", counterpart_account_code="EXP",
137 cash_debit="0", cash_credit="20", counterpart_debit="20",
138 counterpart_credit="0", evidence_ref="SYNTH-TXN-2",
139 ),
140 )
141
142
143 def pipeline_manifest(*, transactions=None):
144 return {
145 "schema_version": 1,
146 "company_code": COMPANY,
147 "fiscal_year": YEAR,
148 "currency": "IRR",
149 "unit": "Rial",
150 "references": [asdict(item) for item in references()],
151 "balance_sheet_policies": [
152 {
153 "statement_section": "Current assets", "note_number": "C01",
154 "subnote_code": "", "category": "ASSETS", "sign_multiplier": 1,
155 "line_label": "Cash and cash equivalents",
156 "policy_evidence_ref": "SYNTH-POL-BS-CASH",
157 },
158 {
159 "statement_section": "Current assets", "note_number": "A01",
160 "subnote_code": "", "category": "ASSETS", "sign_multiplier": 1,
161 "line_label": "Trade receivables", "policy_evidence_ref": "SYNTH-POL-BS-AR",
162 },
163 {
164 "statement_section": "Current liabilities", "note_number": "L01",
165 "subnote_code": "", "category": "LIABILITIES", "sign_multiplier": -1,
166 "line_label": "Trade payables", "policy_evidence_ref": "SYNTH-POL-BS-AP",
167 },
168 {
169 "statement_section": "Equity", "note_number": "E01",
170 "subnote_code": "", "category": "EQUITY", "sign_multiplier": -1,
171 "line_label": "Total equity", "policy_evidence_ref": "SYNTH-POL-BS-EQ",
172 },
173 ],
174 "income_statement_policies": [
175 {
176 "statement_section": "Revenue", "note_number": "R01",
177 "subnote_code": "", "category": "REVENUE", "sign_multiplier": -1,
178 "line_label": "Revenue", "policy_evidence_ref": "SYNTH-POL-IS-REV",
179 },
180 {
181 "statement_section": "Cost of revenue", "note_number": "X01",
182 "subnote_code": "", "category": "COST_OF_REVENUE", "sign_multiplier": 1,
183 "line_label": "Cost of revenue", "policy_evidence_ref": "SYNTH-POL-IS-COST",
184 },
185 ],
186 "equity_movement_policies": [
187 {
188 "statement_section": "Share capital", "note_number": "E01",
189 "subnote_code": "", "equity_component": "SHARE_CAPITAL",
190 "movement_category": "CAPITAL_CONTRIBUTION", "sign_multiplier": -1,
191 "line_label": "Share capital", "policy_evidence_ref": "SYNTH-POL-EQ-CAP",
192 },
193 {
194 "statement_section": "Current year result", "note_number": "P01",
195 "subnote_code": "", "equity_component": "RETAINED_EARNINGS",
196 "movement_category": "NET_PROFIT_LOSS", "sign_multiplier": -1,
197 "line_label": "Current year profit", "policy_evidence_ref": "SYNTH-POL-EQ-PROFIT",
198 },
199 ],
200 "cash_accounts": [
201 {"account_code": "CASH", "evidence_ref": "SYNTH-CASH-SCOPE"},
202 ],
203 "counterpart_policies": [
204 {"account_code": "REV", "activity": "OPERATING", "evidence_ref": "SYNTH-REV-CLASS"},
205 {"account_code": "EXP", "activity": "OPERATING", "evidence_ref": "SYNTH-EXP-CLASS"},
206 ],
207 "transactions": [
208 asdict(item) for item in (
209 cash_transactions() if transactions is None else transactions
210 )
211 ],
212 "cash_balance_notes": [
213 {
214 "statement_section": "Current assets", "note_number": "C01",
215 "subnote_code": "", "evidence_ref": "SYNTH-CASH-NOTE-SELECTION",
216 },
217 ],
218 }
219
220
221 def write_demo_bundle(output_dir: str | Path) -> tuple[Path, Path]:
222 """Write labeled, entirely artificial files into one NEW directory only.
223
224 Do not silently replace or modify an existing location, including a
225 symlink. The caller must specify the directory and opt in explicitly.
226 """
227 directory = Path(output_dir)
228 if directory.exists() or directory.is_symlink():
229 raise FileExistsError("DEMO_OUTPUT_DIRECTORY_MUST_NOT_EXIST")
230 directory.mkdir(parents=True, exist_ok=False)
231 workbook_path = directory / DEMO_WORKBOOK
232 manifest_path = directory / DEMO_MANIFEST
233 workbook_path.write_bytes(source_workbook())
234 manifest_path.write_text(
235 json.dumps(
236 pipeline_manifest(), sort_keys=True, ensure_ascii=True, indent=2,
237 ) + "\n",
238 encoding="utf-8",
239 )
240 (directory / DEMO_NOTICE).write_text(
241 "ARAM SYNTHETIC TEST DATA ONLY.\n"
242 "NOT A REAL COMPANY, FINANCIAL STATEMENT, APPROVAL OR SOURCE LEDGER.\n"
243 "All accounts, amounts, policy references and journal lines are artificial.\n"
244 "The demo result may show eligible_for_analyst_review=true only for\n"
245 "software arithmetic testing. Never use it for accounting decisions.\n",
246 encoding="utf-8",
247 )
248 return workbook_path, manifest_path
249
250
251 def main(argv: list[str] | None = None) -> int:
252 parser = argparse.ArgumentParser(
253 description="Generate an ARAM entirely synthetic Windows inspection demo"
254 )
255 parser.add_argument(
256 "--output-dir", required=True,
257 help="New directory for synthetic XLSX, JSON and warning notice",
258 )
259 args = parser.parse_args(argv)
260 try:
261 workbook, manifest = write_demo_bundle(args.output_dir)
262 except (OSError, ValueError) as exc:
263 parser.exit(2, "ARAM_SYNTHETIC_DEMO_REFUSED: " + str(exc) + "\n")
264 print("SYNTHETIC ONLY; not company data, financial approval or release.")
265 print("Workbook:", workbook)
266 print("Manifest:", manifest)
267 return 0
268
269
270 if __name__ == "__main__":
271 raise SystemExit(main())