ホーム / Skills / 開発効率化 / Surgical Patch ピンポイント修正
開発効率化

Surgical Patch ピンポイント修正

Julius BrusseeApache-2.0Skill の言語: 英語
ライセンス確認済みスクリプトなし
デモ実行記録 · claude-opus-5-5 · 2026年10月
Bug: `paginate([1,2,3,4,5], page=2, size=2)` returns `[4, 5]` but should return `[3, 4]`. Page numbers are 1-based. The files are not in this workspace, so give me the fix as a diff and I will apply it. ```python # utils/pagination.py def paginate(items, page, size): """Return the items on a 1-based page.""" if size <= 0: raise ValueError("size must be positive") start = page * size end = start + size return items[start:end] def page_count(items, size): return (len(items) + size - 1) // size ``` ```python # tests/test_pagination.py from utils.pagination import paginate, page_count def test_page_count(): assert page_count([1, 2, 3, 4, 5], 2) == 3 ```
Skill: surgical-patch

The bug is in how the start index is calculated. start = page * size treats page as 0-based, so page 2 starts at index 4 and returns [4, 5]. For a 1-based page, the start index needs to be (page - 1) * size.

--- a/utils/pagination.py
+++ b/utils/pagination.py
@@ -2,7 +2,7 @@ def paginate(items, page, size):
     """Return the items on a 1-based page."""
     if size <= 0:
         raise ValueError("size must be positive")
-    start = page * size
+    start = (page - 1) * size
     end = start + size
     return items[start:end]
 
--- a/tests/test_pagination.py
+++ b/tests/test_pagination.py
@@ -3,2 +3,10 @@ from utils.pagination import paginate, page_count
 def test_page_count():
     assert page_count([1, 2, 3, 4, 5], 2) == 3
+
+
+def test_paginate_is_one_based():
+    items = [1, 2, 3, 4, 5]
+    assert paginate(items, page=1, size=2) == [1, 2]
+    assert paginate(items, page=2, size=2) == [3, 4]
+    assert paginate(items, page=3, size=2) == [5]
+    assert paginate(items, page=4, size=2) == []

The new test checks the case you reported (page 2), plus the first page, the partial last page, and a page past the end. I couldn't run it because the files aren't in this workspace. After you apply the diff, run pytest tests/test_pagination.py. The new test should fail on the old code and pass with the fix.

Something to consider: this diff only fixes the off-by-one. It still doesn't check that page is valid. Now that pages start at 1, page=0 gives start = -size, so it would return a slice taken from the end of the list instead of failing. If you want that rejected, add if page < 1: raise ValueError("page must be >= 1") next to the existing size check. I didn't include it because it changes behavior beyond the bug you reported.

Real run recorded with claude-code / claude-opus-5-5. Output is shown verbatim, unmodified.

できること

バグ修正や小さな動作変更のための作業ルールです。責任のある層だけを変更し、直ったことを示します。

仕組み

  1. 再現が簡単ならまず再現し、難しければ手に入る中で最も強い証拠を集めます。
  2. 症状から原因となる仕組みまでたどり、その層だけを変更します。
  3. 修正範囲の外で整理、名前の変更、新しい抽象化はせず、関係のない動作やユーザー自身の変更には触れません。
  4. タスクに必要な回帰テストだけを足し、それと影響の近いチェックを実行して、通ったら止まります。

向いている場面

既存のコードベースでのバグ修正で、レビュアーが小さくまとまった差分を望むとき。

知っておきたいこと

オープンソースプロジェクト Caveman に含まれる汎用的な作業パターンの一つです。指示文に Caveman のブランド色はなく、どのプロジェクトでも使えます。

補足とリスク

指示だけのファイルです。スクリプトはなく、ネットワーク接続もファイルの書き込みも行いません。 パッケージには LICENSE、NOTICE、agents/openai.yaml(Codex 用の表示名と既定プロンプト)も含まれます。