Skip to content

test(#671): harden heading policy near-equivalence inventory - #675

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-671-heading-policy-near-equivalence
Jun 5, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-671-heading-policy-near-equivalence

Conversation

@squne121

@squne121 squne121 commented Jun 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

test_heading_policy.py の inventory hardening を pure helper ベースへ寄せ、HEADING_POLICY の canonical heading 集合が implementation.yml 由来 label、create-issue scaffolding heading、明示 ALLOWED_EXTRAS のみで構成されることを exact match で検証するようにした。

  • ALLOWED_EXTRAS を test-local 定数として追加し、空集合を既定にする理由と prose-exemption surface 拡張時の注意を日本語コメントで固定した。
  • _expected_heading_policy_keys() と _assert_heading_policy_near_equivalence() を追加し、HEADING_POLICY の key 集合を副作用なしで検証できるようにした。
  • 既存の superset 検証を near-equivalence 検証へ置き換え、production HEADING_POLICY を mutate しない unknown heading negative test を追加した。

受け入れ条件の達成状況

  • AC1: _expected_heading_policy_keys() と _assert_heading_policy_near_equivalence(policy_keys: set[str]) を追加し、set(HEADING_POLICY.keys()) の exact match を検証する test_heading_policy_near_equivalence を実装した。
  • AC2: ALLOWED_EXTRAS を test-local 定数として明示し、空集合を既定にする理由と prose-exemption surface 拡張時の注意をコメントで固定した。
  • AC3: set(HEADING_POLICY.keys()) | {"Arbitrary English Heading"} を helper に渡し、pytest.raises(AssertionError) で拒否する test_heading_policy_rejects_unknown_heading を追加した。
  • AC4: .claude/skills/create-issue/scripts/tests/ の pytest regression を実行し、243 passed を確認した。

検証コマンド結果

  • rg "def test_heading_policy_near_equivalence" .claude/skills/create-issue/scripts/tests/test_heading_policy.py を実行し、near-equivalence テスト定義を検出した。
  • rg "ALLOWED_EXTRAS" .claude/skills/create-issue/scripts/tests/test_heading_policy.py を実行し、test-local 定数と helper 参照を検出した。
  • rg "def test_heading_policy_rejects_unknown_heading" .claude/skills/create-issue/scripts/tests/test_heading_policy.py を実行し、unknown heading negative test を検出した。
  • uv run pytest .claude/skills/create-issue/scripts/tests/ を実行し、243 passed in 0.94s を確認した。

Allowed Paths 遵守

Checks

  • 上の「検証コマンド結果」に記載した 4 コマンドを worktree で実行し、すべて通過した。
  • 変更は 1 ファイルに限定されており、他の skill / validator / production policy には触れていない。

Schema Change Applicability

  • decision: not_schema_change
  • reason: 今回の変更は test_heading_policy.py 内の helper とテスト構成だけで、runtime contract や consumer schema は変更していない。

Schema Consumer Inventory

N/A — not_schema_change のため。テストコードだけの変更であり、consumer 更新対象は存在しない。

Safety Claim Matrix

.claude/skills/** 配下の変更だが、対象は test file のみで、権限・sandbox・transport・auth・MCP・workflow の挙動変更は含まないことを確認した。

Claim Implemented? Not controlled Evidence Follow-up
heading inventory hardening は prose-exemption の許可面を test で固定するだけで、実行権限や transport 境界を変更しない yes(実装済み) N/A uv run pytest .claude/skills/create-issue/scripts/tests/ が 243 passed で通過し、変更ファイルも test のみであることを確認した N/A

Notes

Closes #671
この PR のマージで Issue #671 を閉じる。

Add pure helpers for expected heading keys, document why ALLOWED_EXTRAS defaults to empty, and assert unknown English headings fail near-equivalence without mutating production policy.
@squne121
squne121 marked this pull request as ready for review June 5, 2026 23:10
@github-actions

github-actions Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #675 closed).

@squne121

squne121 commented Jun 5, 2026

Copy link
Copy Markdown
Owner Author

検証結果レポート

Issue #671: heading_policy inventory テストの near-equivalence hardening

AC 確認コマンド 実行結果(要約) exit code 判定
AC1 rg "def test_heading_policy_near_equivalence" .claude/skills/create-issue/scripts/tests/test_heading_policy.py near-equivalence テスト定義を検出 0 PASS
AC2 rg "ALLOWED_EXTRAS" .claude/skills/create-issue/scripts/tests/test_heading_policy.py ALLOWED_EXTRAS 定数と helper 参照を検出 0 PASS
AC3 rg "def test_heading_policy_rejects_unknown_heading" .claude/skills/create-issue/scripts/tests/test_heading_policy.py unknown heading negative test を検出 0 PASS
AC4 uv run pytest .claude/skills/create-issue/scripts/tests/ 243 passed in 0.76s 0 PASS

総合判定

  • 全 AC PASS: YES
  • FAIL した AC: なし
  • SKIP した AC: なし
  • human_review_required: NO
  • reviewed_head_sha: 76667cf19ab4c9a531b98f8b187e596cff567b77
TEST_VERDICT:
  result: PASS
  mergeable: MERGEABLE
  merge_state_status: CLEAN
  branch_behind_main: false
  baseline_only: false
  verification_commands_pass: 4
  verification_commands_fail: 0
  verification_skipped_count: 0
  runtime_ac_results: []

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • AC coverage: ○。PR 本文の ## 受け入れ条件の達成状況 で AC1-AC4 がすべて [x] になっている。
  • Allowed Paths: 遵守。PR diff は .claude/skills/create-issue/scripts/tests/test_heading_policy.py のみ。
  • CI Verification: gh pr checks 675 で typecheck lint test build python-test e2e deploy-pr validate-generated-artifact PR Body Japanese Check がすべて pass。
  • 検証コマンド結果: PR 本文の ## 検証コマンド結果 と current head の再実行で、issue 記載の 4 コマンドがすべて pass。

Blockers

  • なし

Non-blockers(任意改善)

  • なし

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: 76667cf19ab4c9a531b98f8b187e596cff567b77
merge_ready: true
mergeability:
  mergeable: MERGEABLE
  merge_state_status: CLEAN
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []

@squne121

squne121 commented Jun 5, 2026

Copy link
Copy Markdown
Owner Author

結論

Merge 可。ブロッカーなし。
PR #675 は #671 の直接スコープ、つまり HEADING_POLICY を implementation.yml 由来 label + SCAFFOLDING_HEADINGS + ALLOWED_EXTRAS に exact match させるテスト強化としては成立しています。#671 の AC は満たしています。([GitHub]1)

ただし、敵対的に見ると 「期待集合の導出がまだ完全な SSOT ではない」 という残り香があります。今回の PR で block するほどではありませんが、後続で直した方がよいです。

評価

良い点

PR は ALLOWED_EXTRAS を test-local 定数として追加し、空集合を既定にする理由と、追加時に prose-exemption surface が広がることをコメントで明示しています。これは #671 AC2 に合っています。([GitHub]2)

_expected_heading_policy_keys() と _assert_heading_policy_near_equivalence() により、従来の HEADING_POLICY ⊇ template ∪ scaffolding ではなく、HEADING_POLICY == template ∪ scaffolding ∪ allowed_extras を検査する構造になっています。これは #662 レビュー残件の「余分な canonical English heading を検知できない」問題に対する正しい方向です。([GitHub]2)

negative test も、set(HEADING_POLICY.keys()) | {"Arbitrary English Heading"} を helper に渡し、pytest.raises(AssertionError) で拒否されることを確認しています。pytest.raises() を expected exception の context manager として使うのは pytest 公式の使い方と一致します。([GitHub]2)

変更範囲も .claude/skills/create-issue/scripts/tests/test_heading_policy.py のみで、#671 の Allowed Paths に収まっています。PR 本文では uv run pytest .claude/skills/create-issue/scripts/tests/ が 243 passed と報告されています。([GitHub]3)

指摘事項

1. Non-blocker: implementation.yml の label 抽出が YAML schema-aware ではない

現在の _extract_template_labels() は re.findall(r'^\s+label:\s+(.+)$', text, re.MULTILINE) で label を拾っています。現行 implementation.yml では input/textarea の attributes.label だけを見ればよいので実害は出ていませんが、GitHub Issue Forms は YAML の form schema であり、form element は type / attributes / validations などの key-value 構造を持ちます。さらに checkboxes の options にも label が存在します。([GitHub Docs]4)

つまり将来 checkboxes や別用途の label: が入ると、heading として扱うべきでない label まで期待集合に混入します。今回の PR の目的は「余分な英語見出し許可を検出する」ことなので、期待集合側にノイズが混ざる設計は弱いです。

推奨修正案

import yaml

def _extract_template_labels(yml_path: Path) -> list[str]:
    data = yaml.safe_load(yml_path.read_text(encoding="utf-8"))
    labels: list[str] = []

    for element in data.get("body", []):
        if element.get("type") not in {"input", "textarea"}:
            continue
        label = element.get("attributes", {}).get("label")
        if label:
            labels.append(label)

    return labels

dropdown も Issue body heading になる運用なら含める。ただし checkboxes.options[].label は heading ではないので除外すべきです。

2. Non-blocker: SCAFFOLDING_HEADINGS が test-local duplicate のまま

Background と Runtime Verification Applicability は「GitHub template の textarea label ではないが create-issue scaffolding 由来」として test-local に固定されています。今回の #671 はそれを明示するスコープなので問題ありません。([GitHub]2)

ただし parent #646 は、guard / validator / checker / loop が同一 SSOT から分類結果を使うことを求め、同じような正規表現・分類を各所に書くことを禁止しています。(GitHub)

したがって次の段階では、SCAFFOLDING_HEADINGS をテスト内定数に置き続けるより、create-issue scaffolding の生成元から導出するか、少なくとも production 側の共有定数として持つ方が筋がよいです。

3. Non-blocker: near-equivalence は key 集合だけを見ている

今回の目的は key inventory の hardening なので block しません。ただし HEADING_POLICY の危険な拡張は key 追加だけではなく、accepted_forms の過剰許可でも起きます。#654 / #662 側で accepted_forms exact match や arbitrary prefix bypass 修正は入っていますが、今回の helper 名が heading_policy_near_equivalence だと「policy 全体の準同値」と誤解されやすいです。([GitHub]6)

名前をより限定するなら、以下の方が正確です。

_assert_heading_policy_key_inventory_equivalence(...)
test_heading_policy_key_inventory_near_equivalence

Web調査を踏まえた妥当性

GFM の ATX heading は 1〜6 個の #、0〜3 spaces indent、optional closing # などの仕様があり、#654 / #659 側でこの周辺を扱っている設計は妥当です。今回の PR は GFM parser 自体には触れず、heading inventory の許可面だけを縛る変更なので、スコープ分離として正しいです。([GitHub Pages]7)

GitHub Issue Forms は YAML form definition から issue body markdown へ変換されるため、implementation.yml を SSOT として扱う方針も妥当です。ただし上記の通り、regex ではなく YAML schema を読んだ方が高品質です。([GitHub Docs]4)

Merge判断

Approve / Merge 可。

修正要求にするほどの欠陥はありません。#671 の目的は「#662 の superset 検証を allowed-extras 明示の near-equivalence に強化すること」であり、PR #675 はその目的を満たしています。([GitHub]1)

後続 issue を切るなら、タイトルはこれが適切です。

Harden heading policy expected-key derivation with schema-aware issue-form parsing

本文には次を入れるとよいです。

PR #675 hardened HEADING_POLICY key inventory from superset coverage to near-equivalence, but the expected template-derived heading set is still extracted with a broad regex over label: lines.

Replace regex extraction with YAML schema-aware parsing of .github/ISSUE_TEMPLATE/implementation.yml, filtering only issue body elements whose attributes.label becomes an issue-body heading. Explicitly exclude checkbox option labels and non-submitted markdown elements. Add regression tests proving checkbox/dropdown option labels do not enter the HEADING_POLICY expected-key set unless intentionally supported.

@squne121
squne121 merged commit 20fee7e into main Jun 5, 2026
15 checks passed
@squne121
squne121 deleted the worktree-issue-671-heading-policy-near-equivalence branch June 5, 2026 23:34
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.

実装: heading_policy inventory テストを allowed-extras 明示の準同値検証に強化(英語見出し false-negative 防止)

1 participant