feat: add public h5 dashboard and publish traceability

This commit is contained in:
Wyndham ARR
2026-08-03 13:04:41 +08:00
parent 7e7470821b
commit 2107f00e32
29 changed files with 1047 additions and 71 deletions

View File

@@ -9,7 +9,13 @@ from dataclasses import replace
from datetime import date
from pathlib import Path
from company_reports.publishing import ArtifactToolBuilder, AtomicReportPublisher
from company_reports.publishing import (
ArtifactToolBuilder,
AtomicReportPublisher,
BuiltWorkbook,
sha256_file,
)
from company_reports.repository import ReservedReport
from company_reports.service import CompanyReportService, RunRequest
from tests.test_company_reports_service import FakeRepository, synthetic_snapshot
@@ -94,16 +100,50 @@ class CompanyReportIntegrationTests(unittest.TestCase):
(output_root / "2026" / "07" / "HanaTour-July-2026.xlsx").is_file()
)
def test_same_snapshot_rerun_rebuilds_full_month_with_equal_semantics(self):
def test_same_snapshot_rerun_reuses_publication_when_binary_changes(self):
node = node_binary()
if not node:
self.skipTest("Node.js is unavailable")
class StableVersionRepository(FakeRepository):
def reserve_report(self, report):
reservation = ReservedReport(9001, 1, report.company)
self.reserved.append(reservation)
return reservation
class RebuildingBuilder:
def __init__(self, delegate):
self.delegate = delegate
self.binary_sha256s = []
def build(self, report, work_dir):
built = self.delegate.build(report, work_dir)
with built.path.open("ab") as handle:
handle.write(
f"\nsynthetic-rebuild-marker-{len(self.binary_sha256s)}".encode(
"utf-8"
)
)
handle.flush()
os.fsync(handle.fileno())
os.chmod(built.path, 0o600)
rebuilt = BuiltWorkbook(
path=built.path,
sha256=sha256_file(built.path),
byte_size=built.path.stat().st_size,
summary=built.summary,
)
self.binary_sha256s.append(rebuilt.sha256)
return rebuilt
with tempfile.TemporaryDirectory(prefix="company-report-integration-") as temp_dir:
project_root = Path(temp_dir) / "project"
output_root = project_root / "outputs" / "company_reports"
project_root.mkdir(parents=True)
repository = FakeRepository(synthetic_snapshot())
builder = ArtifactToolBuilder(BUILDER_SCRIPT, node_binary=node, timeout_seconds=90)
repository = StableVersionRepository(synthetic_snapshot())
builder = RebuildingBuilder(
ArtifactToolBuilder(BUILDER_SCRIPT, node_binary=node, timeout_seconds=90)
)
publisher = AtomicReportPublisher(project_root, output_root)
service = CompanyReportService(
repository,
@@ -124,21 +164,26 @@ class CompanyReportIntegrationTests(unittest.TestCase):
second_semantic = second.companies[0].artifact["semantic_sha256"]
self.assertEqual(len(first_semantic), 64)
self.assertEqual(first_semantic, second_semantic)
self.assertNotEqual(builder.binary_sha256s[0], builder.binary_sha256s[1])
self.assertEqual(
first.companies[0].artifact["sha256"],
second.companies[0].artifact["sha256"],
)
self.assertEqual(
first.companies[0].period_row_counts,
second.companies[0].period_row_counts,
)
self.assertEqual(first.companies[0].version_no, 1)
self.assertEqual(second.companies[0].version_no, 2)
self.assertEqual(second.companies[0].version_no, 1)
month_root = output_root / "2026" / "07"
filename = "QBD-July-2026.xlsx"
current = month_root / filename
first_archive = month_root / "archive" / "v0001" / filename
second_archive = month_root / "archive" / "v0002" / filename
self.assertTrue(first_archive.is_file())
self.assertTrue(second_archive.is_file())
self.assertEqual(current.read_bytes(), second_archive.read_bytes())
self.assertFalse((month_root / "archive" / "v0002").exists())
first_archive_bytes = first_archive.read_bytes()
self.assertEqual(current.read_bytes(), first_archive_bytes)
self.assertEqual(current.stat().st_mode & 0o777, 0o600)
self.assertEqual(len(repository.activated), 2)
@@ -147,14 +192,9 @@ class CompanyReportIntegrationTests(unittest.TestCase):
encoding="utf-8"
)
)
second_result = json.loads(
(month_root / "archive" / "v0002" / "QBD-v0002.result.json").read_text(
encoding="utf-8"
)
)
self.assertEqual(
first_result["artifact"]["semantic_sha256"],
second_result["artifact"]["semantic_sha256"],
second.companies[0].artifact["semantic_sha256"],
)
serialized = json.dumps(second.to_dict(), ensure_ascii=False)
self.assertNotIn("SYN-GROUP-A", serialized)