Skip to content

Conversation

@xenOs76
Copy link
Owner

@xenOs76 xenOs76 commented Jan 17, 2026

add more tests for cmd
add test for style handlers
add test for main.go
update go-testcoverag config

Summary by CodeRabbit

  • Tests
    • Expanded test suite: added tests for config loading, command execution, manual-page generation, and style/formatting utilities; adjusted a test entry point name.
  • Refactor
    • Command execution and main process now propagate errors so failures surface and yield non-zero exit status.
  • Chores
    • Increased test coverage threshold to 85%.

✏️ Tip: You can customize this high-level summary in your review settings.

add more tests for cmd
add test for style handlers
add test for main.go
update go-testcoverag config
@xenOs76 xenOs76 self-assigned this Jan 17, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

Execute() now returns an error and main adds Run() to propagate and handle that error; tests were added/updated for command execution, configuration loading, man generation, and style handlers; test coverage threshold increased and exclude paths adjusted.

Changes

Cohort / File(s) Summary
Error handling / CLI entry
cmd/root.go, main.go, main_test.go
cmd.Execute() signature changed to func Execute() error; added func Run() error in main.go which calls cmd.Execute(); main() now prints errors to stderr and exits non‑zero. Added TestRun in main_test.go.
Command tests & behavior
cmd/config_test.go, cmd/man_test.go, cmd/root_test.go
Renamed test TestNewHTTPSWrenchConfigTestConfig_NewHTTPSWrenchConfig; added cmd/man_test.go with TestMan exercising the man command and temp dir handling; expanded cmd/root_test.go with TestRootCmd_LoadConfig, TestRootCmd_Execute, added subtests for config loading (no config, embedded config), flags, CA bundle, and embedded requests metadata.
Style package tests
internal/style/style_handlers_test.go
Added comprehensive unit tests (~234 lines) covering key generation helpers (RSA/ECDSA/ED25519), PrintKeyInfoStyle, LgSprintf, StatusCodeParse, BoolStyle, and CodeSyntaxHighlight with parallel subtests and output assertions.
Coverage config
.testcoverage.yml
Increased threshold.total from 80 to 85; removed internal/style/style_handlers.go and cmd/main.go$ from exclude.paths, leaving only main.go$.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Main as Main (main.Run / main.main)
    participant Cmd as Cmd (cmd.Execute)
    participant Root as Root (rootCmd.Execute)
    participant OS as OS (stderr / os.Exit)

    User->>Main: start program
    Main->>Cmd: Run() calls cmd.Execute()
    Cmd->>Root: rootCmd.Execute() runs CLI
    Root-->>Cmd: return error or nil
    Cmd-->>Main: propagate result
    alt error returned
        Main->>OS: print error to stderr
        Main->>OS: exit(1)
    else success
        Main-->>User: exit normally
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Test/cmd initial #18 — modifies the same test infrastructure and overlapping test files (related to renamed/added tests and coverage adjustments).

Poem

🐰 I hopped through code with nimble feet,
Run calls Execute so errors meet,
Tests sprout in meadows, style blossoms bright,
Coverage climbs by morning light,
A happy rabbit hops tonight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding test coverage for cmd, style handlers, and main.go, which aligns with all file modifications in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Fix all issues with AI agents
In `@cmd/man_test.go`:
- Around line 10-26: The man command currently swallows errors from
doc.GenManTree in the manCmd Run handler, so change the Cobra command to use
RunE for manCmd and return any error from doc.GenManTree (propagating filesystem
errors) instead of only printing them; update the TestMan test to assert success
by checking the generated file exists (e.g. require.FileExists for
filepath.Join(destDir, "https-wrench.1.gz")) and to expect an error when running
with a non-existent dir (rootCmd.SetArgs(... "fake-dir") should lead to a
non-nil error), ensuring rootCmd.Execute() surfaces the failure.

In `@cmd/root_test.go`:
- Around line 61-71: The test currently calls Execute() but ignores its return
value so failures won't fail the test; update TestRootCmd_Execute to capture the
result of Execute() (e.g., err := Execute()) and assert it using
require.NoError(t, err) (or require.Error if the expected behavior is a failure)
after LoadConfig(), referencing the TestRootCmd_Execute test, cfgFile,
initConfig, LoadConfig and Execute() so the test fails on unexpected Execute()
outcomes.
- Around line 15-58: The subtest mutates global test state by setting cfgFile
and calling initConfig() (which sets viper global config), so save the original
cfgFile before changing it and restore it after the subtest, and reset viper's
global state to avoid leaking into other tests: in the "LoadConfig embedded
config file" subtest capture old := cfgFile, then set cfgFile =
"./embedded/config-example.yaml", call initConfig(), and defer a cleanup that
restores cfgFile = old and calls viper.Reset() (or reinitializes the viper
instance used by initConfig()) so TestRootCmd_LoadConfig and other tests don't
produce order-dependent failures.

In `@internal/style/style_handlers_test.go`:
- Around line 44-97: In TestPrintKeyInfoStyle update the typo in the test case
name from "ed21219 private key" to "ed25519 private key" inside the tests slice
so the test case for the ed25519Key (variable ed25519Key) correctly reflects the
key type; locate the tests variable in TestPrintKeyInfoStyle and change the name
field of that struct literal only.
- Around line 100-156: The tests compare raw expected strings against
lipgloss-styled outputs (from LgSprintf, StatusCodeParse, BoolStyle) which
include ANSI escape sequences; update the tests to strip ANSI sequences before
asserting by adding a small helper (e.g., StripANSI or stripANSIEscapeCodes) and
call it on the rendered output (the value returned by LgSprintf,
StatusCodeParse, BoolStyle) prior to require.Equal so you compare plain text;
locate usages of LgSprintf, StatusCodeParse, and BoolStyle in the tests and
replace direct assertions with assertions against StripANSI(rendered) ==
expected.

In `@main_test.go`:
- Around line 9-14: Rename the test function named TestMain to TestRun to avoid
shadowing Go's special TestMain(m *testing.M); update the test declaration to
func TestRun(t *testing.T) and keep the inner subtest calling Run() (and
require.NoError), and ensure any references to TestMain in this file or test
suite are updated accordingly so the test still executes as intended.
🧹 Nitpick comments (2)
cmd/root.go (1)

83-90: Consider simplifying the return logic.

The error handling can be condensed since rootCmd.Execute() already returns the appropriate error (or nil).

♻️ Suggested simplification
 func Execute() error {
-	err := rootCmd.Execute()
-	if err != nil {
-		return err
-	}
-
-	return nil
+	return rootCmd.Execute()
 }
main.go (1)

39-42: Consider simplifying Run().

Similar to Execute(), this can be a one-liner.

♻️ Suggested simplification
 func Run() error {
-	err := cmd.Execute()
-	return err
+	return cmd.Execute()
 }

add cleanup function to tests in cmd/root
fix error handling, typos, file checks
@xenOs76 xenOs76 changed the title ci: complete tests test: add coverage for cmd, style handlers, and main.go Jan 17, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@cmd/root_test.go`:
- Around line 78-89: TestRootCmd_Execute mutates the global cfgFile and viper
state via initConfig() but doesn't restore them; save the original cfgFile at
the start of the subtest, and defer restoring it and re-running initConfig() (or
otherwise resetting viper) so global state is returned to its prior value;
ensure you reference cfgFile and initConfig() in the defer to mirror the cleanup
pattern used in TestRootCmd_LoadConfig and TestRootCmd.

In `@internal/style/style_handlers_test.go`:
- Line 174: The long HTML sample line in the raw string inside
internal/style/style_handlers_test.go exceeds the configured line-length; fix it
by either splitting that long literal into multiple concatenated lines
(preserving the test assertions and exact content) or append a targeted nolint
directive to suppress revive for that line (e.g., add a //nolint:revive comment
on the offending raw string line) so golangci-lint no longer warns; locate the
long line by searching for the raw HTML sample used in the test and update the
raw string accordingly.
♻️ Duplicate comments (1)
internal/style/style_handlers_test.go (1)

100-155: Strip ANSI escape codes before assertions in style-output tests.

LgSprintf, StatusCodeParse, and BoolStyle render via lipgloss, which emits ANSI sequences; direct string equality is brittle and likely to fail. This was already flagged in prior review.

🧽 Suggested fix (strip ANSI before comparing)
 import (
 	"bytes"
 	"crypto"
 	"crypto/ecdsa"
 	"crypto/ed25519"
 	"crypto/elliptic"
 	"crypto/rand"
 	"crypto/rsa"
 	"fmt"
+	"regexp"
 	"testing"
 
 	"github.com/stretchr/testify/require"
 )
 
+var ansiRE = regexp.MustCompile(`\x1b\[[0-9;]*m`)
+
+func stripANSI(s string) string {
+	return ansiRE.ReplaceAllString(s, "")
+}
 ...
-			simple := LgSprintf(Status, "%s", tt)
+			simple := stripANSI(LgSprintf(Status, "%s", tt))
 			require.Equal(t, tt, simple)
 
-			pattern := LgSprintf(Status, "%s - lorem ipsum", tt)
+			pattern := stripANSI(LgSprintf(Status, "%s - lorem ipsum", tt))
 			require.Equal(t, tt+" - lorem ipsum", pattern)
 ...
-			s := StatusCodeParse(tt.statusInt)
+			s := stripANSI(StatusCodeParse(tt.statusInt))
 			require.Equal(t, tt.statusString, s)
 ...
-			s := BoolStyle(tt.statusBool)
+			s := stripANSI(BoolStyle(tt.statusBool))
 			require.Equal(t, tt.statusString, s)

@xenOs76 xenOs76 merged commit 9e230af into main Jan 17, 2026
5 checks passed
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.

2 participants