refactor(terminal): require the pane link hint so dropping the wiring fails to build

The optional option fell back to a duplicated copy of the legacy hint string, so deleting the hook wiring reverted the tooltip silently with every test green.
This commit is contained in:
Brennan Benson
2026-07-28 12:48:50 -07:00
parent 429c06c047
commit 8bbf4546e7
5 changed files with 30 additions and 60 deletions
@@ -1,5 +1,5 @@
// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import type { TerminalLeafId } from '../../../../shared/stable-pane-id'
import { createPaneDOM } from './pane-dom-creation'
@@ -48,21 +48,13 @@ vi.mock('@xterm/xterm', () => ({
})
}))
function setPlatform(userAgent: string): void {
vi.stubGlobal('navigator', { userAgent })
}
afterEach(() => {
vi.unstubAllGlobals()
})
describe('createPaneDOM link tooltips', () => {
it('anchors WebLinks hover text to the unpadded terminal window corner', () => {
const leafId = '11111111-1111-4111-8111-111111111111' as TerminalLeafId
const pane = createPaneDOM(
1,
leafId,
{},
{ linkOpenHint: () => 'open hint' },
{ active: null } as never,
{} as never,
vi.fn(),
@@ -77,42 +69,8 @@ describe('createPaneDOM link tooltips', () => {
expect(pane.linkTooltip.style.display).toBe('none')
})
it('uses desktop modifier-click text for WebLinks hover hints', () => {
const leafId = '11111111-1111-4111-8111-111111111111' as TerminalLeafId
setPlatform('Macintosh')
const macPane = createPaneDOM(
1,
leafId,
{},
{ active: null } as never,
{} as never,
vi.fn(),
vi.fn()
)
webLinksAddonMock.options?.hover?.({} as MouseEvent, 'http://localhost:5180/')
expect(macPane.linkTooltip.textContent).toBe(
'http://localhost:5180/ (⌘+click to open or ⇧⌘+click for system browser)'
)
setPlatform('Windows')
const windowsPane = createPaneDOM(
2,
leafId,
{},
{ active: null } as never,
{} as never,
vi.fn(),
vi.fn()
)
webLinksAddonMock.options?.hover?.({} as MouseEvent, 'http://localhost:5180/')
expect(windowsPane.linkTooltip.textContent).toBe(
'http://localhost:5180/ (Ctrl+click to open or Shift+Ctrl+click for system browser)'
)
})
// Why: the only PaneManager consumer passes linkOpenHint, so the hardcoded fallback
// is unreachable in production — without this, dropping the option stays green.
// Why: the caller owns the hint, so dropping the wiring is a compile error rather
// than a silent fall back to stale copy.
it('re-resolves the caller hint on every hover so setting changes apply live', () => {
const leafId = '11111111-1111-4111-8111-111111111111' as TerminalLeafId
let hint = 'first hint'
@@ -141,6 +99,7 @@ describe('createPaneDOM link tooltips', () => {
1,
leafId,
{
linkOpenHint: () => 'open hint',
formatLinkTooltip: async () => labeledText
},
{ active: null } as never,
@@ -15,12 +15,6 @@ import { ENABLE_WEBGL_RENDERER } from './pane-webgl-renderer'
import { installGuardedLinkProviderRegistration } from './terminal-link-provider-guard'
import { installWindowsCtrlAltChordRepair } from './terminal-windows-ctrl-alt-chord-classification'
function getTerminalUrlOpenHint(): string {
return navigator.userAgent.includes('Mac')
? '⌘+click to open or ⇧⌘+click for system browser'
: 'Ctrl+click to open or Shift+Ctrl+click for system browser'
}
function defaultLinkTooltipText(uri: string, openLinkHint: string): string {
return `${uri} (${openLinkHint})`
}
@@ -82,7 +76,7 @@ export function createPaneDOM(
if (uri) {
linkTooltipHoverToken += 1
const hoverToken = linkTooltipHoverToken
const openLinkHint = options.linkOpenHint?.() ?? getTerminalUrlOpenHint()
const openLinkHint = options.linkOpenHint()
linkTooltip.textContent = defaultLinkTooltipText(uri, openLinkHint)
linkTooltip.style.display = ''
const formatted = options.formatLinkTooltip?.(uri, openLinkHint)
@@ -61,7 +61,9 @@ export type PaneManagerOptions = {
terminalTuiScrollSensitivity?: () => number | undefined
onLinkClick?: (event: MouseEvent | undefined, url: string) => void
/** Resolved per hover so link-routing setting changes apply without recreating panes. */
linkOpenHint?: () => string
// Why: required so dropping the wiring is a compile error — an optional hint with a
// default would silently serve stale copy that no test can distinguish.
linkOpenHint: () => string
formatLinkTooltip?: (
url: string,
openLinkHint: string
@@ -146,7 +146,7 @@ describe('splitManagedPane', () => {
panes,
root: root as unknown as HTMLElement,
styleOptions: {},
managerOptions: {},
managerOptions: { linkOpenHint: () => '' },
createPaneInternal: () => {
panes.set(newPane.id, newPane)
return newPane
@@ -54,7 +54,10 @@ describe('applyTerminalGpuAcceleration', () => {
it('refits after disabling WebGL so DOM renderer dimensions settle', () => {
const pane = createPane()
const options: PaneManagerOptions = { terminalGpuAcceleration: 'auto' }
const options: PaneManagerOptions = {
linkOpenHint: () => '',
terminalGpuAcceleration: 'auto'
}
applyTerminalGpuAcceleration([pane], options, 'off')
@@ -69,7 +72,10 @@ describe('applyTerminalGpuAcceleration', () => {
})
const pane = createPane()
pane.hasComplexScriptOutput = true
const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' }
const options: PaneManagerOptions = {
linkOpenHint: () => '',
terminalGpuAcceleration: 'on'
}
applyTerminalGpuAcceleration([pane], options, 'auto')
@@ -84,7 +90,10 @@ describe('applyTerminalGpuAcceleration', () => {
})
const pane = createPane()
pane.webglDisabledAfterContextLoss = true
const options: PaneManagerOptions = { terminalGpuAcceleration: 'auto' }
const options: PaneManagerOptions = {
linkOpenHint: () => '',
terminalGpuAcceleration: 'auto'
}
applyTerminalGpuAcceleration([pane], options, 'on')
@@ -94,7 +103,10 @@ describe('applyTerminalGpuAcceleration', () => {
it('keeps context-loss latches when the acceleration mode is unchanged', () => {
const pane = createPane()
pane.webglDisabledAfterContextLoss = true
const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' }
const options: PaneManagerOptions = {
linkOpenHint: () => '',
terminalGpuAcceleration: 'on'
}
applyTerminalGpuAcceleration([pane], options, 'on')
@@ -107,7 +119,10 @@ describe('applyTerminalGpuAcceleration', () => {
userAgent: 'Mozilla/5.0 (X11; Linux x86_64)'
})
const pane = createPane()
const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' }
const options: PaneManagerOptions = {
linkOpenHint: () => '',
terminalGpuAcceleration: 'on'
}
applyTerminalGpuAcceleration([pane], options, 'auto')