--- id: OPS_task_0_vscode_debugger_offbyone name: VS Code GUI 调试器抓 off-by-one bug category: OPS timeout_seconds: 1200 --- ## Prompt Background: `/tmp_workspace/pager/core.py::total_pages` returns an incorrect page count on certain boundary inputs (off-by-one). `pager/tests/test_pager.py` already covers both the evenly-divisible and non-evenly-divisible boundary cases. A `Debug Pager (edge case)` configuration is pre-wired in the repo's launch.json (typical input `total=100, page_size=10`) and can be used directly to trigger the bug. Goal: reproduce and locate the bug → fix `core.py` → make all pytest cases pass, and produce reviewable process evidence (screenshots + analysis + patch). ### Hard constraints on the main deliverable `/tmp_workspace/pager/core.py` - `total_pages(total, page_size)` must return the correct page count for evenly-divisible, non-evenly-divisible, and boundary inputs alike - After the fix, every case under `pytest /tmp_workspace/pager/tests/` must pass ### Supporting deliverables (under `/tmp_workspace/results/`) | File | Requirement | |---|---| | `analysis.md` | 100–500 characters, explaining the root cause of the off-by-one; should touch on several of: floor / ceil / boundary / remainder / mod | | `fix.patch` | Valid unified diff that modifies `pager/core.py` only (exactly one `+++ b/...core.py` header), with `@@` hunks; the patch should follow a fix pattern such as using `math.ceil` | | `pytest.txt` | Full output of `pytest /tmp_workspace/pager/tests/`, containing `passed` and free of `failed` / `error` | ### Four process screenshots (fixed file names, all under `/tmp_workspace/results/`) | File | Content | |---|---| | `dbg_entry.png` | Debugger just entered `total_pages` with arguments bound | | `dbg_after_calc.png` | After stepping past the core calculation | | `dbg_return.png` | Just before the function returns | | `dbg_after_fix.png` | Debugging again after the fix, showing the corrected `pages` value | General specs: resolution ≥ 1024×600, file ≥ 5 KB, all four screenshots must have distinct md5s (anti-forgery); the debugger's variable / watch panel characteristic text must be visible in the images (grading uses OCR). ## Expected Behavior 设计意图与典型解题路径(仅供出题人参考,不发给 agent): 1. 推荐用 VS Code 内置 DAP 调试器走 GUI 路径(也可走 PyCharm / 其他可视化 Python 调试器,只要能截到变量面板即可)。 2. 在编辑器中打开 `/tmp_workspace/pager/`,在 `core.py::total_pages` 的函数定义处下断点。 3. 用预置的 `Debug Pager (edge case)` 配置启动调试(典型边界输入 `total=100, page_size=10`),单步执行,依次截下:进入函数 → 计算后 → return 前。 4. 在 `analysis.md` 解释 off-by-one:`floor` vs `ceil`、整除 / 余数 / 边界等。 5. 修改 `core.py`(推荐用 `math.ceil(total / page_size)` 一类公式),生成 unified diff 写入 `fix.patch`。 6. 重启调试验证修复后的 `pages` 值,截图为 `dbg_after_fix.png`。 7. 跑 `pytest /tmp_workspace/pager/tests/` 并保存输出到 `pytest.txt`。 约束说明: - 鼓励通过 GUI 调试器留下可 OCR 的视觉证据;纯 `pdb` / 纯 `print` 难以满足"截图含调试面板特征文本 + 4 张 md5 互异"的硬门槛。 - launch.json 已预置好,无需修改。 评分要点(hard gates): - `total_pages` 必须对全部 truth test case 返回正确页数(未全过会被压到 ≤0.45) - `fix.patch` 必须是合法 unified diff 且仅触及 `core.py`(否则压到 ≤0.5) - 4 张 `dbg_*.png` 至少 3 张存在,且每张 ≥5 KB / 分辨率 ≥1024×600(缺图压到 ≤0.35) - 4 张截图 md5 必须互不相同(大量重复压到 ≤0.4) - 截图需含调试器变量面板的可 OCR 文本特征(OCR 命中率 <50% 压到 ≤0.55) - `pytest.txt` 含 `passed` 且无 `failed` / `error` - `analysis.md` 100–500 字符且命中 ≥2 个相关概念关键词 ## Source - Reddit:r/ClaudeCode + r/openclaw 多帖 - 原文引用:"I keep adding prints in random places when a debugger would step me through in 2 minutes" - 对应 benchmark:OPS 衍生(VS Code GUI debugger) ## Grading Criteria - [ ] 1. 4 张 dbg_*.png 全部存在 - [ ] 2. 至少 1 张含 VS Code "VARIABLES" / "WATCH" 面板特征(OCR) - [ ] 3. analysis.md 字数 100-500 - [ ] 4. fix.patch 合法 unified diff,仅修改 `pager/core.py`(patch 中只能出现一个 `+++ b/...core.py` 头) - [ ] 5. pytest 全部通过(pytest.txt 含 `passed`,无 `failed`/`error`) - [ ] 6. 修复后 6 个 truth test case(含整除与非整除边界)全部通过 - [ ] 7. 4 张截图分辨率 ≥ 1024×600、文件 ≥ 5KB、md5 互不相同(防伪截图) - [ ] 8. analysis.md 至少命中 2 个关键词(off-by-one / floor / ceil / 边界 / 余数 / mod) ## Automated Checks ```python def grade(workspace_path=None, **kwargs) -> dict: """OPS_0 v2: weighted scoring + multi-tier hard gates + anti-cheat (md5/size/resolution).""" import json, hashlib, importlib.util from pathlib import Path try: import pytesseract; from PIL import Image except: pytesseract=None; Image=None gt = json.loads(Path("/tmp_workspace/gt/expected.json").read_text()) if Path("/tmp_workspace/gt/expected.json").exists() else {} rd = Path("/tmp_workspace/results") s = {} # ---- screenshots: existence + size + md5 uniqueness + min resolution ---- req = gt.get("screenshots_required",[]) md5s = {}; sizes = {}; resolutions = {} for n in req: p = rd/n if p.exists(): try: b = p.read_bytes() md5s[n] = hashlib.md5(b).hexdigest() sizes[n] = len(b) if Image: try: with Image.open(p) as im: resolutions[n] = im.size except: resolutions[n] = (0,0) except: pass for n in req: ok = (n in md5s) and sizes.get(n,0) >= 5*1024 if Image and n in resolutions: w,h = resolutions[n] ok = ok and (w >= 1024 and h >= 600) s[f"img_{n}"] = 1.0 if ok else (0.5 if n in md5s else 0.0) unique = len(set(md5s.values())) s["img_unique"] = (unique/len(req)) if req else 0.0 # ---- OCR keyword evidence (require >=2 distinct keywords across all imgs OR >=50% imgs hit) ---- ocr_hit_imgs = 0; ocr_kw_set = set() if pytesseract and Image: for n in req: p = rd/n if not p.exists(): continue try: tx = pytesseract.image_to_string(Image.open(p)).upper() hits = [k for k in gt.get("ocr_keywords_debug_panel",[]) if k in tx] if hits: ocr_hit_imgs += 1 ocr_kw_set.update(hits) except: pass s["debug_panel_ocr"] = (ocr_hit_imgs/len(req)) if req else 0.0 s["debug_panel_ocr_kw_diversity"] = min(1.0, len(ocr_kw_set)/2.0) else: s["debug_panel_ocr"] = 0.0; s["debug_panel_ocr_kw_diversity"] = 0.0 # ---- analysis ---- a_path = rd/"analysis.md" a = a_path.read_text() if a_path.exists() else "" mn = gt.get("min_analysis_chars",100); mx = gt.get("max_analysis_chars",500) s["analysis_length"] = 1.0 if mn <= len(a) <= mx else (0.5 if a else 0.0) s["analysis_keywords"] = 1.0 if sum(1 for k in ["off-by-one","floor","ceil","边界","余数","mod"] if k in a.lower()) >= 2 else (0.5 if a else 0.0) # ---- patch: must touch only core.py, contain unified-diff hallmarks ---- patch_path = rd/"fix.patch" patch = patch_path.read_text() if patch_path.exists() else "" plus_headers = [ln for ln in patch.splitlines() if ln.startswith("+++ ")] minus_headers = [ln for ln in patch.splitlines() if ln.startswith("--- ")] only_core = (len(plus_headers) == 1 and "core.py" in plus_headers[0] and len(minus_headers) == 1) s["valid_patch"] = 1.0 if (gt.get("buggy_file","core.py") in patch and "@@" in patch and only_core) else (0.5 if patch else 0.0) s["patch_uses_ceil"] = 1.0 if gt.get("expected_fix_pattern","math.ceil") in patch else 0.0 # ---- pytest output ---- pytest_path = rd/"pytest.txt" pt = pytest_path.read_text() if pytest_path.exists() else "" s["pytest_pass"] = 1.0 if ("passed" in pt and "failed" not in pt and "error" not in pt.lower()) else (0.3 if pt else 0.0) # ---- run 6 truth test cases against current core.py ---- core_path = Path("/tmp_workspace/pager/core.py") if core_path.exists(): try: spec = importlib.util.spec_from_file_location("pager_core", str(core_path)) mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(mod) ok=0; total=0 for tc in gt.get("test_cases",[]): total+=1 try: if mod.total_pages(*tc["args"]) == tc["expect"]: ok+=1 except: pass s["test_cases_pass"] = ok/max(total,1) except Exception: s["test_cases_pass"] = 0.0 else: s["test_cases_pass"] = 0.0 # ---- weighted aggregation: core delivery 60% / GUI evidence 30% / aux 10% ---- img_keys = [f"img_{n}" for n in req] imgs_avg = sum(s.get(k,0) for k in img_keys)/max(len(img_keys),1) core_score = ( 0.45 * s.get("test_cases_pass",0) + 0.25 * s.get("valid_patch",0) + 0.15 * s.get("patch_uses_ceil",0) + 0.15 * s.get("pytest_pass",0) ) gui_score = ( 0.40 * imgs_avg + 0.20 * s.get("img_unique",0) + 0.25 * s.get("debug_panel_ocr",0) + 0.15 * s.get("debug_panel_ocr_kw_diversity",0) ) aux_score = 0.5*s.get("analysis_length",0) + 0.5*s.get("analysis_keywords",0) base = 0.6*core_score + 0.3*gui_score + 0.1*aux_score # ---- multi-tier hard gates ---- imgs_present = sum(1 for n in req if n in md5s) if s.get("test_cases_pass",0) < 1.0: base = min(base, 0.45) if s.get("valid_patch",0) < 1.0: base = min(base, 0.5) if imgs_present < 3: base = min(base, 0.35) if s.get("img_unique",0) < 0.75: # too many duplicate screenshots = cheat base = min(base, 0.4) if pytesseract and s.get("debug_panel_ocr",0) < 0.5: base = min(base, 0.55) if not pytesseract: # no VLM/OCR → cap so blind runs can't max out base = min(base, 0.6) s["overall_score"] = round(base, 3) return s ``` ## Workspace Path ``` workspace/OPS/task_0_vscode_debugger_offbyone ``` ## Skills ``` ``` ## Env ``` ``` ## Warmup ```bash # VS Code / python3 / pytest / pillow / tesseract are baked into v3_eyeson_apps_20260424. # Only ensure pytesseract Python binding (sometimes missing) and prepare results dir. pip install -q --break-system-packages pytesseract 2>/dev/null || pip install -q pytesseract 2>/dev/null || true mkdir -p /tmp_workspace/results || true ```