Skip to content

Fix: Add --version support to membraned CLI#36

Open
gabrnavarro wants to merge 1 commit intoBennettSchwartz:masterfrom
gabrnavarro:bot/task-31-issue-31
Open

Fix: Add --version support to membraned CLI#36
gabrnavarro wants to merge 1 commit intoBennettSchwartz:masterfrom
gabrnavarro:bot/task-31-issue-31

Conversation

@gabrnavarro
Copy link
Copy Markdown

@gabrnavarro gabrnavarro commented Apr 4, 2026

What changed

Added --version flag to the membraned CLI. Introduced a package-level version variable defaulting to "dev". When --version is passed, the daemon prints membraned <version> and exits 0.

Why

Release builds already inject version via -ldflags="-X main.version=${VERSION}" but there was no way for users to inspect the running binary's version.

Fixes #31

Testing

  • TestVersionFlag: subprocess test confirms --version prints the expected format and exits 0
  • TestVersionDefault: confirms the fallback value is non-empty ("dev")
  • go test ./cmd/membraned/... -v passes both tests
  • go vet ./... clean

Signed-off-by: gabrnavarro <gabrnavarro@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

A test file is added to validate membraned CLI version functionality. Two tests verify that the --version flag outputs correctly and that the version variable is initialized.

Changes

Cohort / File(s) Summary
Version Tests
cmd/membraned/version_test.go
New test file with TestVersionFlag validating --version flag output via subprocess testing pattern, and TestVersionDefault asserting the version variable is non-empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A testing rabbit hops with glee,
Version flags dance wild and free,
Subprocess spawns to validate,
Membraned's version now sealed in fate,
CLI blessed with clarity! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately reflects the main change—adding tests for the --version flag support. However, the PR only adds tests; the actual --version implementation already existed in main.go.
Linked Issues check ✅ Passed The PR adds comprehensive test coverage for --version functionality specified in #31, validating version flag output, exit code, and default fallback value.
Out of Scope Changes check ✅ Passed All changes are scoped to adding test coverage for the --version flag in membraned, which directly addresses the requirements in #31. No unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/membraned/version_test.go`:
- Around line 39-41: The test currently only checks a prefix; change it to
assert exact equality by trimming output (output :=
strings.TrimSpace(out.String())) and comparing it to the exact expected string
built from the package's version constant (e.g., expected := "membraned
"+Version or "membraned "+version if the symbol is lowercase), then use t.Errorf
when output != expected to show both values; update the assertion around the
output variable and remove the HasPrefix check so the test fails on any
formatting or extra output regressions.
- Around line 15-26: The subprocess block duplicates the --version flag logic
instead of exercising the real CLI; replace the inline flag parsing with a reset
of flag.CommandLine and os.Args and then invoke main() so the actual CLI path is
tested: when TEST_VERSION_SUBPROCESS == "1", set flag.CommandLine =
flag.NewFlagSet(os.Args[0], flag.ExitOnError), set os.Args =
[]string{"membraned", "--version"}, then call main() and exit (e.g., os.Exit(0))
after main() returns so the subprocess runs the real version handling code in
main().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fd832600-f415-43fd-8898-c59ec768a343

📥 Commits

Reviewing files that changed from the base of the PR and between 8e04372 and 55bd023.

📒 Files selected for processing (1)
  • cmd/membraned/version_test.go

Comment on lines +15 to +26
if os.Getenv("TEST_VERSION_SUBPROCESS") == "1" {
// We are the subprocess: run the version logic directly.
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
showVersion := flag.Bool("version", false, "print version and exit")
os.Args = []string{"membraned", "--version"}
flag.Parse()
if *showVersion {
fmt.Printf("membraned %s\n", version)
os.Exit(0)
}
os.Exit(1)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Subprocess test is validating duplicated logic, not the real CLI path.

Line 17-Line 25 re-implements --version behavior inline, so this test can still pass even if main() regresses. Execute main() in the subprocess after resetting args/flags.

Proposed fix
 if os.Getenv("TEST_VERSION_SUBPROCESS") == "1" {
-	// We are the subprocess: run the version logic directly.
+	// We are the subprocess: execute the real CLI entrypoint.
 	flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
-	showVersion := flag.Bool("version", false, "print version and exit")
 	os.Args = []string{"membraned", "--version"}
-	flag.Parse()
-	if *showVersion {
-		fmt.Printf("membraned %s\n", version)
-		os.Exit(0)
-	}
-	os.Exit(1)
+	main()
+	os.Exit(0)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if os.Getenv("TEST_VERSION_SUBPROCESS") == "1" {
// We are the subprocess: run the version logic directly.
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
showVersion := flag.Bool("version", false, "print version and exit")
os.Args = []string{"membraned", "--version"}
flag.Parse()
if *showVersion {
fmt.Printf("membraned %s\n", version)
os.Exit(0)
}
os.Exit(1)
}
if os.Getenv("TEST_VERSION_SUBPROCESS") == "1" {
// We are the subprocess: execute the real CLI entrypoint.
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
os.Args = []string{"membraned", "--version"}
main()
os.Exit(0)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/membraned/version_test.go` around lines 15 - 26, The subprocess block
duplicates the --version flag logic instead of exercising the real CLI; replace
the inline flag parsing with a reset of flag.CommandLine and os.Args and then
invoke main() so the actual CLI path is tested: when TEST_VERSION_SUBPROCESS ==
"1", set flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError), set
os.Args = []string{"membraned", "--version"}, then call main() and exit (e.g.,
os.Exit(0)) after main() returns so the subprocess runs the real version
handling code in main().

Comment on lines +39 to +41
output := strings.TrimSpace(out.String())
if !strings.HasPrefix(output, "membraned ") {
t.Errorf("expected output to start with 'membraned ', got: %q", output)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Assertion is too weak; verify exact output.

Line 40 only checks a prefix, which can hide formatting/extra-output regressions. Compare against the exact expected string.

Proposed fix
 output := strings.TrimSpace(out.String())
-if !strings.HasPrefix(output, "membraned ") {
-	t.Errorf("expected output to start with 'membraned ', got: %q", output)
+expected := fmt.Sprintf("membraned %s", version)
+if output != expected {
+	t.Errorf("expected %q, got: %q", expected, output)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/membraned/version_test.go` around lines 39 - 41, The test currently only
checks a prefix; change it to assert exact equality by trimming output (output
:= strings.TrimSpace(out.String())) and comparing it to the exact expected
string built from the package's version constant (e.g., expected := "membraned
"+Version or "membraned "+version if the symbol is lowercase), then use t.Errorf
when output != expected to show both values; update the assertion around the
output variable and remove the HasPrefix check so the test fails on any
formatting or extra output regressions.

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.

Add --version support to membraned CLI

1 participant