From 2016570e2d475d0eef003b773e5e80559884792f Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Thu, 7 May 2026 13:16:03 +0300 Subject: [PATCH] test: add docstrings to rewritten tests and use t.Setenv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses two CodeRabbit feedback items on PR #24: * Docstring coverage warning (was 57.14%, threshold 80%): adds godoc comments to the four test functions added or substantially rewritten in this PR — TestLoadAndSaveManifest, TestAddAndRemoveFromManifest, TestFindInManifest, TestHighlightFileTokensInjectsANSI. * Quick-win nitpick: replaces the manual os.Setenv/os.Unsetenv + defer pattern in TestFindInManifest with t.Setenv, which restores the env var automatically on cleanup even on panic or t.Fatal. go test -race ./... still passes. --- internal/extensions/installer_test.go | 19 +++++++++++-------- internal/ui/render/blocks_test.go | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/internal/extensions/installer_test.go b/internal/extensions/installer_test.go index c10149fa..8008b427 100644 --- a/internal/extensions/installer_test.go +++ b/internal/extensions/installer_test.go @@ -245,6 +245,9 @@ func TestManifestEntryIdentity(t *testing.T) { } } +// TestLoadAndSaveManifest exercises the live *Installer.loadManifest / +// saveManifest round-trip against a temp directory, ensuring an absent +// manifest loads as empty and a saved manifest reads back identically. func TestLoadAndSaveManifest(t *testing.T) { tempDir := t.TempDir() installer := &Installer{ @@ -300,6 +303,9 @@ func TestLoadAndSaveManifest(t *testing.T) { } } +// TestAddAndRemoveFromManifest verifies that *Installer.addToManifest +// followed by removeFromManifest leaves the manifest in its original +// (empty) state, using a temp-directory installer scope. func TestAddAndRemoveFromManifest(t *testing.T) { tempDir := t.TempDir() installer := &Installer{ @@ -343,16 +349,13 @@ func TestAddAndRemoveFromManifest(t *testing.T) { } } +// TestFindInManifest writes a manifest file directly to the path +// resolved by the package-level manifestPathForScope helper and then +// confirms FindInManifest locates the entry by identity (and returns +// nil for a non-existent identity). func TestFindInManifest(t *testing.T) { tempDir := t.TempDir() - if err := os.Setenv("XDG_DATA_HOME", tempDir); err != nil { - t.Fatalf("Setenv() error = %v", err) - } - defer func() { - if err := os.Unsetenv("XDG_DATA_HOME"); err != nil { - t.Logf("Unsetenv() error = %v", err) - } - }() + t.Setenv("XDG_DATA_HOME", tempDir) // Write a manifest entry directly via the package-level path resolver // so FindInManifest (which uses manifestPathForScope) can read it back. diff --git a/internal/ui/render/blocks_test.go b/internal/ui/render/blocks_test.go index b2560343..9ba43adc 100644 --- a/internal/ui/render/blocks_test.go +++ b/internal/ui/render/blocks_test.go @@ -67,6 +67,9 @@ func TestHighlightFileTokens(t *testing.T) { } } +// TestHighlightFileTokensInjectsANSI verifies that HighlightFileTokens +// preserves the original @file references in the output and wraps each +// token with ANSI escape codes for the theme accent color. func TestHighlightFileTokensInjectsANSI(t *testing.T) { theme := style.DefaultTheme()