feat(cli): add internal/{text,compat} packages and acceptance scaffold (PR-6)
text/ gh-style display-width string helpers (Truncate / FuzzyAgo / Pluralize)
compat/ server-CLI version skew probe (kubectl) + 24h TTL cache (gh internal/update)
acceptance/contract/ helpers_test.go for in-process cobra exec + golden assert
(uses iostreams.SetForTest singleton replacement; no t.Parallel)
cmdutil/errors.go: AllCodes() + ClassifyHTTPErrorOutputs() bridge for the
contract test suite (no behavior change in error handling)
go-runewidth promoted from indirect to direct (used by text.Truncate for
display-width-aware CJK truncation).
acceptance/contract/helpers_test.go forward-references cmd.NewRootCmd which
is exported in PR-7 — that file does not compile until then by design.
This commit is contained in:
@@ -184,3 +184,47 @@ func ClassifyHTTPError(err error) ErrorCode {
|
||||
}
|
||||
return CodeServerError
|
||||
}
|
||||
|
||||
// AllCodes returns the registered error code set.
|
||||
// Used by acceptance/contract/errorcodes_test.go to validate that every code
|
||||
// referenced in cli/cmd/ is present here. Update this list whenever a new
|
||||
// ErrorCode constant is added above.
|
||||
func AllCodes() []ErrorCode {
|
||||
return []ErrorCode{
|
||||
// auth
|
||||
CodeAuthUnauthenticated, CodeAuthTokenExpired, CodeAuthBadCredential,
|
||||
CodeAuthForbidden, CodeAuthCrossTenantBlocked, CodeAuthTenantMismatch,
|
||||
// resource
|
||||
CodeResourceNotFound, CodeResourceAlreadyExists, CodeResourceLocked,
|
||||
// input
|
||||
CodeInputInvalidArgument, CodeInputMissingFlag,
|
||||
// server / network
|
||||
CodeServerError, CodeServerTimeout, CodeServerRateLimited,
|
||||
CodeServerIncompatibleVersion, CodeNetworkError,
|
||||
// local
|
||||
CodeLocalConfigCorrupt, CodeLocalKeychainDenied, CodeLocalFileIO,
|
||||
CodeLocalUnimplemented,
|
||||
// mcp
|
||||
CodeMCPReadonlyMode, CodeMCPToolNotAllowed, CodeMCPSchemaUnknown,
|
||||
// v0.1: context use — added in PR-7 (Task 15) when CodeLocalContextNotFound lands
|
||||
}
|
||||
}
|
||||
|
||||
// ClassifyHTTPErrorOutputs returns every code that ClassifyHTTPError can return.
|
||||
// Bridges the AST-friendly literal model with the dynamic switch inside
|
||||
// ClassifyHTTPError. errorcodes_test.go uses this to seed the "referenced codes"
|
||||
// set without trying to AST-introspect a function-call expression.
|
||||
//
|
||||
// IMPORTANT: keep in sync with the switch in ClassifyHTTPError.
|
||||
func ClassifyHTTPErrorOutputs() []ErrorCode {
|
||||
return []ErrorCode{
|
||||
CodeAuthUnauthenticated, // 401
|
||||
CodeAuthForbidden, // 403
|
||||
CodeResourceNotFound, // 404
|
||||
CodeResourceAlreadyExists, // 409
|
||||
CodeServerRateLimited, // 429
|
||||
CodeServerError, // 5xx / parse-failure / default
|
||||
CodeInputInvalidArgument, // 4xx (else)
|
||||
CodeNetworkError, // 非 HTTP error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user