部署优化

This commit is contained in:
andy
2026-08-03 20:59:59 +08:00
parent 5294edab89
commit 727643f1f2
18 changed files with 358 additions and 130 deletions

View File

@@ -1,7 +1,5 @@
from __future__ import annotations
import os
import shutil
import tempfile
import unittest
from pathlib import Path
@@ -19,14 +17,6 @@ from tests.company_reports_acceptance_fixture import (
PROJECT_ROOT = Path(__file__).resolve().parents[1]
BUILDER_SCRIPT = PROJECT_ROOT / "company_reports" / "xlsx" / "build_workbook.mjs"
ARTIFACT_PACKAGE = (
PROJECT_ROOT
/ "company_reports"
/ "xlsx"
/ "node_modules"
/ "@oai"
/ "artifact-tool"
)
def acceptance_reports():
@@ -38,16 +28,6 @@ def acceptance_reports():
)
def artifact_tool_available() -> bool:
configured = os.environ.get("COMPANY_REPORT_ARTIFACT_TOOL_MODULE", "").strip()
return ARTIFACT_PACKAGE.exists() or bool(configured and Path(configured).is_file())
def node_binary() -> str:
configured = os.environ.get("COMPANY_REPORT_NODE_BINARY", "").strip()
return configured or shutil.which("node") or ""
class CompanyReportAcceptanceCoreTests(unittest.TestCase):
def test_all_five_companies_have_contract_complete_month_end_reports(self):
reports = acceptance_reports()
@@ -106,15 +86,10 @@ class CompanyReportAcceptanceCoreTests(unittest.TestCase):
self.assertEqual(dy_row.departure.day, 20)
@unittest.skipUnless(artifact_tool_available(), "artifact-tool dependency is not installed")
class CompanyReportAcceptanceWorkbookTests(unittest.TestCase):
def test_real_builder_exports_reopens_and_renders_all_five_workbooks(self):
node = node_binary()
if not node:
self.skipTest("Node.js is unavailable")
def test_real_builder_exports_and_reopens_all_five_workbooks(self):
builder = ArtifactToolBuilder(
BUILDER_SCRIPT,
node_binary=node,
timeout_seconds=180,
)
with tempfile.TemporaryDirectory(prefix="company-report-acceptance-") as temp_dir:
@@ -125,15 +100,12 @@ class CompanyReportAcceptanceWorkbookTests(unittest.TestCase):
self.assertTrue(built.path.is_file())
self.assertEqual(built.path.name, report.filename)
self.assertEqual(built.summary["formula_count"], 0)
self.assertEqual(built.summary["preview_count"], 3)
self.assertEqual(built.summary["preview_count"], 0)
self.assertEqual(
built.summary["row_counts"],
[len(period.rows) for period in report.periods],
)
self.assertEqual(
len(list((root / report.company / "previews").glob("sheet-*.png"))),
3,
)
self.assertEqual(len(list((root / report.company / "previews").glob("*"))), 0)
if __name__ == "__main__":