Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 20:45 UTC
test(demo): verify demo bundle runs real engine and never overwrites local data
davoodmehraban89 committed
Oct 31, 2026 at 19:02 UTC
bcdfe6164f637fe60216c9225c4b5a577205430c
1 file changed
+95
backend/tests/test_synthetic_five_statement_demo.py
new
+95
@@ -0,0 +1,95 @@
1
+"""Synthetic inspection package creation and safety tests."""
2
+from __future__ import annotations
3
+
4
+from hashlib import sha256
5
+import json
6
+
7
+import pytest
8
+
9
+from aram_backend.five_statement_pipeline_cli import run_pipeline_cli
10
+from aram_backend.synthetic_five_statement_demo import (
11
+ DEMO_MANIFEST, DEMO_NOTICE, DEMO_WORKBOOK,
12
+ main, pipeline_manifest, source_workbook, write_demo_bundle,
13
+)
14
+
15
+
16
+def test_generated_demo_bundle_runs_real_five_statement_pipeline(tmp_path):
17
+ destination = tmp_path / "ARAM-DEMO-SYNTHETIC-ONLY"
18
+ workbook, manifest = write_demo_bundle(destination)
19
+ assert workbook.name == DEMO_WORKBOOK
20
+ assert manifest.name == DEMO_MANIFEST
21
+ assert (destination / DEMO_NOTICE).is_file()
22
+ assert "SYNTHETIC" in (destination / DEMO_NOTICE).read_text(encoding="utf-8")
23
+ assert len(tuple(destination.iterdir())) == 3
24
+
25
+ original_workbook = sha256(workbook.read_bytes()).hexdigest()
26
+ original_manifest = sha256(manifest.read_bytes()).hexdigest()
27
+ result = run_pipeline_cli(str(workbook), str(manifest))
28
+ assert result.eligible_for_analyst_review, result.findings
29
+ assert result.balance_sheet.assets_total == "100"
30
+ assert result.income_statement.net_result == "20"
31
+ assert result.equity_changes.closing_equity_total == "90"
32
+ assert result.cash_flow.closing_cash_and_equivalents == "50"
33
+ assert not result.releasable and not result.official_financial_statement
34
+ assert sha256(workbook.read_bytes()).hexdigest() == original_workbook
35
+ assert sha256(manifest.read_bytes()).hexdigest() == original_manifest
36
+
37
+
38
+def test_example_manifest_is_structurally_parseable_and_not_real_company_data():
39
+ document = pipeline_manifest()
40
+ assert document["schema_version"] == 1
41
+ assert document["company_code"] == "001"
42
+ assert all(str(item["evidence_ref"]).startswith("SYNTH-") for item in document["references"])
43
+ assert all(str(item["line_id"]).startswith("CF-") for item in document["transactions"])
44
+ assert source_workbook()[:2] == b"PK"
45
+
46
+
47
+def test_generator_never_overwrites_an_existing_directory_or_file(tmp_path):
48
+ destination = tmp_path / "EXISTING-DATA"
49
+ destination.mkdir()
50
+ original = destination / "private.xlsx"
51
+ original.write_bytes(b"private untouched")
52
+ before = sha256(original.read_bytes()).hexdigest()
53
+ with pytest.raises(FileExistsError):
54
+ write_demo_bundle(destination)
55
+ assert sha256(original.read_bytes()).hexdigest() == before
56
+ assert list(destination.iterdir()) == [original]
57
+
58
+
59
+def test_generator_never_overwrites_existing_demo_bundle(tmp_path):
60
+ directory = tmp_path / "ARAM-DEMO"
61
+ workbook, manifest = write_demo_bundle(directory)
62
+ digests = (
63
+ sha256(workbook.read_bytes()).hexdigest(),
64
+ sha256(manifest.read_bytes()).hexdigest(),
65
+ )
66
+ with pytest.raises(FileExistsError):
67
+ write_demo_bundle(directory)
68
+ assert (
69
+ sha256(workbook.read_bytes()).hexdigest(),
70
+ sha256(manifest.read_bytes()).hexdigest(),
71
+ ) == digests
72
+
73
+
74
+def test_generator_rejects_symlink_directory(tmp_path):
75
+ destination = tmp_path / "SENSITIVE"
76
+ destination.mkdir()
77
+ link = tmp_path / "ALIAS"
78
+ try:
79
+ link.symlink_to(destination, target_is_directory=True)
80
+ except (OSError, NotImplementedError):
81
+ pytest.skip("Symlinks unavailable on this runner")
82
+ with pytest.raises(FileExistsError):
83
+ write_demo_bundle(link)
84
+ assert not list(destination.iterdir())
85
+
86
+
87
+def test_module_cli_requires_explicit_output_directory(tmp_path):
88
+ with pytest.raises(SystemExit):
89
+ main([])
90
+ destination = tmp_path / "FIRST-DEMO"
91
+ assert main(["--output-dir", str(destination)]) == 0
92
+ assert (destination / DEMO_WORKBOOK).is_file()
93
+ with pytest.raises(SystemExit) as exc:
94
+ main(["--output-dir", str(destination)])
95
+ assert exc.value.code == 2