feat(cli): agent-first WeKnora CLI
The `weknora` command-line client for the WeKnora RAG server. Full command surface: kb / doc / chunk / session / message / agent / model / search / chat / auth / profile / link / api / mcp / skills / config / doctor / schema / exit-codes. Agent-first wire contract: JSON envelope by default, typed error codes mapped to stable exit codes, error.retry_argv / retryable / partial-failure status, global --dry-run preview, the exit-10 confirmation protocol for writes, and control/ANSI/Bidi input hygiene. Stateless env-credential auth (WEKNORA_API_KEY / WEKNORA_TOKEN + WEKNORA_HOST) for headless/CI/agent use. A curated read-only MCP tool surface (`mcp serve`) and embedded Agent Skills (`skills install`). Extensive unit + contract-golden tests and CI.
This commit is contained in:
@@ -74,6 +74,53 @@ func TestWriteBatchEnvelope_EmptyItems_EmitsEmptyArray(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWriteBatchEnvelope_StatusTriState verifies the additive tri-state
|
||||
// envelope.status: "success" (all ok), "partial" (mixed), "error" (all fail).
|
||||
func TestWriteBatchEnvelope_StatusTriState(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
items []output.BatchItem
|
||||
status string
|
||||
}{
|
||||
{
|
||||
name: "all_success",
|
||||
items: []output.BatchItem{
|
||||
{ID: "a", OK: true}, {ID: "b", OK: true},
|
||||
},
|
||||
status: "success",
|
||||
},
|
||||
{
|
||||
name: "partial",
|
||||
items: []output.BatchItem{
|
||||
{ID: "a", OK: true},
|
||||
{ID: "b", OK: false, Error: &output.ErrDetail{Type: "resource.not_found", Message: "missing"}},
|
||||
},
|
||||
status: "partial",
|
||||
},
|
||||
{
|
||||
name: "all_fail",
|
||||
items: []output.BatchItem{
|
||||
{ID: "a", OK: false, Error: &output.ErrDetail{Type: "auth.forbidden", Message: "no perm"}},
|
||||
{ID: "b", OK: false, Error: &output.ErrDetail{Type: "resource.not_found", Message: "missing"}},
|
||||
},
|
||||
status: "error",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
if err := output.WriteBatchEnvelope(&buf, tc.items, false, ""); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
got := buf.String()
|
||||
want := `"status":"` + tc.status + `"`
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("expected %s; got %q", want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteBatchEnvelope_AllFail(t *testing.T) {
|
||||
items := []output.BatchItem{
|
||||
{ID: "id1", OK: false, Error: &output.ErrDetail{Type: "auth.forbidden", Message: "no perm"}},
|
||||
|
||||
Reference in New Issue
Block a user