Files
magpie/internal/gui/sessions_reads_unchecked_test.go
T
yetone 5cf1d3846a sessions: an agent left off in the first "allow selected" is asked about once more, on Sessions and Usage › Requests
baysonfox on X: with magpie installed after Antigravity 2.0, the app's
sessions and calls made without magpie never showed in Usage, while agy
CLI's did. The first consent named the app off beside agy, and a named
agent was never "new" again, so nothing asked about it and nothing on
Usage said why. The reader is fine: the app's calls come from its own
SQLite steps (antigravityRead), read once allowed.

Nothing is turned on by magpie: the gate is the user's privacy choice.
Instead:
- settings.SessionReads gets Kept: agents turned off on their own (a
  sessions/reads post without `all`: Keep off, a Settings › Privacy row,
  `magpie sessions read off <agent>`). A post setting it on takes it out.
- readsNow's New: off, found here and not Kept (was: never named). So an
  agent left off in the first choice's list is asked about once more,
  as one found later already was.
- Usage › Requests shows a line above its rows for those agents
  (readsLater in the usage plugin): Count {names} / Don't count, the
  same {agents} posts as the Sessions page's laterCard. Gone after
  either answer; sessions/reads read at most once a minute.
- Old data: an agent turned off in Settings before Kept existed has no
  entry and is asked once more, for every user with such an agent.

Tests:
- TestSessionReadsUncheckedAgentAskedAgain (count, keep off): sandbox
  HOME with testdata/agy-sessions and the real Antigravity 2.30
  conversation (antigravity-2.30-tools); after the first choice the app
  is off and New, has no rows in /api/usage/requests; Count brings its
  rows in, Keep off keeps none, and neither is asked again. Red on the
  old code (New false after the first choice).
- TestSessionReadsTurnedOffNotAskedAgain: off on its own, under all true
  and all false, is neither on nor New.
- usage-reads-note.test.cjs: the Requests line in Chromium and WebKit,
  en/zh/zh-TW/ja/de at 900/420/390px, both answers, buttons inside the
  line, no sideways scroll; red on the old code (no #ledReads).

Run on mica (mote was full: load 40+, another GUI suite on it), rebased
on 389169f76:
- gofmt -l clean
- go vet on gui, sessions, settings, cli and tui; GOOS=linux -tags nogui
  and GOOS=windows vet on gui, sessions, settings and cli; go build ./...
- go test -count=1 -timeout 45m on internal/gui, sessions, settings, cli
  and tui: all ok except gui's TestGatewayModeListsNoOwnSessions, red
  the same on an untouched 389169f76 copy (#7064)
- GUI, both engines: usage-reads-note, sessions-reads, i18n-keys,
  i18n-en-no-cjk, usage-ledger, usage-request-page, usage-no-reading,
  usage-ledger-fit, ledger-hscroll, usage-phone-head, sessions-usage-off.
  Only usage-ledger's "newest live route needs no return-to-live button"
  was red (en, zh, both engines), red the same on the untouched
  389169f76 copy (#3104). i18n-keys first caught "Leave off" as otel's
  word; renamed to "Don't count".
- After rebasing on dc507aefd: gofmt, vet, the TestSessionReads tests
  and usage-reads-note, i18n-keys, i18n-en-no-cjk and sessions-reads
  again: all ok, 98 of 98 GUI tests.

Broken by hand: recording Kept on every off post (all sent too) turns
TestSessionReadsNewAgent, ...UncheckedAgentAskedAgain and
...TurnedOffNotAskedAgain red.

Not tried: the whole GUI suite (both machines had another GUI suite
running), the full go test ./..., and a real Antigravity 2.0 install
in the GUI; the live Antigravity data was not touched.
2026-11-18 20:59:55 +08:00

130 lines
4.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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"
)
// baysonfox on X, again: magpie was installed after Antigravity 2.0, so the
// first choice ("allow selected") listed the app and it was left off beside
// agy CLI. Named off, it was never "new", so neither the Sessions page nor
// Usage asked again, and the app's calls made without magpie were counted
// nowhere while agy's were. An agent left off in that first choice is asked
// about once more, on both pages; Show/Count reads it and its calls come
// into Usage › Requests; an agent turned off on its own (Keep off,
// Settings › Privacy) is kept off and not asked again. The app's folder is
// a real Antigravity 2.30 conversation (testdata/antigravity-2.30-tools).
func TestSessionReadsUncheckedAgentAskedAgain(t *testing.T) {
for _, allow := range []bool{true, false} {
t.Run(map[bool]string{true: "count", false: "keep off"}[allow], func(t *testing.T) {
h := sandboxHome(t)
copyTree(t, "../sessions/testdata/agy-sessions", filepath.Join(h, ".gemini", "antigravity-cli"))
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{} }); err != nil {
t.Fatal(err)
}
sessions.Reset()
t.Cleanup(sessions.Reset)
mux := http.NewServeMux()
sessionManageRoutes(mux, folderOnly{})
usageRoutes(mux, folderOnly{})
call := func(method, path, body string) []byte {
t.Helper()
w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest(method, path, strings.NewReader(body)))
if w.Code != 200 {
t.Fatalf("%s %s: %d %s", method, path, w.Code, w.Body)
}
return w.Body.Bytes()
}
app := func(r readsJSON) readAgentJSON {
t.Helper()
for _, f := range r.Found {
if f.Agent == "antigravity" {
return f
}
}
t.Fatalf("antigravity not found: %+v", r.Found)
return readAgentJSON{}
}
appRows := func() int {
t.Helper()
var page ledgerJSON
if err := json.Unmarshal(call("GET", "/api/usage/requests?period=all", ""), &page); err != nil {
t.Fatal(err)
}
n := 0
for _, row := range page.Rows {
if row.Agent == "antigravity" {
n++
}
}
return n
}
// the first choice, as the Sessions page's consent posts allow
// selected: every agent found named, the app left off
var r readsJSON
json.Unmarshal(call("POST", "/api/sessions/reads", `{"all":false,"agents":{"agy":true,"antigravity":false}}`), &r)
if a := app(r); a.On || !a.New {
t.Fatalf("the app left off in the first choice = %+v, want off and asked about again", a)
}
if n := appRows(); n != 0 {
t.Fatalf("%d of the app's calls counted before it was allowed", n)
}
body := `{"agents":{"antigravity":false}}`
if allow {
body = `{"agents":{"antigravity":true}}`
}
r = readsJSON{}
json.Unmarshal(call("POST", "/api/sessions/reads", body), &r)
if a := app(r); a.New || a.On != allow {
t.Fatalf("after the answer: %+v", a)
}
if s := settings.Shared().SessionReads; s == nil || s.All || !s.Agents["agy"] {
t.Fatalf("the answer changed the rest of the choice: %+v", s)
}
// the conversation's model calls, read from its database
if n := appRows(); allow && n == 0 || !allow && n != 0 {
t.Fatalf("allowed %v: %d of the app's calls in Usage › Requests", allow, n)
}
// asked once: a later read still says the same
r = readsJSON{}
json.Unmarshal(call("GET", "/api/sessions/reads", ""), &r)
if a := app(r); a.New {
t.Fatalf("asked about again after the answer: %+v", a)
}
})
}
}
// An agent turned off on its own, in Settings › Privacy or by Keep off, is
// the user's answer: it is not asked about again, under either first choice.
func TestSessionReadsTurnedOffNotAskedAgain(t *testing.T) {
for _, all := range []bool{true, false} {
h := sandboxHome(t)
copyTree(t, "../sessions/testdata/antigravity-2.30", filepath.Join(h, ".gemini", "antigravity"))
if err := settings.SetSessionReads(func(*settings.SessionReads) *settings.SessionReads { return &settings.SessionReads{} }); err != nil {
t.Fatal(err)
}
on := true
if err := sessions.SetReads(&all, map[string]bool{"antigravity": on}); err != nil {
t.Fatal(err)
}
if err := sessions.SetReads(nil, map[string]bool{"antigravity": false}); err != nil {
t.Fatal(err)
}
for _, f := range readsNow().Found {
if f.Agent == "antigravity" && (f.On || f.New) {
t.Fatalf("all %v, turned off in Settings: %+v", all, f)
}
}
}
}