Closes the residual bible_bridge wedge case _ensure_on_default_branch
can't fix: local main has diverged from origin/main at the SHA level
(post-squash-merge or rebased-force-push), which needs a destructive
git reset --hard that the bridge correctly refuses to do silently.
git_recover() requires confirm:true (footgun-guard) and refuses on
uncommitted changes (no auto-data-loss), matching the existing
_ensure_on_default_branch pattern. Returns a diagnostic payload
(abandoned branch/SHA/dropped commits, new HEAD) so callers (the
homelab#123 health-watcher workflow) can post a meaningful alert.
Tests use real git repos (a local bare "origin" + a real clone) rather
than mocking subprocess calls, per feedback_mocks_encode_assumed_contracts
-- git_recover's entire job is orchestrating real git commands
correctly.
User description
Summary
POST /bible/recover— the destructive-reset auto-recovery path for the residual bible_bridge wedge case that_ensure_on_default_branch/git_pullcan't fix (local main diverged from origin/main at the SHA level, needsgit reset --hard).confirm: truerequired (footgun-guard, endpoint is destructive). Refuses on uncommitted changes (no auto-data-loss).Test plan
python3 -m pytest tests/test_bible_recover.py -v— 5/5 passed, using real git repos (a local bare "origin" + real clone), not mocksPR Type
Feature, New Endpoint
Description
Introduces
/bible/recoverPOST endpoint to safely resolve diverged local branches viagit reset --hard origin/main.Implements
git_recover()with strict safety guards: requires explicitconfirm=Trueand refuses if uncommitted changes exist.Returns detailed payload reporting abandoned commits, dropped SHAs, and new HEAD state.
Adds comprehensive integration tests using real git repositories to validate recovery logic, safety checks, and edge cases.
Diagram Walkthrough
flowchart TD A[POST /bible/recover] --> B{confirm=True?} B -- No --> C[400 confirm_required] B -- Yes --> D{Uncommitted changes?} D -- Yes --> E[400 uncommitted_changes_present] D -- No --> F[Fetch origin/main] F --> G[Checkout main if needed] G --> H[git reset --hard origin/main] H --> I{Reset success?} I -- No --> J[500 reset_failed] I -- Yes --> K[200 Recovery payload]File Walkthrough
bible_bridge.py
Implement git recovery endpoint and core logicbible_bridge.py
Added
git_recover()function and/bible/recoverPOST route with safetyvalidations, fetch/reset logic, and detailed response payloads.
test_bible_recover.py
Add comprehensive tests for /bible/recovertests/test_bible_recover.py
Added full test suite covering confirm guards, dirty tree rejection,
happy path divergence, non-default branches, and no-op scenarios using
real git repos.