refactor: split backgroundAutoApprove and lift its coverage #450
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman#450
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Code-quality audit (P2).
internal/autoapprove/background.go:106-354—backgroundAutoApproveis ~249 lines and sits at 24.3% line coverage.One body does: enabled-check, safe-command cache short-circuit, directory resolution, delay read, model mutation, delay sleep, prompt-section loading, recent-message context building, judge call, cancellation re-check, verdict recording, flagged broadcast, cache write, approval persistence.
Why it matters
This is the function that auto-answers permission prompts on the user's behalf — the highest-consequence path in the package. The low coverage is a direct consequence of the size: every test has to set up the whole pipeline to exercise any one branch, so most branches are untested. A regression in the cancellation re-check or the verdict-recording order would auto-approve something it shouldn't and no test would catch it.
Suggested fix
Extract two seams so each is independently testable:
resolveJudgeInputs(...)— directory resolution, delay, model, prompt sections, recent-message context. Returns a struct.handleUnsafeVerdict(...)— flagged broadcast + the non-approval path.The remaining body becomes: short-circuit -> resolve inputs -> sleep -> judge -> record -> approve/flag.
Acceptance criteria
backgroundAutoApproveunder ~80 lines.internal/autoapproveline coverage increases;backgroundAutoApproveand its extractions are collectively above 60%.Effort: M.