feat(cli): api --input + completion smoke

api (3-11):
- `--input <file>` reads the request body from disk; `--input -` reads
  from stdin. Matches gh CLI canonical naming verified against the gh
  manual ("The file to use as body for the HTTP request — use \"-\" to
  read from standard input"). `--data` / `--input` are mutually
  exclusive.
- Options.StdinReader (defaults to iostreams.IO.In) for test injection.

completion (3-13 smoke only — release-artifact ship deferred to release
milestone):
- Smoke test asserts cobra's auto-registered bash/zsh/fish/powershell
  scripts produce non-trivially-sized output with the per-shell
  signature (#compdef / complete -c weknora / etc.). Guards against
  cobra bumps silently breaking completion for one shell.

3-14 doctor --no-cache: already implemented (factory.go:297) with
TestDoctor_NoCache_BypassesCache covering it — verified, no change
needed.

Roadmap: 3-11, 3-13 (smoke), 3-14 (verified).
This commit is contained in:
nullkey
2026-05-12 23:41:05 +08:00
committed by lyingbug
parent d54a7a5834
commit 73a88b4f0a
3 changed files with 115 additions and 24 deletions
+26 -3
View File
@@ -117,7 +117,9 @@ func TestAPI_PostWithData(t *testing.T) {
}
}
func TestAPI_DataFile(t *testing.T) {
// TestAPI_InputFile verifies --input <file> reads the request body from
// disk. gh CLI parity (verified against gh manual: `--input <file>`).
func TestAPI_InputFile(t *testing.T) {
_, _ = iostreams.SetForTest(t)
tmp := filepath.Join(t.TempDir(), "body.json")
payload := `{"k":"from-file"}`
@@ -131,12 +133,33 @@ func TestAPI_DataFile(t *testing.T) {
})
defer stop()
opts := &Options{DataFile: tmp}
opts := &Options{Input: tmp}
if err := runAPI(context.Background(), opts, cli, "POST", "/api/v1/x"); err != nil {
t.Fatalf("runAPI: %v", err)
}
if string(seenBody) != payload {
t.Errorf("body from --data-file: got %q, want %q", seenBody, payload)
t.Errorf("body from --input: got %q, want %q", seenBody, payload)
}
}
// TestAPI_InputDash_Stdin verifies the gh-style "--input -" form: the
// payload comes from opts.StdinReader (production-default iostreams.IO.In).
func TestAPI_InputDash_Stdin(t *testing.T) {
_, _ = iostreams.SetForTest(t)
var seenBody []byte
cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
seenBody, _ = io.ReadAll(r.Body)
_, _ = w.Write([]byte(`{}`))
})
defer stop()
payload := `{"k":"from-stdin"}`
opts := &Options{Input: "-", StdinReader: strings.NewReader(payload)}
if err := runAPI(context.Background(), opts, cli, "POST", "/api/v1/x"); err != nil {
t.Fatalf("runAPI: %v", err)
}
if string(seenBody) != payload {
t.Errorf("body from --input -: got %q, want %q", seenBody, payload)
}
}