Files
magpie/internal/sessions/uninstalled_test.go
T
yetone 12610cf2ff sessions: the Usage page's list leaves out sessions taken off the list of an uninstalled agent (_SekiBetu_ on X)
v0.1.3784 hid a forgotten session only on the Sessions manage page; /api/sessions
still listed it. ForgottenOut drops those rows (only while the agent's command
is gone, so Restore and a reinstall list them again), and the hidden list's
stamp is part of the poll's tag so a Delete shows on the next poll.

Run on mote: go test -count=1 ./internal/sessions ok; ./internal/gui fails only
TestCoreScriptBudget, red on clean origin/main too (#6189); go vet darwin and
windows ok; gofmt clean.
Broken by hand: ForgottenOut never hiding turned TestUninstalledAgentSessionsAreForgotten red.
Not tried: a real uninstalled OpenCode; the Usage page in a browser.
2026-11-12 00:25:56 +08:00

76 lines
2.0 KiB
Go

package sessions
import (
"path/filepath"
"testing"
)
// _SekiBetu_ on X: OpenCode uninstalled, its sessions stayed listed with a
// Resume and no Delete. With its command gone Resume is not offered, Delete
// takes the row off the list (its database is not touched), and Restore
// lists it again.
func TestUninstalledAgentSessionsAreForgotten(t *testing.T) {
inZone(t, 0)
data, _ := setupMore(t)
ocMakeDB(t, filepath.Join(data, "opencode", "opencode.db"))
t.Cleanup(ForceCLIGone())
row := func() Managed {
t.Helper()
for _, m := range ListAgent("opencode") {
if m.ID == ocMain {
return m
}
}
t.Fatal("no OpenCode session")
return Managed{}
}
if m := row(); m.Resume == "" || m.Deletable {
t.Fatalf("installed: %+v", m)
}
if _, err := Forget("opencode", ocMain); err == nil {
t.Fatal("forgot a session of an installed agent")
}
defer ForceCLIGone("opencode")()
if oc := find(t, List(0), "opencode", ocMain); oc.Resume != "" {
t.Fatalf("resume offered with opencode gone: %q", oc.Resume)
}
if m := row(); m.Resume != "" || !m.Deletable || !m.Forget {
t.Fatalf("uninstalled: resume %q deletable %v forget %v", m.Resume, m.Deletable, m.Forget)
}
m := row()
tr, err := Forget("opencode", ocMain)
if err != nil {
t.Fatal(err)
}
if !tr.Forgot || !GatewayHidden()("opencode", ocMain, m.Last) {
t.Fatalf("not hidden after Forget: %+v", tr)
}
if got := Trash(); len(got) != 1 || !got[0].Forgot {
t.Fatalf("trash %+v", got)
}
// the Usage page's list (ForgottenOut) leaves it out, and only while the
// command is gone
has := func() bool {
for _, x := range ForgottenOut(List(0)) {
if x.Agent == "opencode" && x.ID == ocMain {
return true
}
}
return false
}
if has() {
t.Fatal("a forgotten session is still in the Usage list")
}
if _, err := Restore(tr.Key); err != nil {
t.Fatal(err)
}
if GatewayHidden()("opencode", ocMain, m.Last) {
t.Fatal("still hidden after Restore")
}
if !has() {
t.Fatal("a restored session is not in the Usage list")
}
}