Files
magpie/internal/settings/gateway_conversations_test.go
T
木子不是木子狸 c9b8263378 sessions, gateway: Sessions lists gateway sessions, and can keep their text on this computer when turned on (#1355, mu-zi-lee)
What changed: the Sessions page lists sessions seen only through the
gateway (from the usage ledger, read-only, a native session of the same id
wins), and shows in gateway mode. A Sessions switch, off by default and
confirmed before it turns on, records each gateway exchange's text under
the config dir (scrubbed, at most 7 days and 256 MiB, cleaned hourly).
Settings sync and restore can't turn it on; POST /api/sessions/recording
turns it on or off and can clear what was kept.

Why: users of magpie as a gateway (gateway mode, LAN clients) had no way
to see their conversations; the owner chose this design on the PR.

Squashed from PR head 6a343ba1 onto origin/main. Conflicts: gui-shell.md
(kept main's placeMenu text, took the PR's Sessions in gateway mode) and
settings_keep_test.go (main's fields plus GatewayConversations).

Run: go build ./..., go vet on gateway, gui, sessions, settings, usage;
go test -race -timeout 900s on those five packages: all ok.
2026-10-10 04:24:18 +08:00

68 lines
1.9 KiB
Go

package settings
import "testing"
func TestGatewayConversationConsentIsMachineLocal(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().GatewayConversations {
t.Fatal("recording on by default")
}
from := Settings{GatewayConversations: true}
from.KeepOwn(Settings{})
if from.GatewayConversations {
t.Fatal("sync enabled recording")
}
from.KeepOwn(Settings{GatewayConversations: true})
if !from.GatewayConversations {
t.Fatal("sync removed local consent")
}
}
func TestGatewayConversationGenericSaveCannotEnable(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if err := Save(Settings{GatewayConversations: true}); err != nil {
t.Fatal(err)
}
if Load().GatewayConversations {
t.Fatal("generic settings save enabled recording")
}
}
func TestGatewayConversationConsentSurvivesStaleSettings(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if err := SetGatewayConversations(true); err != nil {
t.Fatal(err)
}
staleOn := Load()
if !staleOn.GatewayConversations {
t.Fatal("explicit consent was not saved")
}
if err := SetGatewayConversations(false); err != nil {
t.Fatal(err)
}
staleOn.Theme = "dark"
if err := Save(staleOn); err != nil {
t.Fatal(err)
}
if got := Load(); got.GatewayConversations || got.Theme != "dark" {
t.Fatal("stale settings save enabled recording or lost its theme change")
}
staleOff := Load()
if err := SetGatewayConversations(true); err != nil {
t.Fatal(err)
}
staleOff.Theme = "light"
if err := Save(staleOff); err != nil {
t.Fatal(err)
}
if got := Load(); !got.GatewayConversations || got.Theme != "light" {
t.Fatal("stale settings save removed consent or lost its theme change")
}
if err := SetGatewayConversations(false); err != nil {
t.Fatal(err)
}
if got := Load(); got.GatewayConversations || got.Theme != "light" {
t.Fatal("explicit consent change overwrote other settings")
}
}