fix(api): resolve snapshot paths in production image
Some checks failed
CD Pipeline / tests (push) Successful in 1m23s
Code Review / ai-code-review (push) Successful in 13s
CD Pipeline / build-and-deploy (push) Failing after 3m52s
CD Pipeline / post-deploy-checks (push) Has been skipped

This commit is contained in:
Your Name
2026-06-04 22:26:44 +08:00
parent 313af4c050
commit c28212027c
14 changed files with 95 additions and 24 deletions

View File

@@ -16,8 +16,9 @@ from pathlib import Path
from typing import Any
from zoneinfo import ZoneInfo
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "agent_market_governance_snapshot_*.json"
_MARKET_WATCH_WORKFLOW = ".gitea/workflows/agent-market-watch.yaml"
_TAIPEI_TZ = ZoneInfo("Asia/Taipei")

View File

@@ -13,8 +13,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "ai_agent_automation_backlog_*.json"
_SCHEMA_VERSION = "ai_agent_automation_backlog_v1"

View File

@@ -12,8 +12,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "ai_agent_automation_inventory_snapshot_*.json"
_SCHEMA_VERSION = "ai_agent_automation_inventory_snapshot_v1"

View File

@@ -12,8 +12,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "backup_dr_readiness_matrix_*.json"
_SCHEMA_VERSION = "backup_dr_readiness_matrix_v1"

View File

@@ -12,8 +12,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "backup_dr_target_inventory_*.json"
_SCHEMA_VERSION = "backup_dr_target_inventory_v1"

View File

@@ -14,8 +14,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "backup_notification_policy_*.json"
_SCHEMA_VERSION = "backup_notification_policy_v1"

View File

@@ -14,8 +14,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "dependency_drift_check_plan_*.json"
_SCHEMA_VERSION = "dependency_drift_check_plan_v1"

View File

@@ -14,8 +14,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "dependency_risk_policy_*.json"
_SCHEMA_VERSION = "dependency_risk_policy_v1"

View File

@@ -15,8 +15,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "dependency_upgrade_approval_package_template_*.json"
_SCHEMA_VERSION = "dependency_upgrade_approval_package_template_v1"

View File

@@ -11,8 +11,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "docker_build_surface_inventory_*.json"
_SCHEMA_VERSION = "docker_build_surface_inventory_v1"

View File

@@ -11,8 +11,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "javascript_package_inventory_*.json"
_SCHEMA_VERSION = "javascript_package_inventory_v1"

View File

@@ -12,8 +12,9 @@ import json
from pathlib import Path
from typing import Any
_REPO_ROOT = Path(__file__).resolve().parents[4]
_DEFAULT_EVALUATIONS_DIR = _REPO_ROOT / "docs" / "evaluations"
from src.services.snapshot_paths import default_evaluations_dir
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
_SNAPSHOT_PATTERN = "package_supply_chain_inventory_*.json"
_SCHEMA_VERSION = "package_supply_chain_inventory_v1"

View File

@@ -0,0 +1,32 @@
"""
Snapshot path helpers.
Resolve committed documentation snapshot paths across local repo checkouts and
production API images. In containers, service modules live under
``/app/src/services`` instead of ``apps/api/src/services``.
"""
from __future__ import annotations
from pathlib import Path
def resolve_repo_root(anchor: Path) -> Path:
"""Resolve the repository root that contains committed docs snapshots."""
resolved = anchor.resolve()
start = resolved if resolved.is_dir() else resolved.parent
for candidate in (start, *start.parents):
if (candidate / "docs").is_dir():
return candidate
container_root = Path("/app")
if (container_root / "docs").is_dir():
return container_root
parents = list(start.parents)
return parents[2] if len(parents) > 2 else start
def default_evaluations_dir(anchor: Path) -> Path:
"""Resolve the default committed evaluations snapshot directory."""
return resolve_repo_root(anchor) / "docs" / "evaluations"

View File

@@ -0,0 +1,27 @@
from __future__ import annotations
from src.services.snapshot_paths import default_evaluations_dir, resolve_repo_root
def test_resolve_repo_root_supports_monorepo_service_layout(tmp_path):
repo_root = tmp_path / "repo"
evaluations_dir = repo_root / "docs" / "evaluations"
evaluations_dir.mkdir(parents=True)
anchor = repo_root / "apps" / "api" / "src" / "services" / "snapshot.py"
anchor.parent.mkdir(parents=True)
anchor.write_text("", encoding="utf-8")
assert resolve_repo_root(anchor) == repo_root
assert default_evaluations_dir(anchor) == evaluations_dir
def test_resolve_repo_root_supports_api_container_layout(tmp_path):
app_root = tmp_path / "app"
evaluations_dir = app_root / "docs" / "evaluations"
evaluations_dir.mkdir(parents=True)
anchor = app_root / "src" / "services" / "snapshot.py"
anchor.parent.mkdir(parents=True)
anchor.write_text("", encoding="utf-8")
assert resolve_repo_root(anchor) == app_root
assert default_evaluations_dir(anchor) == evaluations_dir