Fix: --tools alone falsely flagged as conflicting with --toolsets#380
Open
sebin wants to merge 2 commits into
Open
Fix: --tools alone falsely flagged as conflicting with --toolsets#380sebin wants to merge 2 commits into
sebin wants to merge 2 commits into
Conversation
getToolsetsFromCmd guarded against passing both --tools and --toolsets at
the same time by reading the --toolsets value and rejecting any value
that was non-empty and not "default". The persistent flag is declared
with default "all", so GetString returns "all" even when the operator
did not pass --toolsets, and the check fires unconditionally:
$ terraform-mcp-server --tools=search_providers
Cannot use both --tools and --toolsets flags together
pflag exposes Changed, which is true only when the operator set the flag
on the command line. Switching the check to Changed tests the intended
condition ("did the user supply --toolsets?") without coupling to the
declared default.
Adds two tests: one for the bug scenario (only --tools), one locking the
intended negative behavior (both flags explicitly set still triggers
the Fatal). Both use a logrus ExitFunc override so Fatal does not
terminate the test binary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #379.
Summary
getToolsetsFromCmdguards against passing both--toolsand--toolsetsat the same time. It does so by reading the--toolsetsvalue withGetStringand rejecting any value that is non-empty and not"default":--toolsetsis declared with default"all"ininit.go.GetStringreturns the default when the operator has not passed the flag, so the check fires every time someone passes only--tools:Change
Replace the value-based check with a
pflag.Flag.Changedcheck.Changedistrueonly when the operator set the flag on the command line, which is precisely the condition the original check was reaching for. The intent (forbid passing both flags) is preserved; the false positive on the declared default goes away.Diff is +8 / -5 in
main.goand a new test file.Verification
go test ./...passes (578/578).Test plan
TestToolsFlagAloneDoesNotConflictWithDefaultToolsets— passes only--tools, asserts the Fatal is not triggered (uses a logrusExitFuncoverride so a Fatal call would be observable without exiting the test binary).TestToolsAndToolsetsTogetherTriggersFatal— locks the negative behavior down: passing both flags explicitly must still Fatal.go test ./...— 578 pass../terraform-mcp-server stdio --tools=search_providersnow starts cleanly.