test(init): add unit tests for printInitCatalog and setInitUsage (plan 2607191917) - #754
Conversation
Direct unit tests for printInitCatalog (bytes.Buffer, no subprocess) and setInitUsage (pflag.FlagSet + captureStderr, no subprocess), as required by tests.md's per-function rule. Closes plan 2607191917. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013KgrSLVGA3ioVKvpNkK9ar
…aults in test setInitUsage now accepts io.Writer (matching printInitCatalog) so the test can pass a bytes.Buffer directly instead of redirecting the global os.Stderr through captureStderr. TestSetInitUsage registers --force on the FlagSet and calls fs.SetOutput(&buf) so fs.PrintDefaults() output also flows into the buffer, covering the path that was silently empty before. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013KgrSLVGA3ioVKvpNkK9ar
…r in setInitUsage setInitUsage now calls fs.SetOutput(w) so both the header (fmt.Fprintf) and the flag list (fs.PrintDefaults) flow to the same writer without callers having to align them independently. TestSetInitUsage asserts "overwrite existing .mdsmith.yml" — a string that only PrintDefaults can emit — so removing that call would now break the test. Also swap var force / BoolVar(&force) for BoolVar(new(bool)) to drop the dead variable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013KgrSLVGA3ioVKvpNkK9ar
… description columns
TestSetInitUsage now registers --force with the actual production description
("Overwrite an existing .mdsmith.yml instead of leaving it unchanged") so
the PrintDefaults pin matches what a real user sees, not an arbitrary stub.
TestPrintInitCatalog adds description/summary assertions ("Open Knowledge
Format bundle config", "Curated no-llm-tells word-lists") so removing the
description column from printInitCatalog's format string would break the test.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013KgrSLVGA3ioVKvpNkK9ar
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
golangci-lint's errcheck flagged the unchecked return value of fmt.Fprintf(w, ...) inside the setInitUsage closure. Add the standard _, _ = discard prefix to match the rest of the file. Co-Authored-By: Claude <noreply@anthropic.com>
|
🟢 Merge Queue — picked up This PR is in the queue and will be batched with other Next: No action needed — you'll get another comment when CI starts on the batch. View merge queue run. |
|
🔵 Merge Queue — CI running Merged into batch branch Next: No action needed — you'll be notified when CI completes. |
|
✅ Merge Queue — merged This PR landed on Next: Done — nothing more to do here. |
Summary
TestPrintInitCatalogdirectly exercisingprintInitCatalogvia abytes.Buffer— no subprocess, asserts both section headers and concrete description text for theokfstarter andwordlistspack.TestSetInitUsagedirectly exercisingsetInitUsagevia abytes.Bufferinjected into the neww io.Writerparameter — no subprocess, asserts the static header flag names and pinsfs.PrintDefaults()via the production--forcedescription.setInitUsageto acceptio.Writer(matchingprintInitCatalog) and callsfs.SetOutput(w)so both the header andPrintDefaults()output flow to the same writer without callers having to align them independently.Closes plan 2607191917.
Test plan
go test ./cmd/mdsmith/...passesTestPrintInitCatalogandTestSetInitUsageappear in output with no subprocessmdsmith check .passesGenerated by Claude Code