feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes

This commit is contained in:
Yun Chan 2026-11-14 11:51:41 +09:00
parent 01ef3293cf
commit 66b6b45ba9
399 changed files with 17828 additions and 11330 deletions

View file

@ -0,0 +1,142 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
type Listener = (...args: unknown[]) => void
const state = vi.hoisted(() => ({
windows: [] as Array<{
visible: boolean
destroyed: boolean
windowListeners: Map<string, Listener>
}>,
}))
vi.unmock('../../../src/main/windows/WindowManager')
vi.mock('electron', () => {
class FakeBrowserWindow {
visible = false
destroyed = false
windowListeners = new Map<string, Listener>()
webContents = {
on: vi.fn(),
send: vi.fn(),
isDestroyed: () => false,
insertCSS: async () => '',
executeJavaScript: async () => undefined,
invalidate: vi.fn(),
setWindowOpenHandler: vi.fn(),
}
showInactive = vi.fn(() => {
this.visible = true
})
show = vi.fn(() => {
this.visible = true
})
hide = vi.fn(() => {
this.visible = false
})
setIgnoreMouseEvents = vi.fn()
setBounds = vi.fn()
setAlwaysOnTop = vi.fn()
moveTop = vi.fn()
loadURL = vi.fn(async () => undefined)
loadFile = vi.fn(async () => undefined)
constructor() {
state.windows.push(this)
}
on(event: string, listener: Listener): this {
this.windowListeners.set(event, listener)
return this
}
isVisible(): boolean {
return this.visible
}
isDestroyed(): boolean {
return this.destroyed
}
}
return {
nativeTheme: { shouldUseDarkColors: true, on: () => undefined, removeListener: () => undefined },
app: { quit: vi.fn(), getPath: vi.fn(() => '.'), on: vi.fn(), getVersion: vi.fn(() => '1.0.0'), isPackaged: false },
BrowserWindow: Object.assign(FakeBrowserWindow, { getAllWindows: vi.fn(() => []) }),
screen: {
getPrimaryDisplay: vi.fn(() => ({ workAreaSize: { width: 1280, height: 720 }, workArea: { x: 0, y: 0, width: 1280, height: 720 } })),
getAllDisplays: vi.fn(() => [{ workArea: { x: 0, y: 0, width: 1280, height: 720 } }]),
getCursorScreenPoint: vi.fn(() => ({ x: 400, y: 400 })),
getDisplayNearestPoint: vi.fn(() => ({ workArea: { x: 0, y: 0, width: 1280, height: 720 } })),
screenToDipRect: vi.fn((_win: unknown, rect: { x: number; y: number; width: number; height: number }) => rect),
},
ipcMain: { on: vi.fn(), once: vi.fn(), handle: vi.fn(), removeHandler: vi.fn() },
Menu: { setApplicationMenu: vi.fn(), buildFromTemplate: vi.fn() },
clipboard: { writeText: vi.fn() },
shell: { openExternal: vi.fn(async () => undefined) },
safeStorage: { isEncryptionAvailable: vi.fn(() => false) },
nativeImage: { createFromPath: vi.fn(), createEmpty: vi.fn() },
Tray: vi.fn(),
dialog: { showErrorBox: vi.fn() },
}
})
vi.mock('@electron-toolkit/utils', () => ({ is: { dev: false } }))
vi.mock('../../../src/main/services/ConfigService', () => ({
configGet: (key: string) => (key === 'language' ? 'ko' : key === 'theme' ? 'dark' : {}),
configSet: vi.fn(),
}))
describe('WindowManager popup hide/show timer race regressions', () => {
beforeEach(() => {
vi.useFakeTimers()
vi.resetModules()
state.windows.length = 0
})
afterEach(() => {
vi.useRealTimers()
vi.restoreAllMocks()
})
it('showHistoryPopup_calledWithin150msAfterHide_cancelsPendingHideTimerAndStaysVisible', async () => {
const wm = await import('../../../src/main/windows/WindowManager')
wm.showHistoryPopup([{ id: 'h-1', text: 'first' }])
expect(wm.isHistoryPopupVisible()).toBe(true)
wm.hideHistoryPopup()
await vi.advanceTimersByTimeAsync(50)
// Re-open before the 150ms hide timer fires
wm.showHistoryPopup([{ id: 'h-1', text: 'second' }])
expect(wm.isHistoryPopupVisible()).toBe(true)
await vi.advanceTimersByTimeAsync(200)
expect(wm.isHistoryPopupVisible()).toBe(true)
// Subsequent hide still hides cleanly after 150ms
wm.hideHistoryPopup()
await vi.advanceTimersByTimeAsync(160)
expect(wm.isHistoryPopupVisible()).toBe(false)
})
it('showCommandPopup_calledWithin150msAfterHide_cancelsPendingHideTimerAndStaysVisible', async () => {
const wm = await import('../../../src/main/windows/WindowManager')
wm.showCommandPopup([{ id: 'cmd-1', name: 'Summarize' }], null)
expect(wm.isCommandPopupVisible()).toBe(true)
wm.hideCommandPopup()
await vi.advanceTimersByTimeAsync(50)
wm.showCommandPopup([{ id: 'cmd-1', name: 'Summarize' }], 'cmd-1')
expect(wm.isCommandPopupVisible()).toBe(true)
await vi.advanceTimersByTimeAsync(200)
expect(wm.isCommandPopupVisible()).toBe(true)
wm.hideCommandPopup()
await vi.advanceTimersByTimeAsync(160)
expect(wm.isCommandPopupVisible()).toBe(false)
})
})