From 69fbbfc252c576a811867de6acad48d01efc77ab Mon Sep 17 00:00:00 2001 From: nullkey Date: Fri, 15 May 2026 05:00:26 +0800 Subject: [PATCH] chore(cli): gofmt sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `gofmt -w cli/` — trailing newlines, minor whitespace alignment. Caught during PR-readiness review (`gofmt -l .` had been non-clean since the em-dash → ASCII bulk replace earlier in the v0.4 series). --- cli/acceptance/contract/helpers_test.go | 4 ++- cli/acceptance/contract/wire_test.go | 41 +++++++++++++------------ cli/acceptance/doc.go | 5 +-- cli/acceptance/e2e/e2e_test.go | 8 ++--- cli/cmd/auth/list.go | 1 - cli/cmd/chat/chat.go | 14 ++++----- cli/cmd/context/add.go | 1 - cli/cmd/context/add_test.go | 1 - cli/cmd/context/remove.go | 1 - cli/cmd/context/remove_test.go | 1 - cli/cmd/context/use_test.go | 6 ++-- cli/cmd/doc/list.go | 6 ++-- cli/cmd/doc/list_test.go | 5 +-- cli/cmd/doc/upload_recursive.go | 1 - cli/cmd/doc/upload_recursive_test.go | 1 - cli/cmd/doctor/doctor.go | 1 - cli/cmd/kb/edit_test.go | 10 +++--- cli/cmd/kb/empty_test.go | 1 - cli/cmd/root_test.go | 1 - cli/cmd/search/kb_test.go | 7 ++--- cli/cmd/session/delete_test.go | 1 - cli/cmd/session/list_test.go | 1 - cli/internal/cmdutil/authretry.go | 2 +- cli/internal/cmdutil/confirm.go | 16 +++++----- cli/internal/cmdutil/errors.go | 4 +-- cli/internal/cmdutil/exit.go | 10 +++--- cli/internal/cmdutil/factory.go | 4 +-- cli/internal/cmdutil/jsonflags.go | 2 +- cli/internal/format/bare.go | 1 - cli/internal/xdg/xdg_test.go | 1 - 30 files changed, 74 insertions(+), 84 deletions(-) diff --git a/cli/acceptance/contract/helpers_test.go b/cli/acceptance/contract/helpers_test.go index 3c285295..5848cfc5 100644 --- a/cli/acceptance/contract/helpers_test.go +++ b/cli/acceptance/contract/helpers_test.go @@ -33,7 +33,9 @@ func TestMain(m *testing.M) { } // update is the standard Go test golden-update flag. -// go test -update ./acceptance/contract/... +// +// go test -update ./acceptance/contract/... +// // Mirrors gh / kubectl / golang-migrate convention. var update = flag.Bool("update", false, "update golden files") diff --git a/cli/acceptance/contract/wire_test.go b/cli/acceptance/contract/wire_test.go index 25933aff..54ae1ceb 100644 --- a/cli/acceptance/contract/wire_test.go +++ b/cli/acceptance/contract/wire_test.go @@ -13,18 +13,18 @@ // // Cases intentionally omitted (with reason): // - doctor.success - non-offline path emits -// unstable timing -// ("reachable in 2ms"). -// Unit tests in cli/cmd/doctor -// cover the all-pass shape; -// doctor.success_offline is -// the deterministic sibling -// kept here. +// unstable timing +// ("reachable in 2ms"). +// Unit tests in cli/cmd/doctor +// cover the all-pass shape; +// doctor.success_offline is +// the deterministic sibling +// kept here. // - auth_login.success - requires stdin pipe -// (--with-token) + keyring- -// aware Secrets store; the -// helper does not yet expose -// a stdin hook. +// (--with-token) + keyring- +// aware Secrets store; the +// helper does not yet expose +// a stdin hook. // - auth_login.error_auth_unauthenticated - same setup as above. // // All cases use leaf-positioned --json (e.g. `version --json`). --json is a @@ -45,15 +45,16 @@ import ( ) // wireCase declares one row in the contract matrix. Optional fields: -// server - mock /api/v1/* endpoints; nil means no network. -// preConfig - seed config.yaml under the per-test XDG_CONFIG_HOME -// (set by newTestFactory); use for cases like -// `context use` that read local state without an -// SDK round-trip. -// wantErr - non-zero exit expected. -// wantStderrSubstring - stderr must contain this substring (typically the -// typed error code, e.g. "auth.unauthenticated"). -// Only meaningful when wantErr=true. +// +// server - mock /api/v1/* endpoints; nil means no network. +// preConfig - seed config.yaml under the per-test XDG_CONFIG_HOME +// (set by newTestFactory); use for cases like +// `context use` that read local state without an +// SDK round-trip. +// wantErr - non-zero exit expected. +// wantStderrSubstring - stderr must contain this substring (typically the +// typed error code, e.g. "auth.unauthenticated"). +// Only meaningful when wantErr=true. type wireCase struct { name string args []string diff --git a/cli/acceptance/doc.go b/cli/acceptance/doc.go index 0d0d7a36..ef7321ad 100644 --- a/cli/acceptance/doc.go +++ b/cli/acceptance/doc.go @@ -5,6 +5,7 @@ // reviewer immediately sees "this is the contract surface - change with care". // // Sub-packages: -// contract/ - envelope JSON shape golden + error.code registry consistency -// e2e/ - real WeKnora server blackbox tests (testscript-style) +// +// contract/ - envelope JSON shape golden + error.code registry consistency +// e2e/ - real WeKnora server blackbox tests (testscript-style) package acceptance diff --git a/cli/acceptance/e2e/e2e_test.go b/cli/acceptance/e2e/e2e_test.go index 70283e5c..cf92b965 100644 --- a/cli/acceptance/e2e/e2e_test.go +++ b/cli/acceptance/e2e/e2e_test.go @@ -7,10 +7,10 @@ // the default `go test ./...` (mirrors gh's acceptance/ build tag pattern; // see https://github.com/cli/cli/tree/trunk/acceptance). To run: // -// cd cli -// WEKNORA_E2E_HOST=https://kb.example.com \ -// WEKNORA_E2E_TOKEN=eyJhbGc... \ -// go test -tags=acceptance_e2e -v ./acceptance/e2e/... +// cd cli +// WEKNORA_E2E_HOST=https://kb.example.com \ +// WEKNORA_E2E_TOKEN=eyJhbGc... \ +// go test -tags=acceptance_e2e -v ./acceptance/e2e/... // // Optional WEKNORA_E2E_KB_NAME_PREFIX customizes the throwaway KB name (default // "cli-e2e-"). Cleanup runs even on test failure via t.Cleanup so the server diff --git a/cli/cmd/auth/list.go b/cli/cmd/auth/list.go index d76c001d..81aa709e 100644 --- a/cli/cmd/auth/list.go +++ b/cli/cmd/auth/list.go @@ -84,4 +84,3 @@ func runList(jopts *cmdutil.JSONOptions, f *cmdutil.Factory) error { } return tw.Flush() } - diff --git a/cli/cmd/chat/chat.go b/cli/cmd/chat/chat.go index 6cb23b90..1c950ce5 100644 --- a/cli/cmd/chat/chat.go +++ b/cli/cmd/chat/chat.go @@ -60,17 +60,17 @@ type ChatService interface { // continue a conversation: the answer text, retrieval references, and the // session pointer to thread follow-ups. type chatData struct { - Answer string `json:"answer"` - References []*sdk.SearchResult `json:"references"` + Answer string `json:"answer"` + References []*sdk.SearchResult `json:"references"` // Thinking holds the reasoning / reflection text emitted by reasoning // models (GPT-5, Claude extended thinking) via response_type=thinking // frames. Omitted when empty (non-reasoning model or model didn't // surface reasoning for this query). - Thinking string `json:"thinking,omitempty"` - SessionID string `json:"session_id"` - AssistantMessageID string `json:"assistant_message_id,omitempty"` - KBID string `json:"kb_id"` - Query string `json:"query"` + Thinking string `json:"thinking,omitempty"` + SessionID string `json:"session_id"` + AssistantMessageID string `json:"assistant_message_id,omitempty"` + KBID string `json:"kb_id"` + Query string `json:"query"` } // NewCmd builds `weknora chat `. diff --git a/cli/cmd/context/add.go b/cli/cmd/context/add.go index c0180cdc..b4cb9cf2 100644 --- a/cli/cmd/context/add.go +++ b/cli/cmd/context/add.go @@ -145,4 +145,3 @@ func validateName(name string) error { } return nil } - diff --git a/cli/cmd/context/add_test.go b/cli/cmd/context/add_test.go index a6478c6f..ec6ff6f8 100644 --- a/cli/cmd/context/add_test.go +++ b/cli/cmd/context/add_test.go @@ -140,4 +140,3 @@ func TestAdd_JSON(t *testing.T) { t.Errorf("first added context must be current=true, got %v", got) } } - diff --git a/cli/cmd/context/remove.go b/cli/cmd/context/remove.go index d2092b8f..ceea85e3 100644 --- a/cli/cmd/context/remove.go +++ b/cli/cmd/context/remove.go @@ -124,4 +124,3 @@ func clearContextSecrets(store secrets.Store, c config.Context, name string) { _ = store.Delete(name, "api_key") } } - diff --git a/cli/cmd/context/remove_test.go b/cli/cmd/context/remove_test.go index e02faf3f..58d72197 100644 --- a/cli/cmd/context/remove_test.go +++ b/cli/cmd/context/remove_test.go @@ -203,4 +203,3 @@ func TestRemove_Current_TTY_PromptNo(t *testing.T) { t.Errorf("aborted remove must not mutate config") } } - diff --git a/cli/cmd/context/use_test.go b/cli/cmd/context/use_test.go index 5155a2f6..6419d99d 100644 --- a/cli/cmd/context/use_test.go +++ b/cli/cmd/context/use_test.go @@ -75,9 +75,9 @@ func TestUse_NotFound_DeterministicTieBreak(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", t.TempDir()) _, _ = iostreams.SetForTest(t) cfg := &config.Config{Contexts: map[string]config.Context{ - "prod": {Host: "https://a"}, - "prom": {Host: "https://b"}, - "prog": {Host: "https://c"}, + "prod": {Host: "https://a"}, + "prom": {Host: "https://b"}, + "prog": {Host: "https://c"}, }} if err := config.Save(cfg); err != nil { t.Fatalf("Save: %v", err) diff --git a/cli/cmd/doc/list.go b/cli/cmd/doc/list.go index 340b86e3..e2a541e2 100644 --- a/cli/cmd/doc/list.go +++ b/cli/cmd/doc/list.go @@ -28,9 +28,9 @@ var docListFields = []string{ } type ListOptions struct { - PageSize int // Items per server batch. With --all-pages, controls - // per-request load. Without, controls the single page size. - Status string // --status: filter by parse_status (server-side query param) + PageSize int // Items per server batch. With --all-pages, controls + // per-request load. Without, controls the single page size. + Status string // --status: filter by parse_status (server-side query param) // Limit caps the returned items client-side (default 30; 0 = no cap). // Applied after pagination / --all-pages accumulation and sort. Limit int diff --git a/cli/cmd/doc/list_test.go b/cli/cmd/doc/list_test.go index 74726830..326bb95f 100644 --- a/cli/cmd/doc/list_test.go +++ b/cli/cmd/doc/list_test.go @@ -128,7 +128,9 @@ func TestList_KBIDRequired(t *testing.T) { } f := &cmdutil.Factory{ Config: func() (*config.Config, error) { return cfg, nil }, - Client: func() (*sdk.Client, error) { return nil, errors.New("client should not be called when kb id is missing") }, + Client: func() (*sdk.Client, error) { + return nil, errors.New("client should not be called when kb id is missing") + }, } cmd := NewCmdList(f) cmd.SetContext(context.Background()) @@ -337,4 +339,3 @@ func TestList_AllPages_WithLimit_StopsAtLimit(t *testing.T) { // Should have called pages 1..3 (60 items) then capped at 50. assert.LessOrEqual(t, len(svc.calls), 3, "should not walk past the page that fills --limit") } - diff --git a/cli/cmd/doc/upload_recursive.go b/cli/cmd/doc/upload_recursive.go index 980f479c..46425fa1 100644 --- a/cli/cmd/doc/upload_recursive.go +++ b/cli/cmd/doc/upload_recursive.go @@ -163,4 +163,3 @@ func walkMatches(root, pattern string) ([]string, error) { } return out, nil } - diff --git a/cli/cmd/doc/upload_recursive_test.go b/cli/cmd/doc/upload_recursive_test.go index db5f094e..1a1c1265 100644 --- a/cli/cmd/doc/upload_recursive_test.go +++ b/cli/cmd/doc/upload_recursive_test.go @@ -191,4 +191,3 @@ func TestUploadRecursive_JSON_BareObject(t *testing.T) { assert.True(t, typed.Silent, "JSON-path partial failure must be Silent") assert.Equal(t, cmdutil.CodeServerError, typed.Code) } - diff --git a/cli/cmd/doctor/doctor.go b/cli/cmd/doctor/doctor.go index a701be6b..278d57b6 100644 --- a/cli/cmd/doctor/doctor.go +++ b/cli/cmd/doctor/doctor.go @@ -450,4 +450,3 @@ func (s *realServices) GetSystemInfo(ctx context.Context) (*sdk.SystemInfo, erro } return cli.GetSystemInfo(ctx) } - diff --git a/cli/cmd/kb/edit_test.go b/cli/cmd/kb/edit_test.go index 653379b0..36f0371f 100644 --- a/cli/cmd/kb/edit_test.go +++ b/cli/cmd/kb/edit_test.go @@ -16,12 +16,12 @@ import ( // fakeEditSvc captures the (id, request) pair handed to UpdateKnowledgeBase // and scripts the GetKnowledgeBase fetch used by the fetch-then-update path. type fakeEditSvc struct { - current *sdk.KnowledgeBase // returned by GetKnowledgeBase + current *sdk.KnowledgeBase // returned by GetKnowledgeBase currentErr error - gotID string - gotReq *sdk.UpdateKnowledgeBaseRequest - resp *sdk.KnowledgeBase - err error + gotID string + gotReq *sdk.UpdateKnowledgeBaseRequest + resp *sdk.KnowledgeBase + err error } func (f *fakeEditSvc) GetKnowledgeBase(_ context.Context, id string) (*sdk.KnowledgeBase, error) { diff --git a/cli/cmd/kb/empty_test.go b/cli/cmd/kb/empty_test.go index 168aa14f..8c944aff 100644 --- a/cli/cmd/kb/empty_test.go +++ b/cli/cmd/kb/empty_test.go @@ -79,4 +79,3 @@ func TestEmpty_NotFound(t *testing.T) { require.ErrorAs(t, err, &typed) assert.Equal(t, cmdutil.CodeResourceNotFound, typed.Code) } - diff --git a/cli/cmd/root_test.go b/cli/cmd/root_test.go index 0c2462a9..a6d661ac 100644 --- a/cli/cmd/root_test.go +++ b/cli/cmd/root_test.go @@ -139,4 +139,3 @@ func TestRoot_ContextFlagPropagation(t *testing.T) { }) } } - diff --git a/cli/cmd/search/kb_test.go b/cli/cmd/search/kb_test.go index b3d3170d..133ea931 100644 --- a/cli/cmd/search/kb_test.go +++ b/cli/cmd/search/kb_test.go @@ -65,9 +65,9 @@ func TestKBSearch_SortByNameLength(t *testing.T) { require.NoError(t, runKBSearch(context.Background(), &KBSearchOptions{Query: "marketing", Limit: 20}, nil, svc)) got := out.String() // Order: shortest name first. - iShort := strings.Index(got,"kb_short") - iMid := strings.Index(got,"kb_mid") - iLong := strings.Index(got,"kb_long") + iShort := strings.Index(got, "kb_short") + iMid := strings.Index(got, "kb_mid") + iLong := strings.Index(got, "kb_long") assert.Less(t, iShort, iMid) assert.Less(t, iMid, iLong) } @@ -116,4 +116,3 @@ func TestKBSearch_NetworkError(t *testing.T) { require.ErrorAs(t, err, &typed) assert.Equal(t, cmdutil.CodeAuthUnauthenticated, typed.Code) } - diff --git a/cli/cmd/session/delete_test.go b/cli/cmd/session/delete_test.go index 1611ce0e..07789d97 100644 --- a/cli/cmd/session/delete_test.go +++ b/cli/cmd/session/delete_test.go @@ -80,4 +80,3 @@ func TestDelete_TTY_ConfirmNo(t *testing.T) { assert.False(t, svc.called) assert.Contains(t, errBuf.String(), "Aborted") } - diff --git a/cli/cmd/session/list_test.go b/cli/cmd/session/list_test.go index 96deae47..9a15cfd2 100644 --- a/cli/cmd/session/list_test.go +++ b/cli/cmd/session/list_test.go @@ -261,4 +261,3 @@ func TestList_AllPages_WithLimit_StopsAtLimit(t *testing.T) { assert.Equal(t, 50, got) assert.LessOrEqual(t, len(svc.calls), 3, "must not fetch beyond what fills --limit") } - diff --git a/cli/internal/cmdutil/authretry.go b/cli/internal/cmdutil/authretry.go index 3a18c398..9952cbb4 100644 --- a/cli/internal/cmdutil/authretry.go +++ b/cli/internal/cmdutil/authretry.go @@ -21,7 +21,7 @@ import ( // - 401 on /api/v1/auth/login or /api/v1/auth/refresh: pass through // (otherwise a stale refresh token causes infinite recursion). // - 401 with no initial token configured (api-key contexts): pass through -// - api-key credentials have no refresh semantic. +// - api-key credentials have no refresh semantic. // - 401 with non-replayable request body (req.GetBody == nil): pass // through. The SDK always uses bytes.Buffer bodies; this is a safety // net for hand-built requests. diff --git a/cli/internal/cmdutil/confirm.go b/cli/internal/cmdutil/confirm.go index 24208f11..bb3a5346 100644 --- a/cli/internal/cmdutil/confirm.go +++ b/cli/internal/cmdutil/confirm.go @@ -10,14 +10,14 @@ import ( // ConfirmDestructive guards a destructive operation (delete, force-overwrite) // behind explicit user approval. Behavior matrix: // -// yes=true → proceed (explicit user opt-in via -y/--yes) -// non-TTY OR jsonOut → return CodeInputConfirmationRequired (exit 10); -// no UI to prompt, agent/CI must re-invoke with -y -// after the human explicitly approves -// TTY + interactive → prompt; user-yes proceeds, user-no returns -// CodeUserAborted ("Aborted." to stderr) -// prompter error → returns CodeInputMissingFlag (rare; stdin closed -// mid-prompt) +// yes=true → proceed (explicit user opt-in via -y/--yes) +// non-TTY OR jsonOut → return CodeInputConfirmationRequired (exit 10); +// no UI to prompt, agent/CI must re-invoke with -y +// after the human explicitly approves +// TTY + interactive → prompt; user-yes proceeds, user-no returns +// CodeUserAborted ("Aborted." to stderr) +// prompter error → returns CodeInputMissingFlag (rare; stdin closed +// mid-prompt) // // The non-TTY branch is the destructive-write protocol: high-risk writes // always require explicit confirmation in scripted contexts, never silent diff --git a/cli/internal/cmdutil/errors.go b/cli/internal/cmdutil/errors.go index ba0b4b86..c6541c09 100644 --- a/cli/internal/cmdutil/errors.go +++ b/cli/internal/cmdutil/errors.go @@ -29,8 +29,8 @@ const ( CodeResourceLocked ErrorCode = "resource.locked" // input.* - flag and argument validation - CodeInputInvalidArgument ErrorCode = "input.invalid_argument" - CodeInputMissingFlag ErrorCode = "input.missing_flag" + CodeInputInvalidArgument ErrorCode = "input.invalid_argument" + CodeInputMissingFlag ErrorCode = "input.missing_flag" // CodeInputConfirmationRequired marks a high-risk write that has no // interactive UI (non-TTY or --json) and was invoked without -y/--yes. // Mapped to exit code 10 (see cli/README.md). Agents must surface the diff --git a/cli/internal/cmdutil/exit.go b/cli/internal/cmdutil/exit.go index b73b4ea2..5397f088 100644 --- a/cli/internal/cmdutil/exit.go +++ b/cli/internal/cmdutil/exit.go @@ -9,10 +9,10 @@ import ( // ExitCode maps an error to the documented CLI exit code. // - 0 success // - 1 generic / unknown typed error - fallback for: resource.already_exists, -// resource.locked, local.* (config_corrupt / keychain_denied / file_io / -// context_not_found / kb_id_required / kb_not_found / projectlink_corrupt / -// user_aborted / upload_file_not_found), mcp.*, server.session_create_failed, -// sse.stream_aborted, and any code outside the named buckets below +// resource.locked, local.* (config_corrupt / keychain_denied / file_io / +// context_not_found / kb_id_required / kb_not_found / projectlink_corrupt / +// user_aborted / upload_file_not_found), mcp.*, server.session_create_failed, +// sse.stream_aborted, and any code outside the named buckets below // - 2 flag / argument problem (cobra parse / unknown subcommand) // - 3 auth.* // - 4 resource.not_found @@ -20,7 +20,7 @@ import ( // - 6 server.rate_limited // - 7 server.* (other than rate_limited/session_create_failed) / network.* // - 10 input.confirmation_required - high-risk write needs explicit -y -// (see cli/README.md) +// (see cli/README.md) // - 130 SIGINT (handled by Go runtime, not this function) func ExitCode(err error) int { if err == nil { diff --git a/cli/internal/cmdutil/factory.go b/cli/internal/cmdutil/factory.go index 931d4e7a..cc68cbde 100644 --- a/cli/internal/cmdutil/factory.go +++ b/cli/internal/cmdutil/factory.go @@ -25,8 +25,8 @@ import ( // Four closures: // - Config: parses ~/.config/weknora/config.yaml (no network) // - Client: constructs the SDK client; only Secrets is sync.Once-cached, -// so callers should hold the returned *sdk.Client across -// multiple SDK calls within one invocation +// so callers should hold the returned *sdk.Client across +// multiple SDK calls within one invocation // - Prompter: returns interactive prompter; agent mode returns AgentPrompter // - Secrets: builds the OS keyring / file fallback credential store the // first time it is requested (probing the keyring at startup diff --git a/cli/internal/cmdutil/jsonflags.go b/cli/internal/cmdutil/jsonflags.go index c1928222..1eaafe2b 100644 --- a/cli/internal/cmdutil/jsonflags.go +++ b/cli/internal/cmdutil/jsonflags.go @@ -50,7 +50,7 @@ const jsonNoOptSentinel = "\x00json-no-value" // - `--json` → bare JSON payload, no field filter // - `--json=id,name` → each object restricted to the listed fields // - `--jq ` → apply a jq expression to the JSON; requires -// --json to be set explicitly +// --json to be set explicitly // // `fields` is the set of available fields the user may pass; rendered in // the command's help. Pass nil to skip the help annotation (uncommon). diff --git a/cli/internal/format/bare.go b/cli/internal/format/bare.go index bc3a8cb6..b4e57e16 100644 --- a/cli/internal/format/bare.go +++ b/cli/internal/format/bare.go @@ -80,4 +80,3 @@ func applyBareFieldFilter(raw []byte, fields []string) ([]byte, error) { return raw, nil } } - diff --git a/cli/internal/xdg/xdg_test.go b/cli/internal/xdg/xdg_test.go index fe15b014..7e68cb44 100644 --- a/cli/internal/xdg/xdg_test.go +++ b/cli/internal/xdg/xdg_test.go @@ -56,4 +56,3 @@ func TestWriteAtomicYAML_RoundTrip(t *testing.T) { } } } -