feat: sync latest ARR implementation

This commit is contained in:
Wyndham ARR
2026-07-31 15:11:42 +08:00
parent d6f8a747fa
commit bf7939dd1a
185 changed files with 17527 additions and 2260 deletions

View File

@@ -67,8 +67,8 @@ class FakeRepository:
def reserve_report(self, _report):
return ReservedReport(44, 2)
def activate_report(self, reservation, artifact, result_json):
self.activated.append((reservation, artifact, result_json))
def activate_report(self, reservation, artifact, result_json, semantic_sha256):
self.activated.append((reservation, artifact, result_json, semantic_sha256))
def mark_failed(self, reservation, code, safe_message):
self.failed.append((reservation, code, safe_message))
@@ -112,7 +112,12 @@ class FakePublisher:
1,
"application/json",
)
repository.activate_report(reservation, artifact, result_json)
repository.activate_report(
reservation,
artifact,
result_json,
str(built.summary["semantic_sha256"]),
)
return PublicationOutcome(
latest_path=work_dir / "latest.xlsx",
latest_result_path=work_dir / "latest.result.json",
@@ -134,7 +139,7 @@ class MonthlyReportsServiceTests(unittest.TestCase):
FakePublisher(),
root / "staging",
)
result = service.run(RunRequest(2026, 7, date(2026, 7, 26)))
result = service.run(RunRequest(2026, 7, date(2026, 7, 8)))
result_path = root / "run.result.json"
write_run_result(result_path, result)
serialized = result_path.read_text(encoding="utf-8")
@@ -149,6 +154,41 @@ class MonthlyReportsServiceTests(unittest.TestCase):
self.assertNotIn("SYN-BLOCK", serialized)
self.assertEqual(len(repository.activated), 1)
def test_published_snapshot_replay_reuses_registered_artifact_without_building(self):
class PublishedRepository(FakeRepository):
def reserve_report(self, _report):
return ReservedReport(
report_version_id=44,
version_no=2,
report_status="active",
published_artifact=FileMetadata(
"monthly_xlsx",
"各渠道情况-2026年07月-更新至7.8.xlsx",
"outputs/monthly_reports/2026/07/archive/v0002/report.xlsx",
"a" * 64,
100,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
),
)
class NeverBuilder:
def build(self, _report, _work_dir):
raise AssertionError("published replay must not rebuild the workbook")
repository = PublishedRepository()
with tempfile.TemporaryDirectory(prefix="monthly-report-service-") as temp_dir:
result = MonthlyReportService(
repository,
NeverBuilder(),
FakePublisher(),
Path(temp_dir) / "staging",
).run(RunRequest(2026, 7, date(2026, 7, 8)))
self.assertEqual(result.status, "success")
self.assertEqual(result.report_version_id, 44)
self.assertEqual(result.artifact["sha256"], "a" * 64)
self.assertEqual(repository.activated, [])
def test_builder_failure_marks_reserved_report_failed(self):
repository = FakeRepository()
with tempfile.TemporaryDirectory(prefix="monthly-report-service-") as temp_dir:
@@ -157,7 +197,7 @@ class MonthlyReportsServiceTests(unittest.TestCase):
FakeBuilder(fail=True),
FakePublisher(),
Path(temp_dir) / "staging",
).run(RunRequest(2026, 7, date(2026, 7, 26)))
).run(RunRequest(2026, 7, date(2026, 7, 8)))
self.assertEqual(result.status, "failed")
self.assertEqual(result.error_code, ErrorCode.OUTPUT_VALIDATION_FAILED)
@@ -176,7 +216,7 @@ class MonthlyReportsServiceTests(unittest.TestCase):
FakeBuilder(),
FakePublisher(),
Path(temp_dir) / "staging",
).run(RunRequest(2026, 7, date(2026, 7, 26)))
).run(RunRequest(2026, 7, date(2026, 7, 8)))
self.assertEqual(result.exit_code, exit_code)
self.assertEqual(result.error_stage, "source")