Skip to content

Commit 996e0bc

Browse files
nedtwiggclaude
andcommitted
Tidy split cwd handling: name PendingShellOpts, share test setup
- Extract `PendingShellOpts` interface in terminal-store so the `{ shell?; args?; cwd? }` shape stops being repeated across the store and the lifecycle module. - Drop a stale narrative comment in Wall.tsx; tighten the remaining one to explain why remote cwds are skipped. - Hoist the duplicated `vi.stubGlobal` setup in terminal-registry.alert.test.ts into shared install/uninstallRegistryTestGlobals helpers so the new pending-shell-opts describe block reuses the existing setup. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 360f127 commit 996e0bc

4 files changed

Lines changed: 44 additions & 57 deletions

File tree

lib/src/components/Wall.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ export function Wall({
611611
const ref = id && api.getPanel(id) ? id : null;
612612
// Carry the currently-selected shell into the split, same as [+].
613613
const defaults = getDefaultShellOpts();
614-
// Inherit the source pane's cwd when known and local (diffplug/mouseterm#4).
615-
// Remote cwds (e.g. from OSC 7 over ssh) aren't usable as a local spawn cwd.
614+
// Remote cwds (OSC 7 over ssh) name a path on the remote host, not one the local shell can chdir to.
616615
const sourceCwd = ref ? getTerminalPaneState(ref).cwd : null;
617616
const inheritedCwd = sourceCwd && !sourceCwd.isRemote ? sourceCwd.path : undefined;
618617
if (defaults?.shell || inheritedCwd) {

lib/src/lib/terminal-lifecycle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { extractSelectionText } from './selection-text';
1212
import {
1313
pendingShellOpts,
1414
registry,
15+
type PendingShellOpts,
1516
type TerminalEntry,
1617
type TerminalOverlayDims,
1718
} from './terminal-store';
@@ -207,7 +208,7 @@ function setupTerminalEntry(id: string, options: { untouched?: boolean } = {}):
207208
return entry;
208209
}
209210

210-
export function setPendingShellOpts(id: string, opts: { shell?: string; args?: string[]; cwd?: string }): void {
211+
export function setPendingShellOpts(id: string, opts: PendingShellOpts): void {
211212
pendingShellOpts.set(id, opts);
212213
}
213214

lib/src/lib/terminal-registry.alert.test.ts

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -221,37 +221,40 @@ function driveToRingingNeedsAttention(id: string): void {
221221
expect(getActivity(id).status).toBe('ALERT_RINGING');
222222
}
223223

224-
describe('terminal-registry alert behavior', () => {
225-
beforeEach(() => {
226-
vi.useFakeTimers();
227-
fakePlatform.reset();
228-
initAlertStateReceiver();
229-
230-
const documentElement = new MockElement();
231-
vi.stubGlobal('document', {
232-
createElement: () => new MockElement(),
233-
documentElement,
234-
});
235-
vi.stubGlobal('getComputedStyle', () => ({
236-
getPropertyValue: () => '#000000',
237-
}));
238-
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
239-
callback(0);
240-
return 0;
241-
});
242-
vi.stubGlobal('MutationObserver', class { observe() {} disconnect() {} });
243-
vi.stubGlobal('window', {
244-
addEventListener: () => {},
245-
removeEventListener: () => {},
246-
});
224+
function installRegistryTestGlobals(): void {
225+
vi.useFakeTimers();
226+
fakePlatform.reset();
227+
initAlertStateReceiver();
228+
229+
const documentElement = new MockElement();
230+
vi.stubGlobal('document', {
231+
createElement: () => new MockElement(),
232+
documentElement,
233+
});
234+
vi.stubGlobal('getComputedStyle', () => ({
235+
getPropertyValue: () => '#000000',
236+
}));
237+
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
238+
callback(0);
239+
return 0;
240+
});
241+
vi.stubGlobal('MutationObserver', class { observe() {} disconnect() {} });
242+
vi.stubGlobal('window', {
243+
addEventListener: () => {},
244+
removeEventListener: () => {},
247245
});
246+
}
248247

249-
afterEach(() => {
250-
disposeAllSessions();
251-
fakePlatform.reset();
252-
vi.unstubAllGlobals();
253-
vi.useRealTimers();
254-
});
248+
function uninstallRegistryTestGlobals(): void {
249+
disposeAllSessions();
250+
fakePlatform.reset();
251+
vi.unstubAllGlobals();
252+
vi.useRealTimers();
253+
}
254+
255+
describe('terminal-registry alert behavior', () => {
256+
beforeEach(installRegistryTestGlobals);
257+
afterEach(uninstallRegistryTestGlobals);
255258

256259
it('starts brand-new sessions as untouched', () => {
257260
const id = 'new-untouched';
@@ -968,35 +971,13 @@ describe('pending shell opts → spawnPty', () => {
968971
let spawnSpy: ReturnType<typeof vi.spyOn>;
969972

970973
beforeEach(() => {
971-
vi.useFakeTimers();
972-
fakePlatform.reset();
973-
initAlertStateReceiver();
974-
const documentElement = new MockElement();
975-
vi.stubGlobal('document', {
976-
createElement: () => new MockElement(),
977-
documentElement,
978-
});
979-
vi.stubGlobal('getComputedStyle', () => ({
980-
getPropertyValue: () => '#000000',
981-
}));
982-
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
983-
callback(0);
984-
return 0;
985-
});
986-
vi.stubGlobal('MutationObserver', class { observe() {} disconnect() {} });
987-
vi.stubGlobal('window', {
988-
addEventListener: () => {},
989-
removeEventListener: () => {},
990-
});
974+
installRegistryTestGlobals();
991975
spawnSpy = vi.spyOn(fakePlatform, 'spawnPty');
992976
});
993977

994978
afterEach(() => {
995-
disposeAllSessions();
996-
fakePlatform.reset();
997979
spawnSpy.mockRestore();
998-
vi.unstubAllGlobals();
999-
vi.useRealTimers();
980+
uninstallRegistryTestGlobals();
1000981
});
1001982

1002983
it('forwards a pending cwd to spawnPty (split inherits source pane cwd)', () => {

lib/src/lib/terminal-store.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ export interface TerminalOverlayDims {
3636
gridTop: number;
3737
}
3838

39+
export interface PendingShellOpts {
40+
shell?: string;
41+
args?: string[];
42+
cwd?: string;
43+
}
44+
3945
export const registry = new Map<string, TerminalEntry>();
40-
export const pendingShellOpts = new Map<string, { shell?: string; args?: string[]; cwd?: string }>();
46+
export const pendingShellOpts = new Map<string, PendingShellOpts>();
4147

4248
export function getEntryByPtyId(ptyId: string): TerminalEntry | null {
4349
for (const entry of registry.values()) {

0 commit comments

Comments
 (0)