From 53442e193bea75d3efd4211ff6a4db28eb8e935a Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 21 Apr 2026 20:33:21 +0200 Subject: [PATCH] store: cover renameSession OnRename + SetSessionID error (89.2%) --- pkg/store/store_test.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/store/store_test.go b/pkg/store/store_test.go index 3c14add..cf26185 100644 --- a/pkg/store/store_test.go +++ b/pkg/store/store_test.go @@ -38,7 +38,8 @@ type stubCore struct { // Records submitted []string queued []string - interrupted bool + interrupted bool + setSessionIDErr error } func (c *stubCore) Submit(_ context.Context, input string, handler agent.EventHandler) { @@ -69,7 +70,7 @@ func (c *stubCore) Usage() string func (c *stubCore) ListModels() string { return c.models } func (c *stubCore) CWD() string { return c.cwd } func (c *stubCore) SetCWD(dir string) error { c.cwd = dir; return nil } -func (c *stubCore) SetSessionID(string) error { return nil } +func (c *stubCore) SetSessionID(string) error { return c.setSessionIDErr } func (c *stubCore) SystemPrompt() string { return c.sysprompt } func (c *stubCore) GenerationParams() backend.GenerationParams { return c.params } func (c *stubCore) SetGenerationParams(p backend.GenerationParams) error { c.params = p; return nil } @@ -601,7 +602,15 @@ func TestSessionStoreShutdown(t *testing.T) { } func TestSessionStoreRename(t *testing.T) { - s := newSessionStore(t) + sink := testSink() + var renamed [2]string + s := store.NewSessionStore(store.SessionStoreConfig{ + Log: sink.NewLogger("test"), + Sink: sink, + ReadFile: func(string) ([]byte, error) { return nil, nil }, + MkdirAll: func(string, os.FileMode) error { return nil }, + OnRename: func(oldID, newID string) { renamed = [2]string{oldID, newID} }, + }) sess := testSession("old") defer sess.Cancel() s.AddSession(sess) @@ -615,6 +624,9 @@ func TestSessionStoreRename(t *testing.T) { if s.Session("new") == nil { t.Error("new session should exist") } + if renamed != [2]string{"old", "new"} { + t.Errorf("OnRename called with %v; want [old new]", renamed) + } } func TestSessionStoreRenameErrors(t *testing.T) { @@ -636,6 +648,13 @@ func TestSessionStoreRenameErrors(t *testing.T) { if err := s.Rename("r", "r2"); err == nil { t.Error("Rename while running should error") } + // SetSessionID error + sess2 := testSession("sid") + sess2.Core.(*stubCore).setSessionIDErr = fmt.Errorf("id error") + s.AddSession(sess2) + if err := s.Rename("sid", "sid2"); err == nil { + t.Error("Rename with SetSessionID error should error") + } } // ===== SessionFileStore =====