部署优化

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

@@ -2,7 +2,6 @@ from __future__ import annotations
import json
import os
import shutil
import tempfile
import unittest
from dataclasses import replace
@@ -22,33 +21,10 @@ from tests.test_company_reports_service import FakeRepository, synthetic_snapsho
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 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 ""
@unittest.skipUnless(artifact_tool_available(), "artifact-tool dependency is not installed")
class CompanyReportIntegrationTests(unittest.TestCase):
def test_missing_and_unmatched_group_codes_export_blank_booking_room(self):
node = node_binary()
if not node:
self.skipTest("Node.js is unavailable")
class CapturingBuilder:
def __init__(self, delegate):
self.delegate = delegate
@@ -70,7 +46,7 @@ class CompanyReportIntegrationTests(unittest.TestCase):
)
)
builder = CapturingBuilder(
ArtifactToolBuilder(BUILDER_SCRIPT, node_binary=node, timeout_seconds=90)
ArtifactToolBuilder(BUILDER_SCRIPT, timeout_seconds=90)
)
publisher = AtomicReportPublisher(project_root, output_root)
service = CompanyReportService(
@@ -101,10 +77,6 @@ class CompanyReportIntegrationTests(unittest.TestCase):
)
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)
@@ -142,7 +114,7 @@ class CompanyReportIntegrationTests(unittest.TestCase):
project_root.mkdir(parents=True)
repository = StableVersionRepository(synthetic_snapshot())
builder = RebuildingBuilder(
ArtifactToolBuilder(BUILDER_SCRIPT, node_binary=node, timeout_seconds=90)
ArtifactToolBuilder(BUILDER_SCRIPT, timeout_seconds=90)
)
publisher = AtomicReportPublisher(project_root, output_root)
service = CompanyReportService(