Skip to content

test: リファクタリング Phase 1 — テスト安全網の構築 (D-1) - #35

Merged
MRyutaro merged 2 commits into
mainfrom
refactor/phase1-tests
Jun 14, 2026
Merged

MRyutaro merged 2 commits into
mainfrom
refactor/phase1-tests

Conversation

@MRyutaro

Copy link
Copy Markdown
Owner

概要

docs/prompts/refactor-instructions.md の Phase 1(安全網の構築) を実施。
チェックポイント保存・復元という壊れると致命的な機能にテストが1つも無い状態(D-1)を解消する。

プロダクションコードは一切変更していない。 追加したのはテスト・dev依存(pytest)・CI のみ。現行挙動をそのまま固定している。

追加したテスト(40件、全パス)

ファイル 対象
test_find_input_vars.py 単純参照 / AugAssign / 関数内ローカル / global宣言 / プリミティブ除外 / UDF再帰
test_find_output_vars.py 作成・削除・アンダースコア除外
test_id_graph.py construct / structure / root equals、ネスト・共有参照・循環参照・None
test_object_hash.py プリミティブ / numpy ハッシュ、インプレース変更 vs 上書きの判別
test_graph.py バージョン採番、エッジ接続、update_graph、削除フラグ
test_optimizer.py OptimizerExact.select_vss の「サイズ極大→再計算」「実行時間極大→マイグレート」2ケース
test_checkpoint_file.py ビルダー set/get
test_migrate_resume.py migrate→resume ラウンドトリップ + 異常系(破損ファイル)
test_integration.py record_event→checkpoint→load_checkpoint(実IPythonシェル、Jupyter不要)

重要ポイント

  • D-2 の現行バグを異常系テストで明示的に固定。 破損した変数グループを読んでも例外を出さず、かつ「ces_to_recompute への再計算追加が破棄される」現行の誤挙動を assert ces_to_recompute == set() でピン留めし、「Phase 4 で反転する」とコメント済み。
  • __skip_record のテストは指示書どおり Phase 4 に保留(カーネルのインスタンス化が重く private name-mangling のため)。

変更ファイル

  • tests/ 一式(新規)
  • pyproject.toml — pytest を dev 依存に追加、[tool.pytest.ini_options] 設定
  • uv.lock — pytest 追加に伴う更新
  • .github/workflows/test.yml — pytest 実行ジョブを新規追加(既存ワークフローは不変)

検証結果

コマンド baseline 本PR
uv run pytest 0(存在せず) 40 passed
uv run black --check elastic_kernel elastic_notebook tests ✅ ✅
import スモーク(kernel / notebook) ✅ ✅
uv run mypy elastic_kernel elastic_notebook 29 29(不変)

挙動差分

  • 意図して変えた挙動: なし(Phase 1 はテスト追加のみ)
  • テストで固定した既存挙動: 上記すべて。D-2 は既知バグとして現行挙動のまま固定。

Stop-And-Ask 該当事項なし。

🤖 Generated with Claude Code

MRyutaro and others added 2 commits June 14, 2026 22:43
プロダクションコードは変更せず、現行挙動を固定するテストを追加:
- find_input_vars / find_created_deleted_vars
- id_graph (construct/structure/root equals, 共有・循環参照)
- object_hash / compare_fingerprint (inplace vs 上書き, numpy)
- DependencyGraph + update_graph
- OptimizerExact.select_vss (migrate/recompute の2ケース)
- CheckpointFile ビルダー
- migrate -> resume ラウンドトリップ + 異常系(破損ファイル)
  ※ 異常系は D-2 の現行バグ挙動を明示的に固定(Phase 4 で反転)
- 統合テスト: record_event -> checkpoint -> load_checkpoint
pytest を dev 依存に追加、[tool.pytest.ini_options] を設定。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
既存ワークフローには手を加えず、push/PRでテストを走らせるジョブを新規追加。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant