Files
Agent-System-Dev/tests/integration/lifecycle/lifecycle_suite.py
T
weichenandCursor 8dda121c0d Fetch and build the three pinned RDM SHAs in CI
Why: test-pg only cloned the default branch, so prev_sha and legacy_sha were never built or attested.
Evidence: SELF python3 -m unittest tests.test_ci_credentials tests.test_lifecycle_pin (11 tests, exit 0).
Impact: the lifecycle suite prints the combination inventory and keeps login and rdm.ping as NOT_RUN.
Refs: .task/feature-svc-d3-real-scenarios.md
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-13 02:59:44 +00:00

118 lines
4.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""真实 Dev/RDM 组合门禁。由 make test-lifecycle 调用。
缺 PostgreSQL、RDM 源码或制品时直接失败,不静默跳过。
登录与 rdm.ping 依赖账户 CLI 公共化,单独标 NOT_RUN,
不因此把已经跑过的真实组合场景记成失败。
"""
import hashlib
import os
import subprocess
import sys
from pathlib import Path
from urllib.parse import urlparse
ROOT = Path(__file__).resolve().parents[3]
PIN = Path(__file__).resolve().parent / "rdm.pin"
def sha256_file(path):
digest = hashlib.sha256()
with open(path, "rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def print_inventory(src, dev, rdm):
print("组合清单")
head = subprocess.run(["git", "-C", str(ROOT), "rev-parse", "HEAD"],
capture_output=True, text=True)
print("dev_sha", head.stdout.strip() if head.returncode == 0 else "NOT_RUN")
modules = subprocess.run(
["git", "-C", str(ROOT), "submodule", "status", "--recursive"],
capture_output=True, text=True)
if modules.returncode == 0:
for line in modules.stdout.splitlines():
print("submodule", " ".join(line.split()[:2]))
else:
print("submodule NOT_RUN")
print("pin")
for line in PIN.read_text().splitlines():
if line.strip() and not line.startswith("#"):
print(" ", line.strip())
print("dev_bin", dev, sha256_file(dev))
print("rdm_bin", rdm, sha256_file(rdm))
digests = Path(src) / "pin-build-digests.txt"
if digests.is_file():
for line in digests.read_text().splitlines():
print("pin_build", line)
else:
print("pin_build NOT_RUN:本进程没有预构建三个 pin")
print("pg_version", pg_version())
print("登录 NOT_RUN:RDM 二进制没有 user/apikey,工作台登录依赖账户方案 U7/U5")
print("rdm.ping NOT_RUN:需要已登录会话,本轮不公共化账户 CLI")
def pg_version():
parsed = urlparse(os.environ.get("AGENT_PG_TEST_DSN", ""))
if not parsed.hostname:
return "NOT_RUN"
env = os.environ.copy()
env.update({
"PGHOST": parsed.hostname,
"PGPORT": str(parsed.port or 5432),
"PGUSER": parsed.username or "",
"PGPASSWORD": parsed.password or "",
"PGDATABASE": parsed.path.lstrip("/"),
})
proc = subprocess.run(["psql", "-tAc", "SHOW server_version"],
env=env, capture_output=True, text=True)
if proc.returncode != 0:
return "NOT_RUN"
return proc.stdout.strip() or "NOT_RUN"
def main():
missing = []
if not os.environ.get("AGENT_PG_TEST_DSN"):
missing.append("AGENT_PG_TEST_DSN")
src = os.environ.get("SVC_RDM_SRC_DIR", "")
if not src or not Path(src).is_dir():
missing.append("SVC_RDM_SRC_DIR")
dev = os.environ.get("SVC_REAL_BIN") or str(ROOT / "bin" / "agent-system")
rdm = os.environ.get("SVC_REAL_RDM_BIN", "")
if not Path(dev).is_file():
missing.append("Dev 制品(SVC_REAL_BIN 或 bin/agent-system)")
if not rdm or not Path(rdm).is_file():
missing.append("RDM 制品(SVC_REAL_RDM_BIN)")
if missing:
print("test-lifecycle 失败。缺:%s" % ", ".join(missing))
return 1
print("将运行 tests.test_svc_realcombo:SQLite 身份、RDM 二进制生命周期、PostgreSQL 身份环境交付")
print("将运行 tests.integration.lifecycle.test_lifecycle_real:pin 上的真实候选与切换")
if os.environ.get("SVC_RDM_ORIGIN"):
print("将运行全轨部署:SVC_RDM_ORIGIN 已设置")
else:
print("全轨部署 NOT_RUN:未设置 SVC_RDM_ORIGIN(由 svc-realcombo 作业覆盖)")
env = os.environ.copy()
env["SVC_TEST_REAL"] = "1"
env["SVC_TEST_PG"] = "1"
env["SVC_REAL_BIN"] = dev
env["SVC_REAL_RDM_BIN"] = rdm
proc = subprocess.run(
[sys.executable, "-m", "unittest",
"tests.test_svc_realcombo",
"tests.integration.lifecycle.test_lifecycle_real", "-q"],
cwd=str(ROOT), env=env)
print_inventory(src, dev, rdm)
if proc.returncode != 0:
print("test-lifecycle 失败:真实组合用例未通过")
return proc.returncode
print("test-lifecycle 可跑场景通过;登录与 rdm.ping 保持 NOT_RUN")
return 0
if __name__ == "__main__":
sys.exit(main())