Files
magpie/internal/sessions/antigravity_insiders_test.go
T
yetoneandRuijia Zhang 04aabf3a01 sessions: read Antigravity Insiders conversations (#5634)
Antigravity - Insiders keeps its conversations in a separate store,
~/.gemini/antigravity-insiders/conversations/<id>.db, with its own
conversation_summaries.db beside it. Only the stable store was scanned,
so Insiders sessions and their token use never reached Sessions or Usage.

Both stores are now read under the existing antigravity agent and its
session-reading choice. An Insiders-only install shows up in Found, and
Dirs lists each store that exists. Each file takes its title and folder
from its own store's summaries. Insiders session ids carry an
"insiders-" prefix in magpie, so a UUID present in both stores stays two
sessions with separate call ids; stable ids are unchanged and nothing on
disk is renamed. Nothing maps a session id back to a path, so the prefix
can't send a reader to the wrong file.

Ported from BUKOWSKIREAL's branch (926d4fe50), unchanged.

Ran (mote, at this head):
- TestAntigravityInsidersSessions: green; red with the three source files
  put back (Insiders missing from Found, Dirs and List).
- go test -count=1 ./internal/sessions ./internal/usage ./internal/usageapi
  ok; go vet ./internal/sessions for darwin, linux and windows ok; gofmt
  clean.
- The author's own run: 42 real Insiders databases read in an isolated
  copy, 2,293 calls, each model's tokens matching an independent decoder.
Not tried: a real Insiders install on our machines; the full suite.

Co-authored-by: Ruijia Zhang <ruijiazhang76@gmail.com>
Reported-by: zhang9083 (Discord #feedback)
2026-11-08 00:33:08 +08:00

117 lines
4.1 KiB
Go

package sessions
import (
"database/sql"
"os"
"path/filepath"
"slices"
"testing"
"time"
)
// Insiders keeps the app's SQLite format in ~/.gemini/antigravity-insiders.
// Reuse the real step bytes from #2190 to exercise discovery through both
// Sessions and Usage, with stable absent and then with the same UUID in both.
func TestAntigravityInsidersSessions(t *testing.T) {
claude, _ := setup(t)
home := filepath.Join(filepath.Dir(claude), "home")
stable := filepath.Join(home, ".gemini", "antigravity")
insiders := filepath.Join(home, ".gemini", "antigravity-insiders")
const id = "37c3c786-9a11-44be-97df-b8fc1ccebc78"
const insiderID = "insiders-" + id
antigravityFixture(t, home, id)
if err := os.Rename(stable, insiders); err != nil {
t.Fatal(err)
}
db, err := sql.Open("sqlite", filepath.Join(insiders, "conversation_summaries.db")+"?_pragma=journal_mode(WAL)")
if err != nil {
t.Fatal(err)
}
defer db.Close()
if _, err := db.Exec(antigravitySummariesSchema); err != nil {
t.Fatal(err)
}
if _, err := db.Exec("INSERT INTO conversation_summaries (conversation_id, title, preview, last_modified_time, workspace_uris, last_user_input_time, app_data_dir) VALUES (?, 'Insiders conversation', '', '2026-11-07 00:12:46+00:00', '[\"file:///work/insiders\"]', '2026-11-07 00:12:43+00:00', 'antigravity-insiders')", id); err != nil {
t.Fatal(err)
}
if !slices.Contains(Found(), "antigravity") {
t.Error("an Insiders-only install is missing from the session reading choice")
}
if !slices.Contains(Dirs(), insiders) {
t.Error("the Insiders session folder is not listed")
}
check := func(stableHere bool, title string) {
t.Helper()
ss := List(0)
s := find(t, ss, "antigravity", insiderID)
if s.Title != title || s.Cwd != filepath.FromSlash("/work/insiders") || !s.ReadOnly || s.Resume != "" {
t.Errorf("Insiders title/folder/read-only/resume = %q/%q/%v/%q", s.Title, s.Cwd, s.ReadOnly, s.Resume)
}
if s.Path != filepath.Join(insiders, "conversations", id+".db") {
t.Errorf("Insiders path = %q", s.Path)
}
want := Tokens{Input: 43032, Output: 979}
if got := model(s, "gemini-3.8-flash").Tokens; got != want {
t.Errorf("Insiders model tokens = %+v, want %+v", got, want)
}
if got := model(s, "antigravity").Tokens; got != (Tokens{Input: 4254, Output: 276, CacheRead: 18561}) {
t.Errorf("Insiders call without a model = %+v", got)
}
if stableHere {
st := find(t, ss, "antigravity", id)
if st.Title != "" || st.Cwd != "" || model(st, "gemini-3.8-flash").Tokens != want {
t.Error("stable's session picked up Insiders' summary or tokens")
}
}
counts := map[string]int{}
msgs := map[string]bool{}
var tokens Tokens
for _, c := range Calls(time.Time{}) {
if c.Agent != "antigravity" {
continue
}
counts[c.Session]++
if c.Session == insiderID {
tokens.add(c.Tokens)
}
if c.Msg == "" || msgs[c.Msg] {
t.Errorf("stable and Insiders share call id %q", c.Msg)
}
msgs[c.Msg] = true
}
if counts[insiderID] != 4 || (stableHere && counts[id] != 4) || (!stableHere && counts[id] != 0) {
t.Errorf("calls by session = %v", counts)
}
if tokens != (Tokens{Input: 47286, Output: 1255, CacheRead: 18561}) {
t.Errorf("Insiders Usage tokens = %+v", tokens)
}
}
check(false, "Insiders conversation")
antigravityFixture(t, home, id)
if !slices.Contains(Dirs(), stable) {
t.Error("the stable app's session folder is not listed")
}
check(true, "Insiders conversation")
if _, err := db.Exec("UPDATE conversation_summaries SET title = 'Renamed Insiders conversation' WHERE conversation_id = ?", id); err != nil {
t.Fatal(err)
}
check(true, "Renamed Insiders conversation")
if err := SetReads(nil, map[string]bool{"antigravity": false}); err != nil {
t.Fatal(err)
}
if len(antigravityFiles()) != 0 || len(antigravityCallFiles()) != 0 {
t.Error("turning off Antigravity still discovers app files")
}
for _, s := range List(0) {
if s.Agent == "antigravity" {
t.Error("turning off Antigravity still lists an app session")
}
}
for _, c := range Calls(time.Time{}) {
if c.Agent == "antigravity" {
t.Error("turning off Antigravity still counts an app call")
}
}
}