MCPcopy
hub / github.com/docker/docker-agent / TestBranchSessionCopiesPrefix

Function TestBranchSessionCopiesPrefix

pkg/session/store_test.go:234–273  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func TestBranchSessionCopiesPrefix(t *testing.T) {
235 t.Parallel()
236
237 tempDB := filepath.Join(t.TempDir(), "test_branch_prefix.db")
238
239 store, err := NewSQLiteSessionStore(t.Context(), tempDB)
240 require.NoError(t, err)
241 defer store.(*SQLiteSessionStore).Close()
242
243 testAgent := agent.New("test-agent", "test prompt")
244 parent := &Session{
245 ID: "parent-session",
246 CreatedAt: time.Now(),
247 Messages: []Item{
248 NewMessageItem(UserMessage("Hello")),
249 NewMessageItem(NewAgentMessage(testAgent.Name(), &chat.Message{
250 Role: chat.MessageRoleAssistant,
251 Content: "Response",
252 })),
253 NewMessageItem(UserMessage("Edited")),
254 },
255 }
256
257 require.NoError(t, store.AddSession(t.Context(), parent))
258
259 parentLoaded, err := store.GetSession(t.Context(), parent.ID)
260 require.NoError(t, err)
261
262 branched, err := BranchSession(parentLoaded, 2)
263 require.NoError(t, err)
264
265 require.NoError(t, store.AddSession(t.Context(), branched))
266
267 loaded, err := store.GetSession(t.Context(), branched.ID)
268 require.NoError(t, err)
269
270 require.Len(t, loaded.Messages, 2)
271 assert.Equal(t, "Hello", loaded.Messages[0].Message.Message.Content)
272 assert.Equal(t, "Response", loaded.Messages[1].Message.Message.Content)
273}
274
275func TestBranchSessionClonesSubSession(t *testing.T) {
276 t.Parallel()

Callers

nothing calls this directly

Calls 13

AddSessionMethod · 0.95
GetSessionMethod · 0.95
NewFunction · 0.92
NewSQLiteSessionStoreFunction · 0.85
NewMessageItemFunction · 0.85
NewAgentMessageFunction · 0.85
BranchSessionFunction · 0.85
ContextMethod · 0.80
NowMethod · 0.80
UserMessageFunction · 0.70
CloseMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected