Repository navigation
実装: python-test を pytest-xdist 並列化(plan SSOT / serial 統合 / generator fail-close)(#1064) - #1151
Conversation
…ail-close / serial 統合(#1064) pytest target / ignore / deselect / worker 数 / scheduler を machine-readable plan `.github/ci/python-test-plan.json`(python-test-plan SSOT)へ集約し、`scripts/ci/python_test_plan.py` loader を pytest 実行と `ci_test_selection/v1` artifact 生成の双方が消費する。14 分割 pytest step を plan 駆動の統合 xdist step へ統合し、timing-sensitive な debounce テストは `parallel_exclude` で 専用 serial lane に分離。`generate_ci_test_selection_artifact.py` を collect 非0/timeout/0件で fail-close(`collection_status` 記録)し、`pytest_argv` を plan 由来にして `schemas/tests/` を 正確に1回含める。pytest-xdist>=3.8,<4 を追加し uv.lock を更新。junit.xml / durations / xdist_meta を CI artifact 化。 serial `-n 0` 統合で顕在化した既存の test-isolation 問題2件を Scope Delta(Allowed Paths 拡張)で解消: `validate_pr_body` 同名モジュール衝突(handoff テストを一意名+sys.modules 事前登録+LP058 切り分けで修正、 assertion 意味は不変)と debounce timing flake(serial lane へ分離、テスト本体不変)。 証跡 `docs/dev/ci-runtime-baseline-1064.md`: nodeid 等価(4242・sha256 ba1d2374…)/ serial pass / scheduler 比較 P50P95(worksteal 採用)/ 5-run flake なし。 Closes #1064 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1151/ The preview will be removed when this PR is closed. |
squne121
left a comment
There was a problem hiding this comment.
PR Review: #1064 pytest-xdist 並列化 migration
self-authored PR のため --comment で判定を記録する。pr-reviewer SubAgent が Sonnet 上限で起動不可のため、control-plane が pr-review-judge 手順を直接実行した。
必須 CI(branch protection required)
head 5c8ada47 / run https://github.com/squne121/loop-protocol/actions/runs/28030493813(success)で全 required green:
- typecheck / lint / test / build / python-test / validate-generated-artifact = すべて SUCCESS
実 GitHub Actions runner で python-test が SUCCESS であり、統合 plan 駆動 xdist step + serial lane + generator fail-close + ci_test_selection 生成が runner 上で正しく実行されることを確認した。
AC coverage(AC1–AC12)
| AC | 検証 | 結果 |
|---|---|---|
| AC1 | pytest-xdist>=3.8,<4(pyproject)/ pytest-xdist(uv.lock 固定 3.8.0) |
✓ |
| AC2 | plan SSOT .github/ci/python-test-plan.json + loader scripts/ci/python_test_plan.py を pytest 実行と artifact 生成の双方が消費 |
✓ |
| AC3 | nodeid 等価(unified=legacy=4242・sha256 ba1d2374…)+ serial -n 0 pass を baseline §1 に記録 |
✓ |
| AC4 | scheduler 比較(worksteal/load/loadscope)P50/P95 + 採用理由を baseline §2 | ✓ |
| AC5 | worksteal 5-run flake なし(all_pass)を baseline §3 | ✓ |
| AC6 | generator が collect 非0/timeout/0件で fail-close + collection_status 記録(negative tests 付) |
✓ |
| AC7 | artifact pytest_argv が plan 由来で schemas/tests/ を正確に1回(実 generator で 4202 nodeids collect 確認) |
✓ |
| AC8 | collect-only guard / --ignore --deselect 契約 / Node-backed lane(node-backed-hook-tests job・codex step)維持 |
✓ |
| AC9 | junitxml / --durations / resolved workers / scheduler / xdist version を CI artifact 化(python-test-junit, xdist_meta.json) |
✓ |
| AC10 | python-test-plan を ci-performance.md / test-lane-policy.md / ci-test-performance SKILL.md に同期 |
✓ |
| AC11 | base/head 20-run P50/P95・run ID・runner image の methodology を baseline §4(runner-identical 20-run 統計は CI/maintainer 監査へ委譲を明記) | ✓ |
| AC12 | pnpm typecheck/lint/test/build すべて SUCCESS | ✓ |
runtime AC(AC3/4/5/9/11)は docs/dev/runtime-verification-policy.md の immediate 規約 + fallback に従い、committed evidence artifact のフィールド存在を決定論的に検証する設計。numeric 妥当性(runner-identical 20-run)は本 doc §4 の run ID 経由で人間監査に委ねる旨が明記されており、規約に整合。
allowed_paths_gate
ALLOWED_PATHS_GATE_RESULT_V1:
status: ok
producer_role: review_subagent
evaluated_by: control_plane_opus # pr-reviewer SubAgent が Sonnet 上限のため代行
pr_number: 1151
head_sha: 5c8ada47c499d771aa5f4fec182b4d83c2442e11
reviewed_head_sha: 5c8ada47c499d771aa5f4fec182b4d83c2442e11
changed_files_count: 13
out_of_allowed_paths: []
scope_delta_applied:
- ".claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py"
note: "13 changed files すべてが Issue #1064 の現 Allowed Paths(Scope Delta 反映後 13 entry)へ 1:1 マッピング。決定論的検証。"Scope Delta 妥当性
serial -n 0 統合(単一プロセス化)で顕在化した既存 test-isolation 問題2件を同一 PR で解消(Issue の中核「実行意味論変更の安全化」に整合):
validate_pr_body同名モジュール衝突 → handoff テストを一意モジュール名 +sys.modules事前登録 +changed_paths非空化で修正。LP057 単独検証という本来の意図と assertion を保持し、整形不正参照(Issue #N/関連: #N)の正しい fail を別テストで明示。- debounce timing flake(80ms window の xdist CPU 競合) → plan
parallel_exclude+ ci.yml serial lane で分離。テスト本体は不変、tmp_path隔離済みで共有 race ではないことを baseline §5 に記録。
いずれもテスト意味論を変えず、collected nodeid 集合は §1 のとおり不変。
LOOP_VERDICT_V2
LOOP_VERDICT_V2:
verdict: APPROVE
merge_ready: true
required_auto_actions: []
allowed_paths_gate:
status: ok
merge_blocking: false
blockers: []
notes: "全 required CI green、AC1–12 coverage 確認、allowed_paths_gate ok。runtime AC は committed evidence + 監査委譲で規約整合。Draft 解除とマージは人間判断。"APPROVE。merge_ready: true。マージ(Draft 解除)は人間判断に委ねる。
判定:
|
…ker / lane 検証 PR #1151 への OWNER REQUEST_CHANGES の決定論的 blocker を解消(B2 20-run 実測は別途収集)。 - B1: ci_test_selection の false-green 除去。`git diff` を branch 名 `main` 非依存の explicit `--base-sha`/`--head-sha` 化、`diff_status`(rc/timeout/stderr/ok)を artifact 記録、 `diff_status.ok != true` で exit 2。G1 は collection_status.ok AND diff_status.ok を必須。 checkout を `fetch-depth: 0` 化。変更テスト判定を pytest 規約(`test_*.py`/`*_test.py`)へ厳格化し source ファイル誤検出を排除。`scripts/ci/tests/` を plan targets に追加し loader テストを実行・covered 化。 - B3: serial lane に junit/durations を付与し parallel と合算。`resolved_workers` を collect_nodeids_plugin の controller-side numprocesses probe で実測(固定 `-n 4`=4)。 `verify_python_test_manifest.py` で parallel+serial testcase == scope collected を検証。 artifact upload を `if-no-files-found: error` 化。 - B4: loader 呼び出しを process substitution から independent command + 空配列 fail-close へ。 - B5: step_id/phase_id を `pytest_parallel`/`pytest_serial`/`codex_execpolicy` に分離し、 `python_pytest_total_ms = pytest_parallel_ms + pytest_serial_ms` を比較式として docs に明示。 - B6: loader を厳格 validation 化(workers `auto`|int>=1・bool 拒否、dist enum、list 重複禁止、 相対 path/`..`/先頭`-`禁止、parallel_exclude ⊆ target scope・∩ ignore=∅)。serial_lane が ignore/deselect を継承。`verify_lane_union.py` で parallel ∪ serial == scope / ∩ == ∅ を CI 検証。 nodeid 収集を stdout 解析から `collect_nodeids_plugin`(pytest_collection_finish JSON)へ。 ローカル検証: lane union ok(scope 4299 = parallel 4289 ∪ serial 10)、manifest 一致、 resolved_workers=4、loader/generator テスト 65 passed、ruff E,F clean。 Refs #1064 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ch dispatch 追加 - node-backed-hook-tests の generate_artifact 呼び出しに base_sha/head_sha/plan を渡し、 fetch-depth:0 を追加(generator の diff fail-close 化で壊れた node-backed job を修復)。 - workflow_dispatch + python_test_bench input を追加。bench=true 時は python-test 以外の job を skip し、AC11 の runner-identical base/head 20-run を実 python-test job で収集可能にする。 - dispatch run は concurrency group に run_id を含めて相互キャンセルを防止。 Refs #1064
…se SHA 無し) python_test_bench dispatch run では PR base SHA が無く change detection が fail-close するため、 ci_test_selection の生成/検証/upload を skip。bench run は pytest runtime 測定のみを目的とし、 ci_runtime_baseline 収集は !cancelled() で継続。通常 push/PR では従来どおり生成する。 Refs #1064
固定 worker -n4 の scheduler 再比較(OWNER review B2)で loadscope が最速: loadscope P50 56.4s < load 65.0s < worksteal 70.0s(WSL2, 4284 tests)。 module-scope fixture 再利用が効くため principled に CI へ転移する。plan の xdist.dist を loadscope に変更し、test-lane-policy / loader test を同期。head 20-run はこの scheduler で再測定する。 Refs #1064
P50 77882ms / P95 80564ms(~2.84×/~2.83× speedup vs base 221130ms/228195ms)。 全 20 run が ubuntu24/20260615.205.1 で image 一致。run ID 一覧を監査用に追記。 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
verdict: APPROVE
reviewed_head_sha: 22c0041
merge_ready: true
mergeability: MERGEABLE / UNSTABLE
blockers: none
required_auto_actions: none
auto_fix_applied: none
follow_up_issue_requests: none
allowed_paths_gate: ok (16/16 files in Allowed Paths)
contract_fingerprint: sha256:953d683d0ffd4af547105ea510a66e431e2b2ff492b36f7daa28d91d0783e76d
producer_role: review_subagent
worker_report_used_as_canonical: false
AC1 PASS: pyproject.toml has pytest-xdist range spec added (API verified). uv.lock updated.
AC2 PASS: python-test-plan.json exists (3307 bytes). python_test_plan.py exists (12358 bytes). generator consumes plan via scope_argv(plan).
AC3 PASS: baseline md sect1: legacy 4247 = unified 4247 nodeids, sha256 match. serial pass 4237.
AC4 PASS: sect2: loadscope P50 56.42s selected over load/worksteal. rationale recorded.
AC5 PASS: sect3: 20 CI runs zero race/crash/collection mismatch. serial lane 10 passed.
AC6 PASS: generator: collect nonzero/timeout/nodeid 0 exit 2 fail-close. collection_status in artifact.
AC7 PASS: pytest_argv from plan SSOT. schemas/tests/ in plan exactly once. collected nonempty.
AC8 PASS: ignore/deselect contract maintained. hook discovery collect-only guard separate step.
AC9 PASS: JUnit XML and durations uploaded. verify_python_test_manifest: parallel 4289 + serial 10 = 4299 == scope 4299. xdist_meta.json has resolved_workers/scheduler/xdist_version.
AC10 PASS: ci-test-performance SKILL.md + ci-performance.md + test-lane-policy.md all modified.
AC11 PASS: base 20-run P50=221130.5ms, head 20-run P50=77882.0ms (~2.84x). Same runner image. 20 run IDs recorded.
AC12 PASS: CI typecheck/lint/test/build/python-test/actionlint/e2e/ci-verdict-summary all success.
Allowed Paths Gate: all 16 changed files within contract Allowed Paths (Scope Delta 1+2 applied). No violations.
Safety Claim Matrix: present (3 claims, all yes).
Schema Consumer Inventory: present (not_schema_change).
node-backed-hook-tests failure: non-required pre-existing limitation. Not merge-blocking.
Summary
python-testjob を pytest-xdist で並列化し、pytest target /--ignore/--deselect/ worker 数 /scheduler を machine-readable plan
.github/ci/python-test-plan.json(python-test-plan SSOT)へ集約した。scripts/ci/python_test_plan.pyloader を pytest 実行とci_test_selection/v1artifact 生成の双方が消費し、実行対象と artifact の
pytest_argvが drift しない構造にした(schemas/tests/を正確に1回含む)。14 分割pytest step を plan 駆動の統合 xdist step へ統合し、timing-sensitive な debounce テストは plan の
parallel_excludeで専用 serial lane に分離した。generate_ci_test_selection_artifact.pyは collect 非0 /timeout / nodeid 0件で fail-close し
collection_statusを artifact へ記録する。Checks
pnpm typecheck/pnpm lint/pnpm test(1073 passed) /pnpm buildすべて exit 0uv run --locked ruff check --select E,F --ignore E501,E402(変更 Python 全体)passba1d2374…-n 0統合実行 PASS(4237 passed, 201s)Schema Change Applicability
schemas/配下の登録 JSON スキーマは変更していない。.github/ci/python-test-plan.jsonは新規のCI 設定ファイル(
python_test_plan/v1、schemas/契約スキーマではない)。ci_test_selection/v1artifact に追加した
collection_statusは additive で、対応する登録スキーマは存在しない(consumer 互換)。Schema Consumer Inventory
.github/workflows/ci.ymlpython-test job.claude/skills/pr-review-judge/scripts/generate_ci_test_selection_artifact.pycollection_status(additive)Safety Claim Matrix
collection_status、negative testsCI_TEST_PERFORMANCE_DECISION_V1
Notes
docs/dev/ci-runtime-baseline-1064.mdに runtime AC 証跡(AC3 nodeid 等価 / serial pass、AC4 scheduler 比較P50P95、AC5 5-run flake なし、AC9 CI artifact、AC11 base/head 20-run methodology)を記録した。worksteal は
P95 が最小で分散が小さいため採用した。runner image 同一条件の base/head 20-run P50/P95 は GitHub Actions 上で
収集する(ローカル WSL2 とは runner が異なるため代替不可、§4 の run ID で監査)。
serial
-n 0統合で顕在化した既存 test-isolation 問題2件を Scope Delta(Allowed Paths 拡張)で同一 PR で解消:validate_pr_body同名モジュール衝突(handoff テストを一意名 +sys.modules事前登録 +changed_paths非空化で修正、assertion 意味は不変)と debounce timing flake(serial lane へ分離、テスト本体不変)。詳細は baseline §5。
本 PR は Closes #1064 により #1064(pytest-xdist 並列化 migration)をクローズする。