ZCode sends its session id to the gateway without the sess_ prefix stored in its database. Routing asks Titles with that bare id, gets no title, and falls back to the folder name even though the Sessions page can show the real title. Titles treats zcode:<id> as an alias for zcode:sess_<id> when it reads local session files, and returns the title under the key Routing asked for (the sess_ key too, which callers ignore). A regression test uses the database id shape ZCode writes and the bare request id it sends. Ported from Flandern's b1a952b73 (fix/zcode-routing-session-titles on flandern12111/magpie), code and test unchanged, reviewed line by line; the body is rewritten (the original had literal \n's), and gateway-sessions.md says it. Run on mote via mote-run, at origin/mainc7bbd3fafplus the change before this one: go test ./internal/sessions -run 'TestZCodeTitlesByRequestID|TestSessionTitles|TestTitles|TestZCode' -count=1: ok. Again at this commit on origin/main14f6d10de: go test ./internal/sessions -count=1 ok. Pushed onc4245c4c2, which changes only internal/gateway's object_root and its doc after 14f6d10de; not run again on it. Broken by hand: the alias lookup removed, TestZCodeTitlesByRequestID red ("zcode:578bd3d1-…: title \"\", want \"A ZCode session's title\""). Not tried: a real ZCode session through a running gateway. Co-authored-by: Flandern <3180066912wzw@gmail.com>
32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
package sessions
|
|
|
|
import (
|
|
"database/sql"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// A ZCode request carries its session's id without the prefix its database
|
|
// gives it (sess_…), so the Routing page asks for the title by that id. The
|
|
// title is found under the database's key and handed back under the id asked
|
|
// for, as it is for the prefixed id.
|
|
func TestZCodeTitlesByRequestID(t *testing.T) {
|
|
home := setupAgents(t)
|
|
const id = "578bd3d1-834b-43fb-b40c-ed9d17ad7731"
|
|
const name = "A ZCode session's title"
|
|
db, err := sql.Open("sqlite", filepath.Join(home, ".zcode", "cli", "db", "db.sqlite"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { db.Close() })
|
|
if _, err := db.Exec(`INSERT INTO session (id, project_id, parent_id, slug, directory, title, title_source, version, time_created, time_updated) VALUES (?, 'p', NULL, 's', '/work/zc', ?, 'generated', '0.16.9', 1790496000000, 1790496000000)`, "sess_"+id, name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := Titles([]string{"zcode:" + id, "zcode:sess_" + id})
|
|
for _, k := range []string{"zcode:" + id, "zcode:sess_" + id} {
|
|
if got[k] != name {
|
|
t.Fatalf("%s: title %q, want %q (all %v)", k, got[k], name, got)
|
|
}
|
|
}
|
|
}
|