test(desktop): trim #130810 lifecycle tests to the two invariants

Keep the shouldQuitOnLastChatClosed decision matrix and the activateWindow
restore -> show -> focus test. The two scenario tests rebuilt main.ts state
in local variables and then asserted it (tautological), and the remaining
activateWindow cases only pin no-op paths.
This commit is contained in:
kshitijk4poor
2026-10-03 14:52:35 +05:30
committed by kshitij
parent 5e8f97c827
commit 7ba530a5a6

View File

@@ -103,28 +103,6 @@ test('explicit relaunch activates a minimized tray-hidden window', () => {
assert.deepEqual(calls, ['restore', 'show', 'focus'])
})
test('explicit relaunch leaves an already-visible focused window alone', () => {
const calls: string[] = []
activateWindow({
isDestroyed: () => false,
isMinimized: () => false,
isVisible: () => true,
isFocused: () => true,
restore: () => calls.push('restore'),
show: () => calls.push('show'),
focus: () => calls.push('focus')
})
assert.deepEqual(calls, [])
})
test('explicit relaunch never touches a destroyed or missing window', () => {
activateWindow({ isDestroyed: () => true })
activateWindow(null)
activateWindow(undefined)
})
// Regression for #130810: the last-chat `closed` fallback quits on
// Windows/Linux when no chat surface remains and no quit is already tearing
// down. It must not consult the overlay-suppression latch, must stay quiet
@@ -203,108 +181,3 @@ test('last-chat fallback quits only for a final non-macOS close outside a quit',
false
)
})
// Regression for #130810: an ordinary primary-window close on Windows/Linux
// sets the overlay-suppression latch (appQuitting = true for #55920) in its
// `close` handler before `closed` fires. With a hidden helper (Quick Entry,
// HUD, pet overlay) still alive, `window-all-closed` never fires, so the
// last-chat fallback is the only quit path — the latch must not block it.
test('primary close with hidden helper still quits despite overlay-suppression latch', () => {
// Mirror main.ts state: overlay latch vs real quit progress are separate.
let appQuitting = false
let quitInProgress = false
const isQuittingForHandoff = false
// `close`: ordinary close, no active-work guard, not prevented. The primary
// window's `close` handler latches overlay suppression on Windows/Linux.
const closePrevented = false
if (!closePrevented) {
appQuitting = true
}
// `closed`: the primary chat surface is gone (remaining === 0) but a hidden
// helper BrowserWindow keeps `window-all-closed` from firing. No before-quit
// has run yet, so no quit is in progress.
const remainingChatWindows = 0
assert.equal(appQuitting, true)
assert.equal(quitInProgress, false)
assert.equal(
shouldQuitOnLastChatClosed({
platform: 'win32',
isQuittingForHandoff,
remainingChatWindows,
quitInProgress
}),
true
)
assert.equal(
shouldQuitOnLastChatClosed({
platform: 'linux',
isQuittingForHandoff,
remainingChatWindows,
quitInProgress
}),
true
)
})
// Regression for #130810: a "Keep Running" answer to the active-work prompt
// holds the quit (before-quit preventDefault / window-close preventDefault)
// and must leave quitInProgress false with the overlay latch reset, so a
// later ordinary close still quits via the fallback.
test('keep-running leaves a later final close able to quit', () => {
let appQuitting = false
let quitInProgress = false
const isQuittingForHandoff = false
// First attempt: active-work guard holds the quit. Mirror the fixed
// before-quit handler — a held quit resets the overlay latch and never sets
// quitInProgress.
const heldForActiveWork = true
if (heldForActiveWork) {
appQuitting = false
} else {
appQuitting = true
quitInProgress = true
}
assert.equal(quitInProgress, false)
assert.equal(appQuitting, false)
// The dialog resolves with "Keep Running": no confirm, no re-quit.
const quitConfirmedWithActiveWork = false
assert.equal(quitConfirmedWithActiveWork, false)
assert.equal(quitInProgress, false)
// Later, work has finished and the user closes the last chat window for
// real: ordinary `close` latches overlay suppression, `closed` finds no
// chat surfaces left and no quit in flight, so the fallback quits.
appQuitting = true
const remainingChatWindows = 0
assert.equal(
shouldQuitOnLastChatClosed({
platform: 'win32',
isQuittingForHandoff,
remainingChatWindows,
quitInProgress
}),
true
)
// And once before-quit really proceeds, the fallback stays quiet (the quit
// teardown already owns the exit).
quitInProgress = true
assert.equal(
shouldQuitOnLastChatClosed({
platform: 'win32',
isQuittingForHandoff,
remainingChatWindows,
quitInProgress
}),
false
)
})