-
Notifications
You must be signed in to change notification settings - Fork 46.3k
fix(desktop): filter messaging sessions by active profile #42934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
BlackishGreen33
wants to merge
6
commits into
NousResearch:main
from
BlackishGreen33:bg/desktop-messaging-profile-filter
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29ba688
🐛 fix(desktop): filter messaging sidebar by profile
BlackishGreen33 8a0b035
🔧 chore(desktop): merge main and address PR feedback
BlackishGreen33 7fed0d4
🔧 chore(desktop): merge main into profile filter pr
BlackishGreen33 b4007ff
Merge remote-tracking branch 'origin/main' into bg/desktop-messaging-…
BlackishGreen33 c35a935
🐛 fix(desktop): preserve messaging rows in all-profile scope
BlackishGreen33 c3efe9b
🐛 fix(desktop): ignore stale messaging refresh callbacks
BlackishGreen33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { ALL_PROFILES } from '@/store/profile' | ||
| import type { SessionInfo } from '@/types/hermes' | ||
|
|
||
| import { filterSessionsByProfileScope } from './profile-scope' | ||
|
|
||
| const session = (id: string, profile?: string): SessionInfo => ({ | ||
| archived: false, | ||
| cwd: null, | ||
| ended_at: null, | ||
| id, | ||
| input_tokens: 0, | ||
| is_active: false, | ||
| last_active: 1, | ||
| message_count: 1, | ||
| model: null, | ||
| output_tokens: 0, | ||
| preview: null, | ||
| profile, | ||
| source: 'feishu', | ||
| started_at: 1, | ||
| title: null, | ||
| tool_call_count: 0 | ||
| }) | ||
|
|
||
| describe('filterSessionsByProfileScope', () => { | ||
| it('keeps only messaging rows from the selected profile', () => { | ||
| const rows = [session('default-row', 'default'), session('research-row', 'research')] | ||
|
|
||
| expect(filterSessionsByProfileScope(rows, 'research').map(s => s.id)).toEqual(['research-row']) | ||
| }) | ||
|
|
||
| it('treats missing profiles as default', () => { | ||
| const rows = [session('legacy-row'), session('research-row', 'research')] | ||
|
|
||
| expect(filterSessionsByProfileScope(rows, 'default').map(s => s.id)).toEqual(['legacy-row']) | ||
| }) | ||
|
|
||
| it('keeps every messaging row when persisted All profiles mode outlives the profile switcher', () => { | ||
| const rows = [session('default-row', 'default'), session('research-row', 'research')] | ||
|
|
||
| expect(filterSessionsByProfileScope(rows, ALL_PROFILES).map(s => s.id)).toEqual([ | ||
| 'default-row', | ||
| 'research-row' | ||
| ]) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { ALL_PROFILES, normalizeProfileKey } from '@/store/profile' | ||
| import type { SessionInfo } from '@/types/hermes' | ||
|
|
||
| export function filterSessionsByProfileScope(sessions: SessionInfo[], profileScope: string): SessionInfo[] { | ||
| if (profileScope === ALL_PROFILES) { | ||
| return sessions | ||
| } | ||
|
|
||
| const scope = normalizeProfileKey(profileScope) | ||
|
|
||
| return sessions.filter(session => normalizeProfileKey(session.profile) === scope) | ||
| } |
104 changes: 104 additions & 0 deletions
104
apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { act, cleanup, renderHook } from '@testing-library/react' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { listAllProfileSessions, type SessionInfo } from '@/hermes' | ||
| import { | ||
| $messagingPlatformTotals, | ||
| $messagingSessions, | ||
| setMessagingPlatformTotals, | ||
| setMessagingSessions, | ||
| setMessagingTruncated | ||
| } from '@/store/session' | ||
|
|
||
| import { useSessionListActions } from './use-session-list-actions' | ||
|
|
||
| vi.mock('@/hermes', async importOriginal => ({ | ||
| ...(await importOriginal<Record<string, unknown>>()), | ||
| getCronJobs: vi.fn(), | ||
| listAllProfileSessions: vi.fn() | ||
| })) | ||
|
|
||
| interface Deferred<T> { | ||
| promise: Promise<T> | ||
| resolve: (value: T) => void | ||
| } | ||
|
|
||
| function deferred<T>(): Deferred<T> { | ||
| let resolve!: (value: T) => void | ||
|
|
||
| const promise = new Promise<T>(done => { | ||
| resolve = done | ||
| }) | ||
|
|
||
| return { promise, resolve } | ||
| } | ||
|
|
||
| function session(id: string, profile: string): SessionInfo { | ||
| return { | ||
| archived: false, | ||
| cwd: null, | ||
| ended_at: null, | ||
| id, | ||
| input_tokens: 0, | ||
| is_active: false, | ||
| last_active: 1, | ||
| message_count: 1, | ||
| model: null, | ||
| output_tokens: 0, | ||
| preview: null, | ||
| profile, | ||
| source: 'telegram', | ||
| started_at: 1, | ||
| title: null, | ||
| tool_call_count: 0 | ||
| } | ||
| } | ||
|
|
||
| describe('useSessionListActions', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| setMessagingSessions([]) | ||
| setMessagingPlatformTotals({ telegram: 3 }) | ||
| setMessagingTruncated(false) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| cleanup() | ||
| setMessagingSessions([]) | ||
| setMessagingPlatformTotals({}) | ||
| setMessagingTruncated(false) | ||
| }) | ||
|
|
||
| it('ignores a stale scope callback before it can invalidate the current messaging request', async () => { | ||
| const alpha = deferred<Awaited<ReturnType<typeof listAllProfileSessions>>>() | ||
| const beta = deferred<Awaited<ReturnType<typeof listAllProfileSessions>>>() | ||
| const alphaRow = session('alpha-row', 'alpha') | ||
| const betaRow = session('beta-row', 'beta') | ||
|
|
||
| vi.mocked(listAllProfileSessions).mockImplementation((_limit, _min, _archived, _order, profile) => | ||
| profile === 'alpha' ? alpha.promise : beta.promise | ||
| ) | ||
|
|
||
| const { rerender, result } = renderHook(({ profileScope }) => useSessionListActions({ profileScope }), { | ||
| initialProps: { profileScope: 'alpha' } | ||
| }) | ||
|
|
||
| const staleAlphaRefresh = result.current.refreshMessagingSessions | ||
|
|
||
| rerender({ profileScope: 'beta' }) | ||
|
|
||
| const betaRefresh = result.current.refreshMessagingSessions() | ||
| const staleAlphaRequest = staleAlphaRefresh() | ||
|
|
||
| await act(async () => { | ||
| beta.resolve({ limit: 100, offset: 0, sessions: [betaRow], total: 1 }) | ||
| await betaRefresh | ||
| alpha.resolve({ limit: 100, offset: 0, sessions: [alphaRow], total: 1 }) | ||
| await staleAlphaRequest | ||
| }) | ||
|
|
||
| expect(vi.mocked(listAllProfileSessions).mock.calls.map(call => call[4])).toEqual(['beta']) | ||
| expect($messagingSessions.get()).toEqual([betaRow]) | ||
| expect($messagingPlatformTotals.get()).toEqual({}) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.