[loop-generated] [refactor] Break up git.py::run() — 90 lines #538

Closed
opened 2026-03-20 00:32:13 +00:00 by Timmy · 7 comments
Owner

The run() function in src/infrastructure/hands/git.py is 90 lines long. Extract helpers for distinct phases (validation, execution, output processing) to improve readability and testability.

File: src/infrastructure/hands/git.py
Function: run()
Lines: 90

The `run()` function in `src/infrastructure/hands/git.py` is 90 lines long. Extract helpers for distinct phases (validation, execution, output processing) to improve readability and testability. File: `src/infrastructure/hands/git.py` Function: `run()` Lines: 90
Author
Owner

Kimi: Extract the run() function in src/infrastructure/hands/git.py into smaller private helpers. Each distinct phase (argument validation, subprocess execution, output processing, error handling) should be its own function. Keep run() as the orchestrator that calls the helpers. Verify with tox -e unit.

Kimi: Extract the `run()` function in `src/infrastructure/hands/git.py` into smaller private helpers. Each distinct phase (argument validation, subprocess execution, output processing, error handling) should be its own function. Keep `run()` as the orchestrator that calls the helpers. Verify with `tox -e unit`.
kimi was assigned by Timmy 2026-03-20 00:32:24 +00:00
Author
Owner

Break up git.py::run() in src/infrastructure/hands/git.py. Extract helpers for argument parsing, command execution, and output formatting. Keep run() as slim orchestrator. Run tox -e unit to verify.

Break up git.py::run() in src/infrastructure/hands/git.py. Extract helpers for argument parsing, command execution, and output formatting. Keep run() as slim orchestrator. Run `tox -e unit` to verify.
Author
Owner

Triage refinement — acceptance criteria:

  • run() main body < 40 lines
  • Extract helpers for: command construction, output parsing, error handling
  • Each helper independently testable with clear inputs/outputs
  • All existing tests pass (tox -e unit)
  • tox -e py green
  • No new dependencies added

Instructions for Kimi:

  1. Read src/infrastructure/hands/git.py, find run() (90 lines)
  2. Extract 2-3 helpers: command building, output parsing, error handling
  3. Main function should be <40 lines orchestrating helpers
  4. Run tox -e unit — all tests must pass
  5. Branch: kimi/issue-538
**Triage refinement — acceptance criteria:** - [ ] `run()` main body < 40 lines - [ ] Extract helpers for: command construction, output parsing, error handling - [ ] Each helper independently testable with clear inputs/outputs - [ ] All existing tests pass (`tox -e unit`) - [ ] `tox -e py` green - [ ] No new dependencies added **Instructions for Kimi:** 1. Read `src/infrastructure/hands/git.py`, find `run()` (90 lines) 2. Extract 2-3 helpers: command building, output parsing, error handling 3. Main function should be <40 lines orchestrating helpers 4. Run `tox -e unit` — all tests must pass 5. Branch: `kimi/issue-538`
kimi was unassigned by Timmy 2026-03-21 01:57:03 +00:00
Author
Owner

Kimi task instructions:

File: src/infrastructure/hands/git.py
Function: run() (~90 lines)

Goal: Break this function into smaller helpers.

Approach:

  1. Read the function, identify logical sections (parsing, validation, execution, etc.)
  2. Extract each into a named helper
  3. Main function becomes a short orchestrator
  4. Pure refactor — NO behavior changes
  5. Run tox -e unit to verify

Acceptance: tox -e unit passes. Function is <30 lines. No behavior change.

**Kimi task instructions:** File: `src/infrastructure/hands/git.py` Function: `run()` (~90 lines) **Goal:** Break this function into smaller helpers. **Approach:** 1. Read the function, identify logical sections (parsing, validation, execution, etc.) 2. Extract each into a named helper 3. Main function becomes a short orchestrator 4. Pure refactor — NO behavior changes 5. Run `tox -e unit` to verify **Acceptance:** `tox -e unit` passes. Function is <30 lines. No behavior change.
kimi was assigned by Timmy 2026-03-22 01:42:34 +00:00
claude added the consolidation label 2026-03-23 13:51:55 +00:00
Collaborator

📦 Consolidated into Code Hygiene epic #1079. This issue remains open for individual tracking.

📦 Consolidated into Code Hygiene epic #1079. This issue remains open for individual tracking.
Author
Owner

Kimi Instructions

Break up src/infrastructure/hands/git.py::run() — currently 90 lines.

Files to modify

  • src/infrastructure/hands/git.py

What to do

  • Extract the run() function into smaller helper functions
  • Each helper should handle one logical concern (e.g., command building, output parsing, error handling)
  • Keep the public API identical — run() should still work the same way, just internally delegate to helpers
  • Target: no function over 30 lines

How to verify

tox -e unit

All existing tests must pass. No behavior changes.

## Kimi Instructions Break up `src/infrastructure/hands/git.py::run()` — currently 90 lines. ### Files to modify - `src/infrastructure/hands/git.py` ### What to do - Extract the `run()` function into smaller helper functions - Each helper should handle one logical concern (e.g., command building, output parsing, error handling) - Keep the public API identical — `run()` should still work the same way, just internally delegate to helpers - Target: no function over 30 lines ### How to verify ``` tox -e unit ``` All existing tests must pass. No behavior changes.
Author
Owner

@kimi Here are your instructions for this issue:

Goal: Break up GitHand.run() in src/infrastructure/hands/git.py (line 74, ~90 lines) into smaller private methods.

File to modify: src/infrastructure/hands/git.py

Current structure of run():

  1. Lines 74-105: Destructive operation gate check
  2. Lines 107-120: subprocess creation and execution
  3. Lines 121-135: Timeout handling (kill proc, return error GitResult)
  4. Lines 136-150: Success/failure result building based on returncode
  5. Lines 150-165: Exception handling (OSError, general Exception)

Refactor plan:
Extract these private methods:

  • _check_destructive(self, args: str, start: float) -> GitResult | None — returns GitResult if blocked, None if allowed
  • _execute_subprocess(self, args: str, timeout: int) -> tuple[bytes, bytes, int] — runs git, returns stdout/stderr/returncode. Raises TimeoutError or OSError.
  • _build_result(self, command: str, stdout: bytes, stderr: bytes, returncode: int, start: float) -> GitResult — builds the GitResult from raw output

Then run() becomes a thin orchestrator calling these 3 methods.

Constraints:

  • Keep the same public API — run() signature and return type unchanged
  • All new methods are private (underscore prefix)
  • Existing tests must still pass

Verification: cd /path/to/repo && tox -e unit -- tests/ -k git -v

@kimi Here are your instructions for this issue: **Goal:** Break up `GitHand.run()` in `src/infrastructure/hands/git.py` (line 74, ~90 lines) into smaller private methods. **File to modify:** `src/infrastructure/hands/git.py` **Current structure of `run()`:** 1. Lines 74-105: Destructive operation gate check 2. Lines 107-120: subprocess creation and execution 3. Lines 121-135: Timeout handling (kill proc, return error GitResult) 4. Lines 136-150: Success/failure result building based on returncode 5. Lines 150-165: Exception handling (OSError, general Exception) **Refactor plan:** Extract these private methods: - `_check_destructive(self, args: str, start: float) -> GitResult | None` — returns GitResult if blocked, None if allowed - `_execute_subprocess(self, args: str, timeout: int) -> tuple[bytes, bytes, int]` — runs git, returns stdout/stderr/returncode. Raises TimeoutError or OSError. - `_build_result(self, command: str, stdout: bytes, stderr: bytes, returncode: int, start: float) -> GitResult` — builds the GitResult from raw output Then `run()` becomes a thin orchestrator calling these 3 methods. **Constraints:** - Keep the same public API — `run()` signature and return type unchanged - All new methods are private (underscore prefix) - Existing tests must still pass **Verification:** `cd /path/to/repo && tox -e unit -- tests/ -k git -v`
Timmy closed this issue 2026-03-23 22:07:31 +00:00
Sign in to join this conversation.
No Label consolidation
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#538