Files
DeepSeek-Reasonix/internal/frontend/cli/rename_test.go
T
yhh 2a62e704d3 refactor(sessionstore): a transcript's durable record leaves the agent
Session persistence moves from internal/runtime/agent to
internal/state/sessionstore: the Session type, its checkpoint and event
log, listing sidecars, branches, leases, recovery copies, migration, and
the compaction and subagent records saved beside a transcript. The agent
keeps the loop and imports the store; history, historycatalog, migration,
guardian, instanceid and sessiontool now reach the store instead of the
agent, which drops layer-order from 26 to 18.

Tests that exercise only store internals moved with it; the rest stay in
agent and qualify the moved names. DigestSessionMessages and
CompactionStateSchemaV1 are exported for the agent tests that build
legacy fixtures.

Baseline: carried with -allow-widen. The moved files bring their essay,
file-size, complexity and orphan debt unchanged under new paths, and
boot.go, acp/service.go, serve/serve.go, agent/task.go and
control/controller.go each gain the one import line the split costs.
2026-09-23 20:08:36 -07:00

86 lines
2.6 KiB
Go

package cli
import (
"encoding/json"
"os"
"path/filepath"
"reasonix/internal/state/sessionstore"
"strings"
"testing"
"time"
"reasonix/internal/base/testenv"
)
func TestRenameSessionUpdatesCustomTitle(t *testing.T) {
dir := testenv.TempDir(t)
sessionPath := filepath.Join(dir, "test-session.jsonl")
if err := os.WriteFile(sessionPath, []byte("{}\n"), 0o644); err != nil {
t.Fatal(err)
}
updatedAt := time.Date(2026, 6, 1, 12, 0, 0, 0, time.UTC)
if err := sessionstore.SaveBranchMetaPreserveUpdated(sessionPath, sessionstore.BranchMeta{
TopicTitle: "Topic",
CreatedAt: updatedAt.Add(-time.Hour),
UpdatedAt: updatedAt,
}); err != nil {
t.Fatalf("seed meta: %v", err)
}
if err := sessionstore.RenameSession(sessionPath, "My Test Title"); err != nil {
t.Fatalf("RenameSession failed: %v", err)
}
metaPath := sessionPath + ".meta"
raw, err := os.ReadFile(metaPath)
if err != nil {
t.Fatalf("reading meta: %v", err)
}
var m struct {
TopicTitle string `json:"topic_title"`
CustomTitle string `json:"custom_title"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatalf("decoding meta: %v", err)
}
if m.CustomTitle != "My Test Title" {
t.Errorf("custom_title = %q, want %q", m.CustomTitle, "My Test Title")
}
if m.TopicTitle != "Topic" {
t.Errorf("topic_title = %q, want preserved Topic", m.TopicTitle)
}
stored, ok, err := sessionstore.LoadBranchMeta(sessionPath)
if err != nil || !ok {
t.Fatalf("LoadBranchMeta after rename ok=%v err=%v", ok, err)
}
if !stored.UpdatedAt.Equal(updatedAt) {
t.Errorf("updated_at changed after rename: got %s want %s", stored.UpdatedAt, updatedAt)
}
if err := sessionstore.RenameSession(sessionPath, "Updated Title"); err != nil {
t.Fatalf("second rename failed: %v", err)
}
raw, _ = os.ReadFile(metaPath)
json.Unmarshal(raw, &m)
if m.CustomTitle != "Updated Title" {
t.Errorf("custom_title after second rename = %q, want %q", m.CustomTitle, "Updated Title")
}
if m.TopicTitle != "Topic" {
t.Errorf("topic_title after second rename = %q, want preserved Topic", m.TopicTitle)
}
}
func TestSessionPickerLabelPrefersCustomTitle(t *testing.T) {
s := sessionstore.SessionInfo{Turns: 5, Preview: "first user message here", TopicTitle: ""}
got := sessionPickerLabel(s)
if got == "" {
t.Fatal("empty label")
}
s.TopicTitle = "My Topic Name"
s.CustomTitle = "My Custom Name"
got = sessionPickerLabel(s)
if !strings.Contains(got, "My Custom Name") {
t.Errorf("label %q should contain custom title", got)
}
if strings.Contains(got, "My Topic Name") {
t.Errorf("label %q should prefer custom title over topic title", got)
}
}