CodeBuddy Code keeps its sessions as WorkBuddy does, ~/.codebuddy/projects/<cwd>/<id>.jsonl. magpie read them for the calls ledger (#1779) but never listed them: allFiles() and Dirs() left them out, parserFor sent them to the Claude parser, and Deletable didn't name the agent. caozeal's branch (85cc186a2) adds them to allFiles, Dirs, parserFor (workbuddyLine) and Deletable, with the meta cwd fallback WorkBuddy has, and the ledger reads through the same list. On top of it: the resume command is `codebuddy --resume <id>` (its CLI's `-r, --resume [sessionId]`, read from @tencent-ai/codebuddy-code 2.168.2's dist/codebuddy.js; codebuddy is one of the package's three bins). The Sessions page's and Usage > Sessions' agent label come from the agent registry (CodeBuddy Code, codebuddy-color) and needed no change; a test now holds them. Fixtures are the real `codebuddy -p` runs already in internal/sessions/testdata/codebuddy (#1779). Tests: - TestCodeBuddy (caozeal's, extended): two sessions with their cwd, title and model tokens; the resume command on each OS's form; Deletable. - TestCodeBuddySessionsListedUnderTheirName (new, internal/gui): /api/sessions, /api/sessions/manage and /api/sessions/stats name them CodeBuddy Code with its icon, resume command and trash. - Broken by hand, each red: allFiles reverted and parserFor reverted ("want 2 CodeBuddy Code sessions, got 0" in both tests), resume reverted (resume ""), Deletable reverted ("not deletable", "offers no trash"). Run ate085d6e92plus this change: - gofmt -l internal/: clean. go vet ./... (darwin): exit 0. GOOS=linux and GOOS=windows go vet -tags nogui ./...: exit 0. - go test -tags nogui -timeout 45m ./... under set -o pipefail: 64 packages ok, 2 red at load average ~110, neither ours: - internal/agent timed out at 45m (TestWSLMoreAgentsPick running; 2702.7s), recorded on #2544. - internal/gui TestRestartWhenIdle "restarted in a tool chain's gap" (30ms sleep vs 80ms idleSettle); passes -count=10 alone; filed #2673. - After rebasing onto origin/main7660399a1(#2576, #2578: gateway model list, gui Claude Desktop chip): internal/sessions ok (169.6s) and internal/gui ok (303.7s) at the rebased head on7660399a1. Co-authored-by: caozeal <21231607+caozeal@users.noreply.github.com>
111 lines
2.9 KiB
Go
111 lines
2.9 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/fs"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
)
|
|
|
|
// CodeBuddy Code's own sessions (~/.codebuddy/projects, the real `codebuddy
|
|
// -p` runs in the sessions package's testdata) reach the Sessions page and
|
|
// Usage > Sessions under CodeBuddy Code's name and icon, with the command that
|
|
// resumes them, and the page offers them to the trash (#2657).
|
|
func TestCodeBuddySessionsListedUnderTheirName(t *testing.T) {
|
|
h := sandboxHome(t)
|
|
src := filepath.Join("..", "sessions", "testdata", "codebuddy")
|
|
dst := filepath.Join(h, ".codebuddy")
|
|
if err := filepath.WalkDir(src, func(p string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rel, _ := filepath.Rel(src, p)
|
|
if d.IsDir() {
|
|
return os.MkdirAll(filepath.Join(dst, rel), 0o755)
|
|
}
|
|
b, err := os.ReadFile(p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(filepath.Join(dst, rel), b, 0o644)
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sessions.Reset()
|
|
t.Cleanup(sessions.Reset)
|
|
|
|
mux := http.NewServeMux()
|
|
sessionRoutes(mux, folderOnly{})
|
|
sessionManageRoutes(mux, folderOnly{})
|
|
get := func(path string, v any) {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
|
|
if w.Code != 200 {
|
|
t.Fatalf("%s: %d %s", path, w.Code, w.Body)
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
type named struct {
|
|
Agent string `json:"agent"`
|
|
Name string `json:"name"`
|
|
Icon string `json:"icon"`
|
|
Resume string `json:"resume"`
|
|
}
|
|
var list struct{ Sessions []named }
|
|
get("/api/sessions", &list)
|
|
n := 0
|
|
for _, s := range list.Sessions {
|
|
if s.Agent != "codebuddy" {
|
|
continue
|
|
}
|
|
n++
|
|
if s.Name != "CodeBuddy Code" || s.Icon != "codebuddy-color" {
|
|
t.Errorf("listed as %q (%s), want CodeBuddy Code (codebuddy-color)", s.Name, s.Icon)
|
|
}
|
|
if !strings.Contains(s.Resume, "codebuddy --resume ") {
|
|
t.Errorf("resume %q", s.Resume)
|
|
}
|
|
}
|
|
if n != 2 {
|
|
t.Fatalf("want 2 CodeBuddy Code sessions, got %d: %+v", n, list.Sessions)
|
|
}
|
|
var manage struct {
|
|
Agents []struct {
|
|
named
|
|
Deletable bool `json:"deletable"`
|
|
}
|
|
}
|
|
get("/api/sessions/manage", &manage)
|
|
found := false
|
|
for _, a := range manage.Agents {
|
|
if a.Agent == "codebuddy" {
|
|
found = true
|
|
if a.Name != "CodeBuddy Code" {
|
|
t.Errorf("the Sessions page's agent is %q, want CodeBuddy Code", a.Name)
|
|
}
|
|
if !a.Deletable {
|
|
t.Error("the Sessions page offers no trash for CodeBuddy Code's sessions")
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("no codebuddy among the Sessions page's agents: %+v", manage.Agents)
|
|
}
|
|
var stats struct {
|
|
Agents map[string]string `json:"agents"`
|
|
}
|
|
get("/api/sessions/stats?days=0", &stats)
|
|
if stats.Agents["codebuddy"] != "CodeBuddy Code" {
|
|
t.Errorf("Usage > Sessions' agent strip names it %q: %v", stats.Agents["codebuddy"], stats.Agents)
|
|
}
|
|
}
|