4.2 KiB
4.2 KiB
phase, plan, subsystem, tags, requires, provides, affects, tech-stack, key-files, decisions, metrics, requirements
| phase | plan | subsystem | tags | requires | provides | affects | tech-stack | key-files | decisions | metrics | requirements | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 07-import-cicd | 05 | cmd/hook |
|
|
|
|
|
|
|
|
|
Phase 7 Plan 5: cmd/hook Install/Uninstall Summary
Git pre-commit hook lifecycle via keyhunter hook install/uninstall, with the pre-commit script bundled at compile time through go:embed.
What Was Built
- cmd/hook.go —
hookCmdparent withinstallanduninstallsubcommands, shared--forceflag,.git/validation viahookPath(), marker-aware overwrite/delete logic. - cmd/hook_script.sh — Embedded bash script carrying the
KEYHUNTER-HOOK v1marker. Reads staged files viagit diff --cached --name-only --diff-filter=ACMR, pipes throughxargs -r keyhunter scan --exit-code, propagates exit code to block commits on findings. Trailing newline preserved. - cmd/hook_test.go — 10 tests:
TestHookInstall_FreshRepo— mode 0o755, marker presentTestHookInstall_NotAGitRepo— error when no.git/TestHookInstall_ExistingNonKeyhunterRefuses— refuses without--forceTestHookInstall_ForceBackupsExisting—.bak.<ts>backup createdTestHookInstall_ExistingKeyhunterOverwrites— updates stale marker hook silentlyTestHookUninstall_RemovesKeyhunter— install then remove lifecycleTestHookUninstall_RefusesForeign— refuses non-marker fileTestHookUninstall_Force— removes foreign with--forceTestHookUninstall_Missing— no-op friendly messageTestHookScript_ContainsRequired— embedded script sanity check
- cmd/stubs.go — Removed
hookCmdstub block; kept every other stub.
Verification
go build ./... # succeeds
go test ./cmd/... -run Hook -v
10 tests, all PASS
Commit: aa8daf8
Deviations from Plan
Auto-fixed Issues
1. [Rule 3 - Blocking] Transient importCmd build error
- Found during: Task 1 verification (
go build) - Issue: Initial
go buildfailed withundefined: importCmdbecause the stubs.go linter-driven update removedimportCmdwhilecmd/import.gowasn't visible in the workspace yet. - Fix: Re-scanned workspace;
cmd/import.gowas present (plan 07-04's output), no action needed beyond ensuringstubs.godoes not redeclareimportCmd. Finalgo buildsucceeds. - Files modified: none beyond plan scope
- Commit:
aa8daf8(same task commit)
Key Decisions
- Marker string as ownership signal.
KEYHUNTER-HOOK v1in the script header lets uninstall/overwrite distinguish our hooks from user-authored ones without an external manifest file. Thev1suffix reserves space for future script format bumps. - Backup-on-force rather than destroy.
--forceinstall renames the existing hook topre-commit.bak.<timestamp>instead of deleting, giving users a recovery path if they aimed the flag carelessly. - No global
viper/config wiring. The hook commands are filesystem-only; introducing config loading would add surface area for zero benefit at this layer.
Files Created/Modified
- Created: cmd/hook.go (~105 lines)
- Created: cmd/hook_script.sh (20 lines)
- Created: cmd/hook_test.go (~180 lines)
- Modified: cmd/stubs.go (removed 6-line stub block)
Self-Check: PASSED
- cmd/hook.go: FOUND
- cmd/hook_script.sh: FOUND
- cmd/hook_test.go: FOUND
- Commit
aa8daf8: FOUND go build ./...: PASSgo test ./cmd/... -run Hook: 10/10 PASS- Stub removed from cmd/stubs.go: CONFIRMED