Skip to content

test(cmd/mdsmith): add dedicated unit tests for runCheck/runFix - #784

Draft
jeduden wants to merge 4 commits into
mainfrom
claude/amazing-hopper-lostfp
Draft

test(cmd/mdsmith): add dedicated unit tests for runCheck/runFix#784
jeduden wants to merge 4 commits into
mainfrom
claude/amazing-hopper-lostfp

Conversation

@jeduden

@jeduden jeduden commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Scheduled architecture audit (2026-08-02) of the 134 files touched
since the last sweep, following
docs/development/architecture/audit-checklist.md.

The one blocker: runCheck (cmd/mdsmith/check.go) and runFix
(cmd/mdsmith/fix.go) — the check and fix CLI subcommand entry
points — had no dedicated in-process unit test, only binary-spawn e2e
coverage. audit-checklist.md promotes a missing unit test to
blocker severity when the function is on a public surface such as a
CLI subcommand entry.

  • Adds TestRunCheck_UnknownFlag_ExitsTwo,
    TestRunCheck_Stdin_ChecksSource,
    TestRunCheck_Files_ExitsOneOnDiagnostics,
    TestRunCheck_Discovered_ChecksConfiguredFiles,
    TestRunFix_UnknownFlag_ExitsTwo,
    TestRunFix_StdinArg_ExitsTwo,
    TestRunFix_Files_FixesGivenFile, and
    TestRunFix_Discovered_FixesConfiguredFiles to
    cmd/mdsmith/main_unit_test.go, matching the TestRunInit_*
    precedent set by the 2026-07-19 audit cycle.
  • Records the full sweep in
    docs/development/architecture-audit.md (blockers/tax/nice-to-have,
    bumps audit-from).
  • Files plans for the two structural tax findings:
  • No blockers found elsewhere: no rule-to-rule imports, no
    reverse-layer imports, no Liskov breaks. The prior cycle's
    isClaimed dedup (plan 2607191918) is confirmed resolved.

Test plan

  • go build ./...
  • go test ./cmd/mdsmith/...
  • go vet ./...
  • go tool -modfile=tools/go.mod golangci-lint run (0 issues)
  • mdsmith check . (clean, 569 files)

Generated by Claude Code

The 2026-08-02 architecture audit flagged runCheck and runFix — the
check and fix CLI subcommand entry points — as missing dedicated
in-process unit tests, only reachable via binary-spawn e2e tests.
audit-checklist.md promotes a missing test on a CLI subcommand entry
to blocker severity.

Adds TestRunCheck_*/TestRunFix_* covering the flag-error, stdin,
explicit-files, and config-discovered branches, matching the
TestRunInit_* precedent already used for the init subcommand.

Also records the full audit sweep in architecture-audit.md and files
plans for the two structural tax findings (query-subcommand
placement, internal/githooks package split).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016AbFuwvqqq2fBiYWa3ubap
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.71%. Comparing base (2ab4b29) to head (c9ecdd2).

Additional details and impacted files
Components Coverage Δ
Go 98.70% <ø> (ø)
TypeScript 99.54% <ø> (ø)

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

claude added 2 commits August 2, 2026 19:26
- Strengthen TestRunCheck_Stdin_ChecksSource and
  TestRunCheck_Discovered_ChecksConfiguredFiles: both fed clean
  Markdown and asserted only exit code 0, which a silent
  stdin-routing or discovery bug could also produce. Switch to
  content with a trailing-space diagnostic and assert exit code 1
  plus the diagnostic source.
- Close the pipe read end in TestRunCheck_Stdin_ChecksSource,
  matching the close-both-ends convention used elsewhere in this
  file.
- Correct the touched-file count in the audit log (148, not 134 —
  two-dot diff --stat is the accurate count) and the internal/githooks
  line count cited in plan/2608021916 (1,346, not 1,347).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016AbFuwvqqq2fBiYWa3ubap
Round 2 of the code-review cycle on PR #784 found that the
stagingHelperShellFunc nice-to-have entry called it "the function" —
it's a const string literal, not a function.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016AbFuwvqqq2fBiYWa3ubap

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds in-process unit tests for the mdsmith check/mdsmith fix CLI entrypoints (runCheck / runFix) as part of the 2026-08-02 architecture audit sweep, and records the audit results plus follow-up plans.

Changes:

  • Add dedicated unit tests in cmd/mdsmith/main_unit_test.go covering runCheck / runFix routing and key exit-code behaviors.
  • Append the 2026-08-02 sweep results to the architecture audit log and bump the audit-from commit.
  • Add two new architecture “tax” plan files and register them in PLAN.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
plan/2608021916_arch-fix-githooks-package-split.md New plan capturing the SRP-driven split of internal/githooks into smaller responsibility-focused packages.
plan/2608021915_arch-fix-query-subcommand-placement.md New plan capturing the refactor to move list query logic out of cmd/mdsmith/main.go.
PLAN.md Registers the two newly added plan files in the plan catalog.
docs/development/architecture-audit.md Records the 2026-08-02 audit findings, notes the new tests added, and updates the audit range.
cmd/mdsmith/main_unit_test.go Adds the new unit tests for runCheck / runFix behaviors.
Suppressed comments (2)

cmd/mdsmith/main_unit_test.go:862

  • runCheck resolves files via loadAndResolve(), which calls loadConfig() and will walk up the directory tree to discover .mdsmith.yml unless it hits a .git boundary. Add a .git marker under the temp dir to keep the test isolated from any parent config and to avoid the rootward discovery walk.
	dir := t.TempDir()
	t.Chdir(dir)
	require.NoError(t, os.WriteFile(filepath.Join(dir, "dirty.md"),
		[]byte("# Title\n\nHello   \n"), 0o644))

cmd/mdsmith/main_unit_test.go:920

  • runFixfixFiles uses loadAndResolve(), which will try to discover config by walking up directories until a .git boundary. Without a .git marker in the temp dir, this test can become environment-dependent (and does extra filesystem walking). Add the .git marker before calling runFix.
	dir := t.TempDir()
	t.Chdir(dir)
	path := filepath.Join(dir, "fixme.md")
	require.NoError(t, os.WriteFile(path, []byte("# Title\n\nHello   \n"), 0o644))

Comment thread cmd/mdsmith/main_unit_test.go
Copilot review on #784 flagged TestRunCheck_Stdin_ChecksSource,
TestRunCheck_Files_ExitsOneOnDiagnostics, and
TestRunFix_Files_FixesGivenFile: none write their own .mdsmith.yml,
so loadConfig's upward discovery walk (internal/config/load.go)
would search from the temp dir all the way to the filesystem root
looking for one, since nothing marks the temp dir as a repo boundary.

Add a gitBoundary test helper that drops a .git marker directory,
matching the .git-boundary check config.Discover already stops at,
and use it in the three affected tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016AbFuwvqqq2fBiYWa3ubap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants