Files
magpie/internal/agent/dsh_lead_test.go
T
yetone 844c355059 dsh: the model shown is the start of the profile in use, and the round's log says what it wrote (#5222)
#5222: with DeepSeek Harness Desktop and four profiles, the desktop
profile started on hy4free while web, headless and open-design started
on deepseek-v4.1-flash, and magpie's log said "wrote dsh's route again"
every half minute or so. Read against dsh 0.2.1-rc.2's own source and
reproduced in a sandbox HOME with dsh's real save (saveSelection through
ConfigEditor.edit and its yaml 2.9.1 library):

- dsh saves a model picked in it into the profile in use alone. The
  profiles drifting apart is dsh's design, and each start is the user's
  own: magpie copies it nowhere.
- magpie never wrote over that pick. After dsh's save the next round
  wrote once, moving magpie's web search entry to follow the new start,
  and then wrote nothing. The log called that "wrote dsh's route again",
  which read as magpie rewriting agent-default-model.
- magpie read the start from the web profile alone, so with the desktop
  app in use the Agents page showed a model its sessions don't start on,
  and picking what it showed changed nothing there.
- A session dsh already has keeps the model of its last request until a
  model is picked in it (selectionFor in dsh-api-session-controller), as
  noticeDsh1 says. The reporter's 429s were OpenCode Zen Free's own free
  limit, reached by a session still on it; the gateway didn't change the
  model.

Now the model and effort fields read the desktop profile when DeepSeek
Harness Desktop is installed (dshLead), else web's as before, and effort
levels are checked against that model. The round logs "dsh's web search
in <file> follows the model it starts on now" when that entry is all it
moved; "wrote dsh's route again" is kept for the route itself.

Run (mote, on origin/main 7dd2434d3; rebased onto 78128b510, which touches
no internal/agent file, and -run TestDsh ./internal/agent run again at
the pushed head: ok):
- go test -run TestDsh ./internal/agent: ok
- go test ./internal/agent, go vet ./internal/agent with GOOS linux and
  windows, gofmt -l: ok (internal/agent 230.6s)
- TestDshShowsTheStartOfTheProfileInUse uses the bytes dsh's own save
  wrote in the sandbox.

Broken by hand, each red:
- dshLead ignoring the desktop profile: "model shown =
  magpie/deepseek/pro, want the desktop profile's magpie/deepseek/flash".
- the search-only write logged as a route write: "the round's log doesn't
  say its one write was the search entry".

Not tried: the real DeepSeek Harness Desktop app with the reporter's
profiles; a user who runs dsh's web profile while the desktop app is
installed still sees the desktop profile's start. Not changed: magpie's
writers find the first agent-default-model entry while dsh writes the
last (dshFind vs findLastIndex); no profile with two was seen (#5229).
2026-11-04 19:23:49 +08:00

108 lines
4.1 KiB
Go

package agent
import (
"bytes"
"log"
"os"
"path/filepath"
"strings"
"testing"
)
// #5222: DeepSeek Harness Desktop with four profiles (desktop, web,
// headless, open-design). A model picked in dsh is saved by dsh into the
// profile in use alone (ConfigEditor.edit), so the desktop profile started
// on hy4free while web, headless and open-design still started on
// deepseek-v4.1-flash. magpie read web's start alone: the Agents page showed
// a model the desktop app's sessions don't start on, and its log said
// "wrote dsh's route again" each time the round moved magpie's web search
// entry after dsh's save, which read as magpie writing over the pick.
//
// The desktop profile's bytes here are what dsh 0.2.1-rc.2's own save
// (dsh-agent-default-model saveSelection through the yaml 2.9.1 library)
// wrote over magpie's entry in a sandbox: the value unquoted, the effort
// added, magpie's comment kept.
func TestDshShowsTheStartOfTheProfileInUse(t *testing.T) {
home, dir, web := dshRouteHome(t)
dshKeyFixture(dir)
apps := t.TempDir()
was := appFolders
appFolders = func() []string { return []string{apps} }
t.Cleanup(func() { appFolders = was })
files := map[string]string{"web": web}
for _, p := range []string{"desktop", "headless", "open-design"} {
f := filepath.Join(dir, "profiles", p, "cordis.patch.yml")
if err := os.MkdirAll(filepath.Dir(f), 0o755); err != nil {
t.Fatal(err)
}
files[p] = f
}
for _, f := range files {
if err := os.WriteFile(f, []byte(dshProfileTemplate), 0o600); err != nil {
t.Fatal(err)
}
}
a := dsh(home)
if err := a.Field("model").Set("magpie/deepseek/pro"); err != nil {
t.Fatal(err)
}
dshWiredOnce()
read := func(p string) string { b, _ := os.ReadFile(files[p]); return string(b) }
ours := "- id: agent-default-model # magpie\n config:\n provider: magpie\n model: \"deepseek/pro\"\n"
saved := "- id: agent-default-model # magpie\n config:\n provider: magpie\n model: deepseek/flash\n reasoningEffort: high\n"
desk := read("desktop")
if !strings.Contains(desk, ours) {
t.Fatalf("magpie's start isn't as this test expects:\n%s", desk)
}
if err := os.WriteFile(files["desktop"], []byte(strings.Replace(desk, ours, saved, 1)), 0o600); err != nil {
t.Fatal(err)
}
// no desktop app: the web profile is the one shown, as before
if got := dsh(home).Field("model").Get(); got != "magpie/deepseek/pro" {
t.Fatalf("without the desktop app the model shown = %q, want web's magpie/deepseek/pro", got)
}
installApp(t, apps, "DeepSeek Harness.app", dshAppPlist)
a = dsh(home)
if got := a.Field("model").Get(); got != "magpie/deepseek/flash" {
t.Fatalf("model shown = %q, want the desktop profile's magpie/deepseek/flash, the one its sessions start on", got)
}
if got := a.Field("effort").Get(); got != "high" {
t.Fatalf("effort shown = %q, want the desktop profile's high", got)
}
// the rounds leave dsh's pick where dsh saved it and copy it nowhere:
// each profile's start is the user's own
var buf bytes.Buffer
log.SetOutput(&buf)
t.Cleanup(func() { log.SetOutput(os.Stderr) })
for range 3 {
var r dshRounds
if trouble := r.once(); trouble != "" {
t.Fatalf("round: %s", trouble)
}
}
log.SetOutput(os.Stderr)
if desk := read("desktop"); !strings.Contains(desk, saved) {
t.Fatalf("the rounds wrote over dsh's own pick:\n%s", desk)
}
for _, p := range []string{"web", "headless", "open-design"} {
if !strings.Contains(read(p), ours) {
t.Fatalf("the %s profile's start moved:\n%s", p, read(p))
}
}
// the one write: magpie's web search entry follows the desktop's start
if !strings.Contains(read("desktop"), " model: \"deepseek/flash\"\n") {
t.Fatalf("magpie's web search entry didn't follow the start:\n%s", read("desktop"))
}
said := buf.String()
if strings.Count(said, "dsh's web search in "+files["desktop"]+" follows the model it starts on now") != 1 {
t.Fatalf("the round's log doesn't say its one write was the search entry:\n%s", said)
}
if strings.Contains(said, "wrote dsh's route again") {
t.Fatalf("the round says it wrote dsh's route again, with the route as it was:\n%s", said)
}
}