Files
magpie/internal/sessions/omp_test.go
T
TryWorld 5e89b7f83d sessions tests: every agent's resume line is asserted on Windows too, not skipped there (#1069)
Ten of resumeCommand's agents (cline, qoder, qoder-cn, droid, grok, omp,
opencode files/db/v2, pi, codex, claude) had their resume check wrapped in
runtime.GOOS != "windows", so on Windows nothing checked the
Set-Location -LiteralPath line resumeCommand builds there, its doubled
single quote included. Each now asserts its own platform's line.

This is the sessions half of TryWorld2026's #1069. Its internal/agent half
(aside refusals, the Codex stale skip) was already done on main by
9650cd50c and 688c062ed, and its TestCursor change by 6a8095421, so those
parts are left out.

Run (at origin/main 5b14ebf49 plus this): gofmt -l clean; go vet,
GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/sessions;
go test -tags nogui ./internal/sessions on macOS ok. On the Windows box
(Windows 11 x64, amd64 test binary, sandbox USERPROFILE/APPDATA/
LOCALAPPDATA/TEMP) the whole package passes. Broken by hand (Windows
branch of resumeCommand building the Unix "cd '...' &&" line): TestCline,
TestQoder, TestDroid, TestGrok, TestOmp, TestOpenCodeFiles, TestOpenCodeDB,
TestOpenCodeV2, TestPi and TestList go red on Windows, each naming the
line it got. Not run: go test ./... (test-only change in one package).
2026-10-13 08:15:14 +08:00

93 lines
2.9 KiB
Go

package sessions
import (
"os"
"path/filepath"
"runtime"
"testing"
)
const (
ompMain = "019a0000-0000-7000-8000-00000000000a"
ompFork = "019a0000-0000-7000-8000-00000000000c"
ompNamed = "019a0000-0000-7000-8000-00000000000d"
)
// omp's sessions (#303): Pi's kind, with its title line and title changes,
// model_usage entries, and its subagents' and advisor's sessions beside it.
func TestOmp(t *testing.T) {
inZone(t, 0)
home := setupAgents(t)
ss := List(0)
if n := count(ss, "omp"); n != 3 {
t.Fatalf("want 3 omp sessions (the subagents and advisor in theirs), got %d", n)
}
m := find(t, ss, "omp", ompMain)
if m.Cwd != "/work/omp" || m.Title != "Port the parser to omp" {
t.Fatalf("omp: %+v", m)
}
// the task tool's summed usage not counted again
for _, c := range []struct {
model string
want Tokens
}{
{"claude-opus-5-5", Tokens{110, 55, 1500, 200, 0}},
{"claude-haiku-5", Tokens{20, 5, 0, 0, 0}}, // a model_usage entry
{"claude-sonnet-5", Tokens{340, 34, 100, 0, 0}}, // the subagent and its own
{"gpt-6-astra", Tokens{50, 10, 0, 0, 0}}, // the advisor
} {
if got := model(m, c.model); got.Tokens != c.want {
t.Fatalf("%s: %+v, want %+v", c.model, got, c.want)
}
}
if len(m.Models) != 4 || !model(m, "claude-opus-5-5").Priced {
t.Fatalf("models %+v", m.Models)
}
if !m.Start.Equal(at("2026-09-28T08:00:00Z")) || !m.Last.Equal(at("2026-09-28T08:02:00Z")) {
t.Fatalf("omp times %s %s", m.Start, m.Last)
}
want := "cd '/work/omp' && omp --resume " + ompMain
if runtime.GOOS == "windows" {
want = "Set-Location -LiteralPath '/work/omp'; omp --resume " + ompMain
}
if m.Resume != want {
t.Fatalf("resume %q", m.Resume)
}
// the fork: what it copied counted in the session it came from
f := find(t, ss, "omp", ompFork)
if f.Tokens != (Tokens{7, 3, 0, 0, 0}) || f.Title != "Port the parser" {
t.Fatalf("fork: %+v", f)
}
if !f.Start.Equal(at("2026-09-29T09:00:00Z")) || !f.Last.Equal(at("2026-09-29T09:00:20Z")) {
t.Fatalf("fork times %s %s", f.Start, f.Last)
}
// begun from a template: the title it was last given
if n := find(t, ss, "omp", ompNamed); n.Title != "Tidy the tests" {
t.Fatalf("named: %+v", n)
}
// a profile's sessions, and those in $XDG_DATA_HOME/omp
from := filepath.Join(home, ".omp", "agent", "sessions", "--work-omp--")
moves := map[string]string{ompNamed: filepath.Join(home, ".omp", "profiles", "work", "agent", "sessions", "--work-omp--")}
if runtime.GOOS != "windows" {
moves[ompFork] = filepath.Join(os.Getenv("XDG_DATA_HOME"), "omp", "sessions", "--work-omp--")
}
for id, to := range moves {
names, _ := filepath.Glob(filepath.Join(from, "*_"+id+".jsonl"))
if len(names) != 1 {
t.Fatalf("fixture for %s: %v", id, names)
}
os.MkdirAll(to, 0o755)
if err := os.Rename(names[0], filepath.Join(to, filepath.Base(names[0]))); err != nil {
t.Fatal(err)
}
}
Reset()
ss = List(0)
for id := range moves {
find(t, ss, "omp", id)
}
}