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.
This commit is contained in:
2 files changed
+25
-8
No files matched your search
@@ -1087,7 +1087,7 @@ function resolveWsRpc(body: NormalizedWsRpcRequestBody): unknown {
|
||||
if (tag === WS_METHODS.terminalOpen) {
|
||||
return {
|
||||
threadId: typeof body.threadId === "string" ? body.threadId : THREAD_ID,
|
||||
terminalId: typeof body.terminalId === "string" ? body.terminalId : "default",
|
||||
terminalId: typeof body.terminalId === "string" ? body.terminalId : DEFAULT_TERMINAL_ID,
|
||||
cwd: typeof body.cwd === "string" ? body.cwd : "/repo/project",
|
||||
worktreePath:
|
||||
typeof body.worktreePath === "string"
|
||||
@@ -1944,10 +1944,12 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
[THREAD_KEY]: {
|
||||
terminalOpen: true,
|
||||
terminalHeight: 280,
|
||||
terminalIds: ["default"],
|
||||
activeTerminalId: "default",
|
||||
terminalGroups: [{ id: "group-default", terminalIds: ["default"] }],
|
||||
activeTerminalGroupId: "group-default",
|
||||
terminalIds: [DEFAULT_TERMINAL_ID],
|
||||
activeTerminalId: DEFAULT_TERMINAL_ID,
|
||||
terminalGroups: [
|
||||
{ id: `group-${DEFAULT_TERMINAL_ID}`, terminalIds: [DEFAULT_TERMINAL_ID] },
|
||||
],
|
||||
activeTerminalGroupId: `group-${DEFAULT_TERMINAL_ID}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import { createJSONStorage, persist } from "zustand/middleware";
|
||||
import { resolveStorage } from "./lib/storage";
|
||||
import {
|
||||
DEFAULT_THREAD_TERMINAL_HEIGHT,
|
||||
DEFAULT_THREAD_TERMINAL_ID,
|
||||
MAX_TERMINALS_PER_GROUP,
|
||||
type ThreadTerminalGroup,
|
||||
} from "./types";
|
||||
@@ -33,6 +34,20 @@ interface PersistedTerminalUiStateStoreState {
|
||||
terminalStateByThreadKey?: Record<string, ThreadTerminalUiState>;
|
||||
}
|
||||
|
||||
function migrateTerminalId(id: string): string {
|
||||
return id === "default" ? DEFAULT_THREAD_TERMINAL_ID : id;
|
||||
}
|
||||
|
||||
function migrateThreadTerminalUiState(state: ThreadTerminalUiState): ThreadTerminalUiState {
|
||||
const terminalIds = state.terminalIds.map(migrateTerminalId);
|
||||
const activeTerminalId = migrateTerminalId(state.activeTerminalId);
|
||||
const terminalGroups: ThreadTerminalGroup[] = state.terminalGroups.map((group) => ({
|
||||
id: group.id,
|
||||
terminalIds: group.terminalIds.map(migrateTerminalId),
|
||||
}));
|
||||
return { ...state, terminalIds, activeTerminalId, terminalGroups };
|
||||
}
|
||||
|
||||
export function migratePersistedTerminalUiStateStoreState(
|
||||
persistedState: unknown,
|
||||
_version: number,
|
||||
@@ -45,9 +60,9 @@ export function migratePersistedTerminalUiStateStoreState(
|
||||
const persistedUiStateByThreadKey =
|
||||
candidate.terminalUiStateByThreadKey ?? candidate.terminalStateByThreadKey ?? {};
|
||||
const terminalUiStateByThreadKey = Object.fromEntries(
|
||||
Object.entries(persistedUiStateByThreadKey).filter(([threadKey]) =>
|
||||
parseScopedThreadKey(threadKey),
|
||||
),
|
||||
Object.entries(persistedUiStateByThreadKey)
|
||||
.filter(([threadKey]) => parseScopedThreadKey(threadKey))
|
||||
.map(([threadKey, state]) => [threadKey, migrateThreadTerminalUiState(state)]),
|
||||
);
|
||||
|
||||
return { terminalUiStateByThreadKey };
|
||||
|
||||
Reference in new issue
Block a user