Skip to content

実装: Task Context 分類器の occurrence 所有範囲の契約を regression test で固定する #2866

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Task Context 分類器の occurrence 所有範囲(1 つの文字範囲は 1 つの occurrence にのみ属する)の契約を、既存 test_classifier.py の範囲で regression test として固定し、種別間の重複認識による wrong-target 判定を防ぐ"
change_kind: code
dedupe_key: "task-context-classifier:occurrence-ownership-regression:v1"

Parent Issue

なし(単独改善)

Parent Goal Ref

Current Validated Scope

  • .claude/hooks/task_context/classifier.py の _find_occurrences(URL / owner/repo#N / bare #N / 隣接 prefix の正規表現を個別に走査する関数)の occurrence 所有範囲のみを対象とする
  • tests/task-context/test_classifier.py に parametrize 済み regression test を追加する
  • 重複認識が実際に見つかった組合せだけを classifier.py で最小修正する

Remaining Parent Gaps

なし

Background

Outcome

tests/task-context/test_classifier.py に追加した parametrize 済み regression test が PASS し、occurrence 種別(URL / owner/repo#N / bare / 隣接 prefix)の全組合せで 1 つの文字範囲が 1 つの occurrence にのみ属すること、および needs_current_repo_resolution と classify の判定が一致することが固定された状態にする。重複認識が見つかった組合せがあれば、その分だけ .claude/hooks/task_context/classifier.py を最小修正する。

Runtime Verification Applicability

decision: immediate
reason: Allowed Paths の .claude/hooks/task_context/classifier.py は hook handler logic であり、#2850 と同様に docs/dev/extension-surface-runtime-policy.yaml の hook-lifecycle-matcher-or-handler-change(default_decision: immediate、verification_profile: hook-chain-runtime-smoke)に該当する。免除条件は満たさない。
applicable_acs: [AC7]
execution_environment: current-head LOOP_PROTOCOL worktree、current Claude Code runtime、run-scoped isolated LOOP_TASK_CONTEXT_STATE_ROOT。canonical production Task Context DB へ synthetic fixture を作らない。既存 narrow adapter scripts/task-context/verify_active_task_prompt_auto_rebind.py を --leaf ordinary-prompt-rebind で実行するだけとし、新しい harness・runner・恒久 runtime gate は追加しない。
skip_conditions: current Claude executable / required Herdr runtime が利用不能、または leaf が inconclusive の場合は exit 77 + SKIP: で停止し、AC7 を PASS 扱いしない。
fallback_policy: unit test の PASS を AC7 の代替にしない。AC7 は変更後の分類器が実 hook chain で退行なく動作することの確認であり、分類の意味は AC1〜AC5 の決定論的テストが担う。
artifact_requirements: 既存 adapter が出力する bounded な leaf evidence(current-head identity、Claude Code 版、leaf result)を PR 本文に要約する。raw prompt 全文・raw transcript・secret は記載しない。新しい artifact 形式は追加しない。
runtime_assertion_bindings:

  • profile: hook-chain-runtime-smoke
    assertion: all_matching_hooks_observed
    ac: AC7
  • profile: hook-chain-runtime-smoke
    assertion: sibling_side_effect_inventory_complete
    ac: AC7

In Scope

  • occurrence 種別間の全組合せ(URL / owner/repo#N / bare #N / 隣接 prefix。外側 span の内側を別種別が再認識しないか)を parametrize の regression test で固定する。代表入力は組合せごとに少なくとも 1 件とする(例: URL span 内の issue#12 形、URL span 内の bare #N、owner/repo#N span 内の bare #N、owner/my-issue#12)
  • 各 case で classify の kind / target 数と、span 内側の重複 occurrence が現在 repo の別参照として現れないことを assert する
  • needs_current_repo_resolution と classify の判定が、全 case で一致することを固定する
  • テストで重複認識が見つかった組合せだけ、classifier.py を最小修正する(走査済み span を除外する等。新 framework・新 dependency は追加しない)
  • 既存の test_classifier.py の既存 test の意味論は変更しない。テストは pytest 標準機能と既存 import(classifier)で書く

Out of Scope

Acceptance Criteria

  • AC1: URL span の内側にある隣接 prefix 形(issue#12 等)と bare #N が、別 occurrence として認識されない(URL 1 件のみが target になる)ことが parametrize test で固定されている
  • AC2: owner/repo#N span の内側にある bare #N と隣接 prefix 形(owner/my-issue#12 等)が、現在 repo の別参照として認識されない(AMBIGUOUS にならない)ことが parametrize test で固定されている
  • AC3: 隣接 prefix 形(Issue#12)と bare #N が同じ #N を二重に認識しない(同一範囲が 1 occurrence のみ)ことが parametrize test で固定されている
  • AC4: 全 occurrence 種別の組合せ case で、needs_current_repo_resolution の結果と classify が current repo 解決を要する判定とが一致することが固定されている
  • AC5: 上記 test で重複が検出された組合せがあれば classifier.py が最小修正され、変更は Allowed Paths の 2 ファイルに閉じる(既存 test の expectation は変更しない)
  • AC6: tests/task-context/ 全体が退行なく PASS する
  • AC7: 既存 narrow adapter の ordinary-prompt-rebind leaf が current head で PASS する(exit 0。exit 77 / SKIP: は PASS 扱いにしない)。
  • AC8: pnpm typecheck / pnpm lint / pnpm test / pnpm build と uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py が PASS する

Verification Commands

# AC1
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_classifier.py::test_given_url_span_when_scanned_then_inner_prefix_and_bare_not_recognized
# AC2
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_classifier.py::test_given_owner_repo_span_when_scanned_then_inner_bare_and_prefix_not_recognized
# AC3
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_classifier.py::test_given_adjacent_prefix_when_scanned_then_hash_owned_by_single_occurrence
# AC4
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_classifier.py::test_given_occurrence_combinations_when_checked_then_resolution_need_matches_classify
# AC5
$ git diff --name-only origin/main
# AC6
$ uv run --locked pytest tests/task-context/ -q
# AC7
# preflight-scope: runtime_only
$ uv run --locked python3 scripts/task-context/verify_active_task_prompt_auto_rebind.py --leaf ordinary-prompt-rebind
# AC8
$ pnpm typecheck
# AC8
$ pnpm lint
# AC8
$ pnpm test
# AC8
$ pnpm build
# AC8
$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py

Allowed Paths

  • .claude/hooks/task_context/classifier.py
  • tests/task-context/test_classifier.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 既存 test の expectation の意味論を変更しなければ AC6 を満たせないと判明した場合(推測で改変せず、Issue comment に矛盾を記録して停止する。実装: 再発防止: 既存テスト無変更宣言と矛盾する新規 AC を refinement 段階で検出する #2862 の範囲)

Required Skills

  • Python 3 / re(lookbehind / 走査済み span の除外)
  • pytest(parametrize)

Required Design References

  • docs/dev/task-context.md
  • docs/dev/extension-surface-runtime-policy.yaml

Delivery Rule

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Oct 1, 2026
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

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions