Files
magpie/internal/gui/sessions_antigravity_test.go
T
yetone d2fa7d8d79 sessions: an Antigravity app conversation shows what was said, not only its title
@yansheng1003 on X: the Sessions page showed an Antigravity 2.0
conversation's title and preview only. HasTranscript left "antigravity"
out, since conversations/<id>.db's step text is encrypted at rest, so
the row had no Show conversation and /api/sessions/transcript said
"this agent's conversations can't be shown".

The app also writes every step in plain text beside the database:
brain/<id>/.system_generated/logs/transcript_full.jsonl in the same
store, in agy CLI's format (user input, planner responses with their
tool_calls, tool results). Antigravity 2.30's language server writes it
in the stable store and in Insiders' (both checked: run in a sandbox
HOME on Windows against a fake model that called read_file).

- transcript.go: antigravity has a transcript; readTranscriptOf reads
  it through agyTranscript (antigravityTranscriptOf), so the viewer,
  TranscriptAt, search, the said index and the Markdown export all get
  it. A conversation with no transcript file is ErrNoTranscript, as
  before.
- antigravity_app.go: antigravityTranscript derives the path from the
  database's (stable, Insiders, a WSL distro's); its size and time are
  folded into the session file's with the -wal's, so a step it adds
  reads the session and the said index again.
- search.go: linesFile is false for antigravity, so the encrypted .db is
  never pre-scanned for the words.
- testdata/antigravity-2.30-tools: that real conversation (db with the
  WAL checkpointed, summary row, brain/ logs).

Tests: TestAntigravityAppTranscript (stable, Insiders, WSL: parts, search
hit and miss, Markdown), TestAntigravityAppNoTranscript,
internal/gui TestSessionAntigravityConversation (/api/sessions marks it,
/api/sessions/transcript gives the five parts).

Run: on mica (mica-run) at base de5fc6700:
- gofmt -l internal/sessions internal/gui: clean.
- go vet ./internal/sessions ./internal/gui, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet on the same, go build .: ok.
- go test -count=1 -timeout 45m ./internal/sessions: ok but for
  TestWSLAgentsGoneListingDrops (load ~48; fixed at its cause in the
  commit before this one); go test ./internal/gui: ok (299s).
- After that fix: go test -run 'WSL|Antigravity|Agy|Gone'
  ./internal/sessions ok; GUI files sessions-talk, -talk-sheet,
  -talk-model, -export, -said, -subagents, -reads, -search, -convert:
  168 of 168 in Chromium and WebKit.
- Old code (de5fc6700 with only the new tests and testdata):
  TestAntigravityAppTranscript red in stable, insiders and wsl ("the
  session isn't marked readable"), TestSessionAntigravityConversation
  red ("listed with no conversation to show ... Transcript:false").
- Windows (win-run on xiaomi-gpu): TestAntigravityAppTranscript (3
  subtests) and TestAntigravityAppNoTranscript pass.
  TestAntigravityAppFolder is red there at the base as well (#5957).
Rebased onto bfddc9cfb, on mote (mote-run) at this tree: gofmt clean,
the three vets and go build ok, go test -count=1 ./internal/sessions
./internal/gui ok (56s, 157s).
Not tried: the real GUI window opening this conversation; the API and
page are covered by the tests above.
2026-11-18 18:55:46 +08:00

83 lines
2.5 KiB
Go

package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/sessions"
"github.com/yetone/magpie/internal/settings"
)
// @yansheng1003 on X: an Antigravity 2.0 conversation showed only its
// title and preview. The Sessions list marks it as one whose conversation
// can be shown, and /api/sessions/transcript, which Show conversation
// asks, gives what was said: the user's turn, the replies, the tool call
// and its result, read from the transcript the app's 2.30 language server
// wrote (sessions' testdata/antigravity-2.30-tools).
func TestSessionAntigravityConversation(t *testing.T) {
h := sandboxHome(t)
copyTree(t, "../sessions/testdata/antigravity-2.30-tools", filepath.Join(h, ".gemini", "antigravity"))
if err := settings.SetSessionReads(func(*settings.SessionReads) *settings.SessionReads {
return &settings.SessionReads{Asked: true, All: true}
}); err != nil {
t.Fatal(err)
}
sessions.Reset()
t.Cleanup(sessions.Reset)
const id = "a9b3e500-3594-49ed-b821-3418225e1990"
mux := http.NewServeMux()
sessionRoutes(mux, folderOnly{})
get := func(path string) []byte {
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)
}
return w.Body.Bytes()
}
var list struct {
Sessions []struct {
Agent, ID string
Transcript bool
}
}
if err := json.Unmarshal(get("/api/sessions"), &list); err != nil {
t.Fatal(err)
}
listed := false
for _, s := range list.Sessions {
if s.Agent == "antigravity" && s.ID == id {
listed = true
if !s.Transcript {
t.Fatalf("listed with no conversation to show: %+v", s)
}
}
}
if !listed {
t.Fatalf("not listed: %+v", list.Sessions)
}
var tr sessions.Transcript
if err := json.Unmarshal(get("/api/sessions/transcript?agent=antigravity&id="+id), &tr); err != nil {
t.Fatal(err)
}
var said []string
for _, p := range tr.Parts {
said = append(said, p.Role+"/"+p.Kind+"/"+p.Name+": "+p.Text)
}
want := []string{
"user/text/: read a.txt",
"assistant/text/: Let me read it.",
`assistant/tool_use/read_file: {"Path":"C:\\Users\\yeton\\agyss\\e2e4\\home\\proj\\a.txt"}`,
"tool/tool_result/: Showing lines 1-1 of 1\n1: hi",
"assistant/text/: a.txt says hi.",
}
if strings.Join(said, "\n|") != strings.Join(want, "\n|") {
t.Fatalf("transcript\n%s\nwant\n%s", strings.Join(said, "\n|"), strings.Join(want, "\n|"))
}
}