Skip to content

Commit 7c3f8ee

Browse files
committed
Fix persisted terminal id migration and stale test terminal ids
- Add migrateTerminalId/migrateThreadTerminalUiState to remap legacy 'default' terminal ids to 'term-1' during store hydration, so persisted state from before the rename is correctly migrated. - Update browser test harness to use DEFAULT_TERMINAL_ID instead of hardcoded 'default' in terminalOpen mock fallback and seeded terminal UI state.
1 parent 1e929ad commit 7c3f8ee

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

apps/web/src/components/ChatView.browser.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ function resolveWsRpc(body: NormalizedWsRpcRequestBody): unknown {
10871087
if (tag === WS_METHODS.terminalOpen) {
10881088
return {
10891089
threadId: typeof body.threadId === "string" ? body.threadId : THREAD_ID,
1090-
terminalId: typeof body.terminalId === "string" ? body.terminalId : "default",
1090+
terminalId: typeof body.terminalId === "string" ? body.terminalId : DEFAULT_TERMINAL_ID,
10911091
cwd: typeof body.cwd === "string" ? body.cwd : "/repo/project",
10921092
worktreePath:
10931093
typeof body.worktreePath === "string"
@@ -1944,10 +1944,12 @@ describe("ChatView timeline estimator parity (full app)", () => {
19441944
[THREAD_KEY]: {
19451945
terminalOpen: true,
19461946
terminalHeight: 280,
1947-
terminalIds: ["default"],
1948-
activeTerminalId: "default",
1949-
terminalGroups: [{ id: "group-default", terminalIds: ["default"] }],
1950-
activeTerminalGroupId: "group-default",
1947+
terminalIds: [DEFAULT_TERMINAL_ID],
1948+
activeTerminalId: DEFAULT_TERMINAL_ID,
1949+
terminalGroups: [
1950+
{ id: `group-${DEFAULT_TERMINAL_ID}`, terminalIds: [DEFAULT_TERMINAL_ID] },
1951+
],
1952+
activeTerminalGroupId: `group-${DEFAULT_TERMINAL_ID}`,
19511953
},
19521954
},
19531955
});

apps/web/src/terminalUiStateStore.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createJSONStorage, persist } from "zustand/middleware";
1212
import { resolveStorage } from "./lib/storage";
1313
import {
1414
DEFAULT_THREAD_TERMINAL_HEIGHT,
15+
DEFAULT_THREAD_TERMINAL_ID,
1516
MAX_TERMINALS_PER_GROUP,
1617
type ThreadTerminalGroup,
1718
} from "./types";
@@ -33,6 +34,20 @@ interface PersistedTerminalUiStateStoreState {
3334
terminalStateByThreadKey?: Record<string, ThreadTerminalUiState>;
3435
}
3536

37+
function migrateTerminalId(id: string): string {
38+
return id === "default" ? DEFAULT_THREAD_TERMINAL_ID : id;
39+
}
40+
41+
function migrateThreadTerminalUiState(state: ThreadTerminalUiState): ThreadTerminalUiState {
42+
const terminalIds = state.terminalIds.map(migrateTerminalId);
43+
const activeTerminalId = migrateTerminalId(state.activeTerminalId);
44+
const terminalGroups: ThreadTerminalGroup[] = state.terminalGroups.map((group) => ({
45+
id: group.id,
46+
terminalIds: group.terminalIds.map(migrateTerminalId),
47+
}));
48+
return { ...state, terminalIds, activeTerminalId, terminalGroups };
49+
}
50+
3651
export function migratePersistedTerminalUiStateStoreState(
3752
persistedState: unknown,
3853
_version: number,
@@ -45,9 +60,9 @@ export function migratePersistedTerminalUiStateStoreState(
4560
const persistedUiStateByThreadKey =
4661
candidate.terminalUiStateByThreadKey ?? candidate.terminalStateByThreadKey ?? {};
4762
const terminalUiStateByThreadKey = Object.fromEntries(
48-
Object.entries(persistedUiStateByThreadKey).filter(([threadKey]) =>
49-
parseScopedThreadKey(threadKey),
50-
),
63+
Object.entries(persistedUiStateByThreadKey)
64+
.filter(([threadKey]) => parseScopedThreadKey(threadKey))
65+
.map(([threadKey, state]) => [threadKey, migrateThreadTerminalUiState(state)]),
5166
);
5267

5368
return { terminalUiStateByThreadKey };

0 commit comments

Comments
 (0)