From b929b8eed25c2afd8d474c1ef6f85c3d9eb8ea64 Mon Sep 17 00:00:00 2001 From: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com> Date: Mon, 12 Oct 2026 03:16:27 +0000 Subject: [PATCH] fix: address Codex review on PR #3616 --- components/VaultView.localShellSave.test.ts | 25 +++++++++++++++++++++ components/VaultView.tsx | 5 ++++- domain/vaultHostCreate.test.ts | 22 ++++++++++++++++++ domain/vaultHostCreate.ts | 5 ++++- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/components/VaultView.localShellSave.test.ts b/components/VaultView.localShellSave.test.ts index fef737608..1e45c9152 100644 --- a/components/VaultView.localShellSave.test.ts +++ b/components/VaultView.localShellSave.test.ts @@ -38,3 +38,28 @@ for (const editing of [false, true]) { }); } } + +// Duplicating a local-shell host opens its copy under a newly generated ID +// that is not in the vault yet; it must be saved as a new entry, not as an +// edit (which would no-op and silently discard the duplicate). +test("local shell save: duplicated host with a new id saves as a new entry", () => { + const opened = createLocalShellHost({ label: "cmd (copy)" }); + const draft = { ...opened, notes: "tweaked" }; + let saved: Host[] = []; + let connected: Host | undefined; + const save = new Function( + "hosts", "editingLocalShellHost", "onUpdateHosts", "onConnect", + "setIsLocalShellHostPanelOpen", "setEditingLocalShellHost", + "upsertHostById", "saveWorkSurfaceHostDraft", + `${compiled} return save;`, + )( + [], opened, + (hosts: Host[]) => { saved = hosts; }, (host: Host) => { connected = host; }, + () => {}, () => {}, upsertHostById, saveWorkSurfaceHostDraft, + ); + save(draft, false); + assert.equal(saved.length, 1); + assert.equal(saved[0].id, draft.id); + assert.equal(saved[0].notes, "tweaked"); + assert.equal(connected, undefined); +}); diff --git a/components/VaultView.tsx b/components/VaultView.tsx index 3952684a3..d491d3220 100644 --- a/components/VaultView.tsx +++ b/components/VaultView.tsx @@ -695,7 +695,10 @@ const VaultViewInner: React.FC = ({ }, []); const handleSaveLocalShellHost = useCallback((host: Host, connectNow?: boolean) => { - const updatedHosts = saveWorkSurfaceHostDraft(hosts, editingLocalShellHost + // A duplicated local host carries a freshly generated ID that is not in the + // vault yet, so it must be saved as a new entry (edit mode would no-op). + const editingExistingHost = hosts.some((entry) => entry.id === editingLocalShellHost?.id); + const updatedHosts = saveWorkSurfaceHostDraft(hosts, editingExistingHost && editingLocalShellHost ? { mode: "edit", openedHost: editingLocalShellHost, requestId: 0 } : { mode: "new", defaultGroup: null, requestId: 0 }, host); if (updatedHosts) onUpdateHosts(updatedHosts); diff --git a/domain/vaultHostCreate.test.ts b/domain/vaultHostCreate.test.ts index 7858e0843..bb8343a67 100644 --- a/domain/vaultHostCreate.test.ts +++ b/domain/vaultHostCreate.test.ts @@ -41,6 +41,28 @@ test('buildVaultHostMergeKey treats group as part of session identity', () => { ); }); +test('buildVaultHostMergeKey normalizes the local-shell default port', () => { + // Vault-editor local hosts omit `port`; CSV export/import round-trips store + // the effective default (22). Both forms must dedupe as the same entry. + const localBase = { + hostname: 'localhost', + username: '', + protocol: 'local' as const, + group: 'lan', + os: 'windows' as const, + localShellName: 'PowerShell', + }; + assert.equal( + buildVaultHostMergeKey({ ...localBase }), + buildVaultHostMergeKey({ ...localBase, port: 22 }), + ); + // An explicit non-default port is still a distinct identity. + assert.notEqual( + buildVaultHostMergeKey({ ...localBase, port: 2222 }), + buildVaultHostMergeKey({ ...localBase, port: 22 }), + ); +}); + test('buildVaultHostFromDraft maps minimal unstructured fields to a vault host', () => { const built = buildVaultHostFromDraft({ hostname: '192.168.1.10', diff --git a/domain/vaultHostCreate.ts b/domain/vaultHostCreate.ts index 9fbf53145..0fc71fd4b 100644 --- a/domain/vaultHostCreate.ts +++ b/domain/vaultHostCreate.ts @@ -185,7 +185,10 @@ const parseKeyPath = (draft: VaultHostDraft): string | undefined => { export const buildVaultHostEndpointKey = ( host: Pick, ): string => - `${(host.protocol ?? 'ssh').toLowerCase()}|${host.hostname.toLowerCase()}|${host.port}|${(host.username ?? '').toLowerCase()}`; + // Local-shell hosts created by the vault editor omit `port`, but CSV + // export/import round-trips store the effective default (22). Normalize so + // a local entry keeps a stable dedupe identity in both forms. + `${(host.protocol ?? 'ssh').toLowerCase()}|${host.hostname.toLowerCase()}|${host.protocol === 'local' ? (host.port ?? DEFAULT_SSH_PORT) : host.port}|${(host.username ?? '').toLowerCase()}`; /** * Session identity for vault import/create dedupe.