Files
magpie/internal/sessions/hermes_visibility_test.go
T
Vocllum 5a41046325 sessions: Hermes Agent's sessions are on the Sessions page, read from its SQLite stores read-only (#569)
Hermes Agent's sessions are read from its SQLite stores — $HERMES_HOME (else ~/.hermes) and each named profile under profiles/, a selected profile home resolving back to its root — through a mode=ro connection, each session parsed in one read transaction for a consistent snapshot while Hermes writes in WAL mode. state.db itself is never modified; SQLite may create an empty state.db-wal and a state.db-shm beside a cleanly closed store, as for OpenCode's. A session's id carries a hash of its store's path, so the same id in two profiles stays two sessions. Titles, messages (respecting Hermes's active/compacted history and model-only display metadata, older schemas' missing columns read as defaults), models and token usage (session_model_usage rows, plus the session counters' main-loop residual) reach the Sessions page and Stats; the cache key includes the WAL's size and time, since usage and titles change without state.db's. Hermes usage is session-level, so it is not in Calls and the ledger is unchanged. Hermes sessions are read only: no resume, no delete, no folder or bar checkbox, with a note saying so (en and zh). Tests: hermes_test, hermes_compaction_test, hermes_display_test, hermes_usage_residual_test, hermes_visibility_test; sessions-manage.test.cjs covers the read-only view. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME, and go test -race ./internal/sessions ./internal/usage pass. (#569)
2026-10-02 23:02:03 +08:00

47 lines
1.3 KiB
Go

package sessions
import (
"database/sql"
"path/filepath"
"testing"
)
func TestHermesLiteralJSONText(t *testing.T) {
for _, text := range []string{"[]", "null", `[{"name":"item"}]`, `[{"type":"text","text":"literal"}]`} {
if got := hermesText(text); got != text {
t.Fatalf("literal %q became %q", text, got)
}
}
if got := hermesText("\x00json:" + `[{"type":"text","text":"encoded"}]`); got != "encoded" {
t.Fatal(got)
}
}
func TestHermesMessageVisibility(t *testing.T) {
setup(t)
root := filepath.Join(t.TempDir(), "hermes")
t.Setenv("HERMES_HOME", root)
path := hermesFixture(t, root, "", "visibility", false)
db, err := sql.Open("sqlite", path)
if err != nil {
t.Fatal(err)
}
defer db.Close()
_, err = db.Exec(`ALTER TABLE messages ADD COLUMN active INTEGER DEFAULT 1;
ALTER TABLE messages ADD COLUMN compacted INTEGER DEFAULT 0;
UPDATE messages SET active=0 WHERE id=2;
UPDATE messages SET active=0, compacted=1 WHERE id=1;`)
if err != nil {
t.Fatal(err)
}
h := newHermesDB(db)
var texts []string
err = h.eachMessage(db, "visibility", func(m hermesMessage) { texts = append(texts, hermesText(m.content)) })
if err != nil {
t.Fatal(err)
}
if len(texts) != 3 || texts[0] != "Please inspect this" {
t.Fatalf("visible messages: %v", texts)
}
}