Skip to content

プロジェクトにPython運用基盤を整備 #39

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "プロジェクトに Python 開発依存管理基盤 (pyproject.toml + uv.lock) と CI 実行 job を整備し、必須検証コマンドに Python テストを組み込む"
change_kind: infrastructure

Parent Issue

なし(単独改善)

Parent Goal Ref

Current Validated Scope

  • 既存 .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py (pyyaml 必須) を uv run pytest <path> で再現実行できる依存管理を、pyproject.toml + uv.lock で実現
  • CI (.github/workflows/ci.yml) に python-test job を pnpm 系 4 job と並列で追加
  • .claude/rules/project-constitution.md の必須検証コマンドに Python テスト実行を組み込み

Remaining Parent Gaps

なし

Outcome

pyproject.toml + uv.lock で Python 開発依存 (pytest, pyyaml) が宣言され、uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py がローカルと CI の両方で exit code 0 で完了する。.github/workflows/ci.yml に python-test job が追加されて pnpm 系 4 job と並列実行される。.claude/rules/project-constitution.md の「必須検証」セクションに Python テストコマンドが追記される。

In Scope

  • pyproject.toml 新規作成([project] + [dependency-groups].dev に pytest と pyyaml)
  • uv lock 実行と uv.lock コミット
  • .github/workflows/ci.yml に python-test job 追加(astral-sh/setup-uv@v5 + uv run pytest)
  • .claude/rules/project-constitution.md の必須検証セクションへの Python テストコマンド追記
  • .gitignore に Python runtime artifacts (.venv/, __pycache__/, .pytest_cache/) 追加(既存確認の上、不足なら追記)

Out of Scope

  • 個別 stdlib-only Python script (edit-issue / open-pr / post-merge-cleanup / create-issue 配下) への PEP 723 inline metadata 導入
  • pre-commit hook (mypy / black / ruff) 導入
  • docs/dev/github-ops.md の uv run python3 記載は既存維持(補足追記のみ)
  • 既存 Python script 群のリファクタリング

Acceptance Criteria

  • AC1: pyproject.toml が repo ルートに存在し、[dependency-groups].dev セクションに pytest と pyyaml が含まれる
  • AC2: uv.lock が repo ルートに存在しコミットされている
  • AC3: uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py がローカルで exit code 0 で完了する
  • AC4: .github/workflows/ci.yml に python-test job が存在し、astral-sh/setup-uv アクションと uv run pytest ステップを含む
  • AC5: CI 上で python-test job が success ステータスになる
  • AC6: .claude/rules/project-constitution.md の必須検証セクションに uv run pytest コマンドが追記されている
  • AC7: .gitignore に .venv/ / __pycache__/ / .pytest_cache/ が含まれる
  • AC8: 既存 pnpm 系 4 job (typecheck / lint / test / build) は変更なく pass する

Verification Commands

# AC1
grep -E "pytest|pyyaml" pyproject.toml

# AC2
test -f uv.lock

# AC3
uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py

# AC4
grep -E "python-test|setup-uv" .github/workflows/ci.yml

# AC5
gh run list --workflow=ci.yml --branch=<branch> --limit=1 --json conclusion --jq '.[0].conclusion'

# AC6
grep -E "uv run pytest" .claude/rules/project-constitution.md

# AC7
grep -E "\.venv|__pycache__|\.pytest_cache" .gitignore

# AC8
pnpm typecheck && pnpm lint && pnpm test && pnpm build

Allowed Paths

  • pyproject.toml
  • uv.lock
  • .github/workflows/ci.yml
  • .claude/rules/project-constitution.md
  • .gitignore

Stop Conditions

Required Skills

  • Python packaging (pyproject.toml, dependency-groups)
  • uv package manager (uv lock, uv run)
  • GitHub Actions (astral-sh/setup-uv@v5)
  • pytest

Notes for Reviewer

Activity

  1. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    you asked

    message time: 2026-05-19 23:39:51

    https://github.com/squne121/loop-protocol
    ● Bash(uv run --with pytest python -m pytest tests/test_model_routing.py::TestLoadModelRouti
    ng::test_invalid_yaml_raises_value_error -x 2>&1 | tail -25)
    ⎿  __________ TestLoadModelRouting.test_invalid_yaml_raises_value_error ___________

     self = <tests.test_model_routing.TestLoadModelRouting object at 0x7f67eb9dc3e0>
     … +19 lines (ctrl+o to expand)
    

    ● VC preflight 解析: 5 件の既存テスト失敗は pyyaml 未導入が原因(コードバグでなく env
    問題)。AC9 は実装者が依存解消(uv run --with pytest --with pyyaml か pyproject.toml
    追加)で対処可能 → GO with warning。
    上記の問題ってPEP6 ?いくつかでスクリプト本体にライブラリインポートを指定する書き方で解決できるのでは?
    それともプロジェクトに仮想環境を導入させたほうが適切か?


    chatgpt response

    論点は「一時的な実行依存として解くべきか」「プロジェクト依存として固定すべきか」です。まず該当リポジトリの構成と、uv/PEP 723 の仕様を確認して判断します。

    現行 main にはその Python テスト名が見えていないため、手元ブランチか未 push 差分の可能性が高いです。ただし原因判定自体は一般化できます。

    結論:PEP 6 ではなく、おそらく PEP 723 のことです。
    ただし、このケースでは PEP 723 だけで解決するのは不適切寄りです。

    PEP 6 は「Bug Fix Releases」の古いプロセス文書で、この話とは関係ありません。(Python Enhancement Proposals (PEPs))
    スクリプト本体に依存を書く仕組みは PEP 723 / Inline script metadata です。単一 Python スクリプトに dependencies や requires-python を埋め込めます。(Python Packaging)

    判断

    今回のコマンドはこれです。

    uv run --with pytest python -m pytest tests/test_model_routing.py::TestLoadModelRouting::test_invalid_yaml_raises_value_error -x

    この場合、uv が実行している入口は pytest です。
    つまり、仮に scripts/model_routing.py の先頭に PEP 723 メタデータを書いても、pytest 実行時に uv がそのスクリプトの依存を自動読取してくれるわけではありません。

    PEP 723 が効くのは、基本的にこういう実行です。

    uv run --script scripts/some_script.py

    または uv が対象スクリプトを直接実行する場合です。uv のドキュメントでも、インラインメタデータは「スクリプト自身の依存を宣言し、uv がそのスクリプト実行用環境を作る」用途として説明されています。(Astral Docs)

    今回の最小修正

    一時的な preflight なら、これでよいです。

    uv run --with pytest --with pyyaml python -m pytest tests/test_model_routing.py::TestLoadModelRouting::test_invalid_yaml_raises_value_error -x

    uv run --with は呼び出し単位で依存を追加できます。uv 公式ドキュメントでも、依存が必要なスクリプトに対して --with rich のように指定する例が示されています。(Astral Docs)

    ただし、これは 検証コマンドの局所修正であって、プロジェクトの再現性は弱いです。

    適切な修正方針

    このリポジトリは現行 main では package.json に Vite/Vitest/TypeScript 系の devDependencies が定義されており、Python テスト依存はまだプロジェクト依存として管理されていません。
    CI も pnpm install、pnpm test、pnpm build が中心で、Python/pytest/pyyaml のセットアップは見えません。

    したがって、Python テストをプロジェクト品質ゲートに含めるなら、pyproject.toml + uv.lock に寄せるべきです。

    推奨はこれです。

    uv init --bare
    uv add --dev pytest pyyaml
    uv lock

    または手書きなら概ねこうです。

    [project]
    name = "loop-protocol-tools"
    version = "0.0.0"
    requires-python = ">=3.12"
    dependencies = []
    
    [dependency-groups]
    dev = [
      "pytest",
      "pyyaml",
    ]

    uv は pyproject.toml の project.dependencies や dependency-groups をプロジェクト依存として扱えます。開発用依存は dependency-groups に置ける、という整理です。(Astral Docs)

    その上で実行はこうします。

    uv run pytest tests/test_model_routing.py

    CI に入れるなら、Node CI とは別 job で以下を追加します。

    python-test:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v4
        - uses: astral-sh/setup-uv@v5
        - run: uv run pytest

    使い分け

    選択肢 適用場面 今回の評価
    uv run --with pytest --with pyyaml ... 一時的な検証、エージェントの preflight 可。ただし暫定
    PEP 723 単体で配布・実行する scripts/foo.py pytest 実行には不十分
    pyproject.toml + uv.lock テスト、CI、複数スクリプト、再現性が必要 最適
    手動 .venv 運用 人間が長期開発環境を固定したい場合 uv project で自動管理すれば十分

    実務判断

    今回の「5件の既存テスト失敗は pyyaml 未導入が原因」という判定自体は妥当です。
    ただし AC9 の対処を 「実装者が --with pyyaml を付ければよい」だけにするのは弱いです。

    より良い指示はこうです。

    Python-based model routing tests depend on PyYAML.
    Do not treat missing PyYAML as an implementation bug, but resolve it as project test dependency.
    
    Required fix:
    - Add pyproject.toml if absent.
    - Add pytest and pyyaml as dev/test dependencies.
    - Add uv.lock.
    - Update the verification command to `uv run pytest tests/test_model_routing.py`.
    - If Python tests are intended as CI gate, add a Python test job to GitHub Actions.
    

    PEP 723 は「単体スクリプトの自己完結性」には有効ですが、pytest で import されるライブラリ/テスト対象コードの依存管理には、プロジェクト依存として固定する方が正しいです。

  2. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    Issue 本文 全面リライト完了 (issue-refinement-loop iteration 1)

    変更理由

    issue-refinement-loop iteration 1 による全面リライト。

    元の本文(2 行)は .github/ISSUE_TEMPLATE/implementation.yml の必須セクションがすべて欠如しており、#issuecomment-4488974198 の実務判断(pyproject.toml + uv.lock + CI python-test job 追加)が永久仕様として反映されていなかった。

    変更セクション一覧

    セクション 変更内容
    ## Outcome 新規追加。具体的な完了状態(pyproject.toml / uv.lock / CI job / project-constitution.md 更新)を記述
    ## In Scope 新規追加。5 項目を列挙
    ## Out of Scope 新規追加。PEP 723 / pre-commit / リファクタリング等を明示除外
    ## Acceptance Criteria 新規追加。AC1-AC8 を - [ ] AC<N>: 形式で列挙
    ## Verification Commands 新規追加。AC1-AC8 と 1:1 対応する検証コマンドを列挙
    ## Allowed Paths 新規追加。5 ファイルを列挙
    ## Stop Conditions 新規追加。7 件を列挙
    ## Required Skills 新規追加。技術領域知識 4 件を列挙
    ## References 新規追加。コメント URL / 関連 Issue / SSOT を列挙

    Guard 結果サマリ

    • template_guard: pass (必須セクション 7/7 存在)
    • outcome_quality_guard: pass (NG パターンなし)
    • diff_threshold: pass (orig 3 行 → new 88 行、増加のため閾値対象外)
    • ac_vc_alignment: pass (AC 8 件 / VC # AC<N> 8 件 一致)

    バックアップ

    tmp/issue_39_backup_1779205328.md

  3. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop iteration 2: 必須 5 セクション追加 + References → Notes for Reviewer リネーム

    変更セクション一覧

    • 追加: ## Machine-Readable Contract(contract_schema_version: v1, issue_kind: implementation)
    • 追加: ## Parent Issue(なし / 単独改善)
    • 追加: ## Parent Goal Ref(Goal / 背景 / 関連を記載)
    • 追加: ## Current Validated Scope(検証済みスコープ 3 項目)
    • 追加: ## Remaining Parent Gaps(なし)
    • リネーム: ## References → ## Notes for Reviewer(内容は維持)

    変更理由

    implementation template の必須セクションが 5 つ欠如していたため追加。配置順は ## Outcome の前(本文先頭)。Issue #42 の単独改善パターンに準拠。

    Guard 結果

    • template_guard: pass
    • outcome_quality_guard: pass
    • diff_threshold: pass(89 行 → 118 行 / 増加のため閾値適用なし)
    • ac_vc_alignment: pass(AC 8 件 / VC 8 件)
  4. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-20)

    • iteration: 2
    • final verdict: approve
    • termination_reason: approved
    • 改善履歴:
      • iteration 1: 全面リライト。implementation template の 8 セクション (Outcome / In Scope / Out of Scope / AC / VC / Allowed Paths / Stop Conditions / Required Skills) を生成し、comment 4488974198 の実務判断 (pyproject.toml + uv.lock + python-test CI job + dev dependency-groups) を本文へ転写
      • iteration 2: 必須 5 セクション (Machine-Readable Contract / Parent Issue / Parent Goal Ref / Current Validated Scope / Remaining Parent Gaps) を Outcome 前に追加。## References → ## Notes for Reviewer にリネームしてテンプレ整合
    • 次アクション: issue-contract-review skill で着手前 preflight を実施 → implement-issue または impl-review-loop へ
    • 前提依存: Issue 実装: setup_check.py の serena MCP コマンド誤りと trustedFolders.json 破壊バグを修正 (PR #38 hotfix) #41 (setup_check.py hotfix) の merge を Stop Conditions に明記済み

    🤖 Generated with Claude Code

  5. added
    state/queued
    phase/implementation
    agent/implementer
    enhancement
    on May 19, 2026
  6. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-20)

    • Outcome: pyproject.toml + uv.lock で Python dev 依存 (pytest, pyyaml) を宣言し、uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py がローカルと CI で pass、.github/workflows/ci.yml に python-test job 追加、.claude/rules/project-constitution.md の必須検証を更新
    • Acceptance Criteria: AC1-AC8 (本文参照)
    • Verification Commands: 本文 ## Verification Commands 参照
    • Allowed Paths: pyproject.toml, uv.lock, .github/workflows/ci.yml, .claude/rules/project-constitution.md, .gitignore
    • Worktree: .claude/worktrees/issue-39-python-runtime
    • Branch: worktree-issue-39-python-runtime
    • VC preflight: baseline fail = 5 (AC1/AC2/AC4/AC6/AC7 missing as expected), 想定外 pass = 0, 実行不可 = 0
    • ラベル付与: state/queued, phase/implementation, agent/implementer, enhancement
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-20T00:00:00Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/39
      checks:
        template_compliance: pass
        state_label: pass
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 5
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
        ac_verifiability: pass
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "AC5 (gh run list) と AC8 (pnpm 系) は実装後に PR 上で検証する"
        - "Issue #41 (setup_check.py hotfix) が未 merge の場合は merge 後に着手 (本 Issue Stop Conditions 参照)"
  7. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-20T00:00:00Z)

  8. squne121 commented on May 19, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-05-20)

    次アクション: 人間がマージ判断 (PR #58 にて)。マージ後は post-merge-cleanup skill を起動推奨。

    PR 本文末尾に本セッション全体 (refinement-loop + contract-review + impl-review-loop) で観測した運用改善候補 6 件 (観測 A-F) を記載済み。

    🤖 Generated with Claude Code

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/implementationstate/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions