Extract self-sudo skip into shared resolve_claude_user() utility#205
Extract self-sudo skip into shared resolve_claude_user() utility#205
Conversation
PR #192 added a self-sudo check to claude.py but missed the identical sudo pattern in triage.py and review.py. In single-user deployments where claude_user matches the bot process user, triage and review subprocesses attempted self-sudo and silently failed. Move the check into config.resolve_claude_user() and apply it in all three locations. Both the spawn path (sudo -u prefix) and cleanup path (killpg vs proc.kill) use the resolved value so they stay in sync. Fixes #194
Review by KaiThis is a clean refactor with good test coverage. A few findings: Warning — inconsistent patch target in new timeout tests
patch("os.killpg") as mock_killpg,The existing tests in the same files use the module-local path:
Both approaches work (same module object), but Suggestion —
Suggestion — timeout trigger mechanism differs between old and new tests The new mock_proc.communicate = AsyncMock(side_effect=TimeoutError)The existing parallel tests use Core logic is correct. |
Review by KaiThe two actionable findings from the prior review have been addressed in this revision: Prior issues resolved:
New findings: Suggestion —
def test_different_user_returns_unchanged(self):
assert resolve_claude_user("some_nonexistent_user_xyz") == "some_nonexistent_user_xyz"This calls the real Everything else looks correct. The |
Review by KaiThe prior review's open suggestion — New findings in this revision: Suggestion —
try:
current_user = pwd.getpwuid(os.getuid()).pw_name
except KeyError:
pytest.skip("UID has no passwd entry")Neither new integration test patches Everything else is correct. The existing tests that use |
Summary
claude.pyintoconfig.resolve_claude_user()shared utilityclaude.py,triage.py,review.pyimport pwdfromclaude.py(only used for the check that moved toconfig.py)kai.config.pwd.getpwuidinstead ofkai.claude.pwd.getpwuidTest plan
TestResolveClaudeUserin test_config.py (None, empty, self-sudo, different user, KeyError)Fixes #194