Skip to content

fix(tests): repair contract health F401 and retired activation_state test fixtures - #8946

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/fix-main-contract-health-ruff-20261118
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/fix-main-contract-health-ruff-20261118

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Restore origin/main test gates across all 7 failing tests/** files introduced after display_report_text removal and activation_state retirement (loopx_goal_activation_v1 migration):

  1. tests/control_plane/test_contract_health.py: remove unused display_report_text import triggering Ruff F401.
  2. Migrate retired raw "activation_state" registry fixtures to canonical build_goal_activation(...):
    • tests/test_chat_operation_actions.py (4 stopped-goal sites)
    • tests/test_zcode_goal_bridge.py (shared _stopped_activation() helper + 5 stopped-goal sites)
    • tests/extensions/test_periodic_report_goal_channel_delivery.py (2 stopped-goal sites)
    • tests/test_manager_context_handoff.py (shared _goal_activation() helper + 6 stopped/invalid-activation sites)
    • tests/test_manager_context_execution.py (1 stopped-goal site)
    • tests/control_plane/test_goal_operator_actions.py (_write_registry stopped-goal branch)

Verification (Exact Head 80f2930e80)

  • ruff check on all 7 modified test files: All checks passed! (rc=0)
  • uv run --extra test python -m pytest -q tests/control_plane/test_contract_health.py tests/test_chat_operation_actions.py tests/test_zcode_goal_bridge.py tests/extensions/test_periodic_report_goal_channel_delivery.py tests/test_manager_context_handoff.py tests/test_manager_context_execution.py tests/control_plane/test_goal_operator_actions.py: 281 passed (rc=0)
  • uv run --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick: passed (selected=3, executed=3, failures=0, bilingual RFC diff & py_compile green)
  • uv run --extra test loopx check --scan-path ... (all 7 touched files): ok=True, errors=0, warnings=0 (public boundary scan clean)

Scope & Boundary

  • Pure tests/** fix (7 files changed, 73 insertions(+), 20 deletions(-)). No runtime (loopx/**), product UI (apps/**), or extension (packages/**) files modified.

@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

负责维护 origin/main 与后端 PR kernel-static-checks 静态门禁的开发者与评审者。

修复前,origin/main(421aa770ea)的 tests/control_plane/test_contract_health.py 第 10 行遗留了一行未被任何用例使用的导入 from loopx.paths import display_report_text(ruff F401)。由于 GitHub Actions 的 kernel-static-checks 作业会全量检查 tests/ 目录,这处 1 行残留导致全仓所有后端 PR 在进入 stage2c-correctness-e2e、typescript-core、kernel-contracts 与 merge-gate 前即确定性失败。修复后,仅删除这 1 行无用导入,不改动任何生产代码、测试断言或规则配置,即可恢复 kernel-static-checks 全量静态检查通过。

在精确头 5973d7351db42f3eeaefb54cb2e8fbe02b2fb4f9 上,本地实跑 pytest -q --no-cov tests/test_stage2c_dependency_lock.py tests/architecture/test_top_level_module_budget.py tests/control_plane/test_contract_health.py 返回 28 passed in 2.91s,ruff check tests loopx/canary loopx/control_plane loopx/domain_packs loopx/presentation 返回 All checks passed!,隔离 HOME 下 loopx canary premerge --tier quick 全部直接检查通过。远端 CI 刚触发仍在运行中,作为未完成诊断记录。

本 PR 严格限于移除 tests/control_plane/test_contract_health.py:10 的未使用导入,不修改任何业务逻辑、测试断言或 lint 配置,亦不替代后续业务 PR 各自已有的功能修复与验证。

改动思路 / Approach

入口为 .github/workflows/python-tests.yml 中 kernel-static-checks 作业调用的 ruff check tests ...;设计上不通过 # noqa 注释或放宽 pyproject.toml lint 规则掩盖问题,而是直接删除不再需要的 from loopx.paths import display_report_text(1 行 -1/+0)。正向覆盖 test_contract_health.py 全部既有断言与全仓静态检查;负向对比已在 421aa770ea 主干直接复现:ruff check tests 精确报 F401(退出码 1)。

当前边界:Touches only tests/control_plane/test_contract_health.py:10 (+0/-1 line).

具体改动 / Changes

  • 规范来源:.github/workflows/python-tests.yml(kernel-static-checks) @ 421aa770eaf6da329ee47fe3f3a23a108d3e8fb0
    • STATIC-RUFF-1 -> implemented:删除 tests/control_plane/test_contract_health.py:10 未使用的 display_report_text 导入,使 ruff check tests loopx/canary loopx/control_plane loopx/domain_packs loopx/presentation 与 test_contract_health.py 在精确头通过。

关键代码讲解

  1. tests/control_plane/test_contract_health.py:9-12:删除第 10 行 from loopx.paths import display_report_text,保留文件其余全部导入(如 report_json_text、check_contract、display_report_value 等)与全部 21 个健康检查单测,确保零运行时及测试语义改变。

对主干的风险 / Risks

运行时与控制面零回归风险(仅删除测试文件 1 行死导入,Pytest 全量 test_contract_health.py 与 test_top_level_module_budget.py / test_stage2c_dependency_lock.py 全部 28 项通过,ruff check tests ... 零报错)。远端 GitHub Actions 刚触发尚有作业运行中,因此待远端校验完成后,若符合低风险测试清理直合策略且 --check-merge-readiness 返回 ready=true,可由维护者或按仓内测试直合流程收敛。

验证项 状态 实跑结果(exact head 5973d7351db42f3eeaefb54cb2e8fbe02b2fb4f9)
uv run --extra test python -m pytest -q --no-cov tests/test_stage2c_dependency_lock.py tests/architecture/test_top_level_module_budget.py tests/control_plane/test_contract_health.py PASS 28 passed in 2.91s
uv run --extra test python -m ruff check tests loopx/canary loopx/control_plane loopx/domain_packs loopx/presentation PASS All checks passed!
HOME=... uv run --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick PASS direct_checks: 4/4, py_compile: 1/1, failures: 0
远端 GitHub CI(gh pr checks 8946) PENDING (diagnostic) 刚创建 PR,5 项 check 运行中、1 项 skipped

我的整体评价 / Verdict

Inspected the single changed test file (tests/control_plane/test_contract_health.py:10); zero UI components, CSS, or rendered presentation surfaces touched. unverified_scope: none.

这 1 行精准清理以最小改动解除阻塞 origin/main 及全仓后端 PR 的 kernel-static-checks 故障,且严格遵循不加豁免、不改规则的原则,无新状态或词汇变更。精确头 5973d7351db42f3eeaefb54cb2e8fbe02b2fb4f9 上适用本地测试与全仓 ruff 检查已全部实跑通过。结论同意(author-owned 自审回退为 COMMENTED)。

English verdict: APPROVE

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/fix-main-contract-health-ruff-20261118 branch from 5973d73 to 80f2930 Compare November 17, 2026 20:36
@loopx-agent loopx-agent changed the title fix(tests): remove unused display_report_text import in test_contract_health fix(tests): repair contract health F401 and retired activation_state test fixtures Nov 17, 2026

@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 DeepMind, self_reported)

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

基于 exact head 8946@80f2930e8054d24b33074bdc2ae9f1790eb05fc0(base main @ ef099ae3ac3c08054b9d928fff48aefe2615b950)的独立代码审查与完整本地验证结果,给出 APPROVE 结论(author-owned PR,按仓库规则以 COMMENTED review 发布)。

动机 / Motivation

所有基于 origin/main 开展验证的开发者及 CI 静态检查与核心测试流水线在运行 Ruff Lint 或 Control Plane / Extension / Chat 测试套件时都会受主干既有的 F401 未使用导入与退役 activation_state 夹具报错影响。改动前,基线 ef099ae 上 tests/control_plane/test_contract_health.py 残留已删除导入 display_report_text 触发 Ruff F401,且 6 个测试文件仍写入已退役键 activation_state 导致停用或非法激活态用例无法按 canonical loopx_goal_activation_v1 触发拒绝路径;改动后,无用导入已移除、6 个测试文件全部迁回生产构造器 build_goal_activation,所有修改测试套件均恢复通过。可观测结果为:7 个受影响测试文件全部通过 ruff check(0 报错)、pytest(281 条全部通过)、canary premerge quick(3 项全过)以及 scoped loopx check(errors=0 且 public boundary scan clean)。本 PR 不修改任何 loopx 运行时代码、apps 前端、packages 扩展、scripts 脚本或文档,不重新引入已退役的 activation_state 运行时兼容分支,也不改写与本次主干回归无关的既有示例路径。若不做本修复,所有基于当前主干开展工作的新 PR 都会持续被假红灯噪声或静态门禁失败阻塞,无法区分自身回归与主干遗留缺陷。

改动思路 / Approach

层面 基线 (ef099ae3ac3c08054b9d928fff48aefe2615b950) 本次精确提交 (80f2930e80)
Lint 导入 tests/control_plane/test_contract_health.py:10 导入未使用的 loopx.paths.display_report_text 删除该死导入,ruff check 归零
停用态构造 直接写入已退役字符串 goal["activation_state"] = "stopped"(及 "active"/"invalid") 复用生产权威构造器 loopx.control_plane.goals.activation.build_goal_activation(state=..., updated_at="2026-04-01T00:00:00Z", reason=...) 生成标准 goal["activation"] 对象
多用例文件组织 每个测试函数内重复硬编码字典 在存在多处重复构造的 tests/test_zcode_goal_bridge.py 与 tests/test_manager_context_handoff.py 提取文件级 _stopped_activation() / _goal_activation() 本地辅助函数

控制流保持纯测试夹具迁移,不引入任何新运行时分支或状态机:被测生产路径(ChatActionService、bridge.zcode_goal_operation、periodic_report_goal_channel_delivery、manager_context、goal operator actions)从注册表 JSON 读取 goal["activation"] 并在停止或非 loopx_goal_activation_v1 状态时按既有 Fail-Closed 路径拒绝执行。

具体改动 / Changes

  • 规范依据声明:no_spec(spec_source: none)— 本 PR 为针对 origin/main 已上线契约(display_report_text 移除与 #8431 退役 activation_state 迁移至 loopx/control_plane/goals/activation.py)的既有测试套件对齐与 Lint 清理,无独立新增功能 RFC;对照基线提交为 ef099ae3ac3c08054b9d928fff48aefe2615b950。
  • tests/control_plane/test_contract_health.py (+0/-1):删除第 10 行未使用的 from loopx.paths import display_report_text。
  • tests/test_chat_operation_actions.py (+21/-4):在 4 处停用测试点(test_managed_pending_reuses_registered_agent_and_goal_instance_scope、test_agent_handoff_fails_closed_on_expiry_binding_activation_or_terms_drift、test_unknown_result_never_grants_resubmission_and_late_evidence_does_not_req...、test_replacement_session_reconciles_under_its_current_binding_without_recons...)改写 goal["activation"] = build_goal_activation(state="stopped", ...)。
  • tests/test_zcode_goal_bridge.py (+14/-5):新增 _stopped_activation() 并迁移 5 处 payload["goals"][0]["activation_state"] = "stopped" 用例(覆盖无效权限拒绝、非激活态清理、bind/start/resume 拒绝与内部守卫校验)。
  • tests/extensions/test_periodic_report_goal_channel_delivery.py (+11/-2):迁移 test_goal_channel_delivery_rejects_canonical_stop_before_send 及其异步运行回调内的 2 处停用构造至 build_goal_activation(...)。
  • tests/test_manager_context_handoff.py (+15/-6):新增 _goal_activation(state) 辅助函数并迁移 6 处状态写入,其中参数化负例严格区分已停止 _goal_activation("stopped") 与显式非法结构 {"schema_version": "loopx_goal_activation_v1", "state": "invalid"},另覆盖停用后重新激活的 replay 恢复用例。
  • tests/test_manager_context_execution.py (+6/-1):将 test_no_launch_after_source_or_registration_changes 中的停用分支改为写入 data["goals"][0]["activation"] = build_goal_activation(...)。
  • tests/control_plane/test_goal_operator_actions.py (+6/-1):更新 _write_registry(..., activation_state="stopped") 夹具,改为写入规范的 goal["activation"]。

对主干的风险 / Risks

  • 阻断项(Blocking Findings):无(0 blocking findings)。全部 7 个文件均为 tests/** 测试夹具与 Lint 清理,零生产运行时语义变化、零兼容性分叉。
  • 反例与负路径核验:已核对 test_manager_context_handoff.py 中的 invalid 参数化分支未误改为调用 build_goal_activation("invalid")(避免构造期即抛异常而掩盖运行期反序列化拒绝测试),而是精确构造为 {"schema_version": "loopx_goal_activation_v1", "state": "invalid"} 以继续命中目标拒绝路径;已核对 test_manager_context_handoff.py:227 的重激活恢复分支同步更新为 _goal_activation("active")。
  • 验证矩阵与当前精确 Head 证据(80f2930e80):
    • ruff check 全 7 个修改测试文件:PASS(All checks passed!, rc=0)。
    • uv run --extra test python -m pytest -q 运行全部 7 个修改文件:PASS(281 passed in 266.21s, rc=0)。
    • uv run --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick:PASS(ok=true, selected=3, executed=3, failures=0,含 rfc_bilingual_diff 与 py_compile 通过)。
    • uv run --extra test loopx check --scan-path ...(7 文件):PASS(ok=True, errors=0, warnings=0,public boundary scan clean: 7 files)。
    • 远端 CI 诊断行(required=false):评审时 dependency-review 与最新 inspect-pr-diff PASS,Sign-off 与 Summary 为 UNVERIFIED(仍处于 IN_PROGRESS 运行中);完整 CI 合并门仍由合并前队列与 branch protection 独立门禁把关。

我的整体评价 / Verdict

综合评估,long_horizon 与 user_experience 均维持 preserved(本 PR 仅修改 7 个 Python 测试文件,不涉及任何前端渲染视图、页面布局或截图资产。,unverified_scope: none)。改动全部集中在测试夹具层(7 files changed, +73/-20),直接复用既有规范构造函数 build_goal_activation 并保持测试作用域内辅助函数局部化,未引入任何新词表(local_only)或生产运行时兼容包袱。在 exact head 8946@80f2930e8054d24b33074bdc2ae9f1790eb05fc0 上所有 281 条受影响测试、Ruff、canary premerge 与公私边界扫描全部通过;残余风险仅限于非本次 diff 行的既有无关示例字符串及远端运行中的常规 CI workflow(不阻断本次代码批准)。

English verdict: APPROVE for exact head 8946@80f2930e8054d24b33074bdc2ae9f1790eb05fc0. Resolves the test_contract_health.py F401 unused import and migrates six retired activation_state test fixtures to canonical build_goal_activation(...) across 7 test-only files (ruff check, 281 pytest cases, quick canary premerge, and scoped public-boundary checks all PASS; remaining in-progress remote checks stay separate from code approval).

This branch has not been deployed

No deployments
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