feat(cli): add api passthrough, chat streaming, doctor warn status

Close the v0.2 RAG demo loop and ship the validation infrastructure:

  - weknora api <method> <path> [--data X | --data-file F]
      Raw passthrough wrapping client.Raw, gh-style. JSON envelope mode
      surfaces status / headers / parsed body. Non-2xx routes through
      cmdutil.ClassifyHTTPStatus (factored out of ClassifyHTTPError so
      both SDK-error and direct-status paths stay aligned — reuse review).

  - weknora chat <text> [--session-id S] [--no-stream]
      KnowledgeQAStream consumer with two output modes:
        - TTY default: token streaming + references footer
        - --json / --no-stream / non-TTY: buffered single envelope
      Auto-creates a session when --session-id is omitted; the id prints
      to stderr at start AND on stream failure (^C scrolls past the
      first announcement, so the recovery hint is re-surfaced when the
      user is most likely to need it).

  - cli/internal/sse/Accumulator
      buffers Content / References / SessionID across SDK callbacks.
      Idempotent post-Done so misbehaving servers don't corrupt state.

  - doctor: ok → ok / warn / fail / skip
      warn marks soft issues that don't block: server within compat range
      but >=1 minor behind CLI; credential storage falling back to file
      because keyring is unavailable. Envelope.ok stays true on warn,
      flips false on fail (exit 1). doctor.error_network golden updated.

  - cli/acceptance/e2e/    real-server RAG full loop
      Build-tagged //go:build acceptance_e2e — kept out of the default
      `go test ./...`. Exercises kb create → doc upload → poll ready →
      search → chat → cleanup against a server pointed at by
      WEKNORA_E2E_HOST / _TOKEN.

  - .github/workflows/cli-e2e.yml
      manual workflow_dispatch + label-gated PR trigger
      ("acceptance-e2e"). No-ops gracefully when the secrets aren't set
      so cross-fork PRs can't accidentally fail the suite.
This commit is contained in:
nullkey
2026-05-11 02:44:13 +08:00
committed by lyingbug
parent 8a0674186e
commit 3fb3583a92
16 changed files with 1935 additions and 67 deletions
+10 -9
View File
@@ -95,12 +95,14 @@ var envelopeCases = []envelopeCase{
// 5. doctor.error_network — base_url returns 500 → ping fail → cascade
// skip on auth_credential + server_version. credential_storage still
// runs (independent). Doctor's RunE always returns nil; envelope.ok=true
// with summary.failed >= 1.
// runs (independent). v0.2 contract: any check=fail flips envelope.ok
// to false and exits 1 (RunE returns SilentError so the data envelope
// written by emit() is preserved as the only stdout content).
{
name: "doctor.error_network",
args: []string{"doctor", "--json"},
server: alwaysServerError,
name: "doctor.error_network",
args: []string{"doctor", "--json"},
server: alwaysServerError,
wantErr: true,
},
// 6-9. kb list / get — SDK paths /api/v1/knowledge-bases[/<id>]
@@ -167,12 +169,12 @@ var envelopeCases = []envelopeCase{
// 14-16. search — top-level command, positional query, --kb required.
{
name: "search.success",
args: []string{"search", "query", "--kb=kb1", "--top-k=3", "--json"},
args: []string{"search", "query", "--kb-id=kb1", "--top-k=3", "--json"},
server: searchTwoResults,
},
{
name: "search.error_resource_not_found",
args: []string{"search", "query", "--kb=missing", "--json"},
args: []string{"search", "query", "--kb-id=missing", "--json"},
server: always404,
wantErr: true,
},
@@ -181,7 +183,7 @@ var envelopeCases = []envelopeCase{
// server mock is never consumed; we still pass --kb to satisfy the
// MarkFlagRequired check that fires earlier in cobra's parse phase.
name: "search.error_input_invalid",
args: []string{"search", "query", "--kb=kb1", "--no-vector", "--no-keyword", "--json"},
args: []string{"search", "query", "--kb-id=kb1", "--no-vector", "--no-keyword", "--json"},
wantErr: true,
},
}
@@ -191,7 +193,6 @@ var envelopeCases = []envelopeCase{
// is contractually forbidden — see helpers_test.go SetForTest comment).
func TestEnvelopeGolden(t *testing.T) {
for _, tc := range envelopeCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
var ts *httptest.Server
var mockClient *sdk.Client