Skip to content

test(verify-tree): add portable CLI contract suite and prune leased host sleep bloat - #10250

Merged
loopx-agent merged 1 commit into
mainfrom
codex/verifytree-portable-contracts-and-prune-20261206
Dec 6, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/verifytree-portable-contracts-and-prune-20261206

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  1. Next-gen rewrite-portable black-box VerifyTree contract suite (tests/verify_tree/test_nextgen_portable_contract_tree.py)

    • Exercises external public CLI contracts strictly via subprocess invocations of LOOPX_VERIFY_BIN (defaulting to [sys.executable, "-m", "loopx.cli"]), asserting only public JSON stdout, exit codes, and durable workspace artifacts — zero internal loopx.* imports, zero monkeypatches, and zero internal prose-substring assertions, so the suite runs unchanged against a next-generation rewrite (TypeScript, Rust, or Go).
    • Covers 5 core VerifyTree nodes in isolated tmp_path + isolated HOME:
      • VT-PREFLIGHT-01: --version and isolated doctor --installation-only contract.
      • VT-BOUNDARY-01: check --scan-path fail-closed rejection on synthetic leaked local home path and synthetic token-like credential shape vs clean pass on clean fixture.
      • VT-TODO-01: bootstrap + register-agent + todo add / list / claim / update / complete lifecycle, including invalid/empty text rejection and durable ACTIVE_GOAL_STATE.md / SQLite readback.
      • VT-LEASE-01: Hard-lease task-lease acquire -> wrong --expected-version / wrong --owner CAS rejection -> matching-version renew / release isolation and inspect readback.
      • VT-TURN-01: quota should-run admission -> idempotent replay under identical --turn-instance-id -> settlement binding safety (todo complete --no-follow-up fails closed with writeback_missing before accountable refresh-state, then succeeds and verifies via quota receipt --include-settlement).
  2. First measured slow / redundant test subtraction (tests/control_plane/test_leased_host_process.py)

    • Compacted ttl_seconds (30s -> 8s) on the 5 short-lease supervisor fault/final-proof tests (rejected, hung, lost_reply, late_reply, returned_host_uses_renewed_deadline_during_final_proof) while retaining the 2700s (30s clamp) test_long_ttl_checks_authority_without_rewriting_lease boundary check.
    • Removed the redundant file-provider duplication across the backend-agnostic TS Host supervisor timing loops while retaining ["file", "sqlite"] canonical provider coverage on test_released_initial_proof_explains_refusal_before_host_launch (alongside full file + sqlite parity in tests/control_plane/test_verify_tree_release_invariants.py).
    • Measured before vs after (uv run --extra test python -m pytest -q --durations=10 tests/control_plane/test_leased_host_process.py):
      • Before: 20 passed in 489.90s (0:08:09)
      • After: 11 passed in 142.99s (0:02:22) (-346.91s wall-clock, -70.8%)

Verification

  • uv run --extra test python -m pytest -q tests/verify_tree/test_nextgen_portable_contract_tree.py: 5 passed in 10.99s
  • uv run --extra test python -m pytest -q --durations=10 tests/control_plane/test_leased_host_process.py: 11 passed in 142.99s (0:02:22) (vs 20 passed in 489.90s before)
  • uv run --extra test python -m pytest -q tests/control_plane/test_verify_tree_release_invariants.py: 7 passed in 12.83s
  • uv run --extra test ruff check tests/verify_tree/test_nextgen_portable_contract_tree.py tests/control_plane/test_leased_host_process.py: passed
  • loopx --format json check --scan-path tests/verify_tree/test_nextgen_portable_contract_tree.py tests/control_plane/test_leased_host_process.py: passed (ok: true, 0 errors)
  • loopx --format json canary premerge --from-git-diff --git-diff-base origin/main: passed (ok: true, 5/5 direct checks, 4/4 catalog canaries, 0 manual holds)

…st sleep bloat

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

维护者与测试运营者在演进 LoopX 控制平面时面临两项实际痛点:其一,现有集成测试直接导入内部 Python 模块并使用 monkeypatch,无法在不重写测试的前提下直接验证未来的下一代重写实现(TypeScript、Rust 或 Go);其二,受租约托管进程测试在每项计时用例上重复执行 file 与 sqlite 两种后端且硬编码 30 秒 TTL 与 35 至 60 秒等待,单文件串行执行耗时高达 489.90 秒(20 项测试)。本 PR 旨在新增完全黑盒、零内部导入的可移植外部 CLI 契约验证树套件,并对托管进程测试进行零不变量损失的首次实测减负。

  • 受影响角色:控制平面维护者、发布资格门禁执行者与未来多语言重写验证者。
  • 改动前后场景:改动前,跨重写可移植的外部 CLI VerifyTree 黑盒套件缺失,且 tests/control_plane/test_leased_host_process.py 每次运行需耗时 489.90 秒(20 项测试)。改动后,新增纯子进程黑盒契约测试覆盖 5 个核心 VerifyTree 节点(10.99 秒通过 5 项),同时受租约托管进程测试在不削弱任何不变量的前提下缩减至 11 项、耗时 142.99 秒(节省 346.91 秒,降幅 70.8%)。
  • 可观测结果:可通过环境变量 LOOPX_VERIFY_BIN 直接驱动任意兼容二进制执行黑盒 VerifyTree 契约检查,且托管进程测试矩阵耗时显著下降。
  • 非目标:本次不修改任何 loopx 生产控制平面或运行时实现,不调整默认策略,也不改动 Opt-1 负责的 canary runner 与 release qualification 脚本。
  • 剩余缺口:仅完成了黑盒核心 5 节点契约与首轮 test_leased_host_process.py 减负;test_delegation_lease_lifetime.py 与大型会话和报告测试文件的后续减负留待后续独立 PR 评估。

改动思路 / Approach

新增的 tests/verify_tree/test_nextgen_portable_contract_tree.py 采用纯粹的外部契约视角:通过 _cli_executable 解析 LOOPX_VERIFY_BIN(默认 [sys.executable, "-m", "loopx.cli"]),并在隔离的 tmp_path 与 HOME 中执行 bootstrap、register-agent、doctor、check、todo、task-lease、quota should-run、refresh-state 与 quota receipt,仅断言公开的进程退出码、JSON 输出字段与落盘状态文件。与既有 tests/control_plane/test_verify_tree_release_invariants.py 相比,现有套件测试内部 Python/TS 边界与内部异常类型,而新套件则完全不导入内部 loopx.* 模块、不使用 monkeypatch、也不依赖内部提示文案子串,从而具备跨语言重写的可移植性。

在 tests/control_plane/test_leased_host_process.py 中,受租约托管进程的 TypeScript 监管器(leased_host_process.ts)仅通过子进程调用 task-lease renew/inspect CLI,与底层存储后端是 file 还是 sqlite 无关;且 file 与 sqlite 的存储等价性已由 test_verify_tree_release_invariants.py 与本文件中保留双后端的 test_released_initial_proof_explains_refusal_before_host_launch 共同覆盖。因此将短租约故障与最终证明用例的 ttl_seconds 从 30 秒压缩为 8 秒(保留 test_long_ttl_checks_authority_without_rewriting_lease 的 2700 秒 30 秒上限钳制检查),并移除重复的 file 慢速计时副本,在不削弱任何语义不变量的前提下达成 70.8% 的时间缩减。

具体改动 / Changes

改动文件分类与核心契约映射

本次改动仅涉及测试文件(tests/verify_tree/test_nextgen_portable_contract_tree.py 新增 769 行;tests/control_plane/test_leased_host_process.py 修改 +27/-13 行),未触及生产代码或文档。

依据规范 docs/architecture/rfcs/verify-tree-v0.md(基线提交 c4564eb12e63ed74cd17834aa2f0db3f25fca36d)中的 VerifyTree 外部契约与减负重构原则,逐项映射如下:

Criterion ID 要求与职责 Exact-Head 状态 证据位置
VT-PREFLIGHT-01 --version 与隔离 doctor --installation-only 预检契约 implemented test_vt_preflight_01_version_and_isolated_doctor
VT-BOUNDARY-01 check --scan-path 对泄露本地路径与凭据形态的失败关闭拦截及干净文件放行 implemented test_vt_boundary_01_public_private_scan_fail_closed
VT-TODO-01 bootstrap + todo add/list/claim/update/complete 生命周期与空白非法文本拒绝 implemented test_vt_todo_01_goal_todo_lifecycle_and_boundary_validation
VT-LEASE-01 硬租约 acquire -> 错误版本/错误 owner CAS 拒绝 -> 匹配版本 renew/release 与 inspect 读回 implemented test_vt_lease_01_hard_lease_cas_and_owner_isolation
VT-TURN-01 quota should-run 准入 -> 同 --turn-instance-id 幂等重放 -> 结算绑定防提前关闭(writeback_missing)与闭环验证 implemented test_vt_turn_01_quota_admission_replay_and_settlement_binding

关键符号与机制说明

  1. tests/verify_tree/test_nextgen_portable_contract_tree.py 中的 _bootstrap_isolated_goal 与 5 个 test_vt_* 用例:全程在独立临时 HOME 中通过外部 CLI 创建并隔离注册表、Agent、Todo、租约与 Turn 收据,动态构造合成敏感字符串以免测试源码自身触发公开边界扫描。
  2. tests/control_plane/test_leased_host_process.py 中的 _build_canonical_execution 与 canonical_execution_by_provider:统一复用同一个夹具构造逻辑(消除重复配置代码),默认为慢速计时测试提供 sqlite 后端与 8 秒 TTL,同时通过 canonical_execution_by_provider 保留 test_released_initial_proof_explains_refusal_before_host_launch 的 file/sqlite 双后端覆盖。

对主干的风险 / Risks

本次变更不改动任何生产路径,对主干运行时零回归风险。主要潜在风险与对策如下:

  • 可移植套件误报边界扫描或环境污染风险: 若黑盒测试泄露宿主机真实 HOME 或在源码中硬编码凭据字面量,会导致 loopx check 阻断;当前实现通过动态拼接合成测试样本并强制隔离 HOME 与 LOOPX_REGISTRY/LOOPX_RUNTIME_ROOT 消除该风险,且 loopx check 扫描两文件返回 0 错误。
  • 8 秒 TTL 在高负载下的竞态风险: 缩短 ttl_seconds 至 8 秒(半衰期约 4 秒)后,在机器运行 8 分片 Gate 6 全量测试的高负载下实测 11 项测试全部稳定通过(耗时 142.99 秒),其中单次 CLI 子进程约 0.5–0.8 秒,留有充足的续约时间裕度。
  • 既有覆盖与重复扫描(durable_smoke_value): 已对照检索 tests/control_plane/test_verify_tree_release_invariants.py 与 tests/control_plane/test_leased_host_process.py,确认新套件是仓库首个纯黑盒、无内部导入的跨重写外部 CLI 契约套件,未与现有内部单元测试重复造轮,且同时交付了实测 346.91 秒测试减负的明确仓库收益。

我的整体评价 / Verdict

本 PR 以最小、高内聚且完全可逆的测试改动同时交付了下一代跨重写外部契约安全网与首次实测慢测试减负:

  • 长程与用户体验影响(outcome_impact): long_horizon 为 improved(外部契约稳定保护未来重写演进,且开发与 Gate 回归等待时间从 489.90 秒降至 142.99 秒);user_experience 为 not_applicable(仅测试层改动,未更改任何产品 CLI 或渲染界面);visual_review 为 not_applicable(reason:改动仅限于 tests/ 目录下的测试文件,未涉及前端界面或终端输出展示;unverified_scope:none)。
  • 验证矩阵与精确 head 状态: 在精确 head 2b4f41b9e5fadb83c065b0e81b77d380625b3b12 上,目标单文件测试全部 PASS:
    • uv run --extra test python -m pytest -q tests/verify_tree/test_nextgen_portable_contract_tree.py:PASS(5 passed in 10.99s)
    • uv run --extra test python -m pytest -q --durations=10 tests/control_plane/test_leased_host_process.py:PASS(11 passed in 142.99s vs baseline 20 passed in 489.90s)
    • uv run --extra test python -m pytest -q tests/control_plane/test_verify_tree_release_invariants.py:PASS(7 passed in 12.83s)
    • uv run --extra test ruff check ... & loopx check --scan-path ...:PASS(0 errors)
    • loopx canary premerge --from-git-diff --git-diff-base origin/main:PASS(5/5 direct checks, 4/4 catalog canaries, 0 manual holds)
  • 代码体量与可简化空间: 变更体量完全必要且无冗余包装,无残余阻塞项。

English verdict: APPROVE — exact head 2b4f41b9e5fadb83c065b0e81b77d380625b3b12 delivers a clean zero-internal-import black-box VerifyTree contract suite (5/5 passing) and a verified -70.8% (489.90s -> 142.99s) wall-clock reduction in test_leased_host_process.py with full invariant preservation and green local canary premerge.

@loopx-agent
loopx-agent merged commit 083d869 into main Dec 6, 2026
18 of 22 checks passed
@loopx-agent
loopx-agent deleted the codex/verifytree-portable-contracts-and-prune-20261206 branch December 6, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant