Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,45 @@ import {
terminalFontSizeForZoom,
terminalSelectionLabel,
terminalSelectionSnapshot,
terminalTooltip,
} from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-session'

describe('terminal tab tooltips', () => {
it('summarizes a long compound heredoc command by its foreground program', () => {
const running = `mkdir -p ~/.doordash-bot/bin && cat > ~/.doordash-bot/bin/dd-cli-mock <<'EOF'
#!/usr/bin/env node
const carts = new Map()
process.stdout.write(JSON.stringify([...carts]))
EOF
chmod +x ~/.doordash-bot/bin/dd-cli-mock && echo '--- smoke test ---' && ~/.doordash-bot/bin/dd-cli-mock submit mock_123`
const tooltip = terminalTooltip({
terminalId: 'terminal-1',
title: 'mkdir',
cwd: '/Users/emirkarabeg',
running,
interactive: false,
active: false,
})

expect(tooltip).toBe('/Users/emirkarabeg — dd-cli-mock')
expect(tooltip).not.toContain('const carts')
})

it('preserves the working-directory tooltip for idle terminals', () => {
const idleTab = {
terminalId: 'terminal-1',
title: 'sim',
cwd: '/Users/emirkarabeg/sim',
running: null,
interactive: false,
active: true,
}

expect(terminalTooltip(idleTab)).toBe('/Users/emirkarabeg/sim')
expect(terminalTooltip({ ...idleTab, cwd: null })).toBe('Terminal')
})
})

describe('suspended terminal resource lifecycle', () => {
it('does not remove a resource when administrative suspension clears its PTYs', () => {
expect(shouldRemoveTerminalResource(0, true, true)).toBe(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ function hideMountedMenuSurfaces(): void {
*/
const COMMAND_SETTLE_MS = 1_000

/** Full working directory, plus whatever the shell is running in it. */
function terminalTooltip(tab: TerminalTabState): string {
/** Full working directory, plus a concise name for whatever the shell is running. */
export function terminalTooltip(tab: TerminalTabState): string {
const where = tab.cwd ?? 'Terminal'
return tab.running ? `${where} — ${tab.running}` : where
return tab.running ? `${where} — ${describeRunningCommand(tab.running)}` : where
}

function sameIds(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
Expand Down Expand Up @@ -902,8 +902,8 @@ export function TerminalSession({ visible, scopeId }: TerminalSessionProps) {
id: tab.terminalId,
title: counts.get(label) === 1 ? label : `${label} ${occurrence}`,
// The label is a basename, and the tab may be running something it
// is not naming yet, so hovering gives the whole picture: where the
// shell is, and what it is doing there.
// is not naming yet, so hovering identifies the working directory and
// foreground program without exposing the literal command.
tooltip: terminalTooltip(tab),
icon: (
<TerminalTabIcon
Expand Down
Loading