cc-haha/desktop/src/stores/tabStore.test.ts
程序员阿江(Relakkes) 2dd8ee4a33 fix: keep open session tab titles in sync
Open session tabs can outlive the title value they were created with, while the sidebar and session detail view read from the refreshed session list. Refresh existing tab titles when a session tab is reopened and after session list refreshes so the top tab bar cannot keep a stale generated title.

Constraint: Sidebar filtering and session refresh should not leave already-open tabs with stale labels.
Rejected: Only rely on WebSocket title update events | restored tabs and already-open tabs can miss later session-list corrections.
Confidence: high
Scope-risk: narrow
Directive: Keep session tab titles derived from current session list data when available.
Tested: cd desktop && bun run test -- --run src/stores/tabStore.test.ts src/stores/sessionStore.test.ts
Tested: cd desktop && bun run lint
Tested: cd desktop && bun run test -- --run
Tested: agent-browser smoke on http://127.0.0.1:1420/ confirmed top tabs match sidebar and session detail titles.
2026-05-07 16:38:27 +08:00

23 lines
812 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { beforeEach, describe, expect, it } from 'vitest'
import { useTabStore } from './tabStore'
describe('tabStore', () => {
beforeEach(() => {
useTabStore.setState({ tabs: [], activeTabId: null })
localStorage.clear()
})
it('refreshes an existing tab title when opening the same session again', () => {
useTabStore.getState().openTab('session-1', '```json {"title":')
useTabStore.getState().openTab('session-1', '使用bash写一个shell随便写点什么东西')
expect(useTabStore.getState().tabs).toHaveLength(1)
expect(useTabStore.getState().tabs[0]).toMatchObject({
sessionId: 'session-1',
title: '使用bash写一个shell随便写点什么东西',
type: 'session',
})
expect(useTabStore.getState().activeTabId).toBe('session-1')
})
})