Skip to content

refactor(src): execution_report を廃止し write_result_to_comment(stdout → PR コメント)に置き換え#82

Merged
HappyOnigiri merged 9 commits intomainfrom
refactor/replace-execution-report-with-write-result-to-comment
Mar 13, 2026
Merged

refactor(src): execution_report を廃止し write_result_to_comment(stdout → PR コメント)に置き換え#82
HappyOnigiri merged 9 commits intomainfrom
refactor/replace-execution-report-with-write-result-to-comment

Conversation

@HappyOnigiri
Copy link
Owner

@HappyOnigiri HappyOnigiri commented Mar 13, 2026

概要 / Summary

execution_report(Claude によるファイル書き込みレポート)を廃止し、Claude の stdout を直接 PR ステータスコメントに書き出す write_result_to_comment 機能に置き換える。

変更内容 / Changes

  • src/report.py を削除し、src/result_report.py を新規作成(format_phase_result_block, merge_result_log_body, build_phase_result_entry
  • src/config.py: execution_report: false(デフォルト)→ write_result_to_comment: true(デフォルト)に差し替え
  • src/claude_runner.py: report_path/report_enabled パラメータを削除、戻り値を strtuple[str, str](commits, stdout)に変更
  • src/state_manager.py: report_body/REPORT_SECTION_*result_log_body/RESULT_LOG_SECTION_* に置き換え、折りたたみ見出しを「実行レポート」→「実行ログ」に変更
  • src/auto_fixer.py: PRContext から execution_report_enabled/reports_dir を削除し write_result_to_comment を追加、各フェーズで stdout を result_blocks に蓄積して upsert_state_comment(result_log_body=...) で保存、レビュー修正フェーズのみ対象コメント URL を付与
  • .refix.yaml.sample / README.md / README.ja.md: 設定キーの説明を更新

テスト / Testing

  • make ci 通過済み(lint + 全 206 テスト)

関連 issues / Related issues

なし

Summary by CodeRabbit

  • 新機能

    • プルリクの状態コメントにClaudeの標準出力を「実行ログ」セクションとして折りたたみ形式で自動記録するようになりました(既定で有効)。各フェーズのstdoutが該当セクションに埋め込まれます。
  • ドキュメント

    • 設定オプション名を execution_report から write_result_to_comment に変更し、既定値を false → true に更新。説明を標準出力を状態コメントへ書き込む挙動に合わせて修正しました。

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6bcbf7a1-c94a-49bd-8744-a71d7598b2f4

📥 Commits

Reviewing files that changed from the base of the PR and between c01d8a3 and 4158629.

📒 Files selected for processing (1)
  • src/auto_fixer.py

📝 Walkthrough

Walkthrough

execution_report フラグを write_result_to_comment に置換し、ファイルベースの報告フロー(src/report.py)を廃止して PR コメント内の結果ログ(src/result_report.py)へ移行。Claude 実行は (new_commits, stdout) のタプルを返すように変更。

Changes

Cohort / File(s) Summary
設定とドキュメント
\.refix.yaml.sample, README.ja.md, README.md, src/config.py
execution_reportwrite_result_to_comment にリネームし、説明とスキーマを更新。デフォルトを falsetrue に変更。
コア処理
src/auto_fixer.py
報告関連名を report_*/report_blocks から result_*/result_blocks に置換。PRContext フィールド名と多数の関数シグネチャを execution_report_enabledwrite_result_to_comment に更新。報告ファイル処理を削除し、build_phase_result_entry/merge_result_log_body を利用する流れへ変更。
ランナー
src/claude_runner.py
run_claude_prompt のシグネチャを変更し戻り値を strtuple[new_commits, stdout] に。report_path/report_enabled と runtime-report 指示を削除し、プロンプト生成と出力処理を簡素化。
状態コメント管理
src/state_manager.py
report_bodyresult_log_bodyREPORT_SECTION_*RESULT_LOG_SECTION_* に改名。抜粋・剥離・トランケート等のロジックを結果ログ用に移行し、StateComment と upsert/load/render API を更新。
報告モジュール
src/report.py (削除), src/result_report.py (追加)
ファイルベース報告モジュールを削除し、フェーズ別 stdout を整形・マージする result_report を追加(タイムスタンプ、フェーズ見出し、コメント URL 埋め込み、マージ処理)。
テスト
tests/...
tests/test_auto_fixer.py, tests/test_claude_runner.py, tests/test_config.py, tests/test_state_manager.py, tests/test_result_report.py (追加), tests/test_report.py (削除)
run_claude_prompt のタプル返却に合わせたモックと期待値を更新。upsert_state_comment 呼び出しで result_log_body を検証するよう変更。旧 report 関連テストを削除し、result_report の単体テストを追加。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

refix:done

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR タイトルは、execution_report を廃止して write_result_to_comment に置き換えるという主要な変更内容を明確に表している。
Description check ✅ Passed PR 説明は、概要・変更内容・テスト・関連 issues の全セクションを含み、リポジトリのテンプレートに準拠している。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/replace-execution-report-with-write-result-to-comment
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@HappyOnigiri HappyOnigiri added the refix: running Refix is currently processing review fixes. label Mar 13, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/auto_fixer.py (1)

343-373: ⚠️ Potential issue | 🟠 Major

失敗した Claude 実行の出力が result log に残りません。

src/claude_runner.py:83-205 は失敗時も stdout / stderr を例外に保持していますが、ここでは成功時にしか result_blocks に追加していません。最初のフェーズで失敗すると result_blocks が空のままなので、state comment に何も残らず、今回追加した write_result_to_comment の主目的を満たせません。少なくとも ClaudeCommandFailedError / ClaudeUsageLimitErrorstdout / stderr からブロックを作ってから upsert_state_comment() する必要があります。

Also applies to: 456-488, 573-595, 734-766

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/auto_fixer.py` around lines 343 - 373, The CI-fix exception handler
currently doesn't persist failed Claude outputs into result_blocks, so when
run_claude_prompt (used in the ci-fix phase) raises (e.g.,
ClaudeCommandFailedError / ClaudeUsageLimitError) the stdout/stderr carried by
the exception are lost; update the except block around run_claude_prompt to
detect if the caught exception exposes stdout/stderr, create a phase result
block via build_phase_result_entry("ci-fix", stdout_or_stderr,
ctx.state_comment_timezone) and append it to result_blocks (merging with
load_state_comment as done now) before calling upsert_state_comment, and apply
the same change to the equivalent handlers for the other phases (the similar
try/except regions referenced at the other locations) so failed-run outputs are
always saved to the state comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/auto_fixer.py`:
- Around line 1140-1156: The upsert_state_comment failure is currently being
treated as a success path because state_saved isn't reliably updated on error;
initialize and keep state_saved = False before the write attempt, set
state_saved = True only inside the successful upsert_state_comment try block,
and in the except block explicitly leave it False (or set to False) so
downstream cacheability/CI-only flow (the code that decides skip/complete for
CI-only PRs) reads the correct failure state; update any subsequent cacheability
check that references state_saved to use this flag so failed writes won't be
treated as saved.

In `@src/result_report.py`:
- Around line 30-38: The current static triple-backtick fence in
result_report.py breaks the report when stdout_text contains ```; update the
stdout rendering to compute a fence string that does not appear in the output
(e.g., start with "`" and append backticks while the fence is found in
stdout_text/stripped_stdout), then use that dynamic fence variable instead of
the fixed "```" when building the lines list (refer to variables/fields fence,
stdout_text, stripped_stdout and the list construction around lines.extend that
adds the "<summary>stdout</summary>" block).

In `@src/state_manager.py`:
- Around line 211-232: The truncation currently slices raw characters in
_truncate_result_log_body_to_fit which can leave unclosed headings, <details>
blocks, or code fences created by the generator in result_report.py and breaks
strip_result_log_section()/extract_result_log_body(); change the logic to parse
result_log_body into its logical "phase" sections using the same
delimiters/structure that result_report.py emits (e.g., the "####" phase
headings plus their following <details> and fenced code blocks), then
iteratively drop entire trailing phases until the remaining joined phases plus
the state comment scaffold (computed via _build_state_comment_body) fit within
max_length, and finally append truncation_notice; ensure the parser guarantees
balanced tags/fences so returned text never contains partial/unclosed tags or
fences and handle the case where no full phase can be kept by returning "".

---

Outside diff comments:
In `@src/auto_fixer.py`:
- Around line 343-373: The CI-fix exception handler currently doesn't persist
failed Claude outputs into result_blocks, so when run_claude_prompt (used in the
ci-fix phase) raises (e.g., ClaudeCommandFailedError / ClaudeUsageLimitError)
the stdout/stderr carried by the exception are lost; update the except block
around run_claude_prompt to detect if the caught exception exposes
stdout/stderr, create a phase result block via
build_phase_result_entry("ci-fix", stdout_or_stderr, ctx.state_comment_timezone)
and append it to result_blocks (merging with load_state_comment as done now)
before calling upsert_state_comment, and apply the same change to the equivalent
handlers for the other phases (the similar try/except regions referenced at the
other locations) so failed-run outputs are always saved to the state comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 855552f3-3791-48c2-b768-441d75aec516

📥 Commits

Reviewing files that changed from the base of the PR and between 5f00234 and 4e19d39.

📒 Files selected for processing (15)
  • .refix.yaml.sample
  • README.ja.md
  • README.md
  • src/auto_fixer.py
  • src/claude_runner.py
  • src/config.py
  • src/report.py
  • src/result_report.py
  • src/state_manager.py
  • tests/test_auto_fixer.py
  • tests/test_claude_runner.py
  • tests/test_config.py
  • tests/test_report.py
  • tests/test_result_report.py
  • tests/test_state_manager.py
💤 Files with no reviewable changes (2)
  • tests/test_report.py
  • src/report.py

@HappyOnigiri
Copy link
Owner Author

HappyOnigiri commented Mar 13, 2026

🤖 Refix Status

対応済みレビュー一覧
Comment ID 処理日時
r3943106283 2026-03-13 19:56:53 JST
discussion_r2930404573 2026-03-13 19:56:54 JST
discussion_r2930404581 2026-03-13 19:56:54 JST
discussion_r2930404599 2026-03-13 19:56:55 JST
r3943233041 2026-03-13 20:11:41 JST
実行レポート

CI 修正

2026-03-13 11:00:00 UTC src/auto_fixer.py CI make ci diff の修正開始

CIの失敗原因: make ci がフォーマッタを実行すると src/auto_fixer.py に差分が生じる(行長超過による自動改行)。
対象箇所は4か所。これらをフォーマッタが期待する形式に手動で修正する。

2026-03-13 11:05:00 UTC src/auto_fixer.py CI修正完了

4箇所の行長超過(88文字超)をruffフォーマッタが期待する形式に整形してcommit & push完了。

  • build_phase_result_entry("ci-fix", ...) in _run_ci_fix_phase
  • build_phase_result_entry("merge-conflict-resolution", ...) in _run_merge_phase
  • merge_result_log_body(...) in _run_merge_phase
  • upsert_state_comment(...) in _run_merge_phase

make ci が全テスト SUCCESS で差分なしを確認済み。

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/auto_fixer.py (1)

1167-1187: ⚠️ Potential issue | 🟠 Major

_cacheable 判定に state_saved を含めてください。

Line 1168-1180 で保存失敗時に state_saved=False になるよう修正されていますが、Line 1229-1234 の _cacheablestate_saved を見ていないため、結果ログ保存失敗でも cacheable 扱いになる可能性が残っています。

修正案
-        _cacheable = (
-            not dry_run
-            and not bool(active_rate_limit)
-            and not bool(active_review_failed)
-            and not _ci_grace
-        )
+        _cacheable = (
+            not dry_run
+            and state_saved
+            and not bool(active_rate_limit)
+            and not bool(active_review_failed)
+            and not _ci_grace
+        )

Also applies to: 1206-1214, 1229-1234

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/auto_fixer.py` around lines 1167 - 1187, The _cacheable determination
must consider whether the state result log was actually saved; update the code
paths that compute the _cacheable flag (the block that currently sets _cacheable
around the later section and the similar blocks near where state_saved is set)
to include state_saved (i.e., make _cacheable false when state_saved is False).
Locate the state save logic that sets state_saved (the try/except using
load_state_comment and upsert_state_comment) and the subsequent _cacheable
computation, and change the boolean expression for _cacheable to AND with
state_saved (or explicitly set _cacheable = False when state_saved is False) so
failed result-log saves never produce a cacheable result; apply the same change
to the other similar occurrence mentioned (the blocks around lines 1206-1214 and
1229-1234).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/auto_fixer.py`:
- Around line 1167-1187: The _cacheable determination must consider whether the
state result log was actually saved; update the code paths that compute the
_cacheable flag (the block that currently sets _cacheable around the later
section and the similar blocks near where state_saved is set) to include
state_saved (i.e., make _cacheable false when state_saved is False). Locate the
state save logic that sets state_saved (the try/except using load_state_comment
and upsert_state_comment) and the subsequent _cacheable computation, and change
the boolean expression for _cacheable to AND with state_saved (or explicitly set
_cacheable = False when state_saved is False) so failed result-log saves never
produce a cacheable result; apply the same change to the other similar
occurrence mentioned (the blocks around lines 1206-1214 and 1229-1234).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ac6c1902-feff-4914-996f-940c89ec4f13

📥 Commits

Reviewing files that changed from the base of the PR and between c16d7e2 and c01d8a3.

📒 Files selected for processing (1)
  • src/auto_fixer.py

…lse ブロック)

結果ログ保存失敗時(state_saved=False)でも cacheable 扱いになる問題を修正。
@HappyOnigiri HappyOnigiri added refix: done Refix finished review checks/fixes for now. and removed refix: running Refix is currently processing review fixes. labels Mar 13, 2026
@HappyOnigiri HappyOnigiri merged commit 2bb3024 into main Mar 13, 2026
2 checks passed
@HappyOnigiri HappyOnigiri deleted the refactor/replace-execution-report-with-write-result-to-comment branch March 13, 2026 11:21
@HappyOnigiri HappyOnigiri added refix: auto-merge-requested Refix has requested auto-merge for this PR. refix: merged PR has been merged after Refix auto-merge. and removed refix: auto-merge-requested Refix has requested auto-merge for this PR. labels Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refix: done Refix finished review checks/fixes for now. refix: merged PR has been merged after Refix auto-merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant