feat(mcpclient): fail-fast on empty bearer token
mcpclient.New previously accepted an empty token and silently omitted the Authorization header at request time. When the env var sourcing the token was missing from a Kubernetes Secret (envFrom doesn't warn on missing keys), this surfaced as an opaque 401 from the upstream MCP server with no log trail — see hyperguild #13 and brain entry "mcpclient-empty-token-silent-401-envfrom-missing-key". mcpclient.New now returns ErrTokenRequired when token is empty. The routing pod's project_create init checks the error and exits with a clear message pointing at routing-secrets, turning a runtime 401 storm into a startup crashloop the operator can fix immediately. Tests pass a dummy "test" token (httptest servers don't enforce bearer auth, so any non-empty value works). Added a regression test asserting empty-token construction returns ErrTokenRequired. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -125,7 +125,7 @@ func newSkill(t *testing.T, f *fakeGiteaMCP) (*project.Skill, *fakeGitHub) {
|
||||
t.Cleanup(ghSrv.Close)
|
||||
|
||||
return project.New(project.Config{
|
||||
Client: mcpclient.New(srv.URL, ""),
|
||||
Client: mustClient(t, srv.URL),
|
||||
GitHub: githubclient.New("ghp_test").WithBaseURL(ghSrv.URL),
|
||||
GiteaOwner: "mathias",
|
||||
GitHubOwner: "mathiasb",
|
||||
@@ -141,13 +141,23 @@ func newSkillNoGitHub(t *testing.T, f *fakeGiteaMCP) *project.Skill {
|
||||
srv := httptest.NewServer(f.handler())
|
||||
t.Cleanup(srv.Close)
|
||||
return project.New(project.Config{
|
||||
Client: mcpclient.New(srv.URL, ""),
|
||||
Client: mustClient(t, srv.URL),
|
||||
GiteaOwner: "mathias",
|
||||
GitHubOwner: "mathiasb",
|
||||
InfraRepo: "infra",
|
||||
})
|
||||
}
|
||||
|
||||
// mustClient builds an mcpclient against an httptest server. Uses a
|
||||
// non-empty dummy token because httptest servers don't enforce bearer
|
||||
// auth, but mcpclient.New now requires non-empty token (see #13).
|
||||
func mustClient(t *testing.T, url string) *mcpclient.Client {
|
||||
t.Helper()
|
||||
c, err := mcpclient.New(url, "test-token")
|
||||
require.NoError(t, err)
|
||||
return c
|
||||
}
|
||||
|
||||
func happyArgs() json.RawMessage {
|
||||
return json.RawMessage(`{
|
||||
"name":"my-experiment",
|
||||
|
||||
Reference in New Issue
Block a user