Add a shared error-code catalog so failures can be traced by stable codes.
Services can resolve legacy aliases and expose the catalog over CLI and HTTP instead of ad-hoc error strings. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"error-code-system/domains"
|
||||
"error-code-system/errcode"
|
||||
)
|
||||
|
||||
func TestCLIListShowValidate(t *testing.T) {
|
||||
reg := errcode.NewRegistry()
|
||||
domains.RegisterAll(reg)
|
||||
prev := errcode.Default
|
||||
errcode.Default = reg
|
||||
t.Cleanup(func() { errcode.Default = prev })
|
||||
|
||||
var out, errBuf bytes.Buffer
|
||||
if code := Run([]string{"list", "--domain", "sys"}, &out, &errBuf); code != 0 {
|
||||
t.Fatal(errBuf.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "sys.internal") || strings.Contains(out.String(), "agent.") {
|
||||
t.Fatalf("list:\n%s", out.String())
|
||||
}
|
||||
|
||||
out.Reset()
|
||||
if code := Run([]string{"show", "TIMEOUT"}, &out, &errBuf); code != 0 {
|
||||
t.Fatal(errBuf.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), string(errcode.AgentTimeout)) {
|
||||
t.Fatalf("show:\n%s", out.String())
|
||||
}
|
||||
|
||||
out.Reset()
|
||||
if code := Run([]string{"validate", "nope"}, &out, &errBuf); code != 1 {
|
||||
t.Fatalf("validate exit %d %s", code, out.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "known=false") || !strings.Contains(out.String(), string(errcode.SysUnknownCode)) {
|
||||
t.Fatalf("validate:\n%s", out.String())
|
||||
}
|
||||
|
||||
out.Reset()
|
||||
if code := Run([]string{"search", "角色"}, &out, &errBuf); code != 0 {
|
||||
t.Fatal(errBuf.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), string(errcode.SquadRoleNotFound)) {
|
||||
t.Fatalf("search:\n%s", out.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user