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
20 changes: 20 additions & 0 deletions src/__tests__/serve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,24 @@ describe('handleServeLine', () => {
expect(invocation.terminalWidth).toBeNull();
expect(typeof deps.loadSettings).toBe('function');
});

it('re-probes terminal width on every request instead of serving the memo', () => {
const deps = createProcessServeDependencies();
const originalWidth = process.env.CCSTATUSLINE_WIDTH;
try {
process.env.CCSTATUSLINE_WIDTH = '80';
expect(deps.resolveTerminalWidth(undefined, 0)).toBe(80);

// A resize between requests must be picked up: the process-global
// memo is reset before each probe.
process.env.CCSTATUSLINE_WIDTH = '120';
expect(deps.resolveTerminalWidth(undefined, 0)).toBe(120);
} finally {
if (originalWidth === undefined) {
delete process.env.CCSTATUSLINE_WIDTH;
} else {
process.env.CCSTATUSLINE_WIDTH = originalWidth;
}
}
});
});
13 changes: 11 additions & 2 deletions src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
getConfigPath,
loadSettingsFrom
} from './utils/config';
import { getTerminalWidth } from './utils/terminal';
import {
getTerminalWidth,
resetTerminalWidthCache
} from './utils/terminal';

// Dependencies of the serve loop, injectable so tests can run hermetically
// (fixed settings, no terminal probe) while production wires process state.
Expand All @@ -22,7 +25,13 @@ export interface ServeDependencies {
export function createProcessServeDependencies(): ServeDependencies {
return {
loadSettings: () => loadSettingsFrom(getConfigPath()),
resolveTerminalWidth: (sessionId, ttlSeconds) => getTerminalWidth({ sessionId, ttlSeconds }),
resolveTerminalWidth: (sessionId, ttlSeconds) => {
// A long-lived serve process must re-probe per request: the width
// memo is process-global, so a terminal resize after the first
// request would serve the stale width forever, ttl or not.
resetTerminalWidthCache();
return getTerminalWidth({ sessionId, ttlSeconds });
},
buildInvocation: terminalWidth => ({
configPath: getConfigPath(),
cwd: process.cwd(),
Expand Down
Loading