remove unused session-listing chain · Entire

remove unused session-listing chain

f4711f2→main·

pfleidi·1mo ago·3 files·+0 added/-672 removed

Delete strategy.ListSessions, GetSession, and three private helpers along with their tests. The chain had no non-test callers in the repo.

Keeps Session/Checkpoint structs (still referenced by explain.go) and NoDescription/ErrNoSession (used elsewhere in the package).

Sessions

d6f9bf29997fView transcript

Changes

3

464 unmodified lines
func TestShadowStrategy_ListSessions_Empty(t *testing.T) {
    dir := t.TempDir()
    _, err := git.PlainInit(dir, false)
    if err != nil {
        t.Fatalf("failed to init git repo: %v", err)
    }

t.Chdir(dir)

sessions, err := ListSessions(context.Background())
    if err != nil {
        t.Errorf("ListSessions(context.Background()) error = %v", err)
    }
    if len(sessions) != 0 {
        t.Errorf("ListSessions(context.Background()) returned %d sessions, want 0", len(sessions))
    }
}

func TestShadowStrategy_GetSession_NotFound(t *testing.T) {
    dir := t.TempDir()
    _, err := git.PlainInit(dir, false)
    if err != nil {
        t.Fatalf("failed to init git repo: %v", err)
    }

t.Chdir(dir)

_, err = GetSession(context.Background(), "nonexistent")
    if !errors.Is(err, ErrNoSession) {
        t.Errorf("GetSession() error = %v, want ErrNoSession", err)
    }
}

func TestShadowStrategy_GetSessionInfo_NoShadowBranch(t *testing.T) {
    dir := t.TempDir()
    repo, err := git.PlainInit(dir, false)

func ListSessions(ctx context.Context) ([]Session, error) {
    repo, err := OpenRepository(ctx)
    if err != nil {
        return nil, fmt.Errorf("failed to open git repository: %w", err)
    }
    defer repo.Close()

// Get checkpoints from the entire/checkpoints/v1 branch
    checkpoints, err := ListCheckpoints(ctx)
    if err != nil {
        return nil, fmt.Errorf("failed to list checkpoints: %w", err)
    }

// Group checkpoints by session ID
    // For multi-session checkpoints, expand SessionIDs array so each session gets the checkpoint
    sessionMap := make(map[string]*Session)
    for _, cp := range checkpoints {
        // Determine which session IDs this checkpoint belongs to
        // Multi-session checkpoints have SessionIDs populated; single-session use SessionID
        sessionIDs := cp.SessionIDs
        if len(sessionIDs) == 0 {
            sessionIDs = []string{cp.SessionID}
        }

for _, sessionID := range sessionIDs {
            if sessionID == "" {
                continue
            }

if existing, ok := sessionMap[sessionID]; ok {
                existing.Checkpoints = append(existing.Checkpoints, Checkpoint{
                    CheckpointID:     cp.CheckpointID,
                    Message:          "Checkpoint: " + cp.CheckpointID.String(),
                    Timestamp:        cp.CreatedAt,
                    IsTaskCheckpoint: cp.IsTask,
                    ToolUseID:        cp.ToolUseID,
                })
            } else {
                // Get description from the checkpoint tree
                description := getDescriptionForCheckpoint(repo, cp.CheckpointID)

sessionMap[sessionID] = &Session{
                    ID:          sessionID,
                    Description: description,
                    Strategy:    "", // Will be set from metadata if available
                    StartTime:   cp.CreatedAt,
                    Checkpoints: []Checkpoint{{
                        CheckpointID:     cp.CheckpointID,
                        Message:          "Checkpoint: " + cp.CheckpointID.String(),
                        Timestamp:        cp.CreatedAt,
                        IsTaskCheckpoint: cp.IsTask,
                        ToolUseID:        cp.ToolUseID,
                    }},
                }
            }
        }
    }

// Check for additional sessions
    strat := NewManualCommitStrategy()
    if additionalSessions, err := strat.GetAdditionalSessions(ctx); err == nil {
        for _, addSession := range additionalSessions {
            if addSession == nil {
                continue
            }
            if existing, ok := sessionMap[addSession.ID]; ok {
                // Merge checkpoints - deduplicate by CheckpointID
                existingCPIDs := make(map[string]bool)
                for _, cp := range existing.Checkpoints {
                    existingCPIDs[cp.CheckpointID.String()] = true
                }
                for _, cp := range addSession.Checkpoints {
                    if !existingCPIDs[cp.CheckpointID.String()] {
                        existing.Checkpoints = append(existing.Checkpoints, cp)
                    }
                }
                // Update start time if additional session is older
                if addSession.StartTime.Before(existing.StartTime) {
                    existing.StartTime = addSession.StartTime
                }
                // Use description from additional source if existing is empty
                if existing.Description == "" || existing.Description == NoDescription {
                    existing.Description = addSession.Description
                }
            } else {
                // New session from additional source
                sessionMap[addSession.ID] = addSession
            }
        }
    }

// Convert map to slice
    sessions := make([]Session, 0, len(sessionMap))
    for _, session := range sessionMap {
        // Sort checkpoints within each session by timestamp (most recent first)
        sort.Slice(session.Checkpoints, func(i, j int) bool {
            return session.Checkpoints[i].Timestamp.After(session.Checkpoints[j].Timestamp)
        })
        sessions = append(sessions, *session)
    }

// Sort sessions by start time (most recent first)
        sort.Slice(sessions, func(i, j int) bool {
        return sessions[i].StartTime.After(sessions[j].StartTime)
        })

return sessions, nil
}

// other functions follow.