Files
zero/internal/tools/apply_patch_paths_test.go
KRATOS a981120432 Audit tail: remaining medium/low correctness fixes (CLI, config, OAuth, tools, LSP, TUI) (#275)
* audit tail: fix remaining medium/low correctness findings

A sweep of the remaining audit findings across CLI, config, OAuth, tools,
LSP, and the TUI. Each fix has a regression test; build/vet/gofmt clean and
the touched packages' suites pass.

CLI
- `zero -p "<prompt>"` now forwards the prompt as the inline `--prompt=<value>`
  form so a prompt whose first character is a dash (e.g. `zero -p "-foo"`) is
  taken verbatim instead of being rejected as a missing flag value (matches the
  cron path).

Config
- mergeProfile no longer drops parseThinkTags across profile merges; an explicit
  value carries over and a nil (unset) never clobbers an existing one.

OAuth
- Refresh carries the existing token_type forward when the refresh response omits
  it (previously silently lost).
- RefreshScheduler.Stop resets started/done so the scheduler can be started again
  instead of being permanently inert after the first Stop.

Tools
- apply_patch header parsing takes the whole post-prefix value (dropping a trailing
  tab timestamp and undoing git's C-style quoting) instead of splitting on spaces,
  so a diff target whose name contains spaces is recognized.

LSP
- Server.Shutdown honors its context (kills immediately on cancel rather than
  waiting out the full grace window), and Manager.Shutdown shuts servers down
  concurrently so total shutdown is bounded by one grace window, not N×grace.

TUI
- /theme auto re-probes the terminal background (RequestBackgroundColor) instead
  of reusing a stale startup reading, so switching to auto re-detects light/dark.
- Specialist card: wire the tool-call count from progress events (was always 0)
  and omit the token segment when the total is 0 rather than show "0 tokens".
- Resume: extract the tool-call row id the same way as the result row and the
  specialist pre-pass (toolCallId first), so call/result dedup and the failed-Task
  visibility rule key on the same string.
- Plan panel: height takes an injected clock (testable, consistent with render),
  and duplicate-content steps inherit distinct prior timestamps positionally.

* tui: test that /theme auto re-probes the terminal background (M17)

The M17 fix lives in handleSubmit's command dispatch (`return m,
tea.RequestBackgroundColor` when the mode is auto), which no test exercised —
only the handleThemeCommand helper was covered. Add a dispatch-level test:
/theme auto must return the background re-probe command, /theme dark must not.
Verified to fail if the dispatch is reverted to `return m, nil`.
2026-06-20 22:21:48 +05:30

33 lines
1.1 KiB
Go

package tools
import (
"slices"
"testing"
)
func TestPatchHeaderPathsHandlesQuotedAndSpacedNames(t *testing.T) {
// git C-quotes a path that contains a space; the old strings.Fields parse kept
// only the first whitespace-delimited token ("a/dir/file" and the literal `name`
// pieces would split), losing the real name. The whole post-prefix value, with a
// trailing tab timestamp dropped and the quotes removed, must survive (L18).
patch := "--- \"a/dir/file name.go\"\t2024-01-01 00:00:00\n" +
"+++ \"b/dir/file name.go\"\n" +
"@@ -1 +1 @@\n-old\n+new\n"
got := patchHeaderPaths(patch)
if !slices.Contains(got, "dir/file name.go") {
t.Fatalf("quoted spaced path not extracted: %v", got)
}
}
func TestPatchHeaderPathsUnspacedStillWorks(t *testing.T) {
patch := "--- a/x.go\n+++ b/x.go\n@@ -1 +1 @@\n-old\n+new\n"
got := patchHeaderPaths(patch)
if !slices.Contains(got, "x.go") {
t.Fatalf("plain path not extracted: %v", got)
}
// /dev/null (a deletion/creation sentinel) must not be reported as a target.
if slices.Contains(got, "/dev/null") {
t.Fatalf("/dev/null should not be a header path: %v", got)
}
}