Skip to content

Commit 7f0dcdf

Browse files
anton-107Isaac
andcommitted
aitools: typed fetch, state and agent CLI timeout errors
`aitools install` failures that used to be `UNCATEGORIZED` now get a specific `error_category`. The installer returns typed errors and `classifyInstallError` maps them: ```text classifyInstallError(err) BlockedError TimedOut -> PLUGIN_CLI_TIMEOUT (agent CLI killed by its timeout) FetchError{Stage, StatusCode, RateLimited} (release / manifest / skill file) context.Canceled -> COMMAND_INTERRUPTED transport failure -> NETWORK / TIMEOUT (no response, or a timeout/reset while reading the body) RateLimited -> RATE_LIMITED (429, or 403 with GitHub's rate-limit headers) clicompat.ErrNotFound -> MANIFEST_NOT_FOUND Stage == release -> RELEASE_LOOKUP_FAILED JSON syntax/type error -> MANIFEST_INVALID otherwise -> SKILLS_FETCH_FAILED StateError{Path} -> STATE_INVALID (unparsable .state.json) ``` - `FetchError` and `StateError` keep the wrapped error's message, so what the user sees does not change. - A fetch that fails on the transport (no response, or a timeout or reset while reading the body) keeps reporting `NETWORK` or `TIMEOUT`, as before. - A missing manifest wraps `clicompat.ErrNotFound`, so `clicompat.IsNotFoundError` stays the one way to check for a missing ref. - An unreadable state file is not a `StateError`: it keeps its filesystem category. - `FetchManifest` reads the whole body (capped at 1 MiB, like the release lookup) before parsing it, so a connection closed cleanly mid-body (`SKILLS_FETCH_FAILED`; a reset reports `NETWORK`) is told apart from an empty or truncated manifest (`MANIFEST_INVALID`). - Changelog fragment: `.nextchanges/cli/aitools-install-fetch-error-categories.md`. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent ae31019 commit 7f0dcdf

14 files changed

Lines changed: 501 additions & 43 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `databricks aitools install --output json` reports more specific `error_category` values: `SKILLS_FETCH_FAILED`, `RELEASE_LOOKUP_FAILED`, `RATE_LIMITED`, `MANIFEST_INVALID`, `STATE_INVALID` and `PLUGIN_CLI_TIMEOUT`. A coding agent CLI that does not answer in time is now reported as `timed out after <duration>` instead of with its stderr. ([#7475](https://github.com/databricks/cli/pull/7475))

‎acceptance/cmd/aitools/telemetry/install-failure/output.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Error: skills manifest at databricks-agent-skills@missing-ref: not found
3333
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"MANIFEST_NOT_FOUND","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"GLOBAL"}}
3434
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"MANIFEST_NOT_FOUND"}}
3535

36-
=== any other HTTP error status from the manifest fetch is not classified yet (the error is untyped)
36+
=== any other HTTP error status from the manifest fetch is SKILLS_FETCH_FAILED
3737

3838
>>> DATABRICKS_SKILLS_REF=broken-ref [CLI] aitools install --skills-only --scope=global --agents=cursor
3939
Installing Databricks skills for Cursor...
@@ -47,8 +47,8 @@ Error: failed to fetch manifest: HTTP 500
4747
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
4848
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
4949
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
50-
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"UNCATEGORIZED","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"GLOBAL"}}
51-
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"UNCATEGORIZED"}}
50+
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"SKILLS_FETCH_FAILED","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"GLOBAL"}}
51+
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"SKILLS_FETCH_FAILED"}}
5252

5353
=== a named agent skipped for the scope takes its category from the agent's outcome
5454

‎acceptance/cmd/aitools/telemetry/install-failure/script‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ title "a manifest the server does not have is MANIFEST_NOT_FOUND"
1515
musterr trace DATABRICKS_SKILLS_REF=missing-ref $CLI aitools install --skills-only --scope=global --agents=cursor
1616
trace print_telemetry
1717

18-
title "any other HTTP error status from the manifest fetch is not classified yet (the error is untyped)"
18+
title "any other HTTP error status from the manifest fetch is SKILLS_FETCH_FAILED"
1919
musterr trace DATABRICKS_SKILLS_REF=broken-ref $CLI aitools install --skills-only --scope=global --agents=cursor
2020
trace print_telemetry
2121

‎cmd/aitools/categorize.go‎

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package aitools
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"io/fs"
78
"net"
@@ -57,6 +58,14 @@ func classifyInstallError(err error) protos.AitoolsErrorCategory {
5758
if skill, ok := errors.AsType[*installer.SkillError](err); ok {
5859
return skillErrorCategory(skill)
5960
}
61+
// FetchError is checked before the standard library types: a response
62+
// that arrived carries a status the net error types know nothing about.
63+
if fetch, ok := errors.AsType[*installer.FetchError](err); ok {
64+
return fetchErrorCategory(fetch)
65+
}
66+
if _, ok := errors.AsType[*installer.StateError](err); ok {
67+
return protos.AitoolsErrorCategoryStateInvalid
68+
}
6069
if tagged, ok := errors.AsType[*categorizedError](err); ok {
6170
return tagged.category
6271
}
@@ -71,11 +80,11 @@ func classifyInstallError(err error) protos.AitoolsErrorCategory {
7180
}
7281

7382
// stdlibErrorCategory classifies errors by their standard library type, which
74-
// the installer wraps with %w: network and timeout errors from fetching the
75-
// manifest or skill files, and filesystem errors from writing skills or the
76-
// install state. JSON decode errors stay UNCATEGORIZED: the manifest, the
77-
// release payload and the install state all decode JSON, so only typed
78-
// installer errors can tell MANIFEST_INVALID from STATE_INVALID.
83+
// the installer wraps with %w: filesystem errors from writing skills or the
84+
// install state, and network and timeout errors, including those of a
85+
// FetchError that got no response. JSON decode errors stay UNCATEGORIZED: the
86+
// manifest, the release payload and the install state all decode JSON, so only
87+
// typed installer errors can tell MANIFEST_INVALID from STATE_INVALID.
7988
func stdlibErrorCategory(err error) protos.AitoolsErrorCategory {
8089
switch {
8190
case errors.Is(err, huh.ErrUserAborted):
@@ -133,7 +142,52 @@ func skillErrorCategory(e *installer.SkillError) protos.AitoolsErrorCategory {
133142
}
134143
}
135144

145+
// fetchErrorCategory maps a FetchError to its category. The first matching
146+
// case wins, so the order matters: an interrupted command is never a fetch
147+
// failure, a transport failure keeps its NETWORK or TIMEOUT category, and the
148+
// release stage is checked before the decode check.
149+
func fetchErrorCategory(e *installer.FetchError) protos.AitoolsErrorCategory {
150+
// The command was interrupted while the request was in flight: the fetch
151+
// did not fail on its own.
152+
if errors.Is(e, context.Canceled) {
153+
return protos.AitoolsErrorCategoryCommandInterrupted
154+
}
155+
// No response arrived (DNS, refused connection, proxy, TLS, client
156+
// timeout), or reading the body failed on the transport (a timeout or a
157+
// reset mid-body): the user cannot reach the host, which NETWORK and
158+
// TIMEOUT already report.
159+
if c := stdlibErrorCategory(e.Err); e.StatusCode == 0 || c == protos.AitoolsErrorCategoryNetwork || c == protos.AitoolsErrorCategoryTimeout {
160+
return c
161+
}
162+
switch {
163+
case e.RateLimited:
164+
return protos.AitoolsErrorCategoryRateLimited
165+
case errors.Is(e, clicompat.ErrNotFound):
166+
return protos.AitoolsErrorCategoryManifestNotFound
167+
// Before the decode check: a release payload that does not decode is a
168+
// failed release lookup, not an invalid manifest.
169+
case e.Stage == installer.FetchStageRelease:
170+
return protos.AitoolsErrorCategoryReleaseLookupFailed
171+
// The response arrived but was not a manifest: content, not transport.
172+
case isManifestDecodeError(e):
173+
return protos.AitoolsErrorCategoryManifestInvalid
174+
default:
175+
return protos.AitoolsErrorCategorySkillsFetchFailed
176+
}
177+
}
178+
179+
// isManifestDecodeError reports whether the response arrived but was not a
180+
// valid manifest.
181+
func isManifestDecodeError(err error) bool {
182+
_, syntax := errors.AsType[*json.SyntaxError](err)
183+
_, typ := errors.AsType[*json.UnmarshalTypeError](err)
184+
return syntax || typ
185+
}
186+
136187
func blockedErrorCategory(e *installer.BlockedError) protos.AitoolsErrorCategory {
188+
if e.TimedOut {
189+
return protos.AitoolsErrorCategoryPluginCLITimeout
190+
}
137191
switch e.Reason {
138192
case installer.ReasonCLINotOnPath:
139193
return protos.AitoolsErrorCategoryCLINotOnPath

‎cmd/aitools/categorize_test.go‎

Lines changed: 166 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import (
77
"fmt"
88
"io/fs"
99
"net"
10+
"net/http"
11+
"net/http/httptest"
1012
"net/url"
1113
"os"
1214
"path/filepath"
15+
"strconv"
16+
"strings"
1317
"syscall"
1418
"testing"
19+
"time"
1520

1621
"github.com/charmbracelet/huh"
1722
"github.com/databricks/cli/libs/aitools/installer"
@@ -42,6 +47,66 @@ func TestClassifyInstallError(t *testing.T) {
4247
err: &installer.BlockedError{Agent: "codex", Reason: installer.ReasonInstallFailed},
4348
want: protos.AitoolsErrorCategoryPluginInstallFailed,
4449
},
50+
{
51+
name: "blocked timeout wins over its reason",
52+
err: &installer.BlockedError{Agent: "claude-code", Reason: installer.ReasonCLINotOnPath, TimedOut: true},
53+
want: protos.AitoolsErrorCategoryPluginCLITimeout,
54+
},
55+
{
56+
name: "release lookup failed",
57+
err: fmt.Errorf("resolve latest skills release: %w", &installer.FetchError{Stage: installer.FetchStageRelease, StatusCode: 500, Err: errors.New("HTTP 500 fetching latest skills release")}),
58+
want: protos.AitoolsErrorCategoryReleaseLookupFailed,
59+
},
60+
{
61+
name: "release lookup with no response is NETWORK",
62+
err: fmt.Errorf("resolve latest skills release: %w", &installer.FetchError{Stage: installer.FetchStageRelease, Err: &url.Error{Op: "Get", URL: "https://example.test", Err: &net.DNSError{Err: "no such host"}}}),
63+
want: protos.AitoolsErrorCategoryNetwork,
64+
},
65+
{
66+
name: "release payload that does not decode is not an invalid manifest",
67+
err: &installer.FetchError{Stage: installer.FetchStageRelease, StatusCode: 200, Err: fmt.Errorf("parse latest skills release: %w", &json.SyntaxError{})},
68+
want: protos.AitoolsErrorCategoryReleaseLookupFailed,
69+
},
70+
{
71+
name: "release lookup rate limited",
72+
err: &installer.FetchError{Stage: installer.FetchStageRelease, StatusCode: 403, RateLimited: true, Err: errors.New("HTTP 403")},
73+
want: protos.AitoolsErrorCategoryRateLimited,
74+
},
75+
{
76+
name: "release lookup denied without rate-limit evidence",
77+
err: &installer.FetchError{Stage: installer.FetchStageRelease, StatusCode: 403, Err: errors.New("HTTP 403")},
78+
want: protos.AitoolsErrorCategoryReleaseLookupFailed,
79+
},
80+
{
81+
name: "manifest fetch rate limited",
82+
err: &installer.FetchError{Stage: installer.FetchStageManifest, StatusCode: 429, RateLimited: true, Err: errors.New("HTTP 429")},
83+
want: protos.AitoolsErrorCategoryRateLimited,
84+
},
85+
{
86+
name: "manifest fetch with no response is NETWORK",
87+
err: &installer.FetchError{Stage: installer.FetchStageManifest, Err: fmt.Errorf("failed to fetch manifest: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: &net.OpError{Op: "dial", Net: "tcp", Err: os.NewSyscallError("connect", syscall.ECONNREFUSED)}})},
88+
want: protos.AitoolsErrorCategoryNetwork,
89+
},
90+
{
91+
name: "skill file fetch that timed out is TIMEOUT",
92+
err: &installer.FetchError{Stage: installer.FetchStageFile, Err: &url.Error{Op: "Get", URL: "https://example.test", Err: os.ErrDeadlineExceeded}},
93+
want: protos.AitoolsErrorCategoryTimeout,
94+
},
95+
{
96+
name: "skill file fetch failed",
97+
err: fmt.Errorf("failed to fetch skills/x/SKILL.md: %w", &installer.FetchError{Stage: installer.FetchStageFile, StatusCode: 500, Err: errors.New("HTTP 500")}),
98+
want: protos.AitoolsErrorCategorySkillsFetchFailed,
99+
},
100+
{
101+
name: "manifest missing at the pinned ref",
102+
err: &installer.FetchError{Stage: installer.FetchStageManifest, StatusCode: 404, Err: fmt.Errorf("skills manifest at x@v9: %w", clicompat.ErrNotFound)},
103+
want: protos.AitoolsErrorCategoryManifestNotFound,
104+
},
105+
{
106+
name: "state file invalid",
107+
err: fmt.Errorf("failed to load install state: %w", &installer.StateError{Path: "/s/.state.json", Err: errors.New("failed to parse state file")}),
108+
want: protos.AitoolsErrorCategoryStateInvalid,
109+
},
45110
{
46111
name: "blocked error with unknown reason is uncategorized",
47112
err: &installer.BlockedError{Agent: "codex", Reason: "some-future-reason"},
@@ -102,12 +167,12 @@ func TestClassifyInstallErrorGenericCauses(t *testing.T) {
102167
err error
103168
want protos.AitoolsErrorCategory
104169
}{
105-
{"network", fmt.Errorf("failed to fetch manifest: %w", urlErr), protos.AitoolsErrorCategoryNetwork},
170+
{"network", fmt.Errorf("fetch: %w", urlErr), protos.AitoolsErrorCategoryNetwork},
106171
// The shape net/http returns for a refused connection: the Errno sits under the network types.
107-
{"network errno", fmt.Errorf("failed to fetch manifest: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: &net.OpError{Op: "dial", Net: "tcp", Err: os.NewSyscallError("connect", syscall.ECONNREFUSED)}}), protos.AitoolsErrorCategoryNetwork},
172+
{"network errno", fmt.Errorf("fetch: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: &net.OpError{Op: "dial", Net: "tcp", Err: os.NewSyscallError("connect", syscall.ECONNREFUSED)}}), protos.AitoolsErrorCategoryNetwork},
108173
// A sandbox that blocks outbound sockets: a network failure, even though the Errno is EACCES.
109-
{"network permission denied", fmt.Errorf("failed to fetch manifest: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: &net.OpError{Op: "dial", Net: "tcp", Err: os.NewSyscallError("connect", syscall.EACCES)}}), protos.AitoolsErrorCategoryNetwork},
110-
{"network timeout", fmt.Errorf("failed to fetch manifest: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: os.ErrDeadlineExceeded}), protos.AitoolsErrorCategoryTimeout},
174+
{"network permission denied", fmt.Errorf("fetch: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: &net.OpError{Op: "dial", Net: "tcp", Err: os.NewSyscallError("connect", syscall.EACCES)}}), protos.AitoolsErrorCategoryNetwork},
175+
{"network timeout", fmt.Errorf("fetch: %w", &url.Error{Op: "Get", URL: "https://example.test", Err: os.ErrDeadlineExceeded}), protos.AitoolsErrorCategoryTimeout},
111176
{"deadline", fmt.Errorf("fetch: %w", context.DeadlineExceeded), protos.AitoolsErrorCategoryTimeout},
112177
{"cancelled", fmt.Errorf("fetch: %w", context.Canceled), protos.AitoolsErrorCategoryCommandInterrupted},
113178
{"cancelled request", &url.Error{Op: "Get", URL: "https://example.test", Err: context.Canceled}, protos.AitoolsErrorCategoryCommandInterrupted},
@@ -144,15 +209,14 @@ func TestWithCategoryKeepsMessage(t *testing.T) {
144209
assert.ErrorIs(t, err, cause)
145210
}
146211

147-
// A corrupt install state must not be blamed on the remote manifest. It stays
148-
// UNCATEGORIZED until the installer returns a typed state error, which should
149-
// change this to STATE_INVALID.
150-
func TestClassifyInstallErrorCorruptStateIsUncategorized(t *testing.T) {
212+
// A corrupt install state must not be blamed on the remote manifest: the
213+
// installer's typed StateError makes it STATE_INVALID.
214+
func TestClassifyInstallErrorCorruptStateIsStateInvalid(t *testing.T) {
151215
dir := t.TempDir()
152216
require.NoError(t, os.WriteFile(filepath.Join(dir, ".state.json"), []byte("{not json"), 0o600))
153217
_, err := installer.LoadState(dir)
154218
require.Error(t, err)
155-
assert.Equal(t, protos.AitoolsErrorCategoryUncategorized, classifyInstallError(fmt.Errorf("failed to load install state: %w", err)))
219+
assert.Equal(t, protos.AitoolsErrorCategoryStateInvalid, classifyInstallError(fmt.Errorf("failed to load install state: %w", err)))
156220
}
157221

158222
// readMissingFile returns the error the OS gives for a missing file, so the
@@ -163,3 +227,96 @@ func readMissingFile(t *testing.T) error {
163227
require.Error(t, err)
164228
return err
165229
}
230+
231+
func TestClassifyCancelledManifestFetchIsCommandInterrupted(t *testing.T) {
232+
ctx, cancel := context.WithCancel(t.Context())
233+
server := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
234+
// Cancel while the request is in flight, then wait for the client to give up.
235+
cancel()
236+
<-r.Context().Done()
237+
}))
238+
t.Cleanup(server.Close)
239+
t.Setenv("DATABRICKS_SKILLS_BASE_URL", server.URL)
240+
241+
_, err := (&installer.GitHubManifestSource{}).FetchManifest(ctx, "v1")
242+
require.ErrorIs(t, err, context.Canceled)
243+
assert.Equal(t, protos.AitoolsErrorCategoryCommandInterrupted, classifyInstallError(err))
244+
}
245+
246+
// A response whose body stalls or is cut off by a reset is a transport
247+
// failure, not a failed fetch: it keeps TIMEOUT or NETWORK.
248+
func TestClassifyManifestBodyTransportFailure(t *testing.T) {
249+
t.Run("stalled body", func(t *testing.T) {
250+
release := make(chan struct{})
251+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
252+
w.Header().Set("Content-Length", "100")
253+
w.WriteHeader(http.StatusOK)
254+
_, _ = w.Write([]byte(`{"skills":`))
255+
w.(http.Flusher).Flush()
256+
select {
257+
case <-release:
258+
case <-r.Context().Done():
259+
}
260+
}))
261+
t.Cleanup(server.Close)
262+
t.Cleanup(func() { close(release) })
263+
t.Setenv("DATABRICKS_SKILLS_BASE_URL", server.URL)
264+
265+
ctx, cancel := context.WithTimeout(t.Context(), 200*time.Millisecond)
266+
defer cancel()
267+
_, err := (&installer.GitHubManifestSource{}).FetchManifest(ctx, "v1")
268+
require.Error(t, err)
269+
assert.Equal(t, protos.AitoolsErrorCategoryTimeout, classifyInstallError(err))
270+
})
271+
272+
t.Run("reset mid-body", func(t *testing.T) {
273+
err := &installer.FetchError{Stage: installer.FetchStageManifest, StatusCode: http.StatusOK, Err: fmt.Errorf("failed to read manifest: %w", &net.OpError{Op: "read", Net: "tcp", Err: os.NewSyscallError("read", syscall.ECONNRESET)})}
274+
assert.Equal(t, protos.AitoolsErrorCategoryNetwork, classifyInstallError(err))
275+
})
276+
277+
t.Run("release body timeout", func(t *testing.T) {
278+
err := &installer.FetchError{Stage: installer.FetchStageRelease, StatusCode: http.StatusOK, Err: fmt.Errorf("parse latest skills release: %w", os.ErrDeadlineExceeded)}
279+
assert.Equal(t, protos.AitoolsErrorCategoryTimeout, classifyInstallError(err))
280+
})
281+
}
282+
283+
func TestClassifyRealManifestFetchErrors(t *testing.T) {
284+
tests := []struct {
285+
name string
286+
status int
287+
body string
288+
// cutOff announces a longer body than is sent, so the connection
289+
// closes mid-body.
290+
cutOff bool
291+
want protos.AitoolsErrorCategory
292+
}{
293+
// A captive portal or broken mirror answers 200 with something else.
294+
{name: "200 with HTML", status: http.StatusOK, body: "<html>login</html>", want: protos.AitoolsErrorCategoryManifestInvalid},
295+
{name: "200 with the wrong JSON shape", status: http.StatusOK, body: `{"skills": []}`, want: protos.AitoolsErrorCategoryManifestInvalid},
296+
{name: "200 with an empty body", status: http.StatusOK, body: "", want: protos.AitoolsErrorCategoryManifestInvalid},
297+
{name: "200 with incomplete JSON", status: http.StatusOK, body: `{"skills":`, want: protos.AitoolsErrorCategoryManifestInvalid},
298+
// The body is read up to 1 MiB: past that the manifest is cut off, so the
299+
// valid object after the padding is never parsed.
300+
{name: "200 with a body over the size cap", status: http.StatusOK, body: strings.Repeat(" ", 1<<20) + "{}", want: protos.AitoolsErrorCategoryManifestInvalid},
301+
{name: "connection closed mid-body", status: http.StatusOK, body: `{"skills":`, cutOff: true, want: protos.AitoolsErrorCategorySkillsFetchFailed},
302+
{name: "404", status: http.StatusNotFound, want: protos.AitoolsErrorCategoryManifestNotFound},
303+
{name: "503", status: http.StatusServiceUnavailable, want: protos.AitoolsErrorCategorySkillsFetchFailed},
304+
}
305+
for _, tc := range tests {
306+
t.Run(tc.name, func(t *testing.T) {
307+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
308+
if tc.cutOff {
309+
w.Header().Set("Content-Length", strconv.Itoa(len(tc.body)+100))
310+
}
311+
w.WriteHeader(tc.status)
312+
_, _ = w.Write([]byte(tc.body))
313+
}))
314+
t.Cleanup(server.Close)
315+
t.Setenv("DATABRICKS_SKILLS_BASE_URL", server.URL)
316+
317+
_, err := (&installer.GitHubManifestSource{}).FetchManifest(t.Context(), "v1")
318+
require.Error(t, err)
319+
assert.Equal(t, tc.want, classifyInstallError(err))
320+
})
321+
}
322+
}

0 commit comments

Comments
 (0)