[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
164
application/state/sftp/uploadTargetPin.test.ts
Normal file
164
application/state/sftp/uploadTargetPin.test.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import type { SftpPane } from "./types";
|
||||
import {
|
||||
assertUploadEndpointUnchanged,
|
||||
captureUploadEndpoint,
|
||||
resolveUploadTargetPane,
|
||||
} from "./uploadTargetPin";
|
||||
|
||||
const pane = (overrides: Partial<SftpPane> & { id: string; connectionId: string; hostId?: string }): SftpPane => ({
|
||||
id: overrides.id,
|
||||
files: [],
|
||||
selectedFiles: new Set(),
|
||||
filter: "",
|
||||
loading: false,
|
||||
reconnecting: false,
|
||||
error: null,
|
||||
showHiddenFiles: false,
|
||||
filenameEncoding: "auto",
|
||||
connectionLogs: [],
|
||||
transferMutationToken: 0,
|
||||
connection: {
|
||||
id: overrides.connectionId,
|
||||
hostId: overrides.hostId ?? "host-a",
|
||||
hostLabel: "A",
|
||||
isLocal: false,
|
||||
status: "connected",
|
||||
currentPath: "/home",
|
||||
},
|
||||
...overrides,
|
||||
});
|
||||
|
||||
test("resolveUploadTargetPane prefers tabId over active pane", () => {
|
||||
const pinned = pane({ id: "tab-1", connectionId: "conn-1", hostId: "host-a" });
|
||||
const active = pane({ id: "tab-2", connectionId: "conn-2", hostId: "host-b" });
|
||||
const resolved = resolveUploadTargetPane({
|
||||
side: "left",
|
||||
tabId: "tab-1",
|
||||
connectionId: "conn-stale",
|
||||
getActivePane: () => active,
|
||||
getPaneByTabId: (id) => (id === "tab-1" ? pinned : null),
|
||||
getPaneByConnectionId: () => null,
|
||||
});
|
||||
assert.equal(resolved.id, "tab-1");
|
||||
assert.equal(resolved.connection?.id, "conn-1");
|
||||
});
|
||||
|
||||
test("resolveUploadTargetPane falls back to connectionId then active", () => {
|
||||
const byConn = pane({ id: "tab-c", connectionId: "conn-c" });
|
||||
const active = pane({ id: "tab-a", connectionId: "conn-a" });
|
||||
assert.equal(
|
||||
resolveUploadTargetPane({
|
||||
side: "left",
|
||||
connectionId: "conn-c",
|
||||
getActivePane: () => active,
|
||||
getPaneByTabId: () => null,
|
||||
getPaneByConnectionId: (id) => (id === "conn-c" ? byConn : null),
|
||||
}).id,
|
||||
"tab-c",
|
||||
);
|
||||
assert.equal(
|
||||
resolveUploadTargetPane({
|
||||
side: "left",
|
||||
getActivePane: () => active,
|
||||
getPaneByTabId: () => null,
|
||||
getPaneByConnectionId: () => null,
|
||||
}).id,
|
||||
"tab-a",
|
||||
);
|
||||
});
|
||||
|
||||
test("assertUploadEndpointUnchanged rejects host switch on same tab", () => {
|
||||
const map = new Map<string, string>([["conn-1", "key-a"]]);
|
||||
const expected = captureUploadEndpoint(
|
||||
pane({ id: "t", connectionId: "conn-1", hostId: "host-a" }).connection!,
|
||||
map,
|
||||
);
|
||||
assert.throws(
|
||||
() => assertUploadEndpointUnchanged(
|
||||
pane({ id: "t", connectionId: "conn-2", hostId: "host-b" }).connection!,
|
||||
expected,
|
||||
map,
|
||||
),
|
||||
/Upload target changed/,
|
||||
);
|
||||
});
|
||||
|
||||
test("assertUploadEndpointUnchanged allows same-host reconnect with new connection id", () => {
|
||||
const map = new Map<string, string>([
|
||||
["conn-old", "key-a"],
|
||||
["conn-new", "key-a"],
|
||||
]);
|
||||
const expected = captureUploadEndpoint(
|
||||
pane({ id: "t", connectionId: "conn-old", hostId: "host-a" }).connection!,
|
||||
map,
|
||||
);
|
||||
assert.doesNotThrow(() => assertUploadEndpointUnchanged(
|
||||
pane({ id: "t", connectionId: "conn-new", hostId: "host-a" }).connection!,
|
||||
expected,
|
||||
map,
|
||||
));
|
||||
});
|
||||
|
||||
test("a strict upload pin rejects a same-endpoint connection replacement", () => {
|
||||
const map = new Map<string, string>([
|
||||
["conn-old", "key-a"],
|
||||
["conn-new", "key-a"],
|
||||
]);
|
||||
const expected = captureUploadEndpoint(
|
||||
pane({ id: "t", connectionId: "conn-old", hostId: "host-a" }).connection!,
|
||||
map,
|
||||
{ pinConnectionId: true },
|
||||
);
|
||||
assert.throws(() => assertUploadEndpointUnchanged(
|
||||
pane({ id: "t", connectionId: "conn-new", hostId: "host-a" }).connection!,
|
||||
expected,
|
||||
map,
|
||||
), /Upload target changed/);
|
||||
});
|
||||
|
||||
test("a slow strict upload probe cannot continue after its tab is rebound", async () => {
|
||||
const map = new Map<string, string>([
|
||||
["conn-old", "key-a"],
|
||||
["conn-new", "key-a"],
|
||||
]);
|
||||
let livePane = pane({ id: "t", connectionId: "conn-old", hostId: "host-a" });
|
||||
const expected = captureUploadEndpoint(livePane.connection!, map, {
|
||||
pinConnectionId: true,
|
||||
});
|
||||
let resolveProbe!: () => void;
|
||||
const probe = new Promise<void>((resolve) => { resolveProbe = resolve; });
|
||||
let uploadCreated = false;
|
||||
const start = async () => {
|
||||
await probe;
|
||||
assertUploadEndpointUnchanged(livePane.connection!, expected, map);
|
||||
uploadCreated = true;
|
||||
};
|
||||
|
||||
const pending = start();
|
||||
livePane = pane({ id: "t", connectionId: "conn-new", hostId: "host-a" });
|
||||
resolveProbe();
|
||||
|
||||
await assert.rejects(pending, /Upload target changed/);
|
||||
assert.equal(uploadCreated, false);
|
||||
});
|
||||
|
||||
test("carried endpoint pin rejects a retargeted tab mid multi-folder upload", () => {
|
||||
// Simulate paste-time pin for host-a; later folder call resolves tab on host-b.
|
||||
const mapAtPaste = new Map<string, string>([["conn-1", "key-a"]]);
|
||||
const pastePin = captureUploadEndpoint(
|
||||
pane({ id: "tab-1", connectionId: "conn-1", hostId: "host-a" }).connection!,
|
||||
mapAtPaste,
|
||||
);
|
||||
const mapAfterRetarget = new Map<string, string>([["conn-2", "key-b"]]);
|
||||
assert.throws(
|
||||
() => assertUploadEndpointUnchanged(
|
||||
pane({ id: "tab-1", connectionId: "conn-2", hostId: "host-b" }).connection!,
|
||||
pastePin,
|
||||
mapAfterRetarget,
|
||||
),
|
||||
/Upload target changed/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user