Skip to content

Issue #54: 重複full-hanchan executionをtest-onlyで削減する - #55

Merged
lisbun merged 1 commit into
mainfrom
claude/issue-54-reduce-duplicate-hanchan-sox3ik
Aug 29, 2026
Merged

lisbun merged 1 commit into
mainfrom
claude/issue-54-reduce-duplicate-hanchan-sox3ik

Conversation

@lisbun

@lisbun lisbun commented Aug 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Profilingで確認された重複full-hanchan executionを、coverageを維持したままtest-onlyで削減する(Closes #54)。production codeの変更なし。

実装前レビュー(#54のコメント)の具体案をそのまま採用した。

1. tests/test_driver_delivery.py

BackwardCompatibilityTest.test_on_delivery_none_matches_pre_existing_behavior が実行していた2回のfull hanchanを、既存 _match_at_position() を使ったdeterministic terminal position(West 4, dealer NORTH)からの短い実行へ置き換えた。

  • on_delivery 引数省略
  • explicit on_delivery=None
  • on_delivery=recorded.extend

の3 pathについて、completed resultとmatch historyが一致することを確認し、callback pathでは recorded が空でないことも維持している。

2. tests/test_round_completion.py

RoundCompletionProjectionTest.setUpClass と MatchCompletionProjectionTest.setUpClass が独立に実行していた同じ _play_deterministic_hanchan() を、functools.cache でラップしたmodule-local helper _deterministic_completed_match() が返す単一のimmutable CompletedMatch で共有した。mutableな MatchState は共有していない(CompletedMatch は @dataclass(frozen=True) で、history も tuple[CompletedRound, ...])。既存のprojection assertions自体は変更していない。

3. tests/test_driver.py

DriverResumeAndEndToEndTest.setUpClass の最初のfull hanchan(from_awaiting_round / first_result)は、genuine multi-round E2E ownerとしてそのまま残した。2本目のfull hanchan(start_round() 後からの実行)は削除し、test_same_seed_selectors_and_resume_point_produce_same_result 側でdeterministic terminal position(West 4, dealer NORTH)から、

  1. AWAITING_ROUNDからrun
  2. 同じseedで start_round() 後からresume

の2つの短い経路を作り、completed result equalityとhistory equalityを確認する形にした。test-only helper _match_at_position() を追加し、RoundPosition / Wind をimportした。

明示的に変更しないもの

test_round_evidence_completion.DriverDeliveryTest.test_a_full_hanchan_delivers_each_completed_round_exactly_once は今回変更していない。round-evidence deliveryのexactly once / order / timing / multi-round integrationの明示的なfull-hanchan ownerとして維持する。

Execution shape

module before after
test_driver_delivery 2 full hanchan 0 full hanchan(3 terminal-round runsへ)
test_round_completion 2 full hanchan 1 shared full hanchan
test_driver 2 full hanchan 1 genuine multi-round full hanchan(+2 terminal-round runs)
合計 6 2

4 duplicate full-hanchan executionsを削減した。wall-clockの固定閾値はacceptance criteriaにしていない(runner varianceのため)。

Preserved contract owners

  • genuine multi-round run_hanchan() completion: test_driver.DriverResumeAndEndToEndTest.test_completes_a_deterministic_multi_round_hanchan(setUpClassのfull hanchanをそのまま使用)
  • resume-from-active-round determinism: test_driver.DriverResumeAndEndToEndTest.test_same_seed_selectors_and_resume_point_produce_same_result(terminal positionからの短い比較へ変更、contractは維持)
  • on_delivery=None backward compatibility: test_driver_delivery.BackwardCompatibilityTest.test_on_delivery_none_matches_pre_existing_behavior(terminal positionからの短い比較へ変更、contractは維持)
  • RoundCompletionFact / MatchCompletionFact projection from a real completed match/history: test_round_completion.RoundCompletionProjectionTest / MatchCompletionProjectionTest(共有fixtureへ変更、assertion自体は無変更)
  • full-hanchan round-evidence delivery exactly once (order/timing込み): test_round_evidence_completion.DriverDeliveryTest.test_a_full_hanchan_delivers_each_completed_round_exactly_once(無変更)

Verification

ローカル環境にPython 3.14が無く(pyproject.toml は requires-python = ">=3.14,<3.15" で、production codeがPEP 758のunparenthesized except構文とPEP 649のdeferred annotation評価に依存しているため、Python 3.11–3.13ではimportできない)、focused testの実行自体はローカルで完了できなかった。代わりに次を実施した。

  • 変更した3ファイルの構文チェック(py_compile)
  • ruff format --check . / ruff check .(全体、pass)
  • 各変更の手動review(CompletedMatch/CompletedRoundが@dataclass(frozen=True)でtuple historyを持つことをsource側で確認、run_hanchanのon_delivery省略時デフォルトがNoneであることをsource側で確認、既存の_match_at_position()/terminal position patternが同modules内の既存testで確立済みであることを確認)

GitHub Actions full suite(python -m unittest discover -s tests -v --durations 30、実際のPython 3.14.7環境)で実測した。このPRのCIは green(1449 tests, OK)。

Before(現在のmain, 16b5949, run 76の実測値)

  • 1449 tests / 149.784s
  • Slowest tests(>1s):
    • 35.435s test_driver_delivery.BackwardCompatibilityTest.test_on_delivery_none_matches_pre_existing_behavior
    • 17.886s test_round_evidence_completion.DriverDeliveryTest.test_a_full_hanchan_delivers_each_completed_round_exactly_once
    • 2.954s test_round_evidence_completion.DriverDeliveryTest.test_the_same_seed_and_selectors_yield_the_same_delivered_values
    • 2.938s test_round_evidence_completion.BackwardCompatibilityTest.test_the_new_callback_changes_no_existing_observable_behavior
    • 2.898s test_round_evidence_completion.BackwardCompatibilityTest.test_without_any_callback_the_result_is_unchanged
    • 1.467s test_round_evidence_completion.DriverDeliveryTest.test_viewer_order_is_deterministic_for_every_delivery
  • setUpClassの隠れたcost(--durationsには現れない、#54本文の実測より):
    • test_driver.DriverResumeAndEndToEndTest.setUpClass ~36.9s(2 full hanchan)
    • test_round_completion.MatchCompletionProjectionTest.setUpClass ~18.35s
    • test_round_completion.RoundCompletionProjectionTest.setUpClass ~18.28s(2クラス合計 ~36.6s、独立な2 full hanchan)

After(このPR, 757f68c, run 77の実測値)

  • 1449 tests / 84.886s(-64.898s, ローカルでの重複full-hanchan除去による約43%の削減。test countは無変更 = test削減が目的ではないことを確認)
  • Slowest tests(>1s):
    • 18.503s test_round_evidence_completion.DriverDeliveryTest.test_a_full_hanchan_delivers_each_completed_round_exactly_once(無変更、明示的owner)
    • 3.166s test_driver.DriverResumeAndEndToEndTest.test_same_seed_selectors_and_resume_point_produce_same_result(新規に可視化。旧2本目full hanchanのsetUpClass隠れcostが、terminal positionからの2つの短いrunとして--durationsに直接現れる形へ変わった)
    • 3.075s / 3.047s / 3.036s test_round_evidence_completion系(無変更)
    • 1.519s test_round_evidence_completion.DriverDeliveryTest.test_viewer_order_is_deterministic_for_every_delivery(無変更)
    • test_on_delivery_none_matches_pre_existing_behavior は上位30件から完全に消えた(旧35.435s → 0.122s未満)
  • setUpClassの残存cost:
    • test_driver.DriverResumeAndEndToEndTest.setUpClass: ~36.9s のまま残存(genuine multi-round E2E ownerとして意図的に維持)
    • test_round_completion: 2クラスで1回のfull hanchan(~18.3s相当)を共有するため、独立2回実行分の隠れcostのうち約半分を除去

self-reviewでblockingな問題は見つからなかったため、Ready for reviewへ進める。mergeはユーザーの明示的な承認を待つ。

test_driver_delivery.BackwardCompatibilityTest / test_round_completionの
setUpClass / test_driver.DriverResumeAndEndToEndTestで独立に実行していた
full-hanchanを、既存の共有可能なfixture境界とdeterministic terminal
position(West 4, dealer NORTH)へ置き換え、6本のfull-hanchan executionを
2本(round_completionの共有1半荘 + driverのgenuine multi-round E2E owner
1半荘)へ削減する。production codeの変更はなし。

- test_driver_delivery: on_delivery省略/explicit None/callbackの3経路を
  full-hanchan 2本から短いterminal-round run 3本の比較へ置き換え
- test_round_completion: RoundCompletionProjectionTestとMatchCompletion
  ProjectionTestが独立に実行していた_play_deterministic_hanchan()を、
  functools.cacheでラップしたmodule-local helperが返す単一のimmutable
  CompletedMatchで共有する(mutableなMatchStateは共有しない)
- test_driver: genuine multi-round E2E ownerをsetUpClassに1本残し、
  resume-from-active-round semanticsはterminal positionからの短い
  AWAITING_ROUND run / start_round()後resumeの比較で独立に確認する

test_round_evidence_completion.DriverDeliveryTestのfull-hanchan
exactly-once ownerは今回変更していない。
@lisbun
lisbun marked this pull request as ready for review August 29, 2026 13:41

@lisbun lisbun 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.

Semantic review

Blocking findings: none.

Issue #54 のscope / acceptance criteria と3ファイルのdiffを照合しました。

  • test_driver_delivery: omitted on_delivery / explicit None / callback の3 pathを同じterminal fixtureで比較しており、backward-compatibility contractを維持しつつfull-hanchan重複を除去できています。progress / ordering / failure semanticsは同moduleのfocused testsが引き続き所有しています。
  • test_round_completion: cache対象はimmutable CompletedMatchのみで、mutable MatchStateを共有していません。既存projection assertionsも維持されています。
  • test_driver: genuine multi-round E2Eを1本残し、resume-from-active-round equivalenceは同一seed / 同一terminal positionのAWAITING_ROUND vs ROUND_IN_PROGRESSで独立に維持されています。
  • test_round_evidence_completion のfull-hanchan exactly-once / order / timing ownerは未変更です。
  • production code変更なし、test count 1449も不変です。

CI run #77も確認しました。CPython 3.14.7、ruff format/check pass、full suite 1449 tests / 84.886s / OK。直接のruntime evidenceもIssueの狙いと一致しています。

実測では immediate baseline 149.784s → 84.886s(-64.898s、約43.3%)。hosted runner varianceはあるため絶対値だけをKPIにはしませんが、full-hanchan execution shapeが6→2へ構造的に減っていることと、旧35.435sのtest_on_delivery_none_matches_pre_existing_behaviorがtop 30から消えたことが強い根拠です。

結論: merge可能です。

@lisbun
lisbun merged commit b85fb02 into main Aug 29, 2026
1 check passed
@lisbun
lisbun deleted the claude/issue-54-reduce-duplicate-hanchan-sox3ik branch August 29, 2026 13:44
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.

Reduce duplicated full-hanchan execution in integration tests

2 participants