Repository navigation
Apply the not-an-agent header guard to the remaining CLI SDK clients - #8144
Conversation
…clients The root and bundle clients drop the SDK agent token from User-Agent under DATABRICKS_NOT_AN_AGENT, but the commands that build their own SDK config still sent it. Call ApplyNotAnAgentHeader on those configs before their clients are built, after any transport a site sets: auth login, auth describe, auth profiles, auth docker, configure, aitools mcp, labs, the api command, the experimental ssh upload client, and the root picked-profile fallbacks. The wrapper now forwards SkipRetryOnIO from its base, which the SDK checks on cfg.HTTPTransport, so fixture transports keep their skip-retry behaviour. The Windows skip in the bundle config test is dropped. Listener-based tests such as cmd/root and bundle/generate run on the Windows CI cell without a skip. Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 3 changed tests (limit=20, 0 not selected) 3 tests: regression=3 unreleased=0 coverage=0 failing=0
TestAccept/cmd/aitools/not-an-agent: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): TestAccept/cmd/api/not-an-agent: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): TestAccept/cmd/auth/describe/not-an-agent: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): same output as main (e6f3460) |
Take the base's profileConfig helper for the picked-profile prompt paths in cmd/root/auth.go, and its TestWorkspaceClientNotAnAgentWrapsTransport in bundle/config/workspace_test.go, which runs on Windows. Keep the SkipRetryOnIO forwarding on the header wrapper and the remaining SDK call sites. Co-authored-by: Isaac <no-reply@databricks.com>
✅ Integration test reportCommit: b0d95ed
Top 6 slowest tests (at least 2 minutes):
|
Git Bash rewrote the leading slash of /api/2.0/clusters/list into a Windows path, so the mock server got no handler. Set MSYS_NO_PATHCONV=1 on both api calls, as the other api acceptance scripts do. Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at 4089a20. Each finding was verified against the code.
No blocking issues found. 4 non-blocking comment(s) below.
This PR extends the DATABRICKS_NOT_AN_AGENT User-Agent guard to the CLI commands that build their own SDK config, and makes the transport wrapper forward SkipRetryOnIO. The production wiring is mostly sound. A few things are worth fixing before merge: the auth describe hunk duplicates a wrap that root already applies, and the acceptance test meant to cover it never reaches it. In auth profiles the wrap lands after the config's metadata fetch. The new unit tests also don't isolate the agent environment, and the new acceptance test stubs a route the testserver already models.
| // pointer (config.Config must not be copied by value), without any profile | ||
| // prompting. | ||
| func verifyWorkspaceAuth(ctx context.Context, cfg *config.Config) (*iam.User, error) { | ||
| agent.ApplyNotAnAgentHeader(ctx, cfg) |
There was a problem hiding this comment.
[nice to have] verifyWorkspaceAuth has one caller, the account branch at line 142, and it passes a.Config. MustAccountClient (cmd/root/auth.go:243) has already wrapped that config, so this line only puts a second noAgentHeaderTransport around the first. The new acceptance/cmd/auth/describe/not-an-agent test uses a workspace PAT profile. It gets its Me request from the root workspace client at line 150 and would still pass with this hunk reverted. Can we drop this line? If it should stay, the test needs an account profile whose Workspaces.List fails, so that it actually reaches this function.
There was a problem hiding this comment.
Done in 8283226: dropped the guard from verifyWorkspaceAuth. Its caller passes the account client config, which MustAccountClient already guards, and a profile picked at a prompt goes through profileConfig, which guards too. So the second wrap is gone and the describe acceptance test no longer needs an account profile.
| callCtx, cancel := context.WithTimeout(ctx, timeout) | ||
| defer cancel() | ||
|
|
||
| agent.ApplyNotAnAgentHeader(ctx, cfg) |
There was a problem hiding this comment.
[nice to have] The wrap runs after cfg.EnsureResolved() at line 73. The comment above that call says it fetches /.well-known/databricks-config through the SDK. So with DATABRICKS_NOT_AN_AGENT=1 CLAUDECODE=1, that request can go out on the unwrapped transport, and only the later Me/Workspaces.List call drops the token. The new test can't see this because its server answers every other path with a 404 and doesn't record it. cmd/labs/project/entrypoint.go:128 has the same ordering: validLogin has already called cfg.EnsureResolved() by then. Can we apply the guard right after cfg is built, before EnsureResolved, the way MustWorkspaceClient does?
There was a problem hiding this comment.
Done in 8283226: the guard now runs before EnsureResolved in profile Load, as MustWorkspaceClient does. The labs validLogin guards its login config before EnsureResolved as well, and the replacement account config before its own EnsureResolved. The SDK host metadata fetch uses an internal client without the agent header visitors, so in v0.204.0 that request never carried the token, with or without the guard. The move keeps the guard ahead of any resolve-time request anyway. The profile test now records the well-known request too and checks it has no agent token with the variable set.
| // TestGuardedClientNotAnAgentDropsAgentHeader checks that the serve's client leaves the agent token out of User-Agent | ||
| // under DATABRICKS_NOT_AN_AGENT, and keeps it without the variable. | ||
| func TestGuardedClientNotAnAgentDropsAgentHeader(t *testing.T) { | ||
| t.Setenv("CLAUDECODE", "1") |
There was a problem hiding this comment.
[nice to have] This test sets CLAUDECODE=1 with t.Setenv and calls useragent.ClearCache itself, so the runner's environment still leaks in. If the suite runs with DATABRICKS_NOT_AN_AGENT=1, or inside another agent that sets its own variable (the SDK then reports agent/multiple), the "variable unset" case fails its Contains "agent/claude-code" assertion. The same setup is in cmd/auth/profiles_test.go:335, cmd/labs/project/entrypoint_test.go:20 and experimental/ssh/internal/client/releases_test.go:417. Can these use testutil.SetAgentEnv(t, "CLAUDECODE", "1") from internal/testutil/agent.go, as the parent's tests do? Note that it clears HOME, which the profiles test already sets itself.
There was a problem hiding this comment.
Done in 8283226: the four tests (aitools mcp serve, auth profiles, labs entrypoint, ssh releases) now call testutil.SetAgentEnv(t, "CLAUDECODE", "1") in place of t.Setenv plus ClearCache. The profile test still sets HOME itself, as before.
| New = "" | ||
|
|
||
| [[Server]] | ||
| Pattern = "GET /api/2.0/preview/scim/v2/Me" |
There was a problem hiding this comment.
[nice to have] .agents/rules/testing.md says to reserve [[Server]] for routes the testserver doesn't model. GET /api/2.0/preview/scim/v2/Me is already handled in libs/testserver/handlers.go:247, which also sets X-Databricks-Org-Id. This stub replaces that with a fixed body and no header. The test only checks the request's User-Agent, so can we drop the [[Server]] block and regenerate the output?
There was a problem hiding this comment.
Done in 8283226: dropped the [[Server]] stub from the describe not-an-agent test. The testserver answers the Me call, and the regenerated output is unchanged.
Co-authored-by: Isaac <no-reply@databricks.com>
Guard the profile validation and labs login config before EnsureResolved, so the host metadata fetch goes through the guarded transport too. Drop the guard in auth describe's workspace check: the account client it receives is already guarded. Tests that set the agent environment use testutil.SetAgentEnv, so the runner's own environment does not leak into the variable-unset case. The auth describe acceptance test drops its Me stub, since the testserver already answers that call. Co-authored-by: Isaac <no-reply@databricks.com>
The Windows CI cells panicked in httptest.NewServer while listening on loopback, which aborted the whole cmd/labs/project test run. The test only needs one cluster response, so it now uses a fixture transport on cfg.HTTPTransport. The not-an-agent wrapper still sits on that transport, so the User-Agent the test checks is the one the guard leaves. Co-authored-by: Isaac <no-reply@databricks.com>
This pull request is stacked on #8143 and merges after it. The CLI commands that build their own SDK config still sent the
agent/<name>User-Agent token underDATABRICKS_NOT_AN_AGENT, so this change applies the guard to those configs.Changes
DATABRICKS_NOT_AN_AGENT, the clients built outside the root command path now drop the agent token:auth login(cluster picker and workspace list),auth describe,auth profiles,auth docker,configure --configure-cluster,aitools mcp(add and serve), the labs entrypoint, installer and login,api, and the experimental SSH upload client.agent.ApplyNotAnAgentHeaderbefore its client is built, after any transport the site sets.SkipRetryOnIOfrom its base. The SDK checks that method oncfg.HTTPTransport, so fixture transports keep their skip-retry behaviour.cmd/rootand the bundle workspace test come from the parent pull request. This branch no longer changes them.Why
The root and bundle clients already drop the token. The other sites build their own config, and the SDK has no per-client option for this, so each site wraps its own config.
Decisions to review
guardedClientincmd/aitools/mcp_serve.gonow takes acontext.Context, so the guard reads the same environment as the command.auth login,auth docker,configure,aitools mcp add, the labs installer and login, and the picked-profile fallbacks get the same call but no check, because they need an interactive prompt or a populated profile store. The checks coverapi,auth describe,auth profiles, the labs cluster client, the SSH upload client andmcp serve's client.DATABRICKS_NOT_AN_AGENTis read without the preview gate, but it is meant for evals and internal use, so its entry goes in at launch.Tests
TestNoAgentHeaderTransportForwardsSkipRetryOnIOcovers the forwarded method for a fixture transport and a plain one.TestGuardedClientNotAnAgentDropsAgentHeader,TestNewHTTP11WorkspaceClientNotAnAgentDropsAgentHeader,TestEnsureRunningClusterNotAnAgentDropsAgentHeaderandTestProfileLoadNotAnAgentDropsAgentHeader.TestWorkspaceClientNotAnAgentWrapsTransportinbundle/config(from the parent) checks the bundle client's transport with the variable set and unset. It has no Windows skip.cmd/api/not-an-agentandcmd/auth/describe/not-an-agentrecord the request User-Agent with and without the variable.cmd/api,cmd/auth,cmd/aitools,cmd/configureandcmd/skillspass with no existing golden changed../task --force fmt-q lint-qreports 0 issues.This pull request and its description were written by Isaac.