mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 00:50:44 +00:00
* fix(sftp): preserve successful uploads with backup cleanup warnings Warn only on confirmed backup cleanup permission refusal after final publication. Preserve actionable warnings across transfer events, history restoration and completion ordering without masking deletion or commit failures. Narrow follow-up to #3830; related #3879. * fix(sftp): retain folder cleanup warnings before child completion
135 lines
4.5 KiB
TypeScript
135 lines
4.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { reportSftpUploadResults } from "./reportSftpUploadResults.ts";
|
|
|
|
const t = (key: string, params?: Record<string, string | number>) => {
|
|
if (key === "sftp.upload.partialSuccess") {
|
|
return `partial ${params?.success}/${params?.failed}`;
|
|
}
|
|
return key;
|
|
};
|
|
|
|
test("does not toast success when zero files uploaded", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
reportSftpUploadResults({
|
|
results: [],
|
|
t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
},
|
|
});
|
|
assert.deepEqual(calls, [{ type: "info", message: "sftp.upload.noFiles" }]);
|
|
});
|
|
|
|
test("toasts cancelled when any result is cancelled", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
reportSftpUploadResults({
|
|
results: [
|
|
{ fileName: "a", success: false, cancelled: true },
|
|
{ fileName: "b", success: true },
|
|
],
|
|
t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
},
|
|
});
|
|
assert.deepEqual(calls, [{ type: "info", message: "sftp.upload.cancelled" }]);
|
|
});
|
|
|
|
test("toasts multi-file success count", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
reportSftpUploadResults({
|
|
results: [
|
|
{ fileName: "a", success: true },
|
|
{ fileName: "b", success: true },
|
|
],
|
|
t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
},
|
|
});
|
|
assert.deepEqual(calls, [{ type: "success", message: "sftp.uploadFiles: 2" }]);
|
|
});
|
|
|
|
test("successful uploads surface cleanup warnings rather than upload failures", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
const warning = "Upload completed; remove backup /remote/.netcatty-backup-a manually.";
|
|
reportSftpUploadResults({
|
|
results: [{ fileName: "a", success: true, warning }], t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
warning: (message) => calls.push({ type: "warning", message }),
|
|
},
|
|
});
|
|
assert.deepEqual(calls, [{ type: "warning", message: warning }, { type: "success", message: "sftp.upload: a" }]);
|
|
});
|
|
|
|
test("terminal drop success names the exact remote destination", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
reportSftpUploadResults({
|
|
results: [{ fileName: "release.tgz", success: true }],
|
|
targetPath: "/srv/releases",
|
|
t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(calls, [{
|
|
type: "success",
|
|
message: "sftp.upload: release.tgz (/srv/releases)",
|
|
}]);
|
|
});
|
|
|
|
test("toasts failures and partial success separately", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
reportSftpUploadResults({
|
|
results: [
|
|
{ fileName: "a", success: true },
|
|
{ fileName: "b", success: false, error: "boom" },
|
|
],
|
|
t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
},
|
|
});
|
|
assert.equal(calls[0]?.type, "error");
|
|
assert.equal(calls[1]?.type, "info");
|
|
assert.match(calls[1]?.message ?? "", /partial 1\/1/);
|
|
});
|
|
|
|
test("partial terminal drop success names the exact remote destination", () => {
|
|
const calls: Array<{ type: string; message: string }> = [];
|
|
reportSftpUploadResults({
|
|
results: [
|
|
{ fileName: "a", success: true },
|
|
{ fileName: "b", success: false, error: "boom" },
|
|
],
|
|
targetPath: "/srv/releases",
|
|
t,
|
|
toast: {
|
|
success: (message) => calls.push({ type: "success", message }),
|
|
error: (message) => calls.push({ type: "error", message }),
|
|
info: (message) => calls.push({ type: "info", message }),
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(calls[1], {
|
|
type: "info",
|
|
message: "partial 1/1 (/srv/releases)",
|
|
});
|
|
});
|