Skip to content

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

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#646"
goal_ref: "guard-japanese-prose と issue contract authoring の境界を SSOT 化し、prose boundary policy の superset 検証を allowed-extras 明示の準同値検証に強化して英語見出し false-negative を機械的に防止する"
change_kind: code

Parent Issue

#646

Parent Goal Ref

Current Validated Scope

  • .claude/skills/create-issue/scripts/tests/test_heading_policy.py に、_expected_heading_policy_keys() と _assert_heading_policy_near_equivalence(policy_keys: set[str]) のような副作用なし helper を追加し、set(HEADING_POLICY.keys()) を (template_labels ∪ SCAFFOLDING_HEADINGS ∪ ALLOWED_EXTRAS) に exact match させる near-equivalence 検証へ変更する
  • ALLOWED_EXTRAS は test-local 定数として明示定義し、空集合を既定とする理由と、追加時に prose-exemption surface が広がることを説明するコメントを付ける
  • negative test は production HEADING_POLICY を直接 mutate せず、set(HEADING_POLICY.keys()) | {"Arbitrary English Heading"} を helper に渡して pytest.raises(AssertionError) で unknown heading を拒否する

Remaining Parent Gaps

Outcome

test_heading_policy.py に _expected_heading_policy_keys() / _assert_heading_policy_near_equivalence(policy_keys: set[str]) のような副作用なし helper、ALLOWED_EXTRAS の明示定義と理由コメント、baseline exact-match test、unknown heading を pytest.raises(AssertionError) で拒否する negative test が追加され、HEADING_POLICY の canonical heading 集合 = (implementation.yml 由来 label ∪ 明示 SCAFFOLDING_HEADINGS ∪ 明示 ALLOWED_EXTRAS) を exact assert できる状態になっている。

In Scope

  • test_heading_policy.py の inventory coverage テストを、副作用なし helper を使う near-equivalence 検証へ変更する
  • ALLOWED_EXTRAS を test-local 定数として明示定義し、空集合を既定とする理由コメントを追加する
  • production HEADING_POLICY を直接 mutate しない unknown heading negative test を追加する

Out of Scope

Acceptance Criteria

  • AC1: test_heading_policy.py に _expected_heading_policy_keys() と _assert_heading_policy_near_equivalence(policy_keys: set[str]) のような副作用なし helper と baseline test が追加され、set(HEADING_POLICY.keys()) が (template_labels ∪ SCAFFOLDING_HEADINGS ∪ ALLOWED_EXTRAS) に exact match することを assert する
  • AC2: ALLOWED_EXTRAS が test-local 定数として明示的に定義され(空集合を含む)、空集合を既定とする理由と prose-exemption surface 拡張時の注意を説明するコメントが付いている
  • AC3: set(HEADING_POLICY.keys()) | {"Arbitrary English Heading"} のような key set を helper に渡し、production HEADING_POLICY を直接 mutate せず pytest.raises(AssertionError) で unknown heading を拒否する negative test が存在する
  • AC4: .claude/skills/create-issue/scripts/tests/ 限定の既存 pytest regression が通過する(test_secret_boundary_contract を含む hooks/tests は対象外)

Verification Commands

# AC1
# baseline fail: current main には test_heading_policy.py は存在するが、この near-equivalence helper / test 名は未追加
$ rg "def test_heading_policy_near_equivalence" .claude/skills/create-issue/scripts/tests/test_heading_policy.py

# AC2
# baseline fail: current main には test-local ALLOWED_EXTRAS 定数と理由コメントが未追加
$ rg "ALLOWED_EXTRAS" .claude/skills/create-issue/scripts/tests/test_heading_policy.py

# AC3
# baseline fail: current main には unknown heading negative test が未追加
$ rg "def test_heading_policy_rejects_unknown_heading" .claude/skills/create-issue/scripts/tests/test_heading_policy.py

# AC4
$ uv run pytest .claude/skills/create-issue/scripts/tests/

Allowed Paths

  • .claude/skills/create-issue/scripts/tests/test_heading_policy.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

  • Python / pytest(parametrize、fixture)

Scope Delta(任意)

N/A

Delivery Rule

Background

PR #662(#654)のレビューで残リスクとして指摘された follow-up。現在の main では test_heading_policy.py が HEADING_POLICY ⊇ (template ∪ scaffolding) の superset 検証を持つが、これは「許可してはいけない余分な canonical English 見出しが HEADING_POLICY に増えていないこと」を縛れていない。#654 の趣旨は false positive 削減だけでなく英語 prose の false negative 防止にあるため、inventory テストを allowed-extras を明示した near-equivalence 検証へ強化し、unknown heading を exact key set 逸脱として落とせるようにする。

関連: #662 (comment)

Runtime Verification Applicability

  • decision: not_applicable
  • 判定: not_applicable
  • 理由: 本 Issue は .claude/skills/create-issue/scripts/tests/test_heading_policy.py の static test hardening のみを扱い、動作検証 AC やプロセス起動・通信・I/O を要求しない

Activity

  1. added
    enhancement
    phase/implementation
    area/ai-ops
    on Jun 5, 2026
  2. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    判定

    Issue #671 は方向性は正しいが、このまま実装に渡すには少し甘い。差し戻し寄りの GO。
    目的は妥当です。#654 / PR #662 で HEADING_POLICY ⊇ template ∪ scaffolding までは確認されたが、余分な canonical English heading の追加を止められない、という follow-up は筋が通っています。#671 自体も、HEADING_POLICY == template_labels ∪ SCAFFOLDING_HEADINGS ∪ ALLOWED_EXTRAS への強化と、未知 heading 追加時の negative test を要求しています。([GitHub]1)

    ただし、現状の契約は AC3 の実装方法が曖昧 です。「余分な英語見出しを追加すると near-equivalence テストが fail する negative test」という表現だけだと、実装者が HEADING_POLICY を monkeypatch して既存 test 関数の副作用に依存する雑なテストを書きがちです。pytest の monkeypatch.setitem 自体は辞書変更用途として公式に想定されていますが、今回の主眼は runtime behavior ではなく expected key set の検証関数そのもの なので、グローバル辞書を直接汚すより、純粋関数に切り出して pytest.raises(AssertionError) で検証する方が堅いです。([pytest ドキュメント]2)

    関連コンテキスト

    #646 の親目的は、guard / validator / checker / loop が同一の prose boundary policy を使い、英語 prose の false negative とテンプレ見出しの false positive を同時に避けることです。特に「正規見出し・機械可読構造・tmp 下書き・公開 mutation」を分類 SSOT に寄せる方針が親契約化されています。([GitHub]3)

    #654 はその child として、canonical / bilingual heading、Machine-Readable Contract、VC command、code fence を prose ratio 判定から除外し、check_issue_contract.py 側でも bilingual heading を section として認識させる実装を要求していました。([GitHub]4) PR #662 はこれを実装し、prose_boundary_policy.py に heading inventory、validate_japanese_content.py の heading 除外、check_issue_contract.py の bilingual 抽出、test_heading_policy.py などを追加しています。([GitHub]5)

    PR #662 の最終レビューでは、B1/B2/M1/M2 は解消済みとされつつ、残リスクとして「HEADING_POLICY は template/scaffolding を含むことしか検証しておらず、余分な英語見出しを許可しても検出できない」と明示されています。#671 はこの指摘を受けた follow-up です。([GitHub]5)

    ブロッカー級の指摘

    1. AC3 は「テスト関数の失敗」をどう検証するかを固定すべき

    現状の AC3 は、未知 heading 追加時に near-equivalence テストが fail することを要求しています。([GitHub]1) しかし実装者が単に HEADING_POLICY["Unknown"] = ... して _is_heading_block() の挙動を見るだけでは、near-equivalence assertion 自体の退行検出能力 を検証したことになりません。

    要求はこう修正した方がよいです。

    ALLOWED_EXTRAS: set[str] = set()
    
    def _expected_heading_policy_keys() -> set[str]:
        template = set(_get_template_canonical_headings())
        scaffolding = set(SCAFFOLDING_HEADINGS)
        return template | scaffolding | ALLOWED_EXTRAS
    
    def _assert_heading_policy_near_equivalence(policy_keys: set[str]) -> None:
        expected = _expected_heading_policy_keys()
        extra = policy_keys - expected
        missing = expected - policy_keys
        assert missing == set()
        assert extra == set()
    
    def test_heading_policy_near_equivalence():
        _assert_heading_policy_near_equivalence(set(HEADING_POLICY.keys()))
    
    def test_heading_policy_rejects_unknown_heading():
        policy_keys = set(HEADING_POLICY.keys()) | {"Arbitrary English Heading"}
        with pytest.raises(AssertionError):
            _assert_heading_policy_near_equivalence(policy_keys)

    この形なら、negative test は production global を mutate せず、検証ロジックの fail 条件だけを直接固定できます。

    2. ALLOWED_EXTRAS の置き場所は test-local でよいが、理由コメントは「空集合の理由」まで書くべき

    #671 は ALLOWED_EXTRAS の定義を要求し、空集合も可としています。([GitHub]1) ただし、空集合の場合に単に ALLOWED_EXTRAS = set() だけだと、後続の実装者が安易に追加してもレビュー観点が弱い。

    コメントは最低限こうするべきです。

    # HEADING_POLICY may only contain:
    # - labels emitted by .github/ISSUE_TEMPLATE/implementation.yml
    # - headings inserted by create-issue scaffolding
    # - explicitly reviewed extras below
    #
    # Empty by default: no non-template/non-scaffolding English heading is currently
    # allowed to be prose-exempt. Adding a key here expands the prose-exemption
    # surface and must explain why it cannot be represented as a template label or
    # scaffolding heading.
    ALLOWED_EXTRAS: set[str] = set()

    この Issue の目的は「英語 prose false-negative 防止」なので、ALLOWED_EXTRAS は単なる逃げ道ではなく、prose 除外面を広げるセキュリティ例外リスト として扱うべきです。

    3. Verification Commands の baseline コメントが古い

    #671 の Verification Commands には「PR #662 マージ前は test_heading_policy.py が存在しないため 0 hit」という説明があります。([GitHub]1) しかし PR #662 は Jun 5, 2026 に main へ merge 済みで、#671 も PR #662 から参照されています。([GitHub]5)

    今の main では test_heading_policy.py は既に存在し、現在のテストは HEADING_POLICY ⊇ template ∪ scaffolding を assert する superset 検証です。([GitHub]6)
    したがって、#671 の VC コメントはこう直すべきです。

    # AC1: near-equivalence test が追加されていること
    rg "def test_heading_policy_near_equivalence" .claude/skills/create-issue/scripts/tests/test_heading_policy.py
    
    # AC2: ALLOWED_EXTRAS が明示されていること
    rg "ALLOWED_EXTRAS" .claude/skills/create-issue/scripts/tests/test_heading_policy.py
    
    # AC3: unknown heading を expected set 外として拒否する negative test
    rg "def test_heading_policy_rejects_unknown_heading" .claude/skills/create-issue/scripts/tests/test_heading_policy.py
    
    # AC4
    uv run pytest .claude/skills/create-issue/scripts/tests/

    「PR #662 マージ前」という歴史的説明は現在の実装契約としてはノイズです。

    非ブロッカーだが直したい点

    #671 は .claude/skills/create-issue/scripts/prose_boundary_policy.py への ALLOWED_EXTRAS 追加も許容しています。([GitHub]1) ただし、この issue の本質は production logic 変更ではなく test hardening です。ALLOWED_EXTRAS を policy 側に置くと「production policy の一部」に見えるため、現時点では test_heading_policy.py に置く方が安全です。production 側に置くなら、lookup_heading_policy() がそれを runtime 許可として参照しないことを明記してください。

    また、GFM の ATX heading は 0〜3 spaces indent、1〜6 個の #、optional closing # などの仕様を持ちます。([GitHub Pages]7) ただし #671 は parsing の再実装ではなく inventory の準同値検証です。GFM edge case をこの Issue に持ち込むと #654 / #672 と責務が混ざるため、scope に入れない方がよいです。#672 は code fence 直後の heading false-fail を別 issue として扱っており、ここで吸収すべきではありません。([GitHub]8)

    実装者に渡すなら、この追記が必要

    Issue #671 の本文に、次の acceptance detail を追加するのがよいです。

    ### Implementation Detail
    
    - near-equivalence 判定は `_assert_heading_policy_near_equivalence(policy_keys: set[str])`
      のような副作用なし helper に切り出すこと。
    - baseline test は `set(HEADING_POLICY.keys())` を helper に渡して exact match を検証すること。
    - negative test は production `HEADING_POLICY` を直接変更するのではなく、
      `set(HEADING_POLICY.keys()) | {"Arbitrary English Heading"}` を helper に渡し、
      `pytest.raises(AssertionError)` で unknown heading が拒否されることを検証すること。
    - `ALLOWED_EXTRAS` は空集合でも必ず定義し、空集合である理由と、追加時に prose-exemption surface が広がる旨をコメントすること。

    最終コメント案

    Verdict: REQUEST_CHANGES before implementation
    
    Issue #671 の方向性は正しいです。PR #662 の follow-up として、現行の
    `HEADING_POLICY ⊇ template ∪ scaffolding` を
    `HEADING_POLICY == template ∪ scaffolding ∪ ALLOWED_EXTRAS`
    に強化する必要があります。
    
    ただし、AC3 が曖昧です。「未知 heading を追加すると fail する negative test」は、
    production `HEADING_POLICY` の monkeypatch に依存せず、near-equivalence 判定 helper を
    副作用なしで切り出して、その helper に unknown key を含む key set を渡し
    `pytest.raises(AssertionError)` で検証する形に固定してください。
    
    また、Verification Commands の「PR #662 マージ前は test_heading_policy.py が存在しない」
    という baseline 説明は現在の main では古いです。PR #662 は既に merge 済みなので、
    現状は「test file は存在するが near-equivalence test / ALLOWED_EXTRAS / negative test が未追加」
    という説明に更新してください。
    
    修正後は実装 GO でよいです。

    結論として、#671 は 必要な hardening issue です。ただし、実装契約に「副作用なし helper で exact key set を検証する」ことを明記しないと、テスト追加に見えて実際には退行検出力の弱い PR が出る可能性があります。

  3. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-05T22:57:01Z)

    • Outcome: near-equivalence helper / baseline exact-match test / unknown heading negative test / test-local ALLOWED_EXTRAS 方針を body に反映済み
    • Acceptance Criteria: AC1 helper + exact match、AC2 ALLOWED_EXTRAS rationale、AC3 helper-based negative test、AC4 pytest regression
    • Verification Commands: AC1-AC3 は baseline fail の rg、AC4 は regression gate の uv run pytest
    • Allowed Paths: .claude/skills/create-issue/scripts/tests/test_heading_policy.py
    • Worktree: .claude/worktrees/issue-671-heading-policy-near-equivalence
    • Branch: worktree-issue-671-heading-policy-near-equivalence
    • VC preflight: baseline fail = 3, expected pass = 1, 実行不可 = 0
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: '2026-06-05T22:57:01Z'
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/671
      body_sha256: e768b985ff4331576d7115f6d21dd75c9d2aacc6aca286528ffcb51f7c72b922
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 3
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 1
          vc_skipped: 0
          classifications:
          - ac: AC1
            command: $ rg "def test_heading_policy_near_equivalence" .claude/skills/create-issue/scripts/tests/test_heading_policy.py
            exit_code: 1
            category: expected_baseline_fail
            scope_class: baseline_fail_expected
            confidence: high
            evidence:
              stdout_excerpt: ''
              stderr_excerpt: ''
            decision: go
          - ac: AC2
            command: $ rg "ALLOWED_EXTRAS" .claude/skills/create-issue/scripts/tests/test_heading_policy.py
            exit_code: 1
            category: expected_baseline_fail
            scope_class: baseline_fail_expected
            confidence: high
            evidence:
              stdout_excerpt: ''
              stderr_excerpt: ''
            decision: go
          - ac: AC3
            command: $ rg "def test_heading_policy_rejects_unknown_heading" .claude/skills/create-issue/scripts/tests/test_heading_policy.py
            exit_code: 1
            category: expected_baseline_fail
            scope_class: baseline_fail_expected
            confidence: high
            evidence:
              stdout_excerpt: ''
              stderr_excerpt: ''
            decision: go
          - ac: AC4
            command: $ uv run pytest .claude/skills/create-issue/scripts/tests/
            exit_code: 0
            category: regression_gate
            scope_class: regression_gate
            confidence: high
            evidence:
              stdout_excerpt: ''
              stderr_excerpt: ''
            decision: go
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
          conditions:
            docs_product_requires_spec_evidence:
              status: n/a
              evidence: []
            tasks_md_not_direct_source:
              status: n/a
              evidence: []
            specify_not_canonical:
              status: n/a
              evidence: []
            diff_first_rationale_present:
              status: n/a
              evidence: []
            generated_task_trace_present:
              status: n/a
              evidence: []
            task_dependencies_materialized:
              status: n/a
              evidence: []
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
      - Current Validated Scope と In Scope の語彙差は non-blocking(checker warning のみ)
  4. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 完了。owner comment の指摘を本文へ反映し、review / contract gate を再通過しました。

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: https://github.com/squne121/loop-protocol/issues/671#issuecomment-4636232527
        generated_at: '2026-06-05T22:57:01Z'
        body_sha256: e768b985ff4331576d7115f6d21dd75c9d2aacc6aca286528ffcb51f7c72b922
      metadata:
        title_prefix_ready: true
        phase_label_ready: true
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: '2026-06-05T22:58:03Z'
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues: []
      note_only_observations: []
  5. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-06-05T23:21:30Z)

    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/675"
      head_sha: "76667cf19ab4c9a531b98f8b187e596cff567b77"
      issue_number: 671
      termination_reason: approved
      iteration: 1
      required_auto_actions: []
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues: []
      note_only_observations: []
  6. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-06-05T23:39:44Z)

    POST_MERGE_CLEANUP_REPORT_V1:
      status: partial
      generated_at: 2026-06-05T23:39:44Z
      generated_by: post-merge-cleanup-worker
      human_review_required: false
      cleaned_branches:
        - worktree-issue-671-heading-policy-near-equivalence
      cleaned_worktrees:
        - /home/squne/projects/LOOP_PROTOCOL/.claude/worktrees/issue-671-heading-policy-near-equivalence
      unresolved_cleanup_items:
        - "root worktree に untracked が残存: .antigravitycli/, .claude/investigation/, .codex/skills, .specify/templates/overrides/, artifacts/"
        - "worktree-issue-606-gh-api-comment-body-patch-mutation は remote gone だが linked issue #606 が OPEN のため keep"
        - "worktree-issue-647-issue-refinement-loop-fail-closed-overri は remote gone だが linked issue #647 が OPEN かつ worktree に差分ありのため keep"
      parent_issue_status:
        parent_issue_number: 646
        all_children_closed: false
        recommended_action: keep_open
      superseded_prs: []
      follow_up_issue_requests: []
      stash_restored: n/a
      stash_entry_ref: null
      warnings:
        - "git branch -d は HEAD 未到達 warning を出したが、PR #675 merge 後に remote head なしを確認済み"
      errors: []
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: post-merge-cleanup
      follow_up_issues:
        - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/675:review-comment-4636356586"
          status: created
          issue:
            number: 678
            url: "https://github.com/squne121/loop-protocol/issues/678"
          reason: null
      note_only_observations: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ai-opsenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions