(t *testing.T)
| 1061 | } |
| 1062 | |
| 1063 | func TestResolveSessionID_ExcludesSubSessions(t *testing.T) { |
| 1064 | t.Parallel() |
| 1065 | |
| 1066 | tempDB := filepath.Join(t.TempDir(), "test_resolve_subsessions.db") |
| 1067 | |
| 1068 | store, err := NewSQLiteSessionStore(t.Context(), tempDB) |
| 1069 | require.NoError(t, err) |
| 1070 | defer store.(*SQLiteSessionStore).Close() |
| 1071 | |
| 1072 | sqliteStore := store.(*SQLiteSessionStore) |
| 1073 | |
| 1074 | // Create a parent session |
| 1075 | parent := &Session{ |
| 1076 | ID: "parent", |
| 1077 | CreatedAt: time.Now().Add(-2 * time.Hour), |
| 1078 | } |
| 1079 | err = store.AddSession(t.Context(), parent) |
| 1080 | require.NoError(t, err) |
| 1081 | |
| 1082 | // Create a sub-session directly in the database to avoid the AddSubSession complexity |
| 1083 | // This simulates an existing sub-session without going through the full API |
| 1084 | subSessionTime := time.Now().Add(-1 * time.Hour) |
| 1085 | _, err = sqliteStore.db.ExecContext(t.Context(), |
| 1086 | `INSERT INTO sessions (id, tools_approved, input_tokens, output_tokens, title, cost, send_user_message, max_iterations, working_dir, created_at, starred, permissions, agent_model_overrides, custom_models_used, thinking, parent_id) |
| 1087 | VALUES (?, 0, 0, 0, '', 0, 1, 0, '', ?, 0, '', '{}', '[]', 1, ?)`, |
| 1088 | "subsession", subSessionTime.Format(time.RFC3339), "parent") |
| 1089 | require.NoError(t, err) |
| 1090 | |
| 1091 | // Create another root session (most recent root) |
| 1092 | root2 := &Session{ |
| 1093 | ID: "root2", |
| 1094 | CreatedAt: time.Now(), |
| 1095 | } |
| 1096 | err = store.AddSession(t.Context(), root2) |
| 1097 | require.NoError(t, err) |
| 1098 | |
| 1099 | // -1 should resolve to root2, not the subsession |
| 1100 | id, err := ResolveSessionID(t.Context(), store, "-1") |
| 1101 | require.NoError(t, err) |
| 1102 | assert.Equal(t, "root2", id) |
| 1103 | |
| 1104 | // -2 should resolve to parent |
| 1105 | id, err = ResolveSessionID(t.Context(), store, "-2") |
| 1106 | require.NoError(t, err) |
| 1107 | assert.Equal(t, "parent", id) |
| 1108 | } |
| 1109 | |
| 1110 | func TestResolveSessionID_InMemory(t *testing.T) { |
| 1111 | t.Parallel() |
nothing calls this directly
no test coverage detected