test(cli): lift Go coverage from 18% to 70.5% — fixes #144#154
Draft
test(cli): lift Go coverage from 18% to 70.5% — fixes #144#154
Conversation
The coverage gate in .github/workflows/test.yml was failing every PR
because the cmd package had drifted to 18% after recent install.go and
ma.go additions (--wizard, --fast, shot-scraper module, managed-agents
provisioning) shipped without proportional unit tests. This commit adds
16 test files (~1100 LOC) targeting pure helpers and exercising the
RunE handlers in-process so they actually contribute to coverage —
unlike framework/cli/cmd/integration_test.go which spawns the binary
via os/exec and gets no instrumentation credit.
Per-package result :
github.com/izo/ulk/cmd 33.9% → 55.1% (+21pp)
github.com/izo/ulk/internal/config 70.4% → 75%+ (+InjectStatusLine, SetEnvVar)
github.com/izo/ulk/internal/installer 58.9% → 71.0% (+Bundle/External/MCP/Config/Hook modules)
github.com/izo/ulk/internal/registry 60.7% → 91.1% (+LoadCLIRegistry, ByCategories)
github.com/izo/ulk/tui 73.1% → 84.3% (+PrintSplash, PrintFastHeader, PrintDone)
TOTAL 18.0% → 70.5% (+52.5pp, gate ≥70% passes)
New cmd test files :
- selfupdate_test.go binaryAssetName, assetURL, httpGet (httptest), fetchExpectedHash
- install_deps_test.go filterByPriority (4 cases), installCmdFor
- ma_test.go parseAgentYAMLFile, collectAgentYAMLs, buildMAPayload
- install_helpers_test.go countEnabledModules, resolveClaudeDir, validateSourceDir,
parseInstallFlags, printModules/printProgress, loadOrNewState
- short_runners_test.go runMigrate / runRollback / runUpdate "no install" branches, allKeys
- inproc_test.go in-process runDoctor / runStatus / runCheck / runVerify
(text + --json branches) — these don't run via the binary
so their coverage is captured
- inproc_install_test.go runInstall source-missing + dry-run paths
- inproc_install_deps_test.go runInstallDeps source-missing / registry-missing /
empty-filter / all-present paths
- inproc_audit_test.go runAuditReport (default + ma-audit branch),
collectManagedAgentsInfo
- ma_runtime_test.go runMA / runMAList / runMAProvision (no API key paths),
loadAgentIDFromFile (4 paths), parseSSEStream (all event types)
- ma_provision_test.go runMAProvision dry-run with seed YAMLs (priority filter,
--agent flag, already-provisioned branch)
- uninstall_runtime_test.go runUninstall flag-validation branches
New internal package tests :
- internal/registry/cli_tools_test.go LoadCLIRegistry + ByCategories (filter, dedup)
- internal/installer/modules_install_test.go Bundle/External/MCP/Config/Hook modules
(DryRun + missing-dep + msgOnly branches)
- internal/config/hooks_extra_test.go InjectStatusLine, SetEnvVar (create + merge)
- tui/screens_test.go PrintSplash, PrintFastHeader, PrintDone
Closes #144.
https://claude.ai/code/session_01TyhPjizanX1g8xSQ6chwTu
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Le job
Go CLI > Coverage gateéchouait sur toute PR qui touchait.github/workflows/**parce que la couverture Go avait dérivé à 18% sur le packagecmdaprès les ajouts récents (--wizard,--fast, shot-scraper module, managed-agents provisioning) sans tests proportionnels.Ce PR ajoute 16 fichiers de tests (~1100 lignes) ciblant les helpers purs ET appelant les handlers
RunEcobra en in-process (les testsintegration_test.goqui spawn le binaire viaos/execne comptent pas pour la coverage).Résultat
cmdinternal/configinternal/installerinternal/registrytuiStratégie
3 catégories de tests :
1. Helpers purs (zero-IO) — fonctions sans effet de bord, faciles à tester :
binaryAssetName,assetURL,filterByPriority,installCmdFor,parseInstallFlags,countEnabledModules,buildMAPayload,parseSSEStream,LoadCLIRegistry,ByCategories, etc.2. Helpers IO contrôlable — fonctions qui lisent/écrivent dans le filesystem, testables avec
t.TempDir()+t.Setenv("HOME", ...):parseAgentYAMLFile,collectAgentYAMLs,loadAgentIDFromFile,runAuditReport,runMAProvision --dry-run,InjectStatusLine,SetEnvVar.3. Handlers RunE in-process — appel direct du
RunE(au lieu de spawn binary) avec stdout capturé, en isolation viaHOME=tmpdir:runDoctor,runStatus,runCheck,runVerify,runMigrate,runRollback,runUpdate,runInstall --dry-run,runInstallDeps,runUninstall. C'est cette catégorie qui a fait montercmdde +21pp car elle exerce le code que les tests d'intégration ne pouvaient pas instrumenter.Pour HTTP, j'utilise
httptest.NewServersur les fonctions qui prennent une URL en paramètre (fetchExpectedHash,httpGet).fetchLatestReleaseetrunSelfUpdateont une URL en const non-injectable, donc restent partiellement non-testés sans refactor (out of scope).Test plan
go test ./framework/cli/...→ tous verts en localGo CLI (ubuntu-latest)et(macos-latest)doivent passer le gate.github/workflows/**(notamment v0.5+ macOS) ne verront plus le rouge récurrentCloses #144.
https://claude.ai/code/session_01TyhPjizanX1g8xSQ6chwTu
Generated by Claude Code