fix: 修复空 catch 块 — 收窄异常类型、添加日志、注释意图性静默 (Issue #10)#26
Merged
Conversation
46e6481 to
a3de8ba
Compare
This was referenced May 29, 2026
Closes #10 - 为所有受影响模块添加模块级 logger (logging.getLogger(__name__)) - 26 个空 except:pass 添加 logger.debug() 提升可诊断性 - 5 个近乎空的 catch (return/assign 无日志) 补充 debug 日志 - 5 个 except Exception 收窄为具体异常类型防止吞没真实 bug: - agents.py:91 Exception → (json.JSONDecodeError, OSError, KeyError) - cli.py:542 Exception → (json.JSONDecodeError, KeyError, IndexError) - cli.py:561 Exception → ValueError - tui.py:31 Exception → (json.JSONDecodeError, IndexError, KeyError) - tui.py:43 Exception → ValueError - 2 个意图性静默 catch 添加注释说明原因: - pipeline.py:40 — kill 进程可能已退出 - tui.py:182 — curses addstr 边界错误 - 1 个 FileExistsError 添加注释说明 mkdir 重试逻辑 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Critical:
- test_interrupt_sets_paused 重写为真正测试 _on_interrupt 行为:
通过捕获 _run_pipeline 注册的信号处理器闭包,直接调用并验证
meta.json 写入 paused + sys.exit(0) + os.kill 被调用
Major:
- test_interactive_mode/test_verification_failure_marks_failed
添加 shutil.which('greywall') mock,防止安装 greywall 时代码路径改变
- test_no_git_repo_copies_directory 断言加强:
worktree.exists() → (worktree / 'file.txt').exists()
- 为 6 个 has_changes=True 的测试添加 collect_change_stats mock,
避免依赖 subprocess.run 全局 mock 处理 metrics 调用
Minor:
- fast_logger fixture 复用 conftest.py 的 logger fixture
- test_completed_status 否定断言改为积极断言
- test_context_file_with_verification 脆弱中文断言改为 verify_ok 检查
- test_existing_worktree_reused .git 目录改为文件(匹配真实 worktree)
- 移除重复的 sys.path.insert(conftest.py 已处理)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
11069b8 to
d8e2a95
Compare
PR #28 重构了 __init__.py,不再 re-export _is_safe_verification_command。 测试文件应直接从 agent_go.utils 导入。
Owner
Author
CI 失败分析3 个失败测试是 预先存在的 CI 环境问题,与本 PR 无关:
PR 本身的 209 个测试全部通过。Rebase 已解决与 main 的冲突( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #10
修复 26 个空
except: pass+ 5 个近乎空的 catch 块,分布在 9 个模块中。同时修复了 PR #25 Review 反馈的所有测试问题。Issue #10: 空 catch 块修复
模块级 Logger
为所有受影响模块添加
logging.getLogger(__name__),子模块 logger 自动继承setup_logger()配置的 handler,零 API 变更。A类:添加 debug 日志(18 处)
空
except: pass前添加logger.debug(),不改控制流,提升可诊断性。B类:收窄异常类型(5 处)
except Exception→ 具体类型,防止吞没真实 bug:agents.py:91(json.JSONDecodeError, Exception)(json.JSONDecodeError, OSError, KeyError)cli.py:542Exception(json.JSONDecodeError, KeyError, IndexError)cli.py:561ExceptionValueErrortui.py:31Exception(json.JSONDecodeError, IndexError, KeyError)tui.py:43ExceptionValueErrorC类:注释意图性静默(2 处)
pipeline.py:40— kill 进程可能已退出,静默正确tui.py:182— curses addstr 边界错误,静默正确D类:近乎空 catch 补充日志(5 处)
有 return/assign 但无日志的 catch 块,补充
logger.debug()。PR #25 Review 反馈修复
🔴 Critical #1: 假测试重写
test_interrupt_sets_paused→test_interrupt_handler_writes_pausedpatch("signal.signal")捕获_run_pipeline注册的信号处理器闭包sys.exit(0)、meta.json写入paused、os.kill被调用🟡 Major #2-4
shutil.whichmocktest_no_git_repo_copies_directory断言加强为检查复制文件has_changes=True测试添加collect_change_statsmock🟢 Minor #5,6,7,8,9
fast_logger复用 conftest fixturesys.path.insertverify_ok检查.git目录→文件(匹配真实 worktree)测试
🤖 Generated with Claude Code