changqiu4890 on Discord: Routing -> Requests showed dsh's requests with no session id. dsh 0.2.1's pi-ai routes (openai-completions, anthropic), which magpie configures, send no session header (pi-ai's session affinity is withheld by dsh's compat gate), so a route had only its Conv, the hash of its first user message. The Context page already found dsh's session by that hash (dshConvs); the Routing page grouped by header session only. pricedRoutes now gives a dsh route with no session of its own the dsh session whose Convs hold its Conv (convOwners, shared with the Context page's joinConvs), from an index rebuilt at most every 2s when a conv is missing and every minute otherwise. Grouping and titles (dsh:<id>) follow. A route with its own session, another agent's route, and a conv two sessions share stay as they were. Run (mote-run, this tree): - go test -tags nogui ./internal/gui/ ./internal/sessions/: ok, ok - TestRoutingDshRoutesNameTheirSession and TestContext*: ok - GUI routing-sessions, routing-session-folder, routing-by-key, ctx-route, routing-day-window: Chromium 160/0, WebKit 80/0 - go vet darwin, linux (nogui), windows ./internal/gui; go build all three - gofmt -l clean Broken by hand: `r.Session = owners[k]` -> `_ = owners[k]`; the new test's dsh chat and messages routes went red. Not tried: a real dsh through magpie. A brand-new session's first request shows no session until dsh writes its session file and the index refreshes. The in-flight list (Active, concurrency endpoint) is unchanged.
71 lines
2.4 KiB
Go
71 lines
2.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
)
|
|
|
|
// changqiu4890 on Discord: dsh sends no session id on its chat-completions
|
|
// and messages routes, so the Routing page's requests list put every dsh
|
|
// request under "No session ID". The routes it is served name the dsh
|
|
// session their conversation id was read from, as the Context page does
|
|
// (TestContextDshSessionTitles); another agent's route, and a conversation
|
|
// no file holds, stay as they came.
|
|
func TestRoutingDshRoutesNameTheirSession(t *testing.T) {
|
|
sandboxHome(t)
|
|
home := t.TempDir()
|
|
t.Setenv("DSH_HOME", home)
|
|
sessions.Reset()
|
|
t.Cleanup(sessions.Reset)
|
|
resetRouteConvs := func() {
|
|
routeConvs.Lock()
|
|
routeConvs.of, routeConvs.at = nil, time.Time{}
|
|
routeConvs.Unlock()
|
|
}
|
|
resetRouteConvs()
|
|
t.Cleanup(resetRouteConvs)
|
|
defer func(f, k time.Duration) { convsFresh, convsKept = f, k }(convsFresh, convsKept)
|
|
convsFresh = 0
|
|
|
|
const chat, msgs = "session-508e7b0a-37c0-41f7-ac62-e48ab3146111", "session-8d93476d-ca34-461c-9e8e-7031c1dedfff"
|
|
route := func(id int64, agent, conv, session string) gateway.Route {
|
|
return gateway.Route{ID: id, Agent: agent, Conv: conv, Session: session}
|
|
}
|
|
routes := []gateway.Route{
|
|
route(1, "dsh", "magpie-950998433c3e70e50dc32994", ""), // chat-completions turn
|
|
route(2, "dsh", "magpie-be31a0561e12cf603d3e79d9", ""), // messages turn
|
|
route(3, "dsh", "magpie-000000000000000000000000", ""), // no file's
|
|
route(4, "other", "magpie-950998433c3e70e50dc32994", ""), // not dsh
|
|
route(5, "dsh", "magpie-950998433c3e70e50dc32994", "own-1"), // names its own
|
|
}
|
|
sessionsOf := func() map[int64]string {
|
|
out := map[int64]string{}
|
|
for _, r := range pricedRoutes(routes) {
|
|
out[r.ID] = r.Session
|
|
}
|
|
return out
|
|
}
|
|
// listed before dsh wrote its files: nothing to name yet
|
|
if got := sessionsOf(); got[1] != "" || got[2] != "" {
|
|
t.Fatalf("before the files: %v", got)
|
|
}
|
|
fixture := filepath.Join("..", "sessions", "testdata", "dsh-gateway", "sessions")
|
|
if err := os.CopyFS(filepath.Join(home, "sessions"), os.DirFS(fixture)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sessions.Reset()
|
|
// a session begun since the last listing is found on the next poll
|
|
got := sessionsOf()
|
|
want := map[int64]string{1: chat, 2: msgs, 3: "", 4: "", 5: "own-1"}
|
|
for id, w := range want {
|
|
if got[id] != w {
|
|
t.Errorf("route %d: session %q, want %q", id, got[id], w)
|
|
}
|
|
}
|
|
}
|