[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:
254
electron/preload/api.stageUploadFile.test.cjs
Normal file
254
electron/preload/api.stageUploadFile.test.cjs
Normal file
@@ -0,0 +1,254 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const test = require("node:test");
|
||||
|
||||
const { createPreloadApi } = require("./api.cjs");
|
||||
|
||||
function createFile(name, chunks) {
|
||||
let index = 0;
|
||||
return {
|
||||
name,
|
||||
stream: () => ({
|
||||
getReader: () => ({
|
||||
async read() {
|
||||
if (index >= chunks.length) return { done: true };
|
||||
return { done: false, value: Uint8Array.from(chunks[index++]) };
|
||||
},
|
||||
releaseLock() {},
|
||||
}),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function createBlockingFile(name) {
|
||||
let markReadStarted;
|
||||
let finishRead;
|
||||
const readStarted = new Promise((resolve) => { markReadStarted = resolve; });
|
||||
return {
|
||||
file: {
|
||||
name,
|
||||
stream: () => ({
|
||||
getReader: () => ({
|
||||
read() {
|
||||
markReadStarted();
|
||||
return new Promise((resolve) => { finishRead = resolve; });
|
||||
},
|
||||
cancel() {
|
||||
finishRead?.({ done: true });
|
||||
return Promise.resolve();
|
||||
},
|
||||
releaseLock() {},
|
||||
}),
|
||||
}),
|
||||
},
|
||||
readStarted,
|
||||
};
|
||||
}
|
||||
|
||||
test("superseding pathless upload staging uses an independent temp file", async (t) => {
|
||||
const dir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "netcatty-preload-stage-race-"));
|
||||
t.after(() => fs.promises.rm(dir, { recursive: true, force: true }));
|
||||
const created = [];
|
||||
const deleted = [];
|
||||
const ipcRenderer = {
|
||||
on() {},
|
||||
removeListener() {},
|
||||
async invoke(channel, payload) {
|
||||
if (channel === "netcatty:tempdir:createUploadPath") {
|
||||
const localPath = path.join(dir, `${payload.transferId}_${payload.fileName}.part`);
|
||||
created.push({ payload, localPath });
|
||||
return localPath;
|
||||
}
|
||||
if (channel === "netcatty:deleteTempFile") {
|
||||
deleted.push(payload.filePath);
|
||||
await fs.promises.unlink(payload.filePath).catch(() => {});
|
||||
return { success: true };
|
||||
}
|
||||
throw new Error(`Unexpected IPC call: ${channel}`);
|
||||
},
|
||||
};
|
||||
const api = createPreloadApi({ ipcRenderer, webUtils: {} });
|
||||
const firstFile = createBlockingFile("same.bin");
|
||||
|
||||
const first = api.stageUploadFile(firstFile.file, "same-transfer");
|
||||
await firstFile.readStarted;
|
||||
const second = api.stageUploadFile(createFile("same.bin", [[4, 5, 6]]), "same-transfer");
|
||||
|
||||
await assert.rejects(first, /superseded/i);
|
||||
const secondPath = await second;
|
||||
|
||||
assert.equal(created.length, 2);
|
||||
assert.notEqual(created[0].payload.transferId, created[1].payload.transferId);
|
||||
assert.notEqual(created[0].localPath, created[1].localPath);
|
||||
assert.equal(secondPath, created[1].localPath);
|
||||
assert.deepEqual(await fs.promises.readFile(secondPath), Buffer.from([4, 5, 6]));
|
||||
await assert.rejects(fs.promises.stat(created[0].localPath), { code: "ENOENT" });
|
||||
assert.deepEqual(deleted, [created[0].localPath]);
|
||||
});
|
||||
|
||||
test("failed upload path allocation releases the staging controller", async () => {
|
||||
const api = createPreloadApi({
|
||||
webUtils: {},
|
||||
ipcRenderer: {
|
||||
on() {},
|
||||
removeListener() {},
|
||||
async invoke(channel) {
|
||||
if (channel === "netcatty:tempdir:createUploadPath") throw new Error("path unavailable");
|
||||
throw new Error(`Unexpected IPC call: ${channel}`);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await assert.rejects(api.stageUploadFile(createFile("file.bin", [[1]]), "failed-path"), /path unavailable/);
|
||||
assert.deepEqual(await api.cancelStagedUploadFile("failed-path"), { success: false });
|
||||
});
|
||||
|
||||
test("native tree scans use a bridge-safe cancellation id", async () => {
|
||||
const sent = [];
|
||||
const invoked = [];
|
||||
const api = createPreloadApi({
|
||||
webUtils: {},
|
||||
ipcRenderer: {
|
||||
on() {},
|
||||
removeListener() {},
|
||||
send(...args) { sent.push(args); },
|
||||
async invoke(channel, payload) {
|
||||
invoked.push({ channel, payload });
|
||||
return [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await api.listLocalTree("/tmp/project", {
|
||||
scanId: "scan-123",
|
||||
onProgress: () => {},
|
||||
});
|
||||
await api.cancelLocalTreeScan("scan-123");
|
||||
|
||||
assert.deepEqual(invoked, [{
|
||||
channel: "netcatty:local:tree",
|
||||
payload: {
|
||||
path: "/tmp/project",
|
||||
progressChannel: "netcatty:local:tree-progress:scan-123",
|
||||
entriesChannel: undefined,
|
||||
cancelChannel: "netcatty:local:tree-cancel:scan-123",
|
||||
limits: undefined,
|
||||
},
|
||||
}]);
|
||||
assert.deepEqual(sent, [["netcatty:local:tree-cancel:scan-123"]]);
|
||||
});
|
||||
|
||||
test("listLocalTree keeps the entries listener until the tree-end marker arrives", async () => {
|
||||
const listeners = new Map();
|
||||
const batches = [];
|
||||
let removed = false;
|
||||
const api = createPreloadApi({
|
||||
webUtils: {},
|
||||
ipcRenderer: {
|
||||
on(channel, handler) {
|
||||
listeners.set(channel, handler);
|
||||
},
|
||||
removeListener(channel) {
|
||||
if (channel.startsWith("netcatty:local:tree-entries:")) removed = true;
|
||||
listeners.delete(channel);
|
||||
},
|
||||
send() {},
|
||||
async invoke(channel, payload) {
|
||||
assert.equal(channel, "netcatty:local:tree");
|
||||
const entriesChannel = payload.entriesChannel;
|
||||
const handler = listeners.get(entriesChannel);
|
||||
assert.equal(typeof handler, "function");
|
||||
// Simulate the invoke reply racing ahead of a late nested batch.
|
||||
queueMicrotask(() => {
|
||||
handler({}, [
|
||||
{
|
||||
localPath: "/tmp/project/nested/deep.txt",
|
||||
relativePath: "project/nested/deep.txt",
|
||||
type: "file",
|
||||
size: 1,
|
||||
lastModified: 1,
|
||||
},
|
||||
]);
|
||||
handler({}, { type: "tree-end" });
|
||||
});
|
||||
return [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await api.listLocalTree("/tmp/project", {
|
||||
scanId: "scan-nested",
|
||||
onEntries: (batch) => {
|
||||
batches.push(batch);
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(batches.length, 1);
|
||||
assert.equal(batches[0][0].relativePath, "project/nested/deep.txt");
|
||||
assert.equal(removed, true);
|
||||
});
|
||||
|
||||
test("openSftpForSession keeps the SSH source session id when options include an SFTP session id", async () => {
|
||||
const invoked = [];
|
||||
const api = createPreloadApi({
|
||||
webUtils: {},
|
||||
ipcRenderer: {
|
||||
on() {},
|
||||
removeListener() {},
|
||||
async invoke(channel, payload) {
|
||||
invoked.push({ channel, payload });
|
||||
return { sftpId: "opened-sftp" };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const sftpId = await api.openSftpForSession("ssh-session-1", {
|
||||
sessionId: "sftp-left-browse-session",
|
||||
hostname: "192.168.9.138",
|
||||
port: 22,
|
||||
username: "zlhrs",
|
||||
});
|
||||
|
||||
assert.equal(sftpId, "opened-sftp");
|
||||
assert.equal(invoked.length, 1);
|
||||
assert.equal(invoked[0].channel, "netcatty:sftp:openForSession");
|
||||
assert.equal(invoked[0].payload.sessionId, "ssh-session-1");
|
||||
assert.equal(invoked[0].payload.expectedEndpoint.sessionId, "sftp-left-browse-session");
|
||||
});
|
||||
|
||||
test("strict openSftpForSession closes and rejects a mismatched source result", async () => {
|
||||
const invoked = [];
|
||||
const api = createPreloadApi({
|
||||
webUtils: {},
|
||||
ipcRenderer: {
|
||||
on() {},
|
||||
removeListener() {},
|
||||
async invoke(channel, payload) {
|
||||
invoked.push({ channel, payload });
|
||||
if (channel === "netcatty:sftp:openForSession") {
|
||||
return { sftpId: "wrong-route-sftp", sourceSessionId: "other-session" };
|
||||
}
|
||||
return { success: true };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
api.openSftpForSession("requested-session", {
|
||||
hostname: "target.example",
|
||||
username: "alice",
|
||||
requireExactSourceSession: true,
|
||||
}),
|
||||
/requested terminal connection is no longer available/,
|
||||
);
|
||||
|
||||
assert.equal(invoked[0].payload.requireExactSourceSession, true);
|
||||
assert.deepEqual(invoked[1], {
|
||||
channel: "netcatty:sftp:close",
|
||||
payload: { sftpId: "wrong-route-sftp" },
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user