Skip to content

fix: test_isolated_anchor_single_authority のtransient判定を構造化reason_codeベースに改修する - #2319

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-2317-reason-code-skip
Aug 23, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-2317-reason-code-skip

Conversation

@squne121

@squne121 squne121 commented Aug 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • test_isolated_anchor_single_authority.py の transient-failure skip 判定を、production が既に細分類済みの構造化 reason_code(closed enum)ベースの判定へ改修した。旧来の broad substring OR-chain(stdout/stderr 双方の "rate_limited" in ... 系)は、BLOCKERS: GH_API_FAILURE のみが存在する genuine failure を skip してしまう false-green リスクを持っていたため置き換えた。
  • あわせて #2257 AC4 が要求していた reason_code/source/operation の stdout 三値一貫投影の未実装差分を解消した(run_refinement_preflight.py::_build_compact_stdout() に status == "environment_failure" 時のみ REASON_CODE/SOURCE/OPERATION の3行を出力する最小限の追加)。

Scope Delta(範囲追加の申告)

  • 追加ファイル: pyproject.toml(Issue 実装: test_isolated_anchor_single_authority のtransient failure skip判定を構造化reason_codeベースに改修する #2317 の Allowed Paths には含まれていない)
  • 変更内容: [tool.pytest.ini_options].markers の github_live マーカーの docstring を、従来「real GitHub API write access(実際の GitHub API 書き込みアクセス)のみ」をカバーする記述から、「unauthenticated live GitHub REST/API reads(無認証の live GitHub REST/API 読み取り)」も含む記述へ一般化した。マーカー名・addopts の除外条件(-m 'not github_live')は変更していない、docstring(説明文)のみの 1 行差分。
  • 必要性: 本 PR のレビュー対応で新たに @pytest.mark.github_live を付与した 2 件の live-network テスト(scripts/agent-guards/tests/ 配下、blocker 3 の修正対応)を、default の python-test CI ターゲットから正しく除外するために必要。マーカーの意味を実態(読み取り専用の live GitHub アクセスも含む)に合わせて拡張しないと、CI ドキュメント上の説明と実際の運用が乖離する。
  • OWNER 事前承認: OWNER squne121 による本 PR への REQUEST_CHANGES コメント(issuecomment-5384827550)にて、github_live マーカーの一般化作業は「Allowed Pathsをやや超える可能性があるが、Scope Deltaとして許容する価値がある」と明示的に事前承認されている。本項目はその承認範囲に厳密に一致する。
  • contract 再レビュー: allowed_paths_review_gate.py は live Issue 実装: test_isolated_anchor_single_authority のtransient failure skip判定を構造化reason_codeベースに改修する #2317 の Allowed Paths(scripts/agent-guards/tests/test_isolated_anchor_single_authority.py、.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py、.claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py)に対して機械的に判定するため status=fail_closed を返すが、本セクションの追加により reviewer が Scope Delta として明示的に評価できる状態にした。

CI_TEST_PERFORMANCE_DECISION_V1(該当性確認)

pyproject.toml は ci-test-performance Skill の paths に一致するため、判断マトリクスに従い該当性を確認した。

  • decision_scope: review_only(CI ワークフロー自体・依存関係バージョン・実行対象範囲の変更ではなく、既存マーカーの docstring 一般化のみ)
  • lane_classification.python_unit.applicable: true(判断マトリクスで pyproject.toml は python_unit 必須)
    • evidence: 本 PR の Checks セクションに記載済みの以下のコマンドで既に検証済み(markers 定義変更後も addopts の除外条件は不変のため、default python-test ターゲットの collect 件数・実行対象に変化なし)
      • uv run pytest scripts/agent-guards/tests/test_isolated_anchor_single_authority.py -k "not live_subprocess and not credentialless_authority" → 7 passed
      • uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py → 87 passed
  • lane_classification.fast_static / contract_artifact / integration: いずれも applicable: false(判断マトリクスで pyproject.toml は該当なし、かつ本変更は CI ワークフロー・schema・skill 定義を変更しない)
  • CI_TEST_PERFORMANCE_ASSESSMENT_V2 は非該当と判断した: 本変更は claim.kind: none(高速化・性能改善・budget を主張しない、docstring のみの説明文変更)であり、performance_evidence.status: not_required となるため、20-run baseline や runtime_delta 等の性能証跡は不要。

Checks

  • pnpm typecheck — Python 中心の変更のためスキップ(TS 変更なし)
  • pnpm lint — Python 中心の変更のためスキップ(TS 変更なし)
  • pnpm test — Python 中心の変更のためスキップ(TS 変更なし)
  • pnpm build — Python 中心の変更のためスキップ(TS 変更なし)
  • 上記コマンドをすべてローカルで実行し、成功したことを確認してからチェックしてください
  • 代わりに以下の Python 検証コマンドを実行し、全て PASS を確認した:
    • uv run pytest scripts/agent-guards/tests/test_isolated_anchor_single_authority.py -k "not live_subprocess and not credentialless_authority" → 7 passed
    • uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py → 87 passed
    • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py → 24 passed
    • uvx ruff check <changed files> → All checks passed

Schema Change Applicability

  • decision: not_schema_change
  • reason: run_refinement_preflight.py の _build_compact_stdout() に対する変更は、既存の result dict(producer 側では既に reason_code/source/operation キーを保持)の未投影フィールドを stdout に追加投影するのみであり、refinement_preflight_result/v1 の JSON schema のキー集合・型は変更していない(実装: Claude-GPT issue-refinement preflight の anchor comment 取得を credentialless transport へ統一する #2257 AC4 が元々要求していた stdout 投影の未実装差分を埋めるものであり、schema 自体の変更ではない)。

Schema Consumer Inventory

N/A(not_schema_change のため)

Visual Impact Declaration(視覚影響申告)

UI(DOM/CSS)変更を含まないため省略。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
live subprocess テストの skip 判定は genuine failure を false-green にしない(closed-set exact-match、stdout のみ判定、重複/空値は hard failure 維持) yes test_transient_environment_failure_predicate_false_for_genuine_reason_codes / test_transient_environment_failure_predicate_false_without_reason_code_line / test_transient_environment_failure_predicate_false_for_duplicate_or_empty_reason_code(全 PASS、本 PR に含まれる決定論的 unit test) N/A

Notes

…eベースに改修する (#2317)

PR #2310 CI failure triage(run 32617957047)で発覚した、既存の broad substring
OR-chain(`"rate_limited" in stdout or ... or ... in result.stderr`)が
production 側の `BLOCKERS: GH_API_FAILURE` genuine failure を見落とし
transient skip として false-green 化しうる問題を修正する。

- run_refinement_preflight.py: _build_compact_stdout() に、
  status == "environment_failure" のときのみ REASON_CODE/SOURCE/OPERATION
  の3行を一貫して出力する最小限の追加を行う(#2257 AC4 未実装差分の解消)。
- test_isolated_anchor_single_authority.py: stdout の REASON_CODE: 行を
  厳密パースし、値が closed set
  {rate_limited, upstream_environment_failure, transport_connectivity_failure}
  の完全一致の場合にのみ True を返す
  _is_transient_environment_failure_reason_code() predicate を新設し、
  live subprocess テストの skip 判定を旧 substring OR-chain から置き換える。
  stderr は判定ソースとして使用しない。
- test_refinement_preflight.py: formatter (_build_compact_stdout()) の
  contract unit test を追加する(既存 TestBuildCompactStdout に集約)。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2319 closed).

@squne121

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #2319 の中心方針は正しいです。GH_API_FAILURE という blocker 文字列を雑に拾うのではなく、production が生成する reason_code を stdout に投影し、transient 3種だけを exact-match で SKIP する変更は、#2310 で実際に起きた false-green / flaky CI 問題への改善になっています。さらに #2257 / PR #2260 で未完だった reason_code / source / operation の stdout projection も補完しています。

ただし、このまま merge は勧めません。P1 相当が3点あります。特に1点目は明確なテスト契約違反です。

P1 — 新規 formatter test が canonical schema に存在しない値を使っている

これは最も明確な blocker です。

追加された2箇所の formatter test は、

source: github_api
operation: fetch_issue

を使っています。

ところが canonical refinement_preflight_result/v1 schema で許可される値は、

source:
  credentialless_transport
  gh_cli
  internal

operation:
  read_issue
  list_issue_comments
  read_issue_comment
  write_artifacts
  load_fixture
  planner_invocation
  unspecified

です。github_api も fetch_issue も schema-invalid です。

しかも status == environment_failure なら、この3フィールドは canonical schema 上で必須です。

したがって現在のテストは「canonical result → compact stdout」の contract を検証していません。production では生成され得ない synthetic object に対して formatter が文字列を出せることを検証しているだけです。

修正は小さくて十分です。少なくとも positive fixture を、

"reason_code": "rate_limited",
"source": "credentialless_transport",
"operation": "read_issue",

にしてください。さらに質を上げるなら _build_result() 経由で fixture を作るか、fixture 自体を schema validate してから _build_compact_stdout() へ渡すと、schema と formatter test の再ドリフトを防げます。ただし後者は harness を増やすので、この個人開発前提なら単純に schema-valid な値へ直すだけで十分です。

P1 — transient parser が STATUS: environment_failure を確認していない

現在の skip 判定は実質、

returncode == 3
and exactly_one_REASON_CODE
and reason_code in TRANSIENT_SET

です。_stdout_indicates_transient_environment_failure() 自体は STATUS: を一切見ません。

そのため、たとえば将来の projection drift で、

STATUS: blocked
REASON_CODE: rate_limited
BLOCKERS:
  - GH_API_FAILURE

になっても、return code が 3 なら SKIP できます。

これは単なる架空の厳格化要求ではありません。#2317 の事前 adversarial review で既に、

  • returncode == 3
  • STATUS: environment_failure exactly one
  • REASON_CODE: exactly one
  • duplicate / empty / malformed は hard failure
  • stderr は判断に使わない

まで要求されています。

PR は REASON_CODE の exactly-one は実装しましたが、STATUS の exactly-one を落としています。

ここは security hardening ではなく false-green 防止そのものなので直す価値があります。例えば parser を過剰に一般化せず、

status_matches = [...]
reason_matches = [...]

return (
    len(status_matches) == 1
    and status_matches[0] == "environment_failure"
    and len(reason_matches) == 1
    and reason_matches[0] in TRANSIENT_CODES
)

程度で十分です。

逆に SOURCE / OPERATION まで skip predicate で厳格 validation する必要はないと思います。SKIP 判定に必要なのは status + reason であり、それ以上は harness 化しすぎます。

P1 — 「best-effort live smoke」にしたという設計判断が、実際の CI topology に反映されていない

ここはこのプロジェクトの運用方針を考えると最も重要です。

#2317 の事前レビューでは、未認証 GitHub API を使うこの live test を「authoritative merge-blocking runtime evidence」ではなく best-effort live smoke にすることが推奨されていました。deterministic tests を required CI に置き、外部ネットワーク live test は分離する方針です。

しかし現在、

scripts/agent-guards/tests/

は通常の python-test target にそのまま含まれています。

一方、問題の2つの real-network test には marker がありません。

つまり #2319 後も、毎PRの required Python suite が real anonymous GitHub API を叩き続けます。

これは既に理論上の懸念ではありません。PR #2310 は自分の変更と無関係なのに、この credentialless GitHub live call の transient GH_API_FAILURE で CI が赤くなり、再実行が必要になったことを明記しています。

さらに github_credentialless_read.py 自身が「anonymous GitHub REST 60 req/h を受け入れ、それが通常 workload に不足すると実証されたら follow-up を行う」と明記しています。 GitHub の現在の公式仕様も、未認証 REST API は送信元 IP あたり 60 requests/hour です。([docs.github.com]1)

つまりその follow-up 条件は、実質もう満たされています。

ただし、ここで authenticated broker や credential forwarding を作るのは勧めません。個人趣味開発では明らかに過剰です。

このリポジトリには既に、

addopts = "--import-mode=importlib -m 'not github_live'"

という live test を通常 CI から外す仕組みがあります。 pytest 自体も custom marker と -m "not ..." による選択を正式にサポートしています。([pytest 公式ドキュメント]2)

したがって最小修正は、既存 github_live marker の意味を「authenticated write」から「real GitHub network interaction」へ少し一般化し、このファイル中の2つの real-network test だけに付けることです。formatter/parser/static wiring tests は通常 CI に残します。

これなら新しい workflow、broker、retry harness は不要です。必要なときだけ pytest -m github_live ... で確認できます。さらに自動 smoke が欲しくなった時だけ workflow_dispatch / scheduled workflow を後付けできます。GitHub Actions は manual / scheduled trigger を標準サポートしています。([GitHub Docs]3)

P2 — Issue review で避けるよう言われた cross-layer formatter test が重複追加されている

#2317 の review では責務を明確に分けるよう指摘されています。

test_refinement_preflight.py は formatter contract、test_isolated_anchor_single_authority.py は parser / transient predicate / live subprocess を担当し、agent-guards 側から production formatter を importlib load するテストは増やさない、という方針でした。

PR は前半を正しく実装し、TestBuildCompactStdout に formatter tests を追加しています。

ところが同時に agent-guards 側にも _load_run_refinement_preflight_module() を新設し、ほぼ同じ formatter projection tests をもう一度追加しています。

これは機能バグではありませんが、

  • import coupling が増える
  • 同じ contract fixture が2箇所に増える
  • 今回のように schema-invalid な github_api/fetch_issue fixture まで重複する
  • テストファイルが既に大きいのにさらに100行超膨らむ

という純粋なメンテナンス損です。

_load_run_refinement_preflight_module() と agent-guards 側の2つの formatter tests は削除し、parser testsだけ残すのがよいです。

評価できる点

REASON_CODE / SOURCE / OPERATION を environment_failure の時だけ出す production change 自体は適切です。#2257 の schema contract と揃います。

また transient set を

rate_limited / upstream_environment_failure / transport_connectivity_failure

の3つに限定し、bare 403、auth dependency、malformed response、internal error 等を hard failure のままにしている判断も維持すべきです。GitHub 公式でも primary rate-limit は 403/429 と x-ratelimit-remaining: 0、secondary rate-limit は Retry-After 等を基に扱うため、現行 transport の bare 403 を transient にしない分類は妥当です。 ([docs.github.com]1)

stderr を skip 判定から外したのも正しいです。ここを再び fuzzy substring に戻すべきではありません。

私なら merge 前にこう直す

優先順位は、① schema-invalid test fixture 修正 → ② STATUS も含めた strict parser → ③ real-network 2テストを通常 CI から外す → ④ duplicated cross-layer tests 削除です。

特に③は Issue の Allowed Paths を少し超える可能性がありますが、このプロジェクトの目的からすると、追加の security mechanism を作るよりはるかに費用対効果が高いです。pyproject.toml の既存 marker 機構を使うだけなので、scope delta を許容する価値があります。

現状を点数化するなら、production fix 8/10、test contract 5/10、CI運用 5/10です。中心実装はかなり近いですが、「schema-valid な contract test」と「live external dependency を merge gate から離す」の2点を直してからマージするのがよいです。

OWNER REQUEST_CHANGES on PR #2319 (4 blockers):
- Fix schema-invalid source/operation fixture values in the newly added
  formatter tests (github_api/fetch_issue -> credentialless_transport/
  read_issue, the values valid for status: environment_failure per
  refinement_preflight_result/v1 schema).
- Harden _stdout_indicates_transient_environment_failure() to also require
  STATUS: environment_failure to appear exactly once, in addition to the
  pre-existing REASON_CODE exactly-once check.
- Mark the two real-network tests with @pytest.mark.github_live so they are
  excluded from the default python-test run, and generalize the marker's
  pyproject.toml description beyond "gh CLI write access" to cover
  unauthenticated live GitHub REST reads too.
- Remove the near-duplicate formatter-contract tests and the
  _load_run_refinement_preflight_module() helper from
  test_isolated_anchor_single_authority.py; test_refinement_preflight.py
  already owns formatter contract testing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

fix_delta iteration 1 (OWNER REQUEST_CHANGES)

対応 head: 509a7764894efd7ab07262fee45da54e978d3baf

P1: schema-invalid fixtures

refinement_preflight_result_v1.schema.json を正本として確認したところ、status: environment_failure 時の source enum は credentialless_transport | gh_cli | internal、operation enum に read_issue を含み、github_api / fetch_issue はいずれも enum 外だった。新規追加した formatter テスト(test_environment_failure_emits_reason_code_source_operation_and_no_raw_detail_leak / test_non_environment_failure_omits_reason_code_source_operation、test_refinement_preflight.py 側)のフィクスチャ値を source: credentialless_transport / operation: read_issue に修正した。

P1: STATUS の exactly-once 厳格化

_stdout_indicates_transient_environment_failure() に STATUS: environment_failure が正確に1回のみ出現することを要求する _extract_status_line_value() を追加し、REASON_CODE の exactly-once チェックと同じ厳格さを STATUS にも適用した(SOURCE/OPERATION は OWNER 指示どおり対象外)。回帰テスト test_stdout_indicates_transient_environment_failure_requires_status_exactly_once を追加(STATUS欠落・重複・不一致の3ケース+正常系)。

P1: github_live marker(Scope Delta)

実ネットワーク呼び出しを行う2テスト(test_isolated_anchor_comment_resolves_via_single_credentialless_authority / test_ac5_ac6_skill_runtime_exec_with_human_context_live_subprocess_resolves_anchor_via_credentialless_authority)に @pytest.mark.github_live を付与し、既定の python-test(addopts -m 'not github_live')から除外されることを確認した。pyproject.toml の marker docstring も "gh CLI write access" 限定の記述から「real GitHub network interaction」(未認証 live REST read を含む)を包含する記述へ一般化した。

Scope Delta: pyproject.toml は Issue #2317 の原 Allowed Paths 外だが、blocker 3 の指示どおりマーカー説明の一般化に必要な変更として追加した(1行の docstring 文言変更のみ)。

P2: 重複テストの除去

test_isolated_anchor_single_authority.py から formatter contract テスト(AC1/AC2 相当)2件と _load_run_refinement_preflight_module() ヘルパーを削除し、責務を test_refinement_preflight.py(formatter contract テストの正本)に一本化した。test_isolated_anchor_single_authority.py にはパーサー/述語/live-subprocess テストのみが残る。

検証結果

  • pnpm typecheck / pnpm lint / pnpm test(1876 tests pass)/ pnpm build: 全て green
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: 24 passed
  • uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py scripts/agent-guards/tests/test_isolated_anchor_single_authority.py: 93 passed, 2 deselected(github_live の2件が正しく除外されることを確認)

CI/test-lane 関連パスの変更(pyproject.toml マーカー記述変更)については、テストの実行時間やレーン構成に対する新規パフォーマンス主張は行っていない(テスト除外の正しさに関する修正のみ)。

このコメントは実装反映のみで、PR は Draft のまま・マージ操作は行っていない。

@squne121

Copy link
Copy Markdown
Owner Author

pr-review-judge の REQUEST_CHANGES(iteration 2, head 509a776)で挙げられた唯一の blocker(pyproject.toml の Allowed Paths 外変更に Scope Delta 記載がない)に対応した。

  • PR 本文に ## Scope Delta(範囲追加の申告) セクションを追加し、pyproject.toml の github_live マーカー docstring 一般化を明示的に申告した。
  • OWNER squne121 の REQUEST_CHANGES コメント(issuecomment-5384827550)で本作業が Scope Delta として事前承認されていることを引用した。
  • pyproject.toml は ci-test-performance Skill の対象パスに一致するため ## CI_TEST_PERFORMANCE_DECISION_V1(該当性確認) セクションも追加し、decision_scope: review_only / lane_classification.python_unit.applicable: true(既存 Checks の pytest 実行結果で充足)/ CI_TEST_PERFORMANCE_ASSESSMENT_V2 非該当(claim.kind: none)と判定した。

コード変更は行っていない(本 iteration は PR 本文メタデータのみの修正)。head SHA は変わらないため、再レビューを依頼する。

@squne121

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN, isDraft=true, state=OPEN

Blockers

なし

確認事項(impl-review-loop iteration サマリ)

  • OWNER REQUEST_CHANGES(https://github.com/squne121/loop-protocol/pull/2319#issuecomment-5384827550)の4件のBlocker(P1x3, P2x1)はすべて head 6fd5a83e2f9229b156de89287fcc231df22a561e 時点のコードで解消確認済み。
    1. formatter test の schema-invalid source/operation を credentialless_transport/read_issue に修正。
    2. _stdout_indicates_transient_environment_failure() が STATUS: environment_failure の exactly-one チェックも行うよう厳格化(回帰テスト追加済み)。
    3. real-network 2テストに @pytest.mark.github_live を付与し、通常の python-test target から除外(マーカーの説明も一般化)。
    4. scripts/agent-guards/ 側の重複 formatter projection tests と _load_run_refinement_preflight_module() を削除。
  • fix_delta の過程で pyproject.toml が Issue 実装: test_isolated_anchor_single_authority のtransient failure skip判定を構造化reason_codeベースに改修する #2317 の Allowed Paths 外になった件は、Issue 本文の Allowed Paths を更新(Scope Delta として明記・OWNER 事前承認を引用)することで解消。allowed_paths_review_gate.py は live Issue 本文と live PR file list に対して status: ok, violations: [] を返す。
  • 必須CI(typecheck, lint, test, build, python-test, validate-generated-artifact)は全て SUCCESS。visual-impact-policy-trusted は required set 外の既知 infra flake であり blocker にしない。
verdict: APPROVE
reviewed_head_sha: "6fd5a83e2f9229b156de89287fcc231df22a561e"
blockers: []
warnings: []

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.

実装: test_isolated_anchor_single_authority のtransient failure skip判定を構造化reason_codeベースに改修する

1 participant