Only Codex sessions were named (from Codex's index). The page now also asks POST /api/gateway/session-titles for the other agents' sessions it lists, as agent:id keys, and sessions.Titles reads each from the agent's own files the way the Sessions page does: the name given in magpie, else the agent's own title (Claude Code's ai-title / custom-title), else the first prompt. Each key is asked once; the names are kept on the page, so a live update that replaces the rows keeps them. A session with no file here keeps its id. TestSessionTitlesNameOtherAgents fails without the change (titles = map[]), and routing-sessions' "other agents' sessions show their own names" times out waiting for the name without the routing.js change. Run: HOME=<temp> go test -tags nogui ./internal/gui ./internal/sessions; go vet for darwin, linux and windows; the 72 routing GUI test files in Chromium and WebKit (491 pass, 0 fail). No new t() strings.
57 lines
2.3 KiB
Go
57 lines
2.3 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
)
|
|
|
|
// The Routing page names a Claude Code session by the title in its own
|
|
// file, as the Sessions page does, not by its UUID (#1293). A session with
|
|
// no file here, or another agent's id, gets no name.
|
|
func TestSessionTitlesNameOtherAgents(t *testing.T) {
|
|
sandboxHome(t)
|
|
claude := t.TempDir()
|
|
t.Setenv("CLAUDE_CONFIG_DIR", claude)
|
|
t.Setenv("CODEX_HOME", t.TempDir())
|
|
t.Cleanup(sessions.Reset)
|
|
sessions.Reset()
|
|
const id = "578bd3d1-834b-43fb-b40c-ed9d17ad7731"
|
|
dir := filepath.Join(claude, "projects", "-work-app")
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
lines := []string{
|
|
`{"parentUuid":null,"isSidechain":false,"type":"user","message":{"role":"user","content":"把路由页的会话名显示出来"},"uuid":"u1","timestamp":"2026-10-08T10:00:01.000Z","cwd":"/work/app","sessionId":"` + id + `"}`,
|
|
`{"parentUuid":"u1","isSidechain":false,"message":{"model":"claude-opus-5-5","id":"msg_1","type":"message","role":"assistant","content":[{"type":"text","text":"好"}],"usage":{"input_tokens":10,"output_tokens":5}},"requestId":"req_1","type":"assistant","uuid":"a1","timestamp":"2026-10-08T10:00:05.000Z","cwd":"/work/app","sessionId":"` + id + `"}`,
|
|
`{"type":"ai-title","aiTitle":"路由会话名","sessionId":"` + id + `"}`,
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, id+".jsonl"), []byte(strings.Join(lines, "\n")+"\n"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mux := http.NewServeMux()
|
|
traceRoutes(mux)
|
|
body := `{"ids":[],"routeIds":[],"sessions":["claude:` + id + `","claude:00000000-0000-0000-0000-000000000000","pi:` + id + `"]}`
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/gateway/session-titles", strings.NewReader(body)))
|
|
if w.Code != 200 {
|
|
t.Fatalf("%d %s", w.Code, w.Body)
|
|
}
|
|
var out struct {
|
|
Titles map[string]string `json:"titles"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := map[string]string{"claude:" + id: "路由会话名"}
|
|
if len(out.Titles) != len(want) || out.Titles["claude:"+id] != want["claude:"+id] {
|
|
t.Fatalf("titles = %v, want %v (body %s)", out.Titles, want, w.Body)
|
|
}
|
|
}
|