From c452ebd1c142995d90c11247cf62a323c3831f5b Mon Sep 17 00:00:00 2001 From: ogt Date: Thu, 2 Jul 2026 15:08:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20P4=20report=20=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=9F=B7=E8=A1=8C=E8=B7=AF=E5=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ops/report_source_deploy_runtime_truth.py | 8 ++- ...test_source_deploy_runtime_truth_report.py | 50 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/scripts/ops/report_source_deploy_runtime_truth.py b/scripts/ops/report_source_deploy_runtime_truth.py index 2f6acf4..a53bd85 100644 --- a/scripts/ops/report_source_deploy_runtime_truth.py +++ b/scripts/ops/report_source_deploy_runtime_truth.py @@ -12,16 +12,20 @@ import argparse import hashlib import json import subprocess +import sys import urllib.error import urllib.request from collections.abc import Callable, Iterable from pathlib import Path from typing import Any -from scripts.ops.check_production_version_truth import parse_config_version - ROOT = Path(__file__).resolve().parents[2] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +from scripts.ops.check_production_version_truth import parse_config_version + DEFAULT_HEALTH_URL = "https://mo.wooo.work/health" DEFAULT_GITEA_REMOTE = "ssh://git@192.168.0.110:2222/wooo/ewoooc.git" DEFAULT_TRACKED_FILES = ( diff --git a/tests/test_source_deploy_runtime_truth_report.py b/tests/test_source_deploy_runtime_truth_report.py index f5bead5..0ef8e36 100644 --- a/tests/test_source_deploy_runtime_truth_report.py +++ b/tests/test_source_deploy_runtime_truth_report.py @@ -1,4 +1,7 @@ import json +import subprocess +import sys +import urllib.parse from pathlib import Path from scripts.ops import report_source_deploy_runtime_truth as report @@ -220,3 +223,50 @@ def test_source_override_still_requires_committed_file_confirmation(tmp_path): assert payload["result"] == "BLOCKED" assert payload["summary"]["tracked_files_committed"] is False assert any("uncommitted source-control changes" in error for error in payload["errors"]) + + +def test_script_runs_by_path_when_called_from_outside_repo(tmp_path): + source_root = _write_source_root(tmp_path) + health_payload = urllib.parse.quote( + json.dumps({"status": "healthy", "database": "postgresql", "version": "V10.725"}) + ) + + result = subprocess.run( + [ + sys.executable, + str(Path(report.__file__).resolve()), + "--source-root", + str(source_root), + "--health-url", + f"data:application/json,{health_payload}", + "--tracked-file", + "config.py", + "--tracked-file", + "proof.txt", + "--source-head", + LOCAL_HEAD, + "--source-branch", + "main", + "--origin-main", + LOCAL_HEAD, + "--origin-dev", + LOCAL_HEAD, + "--gitea-main", + LOCAL_HEAD, + "--gitea-dev", + LOCAL_HEAD, + "--head-config-version", + "V10.725", + "--tracked-files-committed", + "--json", + ], + cwd="/tmp", + check=True, + text=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + payload = json.loads(result.stdout) + assert payload["result"] == "PASS" + assert payload["summary"]["truth_layers_separated"] is True