Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions web/src/components/SessionList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ describe('session list search helpers', () => {
})

describe('getVisibleSessionPreview', () => {
it('keeps selected and active sessions inside the collapsed preview without promoting them', () => {
it('keeps selected and pending sessions inside the collapsed preview without promoting them', () => {
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
id: `s-${index + 1}`,
active: index === 4,
pendingRequestsCount: index === 4 ? 1 : 0,
metadata: { path: '/work/hapi' },
updatedAt: 100 - index
}))
Expand All @@ -118,6 +118,19 @@ describe('getVisibleSessionPreview', () => {
expect(preview.map(session => session.id)).toEqual(['s-1', 's-5', 's-6'])
})

it('does not exceed the limit just because many sessions are active', () => {
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
id: `s-${index + 1}`,
active: true,
metadata: { path: '/work/hapi' },
updatedAt: 100 - index
}))

const preview = getVisibleSessionPreview(sessions, { limit: 4 })

expect(preview.map(session => session.id)).toEqual(['s-1', 's-2', 's-3', 's-4'])
})

it('does not move an already-visible selected session to the top', () => {
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
id: `s-${index + 1}`,
Expand Down Expand Up @@ -145,7 +158,7 @@ describe('getVisibleSessionPreview', () => {


describe('expandSelectedSessionCollapseOverrides', () => {
it('expands collapsed project, machine, and session preview overrides for selected sessions', () => {
it('expands collapsed project and machine, but preserves session preview folding', () => {
const overrides = new Map<string, boolean>([
['machine-1::/work/hapi', true],
['sessions::machine-1::/work/hapi', true],
Expand All @@ -158,18 +171,18 @@ describe('expandSelectedSessionCollapseOverrides', () => {
})

expect(result.has('machine-1::/work/hapi')).toBe(false)
expect(result.get('sessions::machine-1::/work/hapi')).toBe(false)
expect(result.get('sessions::machine-1::/work/hapi')).toBe(true)
expect(result.has('machine::machine-1')).toBe(false)
})

it('sets missing session preview override to expanded', () => {
it('leaves missing session preview override unset', () => {
const overrides = new Map<string, boolean>()

const result = expandSelectedSessionCollapseOverrides(overrides, {
key: 'machine-1::/work/hapi',
machineId: 'machine-1'
})

expect(result.get('sessions::machine-1::/work/hapi')).toBe(false)
expect(result.has('sessions::machine-1::/work/hapi')).toBe(false)
})
})
9 changes: 1 addition & 8 deletions web/src/components/SessionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,6 @@ export function expandSelectedSessionCollapseOverrides(
changed = true
}

// Session preview keys use inverted semantics: false = expanded, true/missing = collapsed.
const sessionPreviewKey = `sessions::${group.key}`
if (overrides.get(sessionPreviewKey) !== false) {
next.set(sessionPreviewKey, false)
changed = true
}

const machineKey = `machine::${group.machineId ?? UNKNOWN_MACHINE_ID}`
if (overrides.has(machineKey) && overrides.get(machineKey)) {
next.delete(machineKey)
Expand Down Expand Up @@ -438,7 +431,7 @@ export function getVisibleSessionPreview(

const requiredIds = new Set<string>()
for (const session of sessions) {
if (session.active) requiredIds.add(session.id)
if (session.pendingRequestsCount > 0) requiredIds.add(session.id)
}
if (options.selectedSessionId && sessions.some(session => session.id === options.selectedSessionId)) {
requiredIds.add(options.selectedSessionId)
Expand Down
Loading