| id | 2607191917 |
|---|---|
| title | Add dedicated unit tests for printInitCatalog and setInitUsage |
| status | ✅ |
| model | haiku |
| summary | printInitCatalog and setInitUsage (cmd/mdsmith/init.go) have no dedicated unit test; only e2e subprocess tests exercise them. Flagged by the 2026-07-19 audit and its own 3x code-review pass as inverted-pyramid tax findings. |
Give printInitCatalog and setInitUsage their own unit
tests. Lock mdsmith init --list and --help behavior at
the unit layer, not only through e2e subprocess tests.
The 2026-07-19 audit (see the audit log) found this gap:
printInitCatalogin init.go has noTestPrintInitCatalogin init_unit_test.go.- Its only exercise today is the e2e subprocess assertion
for
mdsmith init --listin e2e_test.go. - tests.md states: "A new function lands together with its dedicated unit test by name."
- The same doc also says an e2e test reachable through the
integration layer should move down.
printInitCatalogwrites to anio.Writer. It needs no subprocess to exercise.
A follow-up 3x code-review pass on the PR that filed this plan found the identical shape one function over:
setInitUsagein init.go has noTestSetInitUsageanywhere in init_unit_test.go.- Its only exercise is the e2e subprocess assertion for
mdsmith init --helpin e2e_coverage_test.go. - Same tests.md citation applies:
setInitUsageinstalls a closure on a*pflag.FlagSetand needs no subprocess to exercise directly.
Both are tax, not blocker. Neither is itself a CLI
subcommand entry point, an LSP handler, or a rule.Rule
method — both are helpers runInit wires up.
- Add
TestPrintInitCatalogin init_unit_test.go, writing to abytes.Bufferand asserting both sections ("Starters (mdsmith init --starter ):" and "Packs (mdsmith init --add ):") plus at least one known starter name and one known pack name appear in the output. - Add
TestSetInitUsagein init_unit_test.go, building a*pflag.FlagSet, callingsetInitUsage, then invokingfs.Usage()insidecaptureStderr(the closure writes to the hardcodedos.Stderr, so this is the only viable capture point — see the otherrunInittests in this file for the pattern) and asserting the printed text names--starter,--from-markdownlint,--add,--force, and--list. - Leave the existing e2e
--listand--helptests in place — they still cover the full CLI dispatch path — but do not duplicate the content assertions there beyond a smoke check. go build ./...passes.go test ./cmd/mdsmith/...passes.
-
TestPrintInitCatalogexists in init_unit_test.go and exercisesprintInitCatalogdirectly (no subprocess). -
TestSetInitUsageexists in init_unit_test.go and exercisessetInitUsagedirectly (no subprocess). -
go test ./...is green. -
mdsmith check .is green.