Skip to content

Hide web token "already set" message#1949

Merged
lionello merged 4 commits intomainfrom
lio/fix-webtoken-msg
Feb 28, 2026
Merged

Hide web token "already set" message#1949
lionello merged 4 commits intomainfrom
lio/fix-webtoken-msg

Conversation

@lionello
Copy link
Member

@lionello lionello commented Feb 27, 2026

Description

Best reviewed per commit. I've renamed "cluster" to "fabricAddr".

Linked Issues

Fixes #1886

Checklist

  • I have performed a self-review of my code
  • I have added appropriate tests
  • I have updated the Defang CLI docs and/or README to reflect my changes, if necessary

Summary by CodeRabbit

  • Chores
    • Unified the CLI to consistently use a fabric address for connection targets (flag and config mapping preserved), improving reliability of connect/login/logout/whoami/workspace flows and token handling.
    • Updated debugging, provisioning, and tooling flows to reference the new address field so printed URLs, debug sessions, and setup/login prompts reflect the unified address.
    • Tests and mocks updated to match the new address-based wiring.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6afaba and daef760.

📒 Files selected for processing (1)
  • src/cmd/cli/command/globals.go

📝 Walkthrough

Walkthrough

This PR consistently replaces the "cluster" concept with "fabricAddr" across CLI commands, client connection code, login/logout flows, agent/debug/mcp components, and related tests—updating struct fields, function signatures, flag bindings, and call sites without altering core control flow.

Changes

Cohort / File(s) Summary
CLI command wiring & globals
src/cmd/cli/command/commands.go, src/cmd/cli/command/commands_test.go, src/cmd/cli/command/globals.go, src/cmd/cli/command/globals_test.go
Flag binding and global config now expose FabricAddr instead of Cluster; tests updated to assert FabricAddr.
Command implementations
src/cmd/cli/command/... (compose.go, compose_test.go, debug.go, generate.go, init.go, login.go, logout.go, mcp.go, session.go, whoami.go, workspace.go)
All command handlers pass global.FabricAddr to client/login/agent/debug initialization and SetupClient literals; error/debug paths updated accordingly.
Client connection layer
src/pkg/cli/client/cluster.go, src/pkg/cli/connect.go
Renamed DefaultCluster → DefaultFabricAddr and updated public APIs to accept fabricAddr (NormalizeHost, token helpers, Connect, ConnectWithTenant, etc.).
Login/logout surfaces
src/pkg/login/login.go, src/pkg/login/login_test.go, src/pkg/cli/logout.go, src/pkg/cli/logout_test.go
Replaced cluster parameter with fabricAddr across login flows, token saving/removal, and interactive/non-interactive flows; tests updated.
Agent and tools interfaces
src/pkg/agent/agent.go, src/pkg/agent/tools/interfaces.go, src/pkg/agent/tools/default_tool_cli.go, src/pkg/agent/tools/auth.go
agent.New and tool interface methods renamed to accept fabricAddr; StackConfig/struct fields updated to FabricAddr.
Agent tool tests
src/pkg/agent/tools/*_test.go (deploy_test.go, destroy_test.go, estimate_test.go, listConfig_test.go, removeConfig_test.go, services_test.go, setConfig_test.go)
Mock CLI method signatures and test StackConfig usage updated from ClusterFabricAddr; log messages and call sites adjusted.
Debug, MCP, and tools aliasing
src/pkg/debug/debug.go, src/pkg/mcp/mcp_server.go, src/pkg/mcp/tools/tools.go
NewDebugger and related calls accept fabricAddr; ToolTracker and MCP logging use fabricAddr; StackConfig exposed as alias to agentTools.StackConfig.
Setup & provisioning
src/pkg/setup/setup.go, src/cmd/cli/command/generate.go
SetupClient struct now includes FabricAddr (Cluster removed); provisioning/login/ToS flows use FabricAddr.
Misc tests & small fixes
src/pkg/cli/composeUp_test.go, src/pkg/cli/configSet_test.go, src/pkg/cli/getServices_test.go, various test files
Minor test adaptations: generic call-site removal, receiver changes for mocks, added test short-mode skip, and other name updates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • Rename packages #1730: Overlaps with CLI/client signature and cluster→fabricAddr renames in the connection layer.
  • Stack tools #1713: Touches debug.NewDebugger and agent initialization changes similar to this PR.
  • MCP login bug #1767: Related to GetClientWithRetry and authentication/connect logic affected by the cluster→fabricAddr refactor.

Suggested reviewers

  • jordanstephens
  • edwardrf

Poem

🐰 A hop, a rename, through code I dart,
From cluster to fabric, each function a part.
Flags and tokens now call a new name,
Tests updated, logs sing the same.
🥕 Cheers — the refactor's a tidy art!

🚥 Pre-merge checks | ✅ 1 | ❌ 4

❌ Failed checks (4 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title focuses on hiding a web token message, but the changeset primarily implements a comprehensive refactoring renaming 'cluster' to 'fabricAddr' across 40+ files with minimal changes to address the linked issue #1886. Update the title to reflect the primary change: 'Refactor cluster identifier to fabricAddr' or similar, or separately address issue #1886's message suppression in a focused commit.
Linked Issues check ⚠️ Warning Issue #1886 requires consolidating AWS_WEB_IDENTITY_TOKEN_FILE checks in two places (cluster.go and login.go) to suppress redundant messages, but the changeset only renames parameters without addressing the duplicate check/set logic or message suppression. Modify cluster.go and login.go to consolidate the AWS_WEB_IDENTITY_TOKEN_FILE environment variable checks and eliminate the redundant 'already set' message, or document why consolidation was not needed.
Out of Scope Changes check ⚠️ Warning The changeset extensively refactors 'cluster' to 'fabricAddr' across 40+ files (commands, packages, tests), which is a large-scope refactoring unrelated to the core issue #1886 about suppressing a redundant warning message. This appears to be scope creep or a separate refactoring bundled with the fix. Separate the cluster-to-fabricAddr refactoring into a distinct PR, leaving only the message suppression changes for issue #1886 in this PR.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
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 docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lio/fix-webtoken-msg

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

level=warning msg="[linters_context] running gomodguard failed: unable to read module file go.mod: current working directory must have a go.mod file: if you are not using go modules it is suggested to disable this linter"
level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

Copy link
Contributor

@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: 1

🧹 Nitpick comments (4)
src/pkg/cli/connect.go (1)

15-17: Debug message still references "cluster" after parameter rename.

The parameter was renamed to fabricAddr, but the debug message on line 17 still says "cluster %q". Consider updating for consistency:

 func Connect(fabricAddr string, requestedTenant types.TenantNameOrID) *client.GrpcClient {
 	host := client.NormalizeHost(fabricAddr)
-	term.Debugf("Using tenant %q for cluster %q", requestedTenant, host)
+	term.Debugf("Using tenant %q for fabric %q", requestedTenant, host)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pkg/cli/connect.go` around lines 15 - 17, Update the debug message in the
Connect function to reflect the renamed parameter: replace the outdated "cluster
%q" wording with something like "fabric %q" or "fabric address %q". Locate the
term.Debugf call in Connect (variables requestedTenant and host) and modify the
format string so it reads "Using tenant %q for fabric %q" (or similar) while
keeping the same arguments.
src/pkg/agent/tools/setConfig_test.go (1)

97-103: Consider renaming the test constant for consistency.

The test struct field was renamed to fabricAddr, but the constant is still named testCluster. This is a minor inconsistency.

 	const (
-		testCluster    = "test-cluster"
+		testFabricAddr = "test-fabric"
 		testConfigName = "test-config"
 		testValue      = "test-value"
 	)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pkg/agent/tools/setConfig_test.go` around lines 97 - 103, Rename the test
constant testCluster to a name consistent with the renamed test struct field
(e.g., testFabricAddr or testFabric) and update all usages in the
setConfig_test.go file so the constant name matches the struct field fabricAddr;
ensure testConfigName and testValue remain unchanged and adjust any test case
initializers that refer to testCluster to use the new constant name (look for
the constants block and the tests []struct initializer).
src/pkg/mcp/mcp_server.go (1)

34-34: Consider renaming analytics property key for consistency.

You now pass t.fabricAddr under the "cluster" property key. If analytics consumers already migrated, consider using a fabricAddr key to avoid semantic drift.

Possible cleanup
- track.Evt("MCP Tool Called", track.P("tool", name), track.P("client", t.client), track.P("cluster", t.fabricAddr), track.P("provider", *t.providerId))
+ track.Evt("MCP Tool Called", track.P("tool", name), track.P("client", t.client), track.P("fabricAddr", t.fabricAddr), track.P("provider", *t.providerId))

- track.Evt("MCP Tool Done", track.P("tool", name), track.P("client", t.client), track.P("cluster", t.fabricAddr), track.P("provider", *t.providerId), track.P("error", err))
+ track.Evt("MCP Tool Done", track.P("tool", name), track.P("client", t.client), track.P("fabricAddr", t.fabricAddr), track.P("provider", *t.providerId), track.P("error", err))

Also applies to: 41-41

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pkg/mcp/mcp_server.go` at line 34, Rename the analytics property key so
it consistently reflects the underlying value: replace the use of the "cluster"
property when calling track.Evt with a "fabricAddr" property (e.g., change
track.Evt(..., track.P("cluster", t.fabricAddr), ...) to track.P("fabricAddr",
t.fabricAddr)). Update every occurrence in this file where t.fabricAddr is
passed under "cluster" (including the other call around line 41) to use
"fabricAddr" instead so analytics payloads remain semantically consistent.
src/cmd/cli/command/commands_test.go (1)

113-117: Make the test helper scheme-agnostic for future HTTPS test servers.

The current helper strips only http://. If a test later uses TLS (https://), the --cluster argument may include a scheme unexpectedly.

♻️ Suggested tweak
 func testCommand(t *testing.T, args []string, fabricAddr string) error {
 	t.Helper()
 	if fabricAddr != "" {
-		args = append(args, "--cluster", strings.TrimPrefix(fabricAddr, "http://"))
+		addr := strings.TrimPrefix(strings.TrimPrefix(fabricAddr, "http://"), "https://")
+		args = append(args, "--cluster", addr)
 	}
 	RootCmd.SetArgs(args)
 	return RootCmd.ExecuteContext(context.Background()) // t.Context() only works for first test?
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/cli/command/commands_test.go` around lines 113 - 117, In testCommand,
the helper currently strips only the "http://" prefix from fabricAddr which
fails for "https://" test servers; update the logic in testCommand to be
scheme-agnostic by parsing fabricAddr (e.g., using url.Parse or equivalent) and
extracting only the Host (or Hostname:Port) before appending the "--cluster" arg
so both "http://" and "https://" (and any other schemes) are handled correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cmd/cli/command/globals.go`:
- Line 150: The ToMap serialization uses the wrong key "DEFANG_CLUSTER" for the
FabricAddr field, causing config round-trip drift; update the map assignment in
ToMap to use "DEFANG_FABRIC" instead of "DEFANG_CLUSTER" so FabricAddr
(global.FabricAddr) is serialized under the same key the initializer reads,
ensuring consistent load/save behavior.

---

Nitpick comments:
In `@src/cmd/cli/command/commands_test.go`:
- Around line 113-117: In testCommand, the helper currently strips only the
"http://" prefix from fabricAddr which fails for "https://" test servers; update
the logic in testCommand to be scheme-agnostic by parsing fabricAddr (e.g.,
using url.Parse or equivalent) and extracting only the Host (or Hostname:Port)
before appending the "--cluster" arg so both "http://" and "https://" (and any
other schemes) are handled correctly.

In `@src/pkg/agent/tools/setConfig_test.go`:
- Around line 97-103: Rename the test constant testCluster to a name consistent
with the renamed test struct field (e.g., testFabricAddr or testFabric) and
update all usages in the setConfig_test.go file so the constant name matches the
struct field fabricAddr; ensure testConfigName and testValue remain unchanged
and adjust any test case initializers that refer to testCluster to use the new
constant name (look for the constants block and the tests []struct initializer).

In `@src/pkg/cli/connect.go`:
- Around line 15-17: Update the debug message in the Connect function to reflect
the renamed parameter: replace the outdated "cluster %q" wording with something
like "fabric %q" or "fabric address %q". Locate the term.Debugf call in Connect
(variables requestedTenant and host) and modify the format string so it reads
"Using tenant %q for fabric %q" (or similar) while keeping the same arguments.

In `@src/pkg/mcp/mcp_server.go`:
- Line 34: Rename the analytics property key so it consistently reflects the
underlying value: replace the use of the "cluster" property when calling
track.Evt with a "fabricAddr" property (e.g., change track.Evt(...,
track.P("cluster", t.fabricAddr), ...) to track.P("fabricAddr", t.fabricAddr)).
Update every occurrence in this file where t.fabricAddr is passed under
"cluster" (including the other call around line 41) to use "fabricAddr" instead
so analytics payloads remain semantically consistent.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 751d287 and b6afaba.

📒 Files selected for processing (39)
  • src/cmd/cli/command/commands.go
  • src/cmd/cli/command/commands_test.go
  • src/cmd/cli/command/compose.go
  • src/cmd/cli/command/compose_test.go
  • src/cmd/cli/command/debug.go
  • src/cmd/cli/command/generate.go
  • src/cmd/cli/command/globals.go
  • src/cmd/cli/command/globals_test.go
  • src/cmd/cli/command/init.go
  • src/cmd/cli/command/login.go
  • src/cmd/cli/command/logout.go
  • src/cmd/cli/command/mcp.go
  • src/cmd/cli/command/session.go
  • src/cmd/cli/command/whoami.go
  • src/cmd/cli/command/workspace.go
  • src/pkg/agent/agent.go
  • src/pkg/agent/tools/auth.go
  • src/pkg/agent/tools/default_tool_cli.go
  • src/pkg/agent/tools/deploy_test.go
  • src/pkg/agent/tools/destroy_test.go
  • src/pkg/agent/tools/estimate_test.go
  • src/pkg/agent/tools/interfaces.go
  • src/pkg/agent/tools/listConfig_test.go
  • src/pkg/agent/tools/removeConfig_test.go
  • src/pkg/agent/tools/services_test.go
  • src/pkg/agent/tools/setConfig_test.go
  • src/pkg/cli/client/cluster.go
  • src/pkg/cli/composeUp_test.go
  • src/pkg/cli/configSet_test.go
  • src/pkg/cli/connect.go
  • src/pkg/cli/getServices_test.go
  • src/pkg/cli/logout.go
  • src/pkg/cli/logout_test.go
  • src/pkg/debug/debug.go
  • src/pkg/login/login.go
  • src/pkg/login/login_test.go
  • src/pkg/mcp/mcp_server.go
  • src/pkg/mcp/tools/tools.go
  • src/pkg/setup/setup.go

@lionello lionello requested a review from edwardrf February 27, 2026 18:40
@lionello lionello merged commit 540f1c7 into main Feb 28, 2026
14 checks passed
@lionello lionello deleted the lio/fix-webtoken-msg branch February 28, 2026 16:32
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.

AWS_WEB_IDENTITY_TOKEN_FILE is already set; not using token file always appear as we check and set it in 2 different places

3 participants