feat(cli): --json field-select, --jq, auth token, doc --from-url
Output ergonomics:
- `--json` accepts a comma-separated field list (gh-parity); selects
named keys from the per-command payload. Bare `--json` keeps the
full shape.
- `--jq <expr>` evaluates a gojq expression over the JSON; pairs with
`--json field-list` so projection runs before jq.
- `--version` is a global cobra flag in addition to the `version`
subcommand; both render the same line.
- Per-command `--help` now renders the available JSON field list under
"JSON fields available via `--json id,name,...`" (field-discovery
parity with gh / kubectl `-o jsonpath`).
New commands:
- `auth token` — print the active context's credential to stdout for
shell command substitution (`WEKNORA_TOKEN=$(weknora auth token)`).
Default: raw secret, no trailing newline. `--json` emits
`{token, mode, context}`.
- `doc upload --from-url <URL>` — ingest a remote URL via the SDK
`CreateKnowledgeFromURL`. `--name` forwarded as `FileName` so the
server's known-extension heuristic upgrades crawl-mode to
file-download-mode where appropriate.
Includes the simplify post-review polish pass (field-filter unit
tests, --json/--jq compose check, agent_help copy fixes).
This commit is contained in:
@@ -67,7 +67,7 @@ func TestDoctor_AllOK(t *testing.T) {
|
||||
systemInfo: &sdk.SystemInfo{Version: "1.0.0"},
|
||||
userResp: goodUserResp(),
|
||||
}
|
||||
r := runChecks(context.Background(), &Options{JSONOut: true}, svc, "1.0.0")
|
||||
r := runChecks(context.Background(), &Options{}, svc, "1.0.0")
|
||||
if !r.Summary.AllPassed {
|
||||
t.Errorf("expected all_passed, got summary %+v", r.Summary)
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func TestDoctor_AllOK(t *testing.T) {
|
||||
if r.Summary.Failed != 0 || r.Summary.Skipped != 0 {
|
||||
t.Errorf("expected 0 fail / 0 skip, got %+v", r.Summary)
|
||||
}
|
||||
emit(&Options{JSONOut: true}, r)
|
||||
emit(&cmdutil.JSONOptions{}, r)
|
||||
if !strings.Contains(out.String(), `"all_passed":true`) {
|
||||
t.Errorf("envelope should embed all_passed=true, got %q", out.String())
|
||||
}
|
||||
@@ -280,7 +280,7 @@ func TestDoctor_VersionSkewWarns(t *testing.T) {
|
||||
|
||||
// Envelope ok stays true (warn is non-blocking).
|
||||
out, _ := iostreams.SetForTest(t)
|
||||
emit(&Options{JSONOut: true}, r)
|
||||
emit(&cmdutil.JSONOptions{}, r)
|
||||
if !strings.Contains(out.String(), `"ok":true`) {
|
||||
t.Errorf("envelope.ok must be true on warn-only run, got %q", out.String())
|
||||
}
|
||||
@@ -381,7 +381,7 @@ func TestDoctor_EmitEnvelope_OK_WhenWarnOnly(t *testing.T) {
|
||||
{Name: "credential_storage", Status: StatusOK},
|
||||
},
|
||||
}
|
||||
emit(&Options{JSONOut: true}, r)
|
||||
emit(&cmdutil.JSONOptions{}, r)
|
||||
got := out.String()
|
||||
if !strings.Contains(got, `"ok":true`) {
|
||||
t.Errorf("envelope.ok must be true on warn-only result, got %q", got)
|
||||
@@ -400,7 +400,7 @@ func TestDoctor_EmitEnvelope_NotOK_OnFail(t *testing.T) {
|
||||
{Name: "credential_storage", Status: StatusOK},
|
||||
},
|
||||
}
|
||||
emit(&Options{JSONOut: true}, r)
|
||||
emit(&cmdutil.JSONOptions{}, r)
|
||||
got := out.String()
|
||||
if !strings.Contains(got, `"ok":false`) {
|
||||
t.Errorf("envelope.ok must be false when any check fails, got %q", got)
|
||||
@@ -418,7 +418,7 @@ func TestDoctor_HumanMarker_Warn(t *testing.T) {
|
||||
{Name: "server_version", Status: StatusWarn, Details: "older"},
|
||||
},
|
||||
}
|
||||
emit(&Options{JSONOut: false}, r)
|
||||
emit(nil, r)
|
||||
got := out.String()
|
||||
if !strings.Contains(got, "⚠") {
|
||||
t.Errorf("human output should contain ⚠ glyph for warn, got %q", got)
|
||||
@@ -443,7 +443,7 @@ func TestDoctor_WarnedField_OmittedAtZero(t *testing.T) {
|
||||
{Name: "credential_storage", Status: StatusOK},
|
||||
},
|
||||
}
|
||||
emit(&Options{JSONOut: true}, r)
|
||||
emit(&cmdutil.JSONOptions{}, r)
|
||||
got := out.String()
|
||||
if strings.Contains(got, `"warned"`) {
|
||||
t.Errorf("envelope should omit `warned` field when zero, got %q", got)
|
||||
|
||||
Reference in New Issue
Block a user