Files
Multi-Debrid-Downloader/tests/extract-action.test.ts
T
Sucukdeluxe e52957a983 fix(extraction): repair missing archives before manual retry
Persist selected manual extraction repair requests, re-download only missing multipart members, and resume extraction after successful repairs across Stop, failures, and application restarts.

Allow complete archive sets and missing sets from the same package to progress together, preserve existing parts, and keep retry generations and run contexts isolated after failed repair downloads.

Expose direct child retries for persisted repair items and validate repair state through storage normalization and renderer deltas.
2026-08-23 11:37:21 +02:00

123 lines
3.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { DownloadItem, PackageEntry } from "../src/shared/types";
import { buildExtractNowContextAction } from "../src/renderer/views/downloads/extract-action";
function item(id: string, packageId: string, status: DownloadItem["status"], fullStatus: string): DownloadItem {
return {
id,
packageId,
url: `https://example.invalid/${id}`,
provider: "realdebrid",
status,
retries: 0,
speedBps: 0,
downloadedBytes: status === "completed" ? 100 : 0,
totalBytes: 100,
progressPercent: status === "completed" ? 100 : 0,
fileName: `${id}.part1.rar`,
targetPath: `C:\\Downloads\\${id}.part1.rar`,
resumable: true,
attempts: 0,
lastError: "",
fullStatus,
createdAt: 1,
updatedAt: 1
};
}
function pkg(id: string, itemIds: string[]): PackageEntry {
return {
id,
name: id,
outputDir: `C:\\Downloads\\${id}`,
extractDir: `C:\\Downloads\\_entpackt\\${id}`,
itemIds,
enabled: true,
cancelled: false,
status: "completed",
priority: "normal",
createdAt: 1,
updatedAt: 1
};
}
describe("extract now context action", () => {
it("targets one completed child item so the manager can resolve its complete archive set", () => {
const items = { part2: item("part2", "pkg-1", "completed", "Fertig") };
const action = buildExtractNowContextAction({
contextItemId: "part2",
selectedPackageIds: [],
selectedItemIds: ["part2"],
packages: { "pkg-1": pkg("pkg-1", ["part2"]) },
items
});
expect(action).toEqual({
label: "Jetzt entpacken",
request: { packageIds: [], itemIds: ["part2"] },
targetCount: 1
});
});
it("targets every selected package that has completed unextracted files", () => {
const items = {
a: item("a", "pkg-a", "completed", "Entpack-Fehler: Passwort"),
b: item("b", "pkg-b", "completed", "Entpacken - Ausstehend"),
c: item("c", "pkg-c", "queued", "Wartet")
};
const action = buildExtractNowContextAction({
selectedPackageIds: ["pkg-a", "pkg-b", "pkg-c"],
selectedItemIds: [],
packages: {
"pkg-a": pkg("pkg-a", ["a"]),
"pkg-b": pkg("pkg-b", ["b"]),
"pkg-c": pkg("pkg-c", ["c"])
},
items
});
expect(action).toEqual({
label: "Jetzt entpacken (2)",
request: { packageIds: ["pkg-a", "pkg-b"], itemIds: [] },
targetCount: 2
});
});
it("hides the action for extracted or incomplete selections", () => {
const items = {
extracted: item("extracted", "pkg-1", "completed", "Entpackt in 4s"),
queued: item("queued", "pkg-2", "queued", "Wartet")
};
expect(buildExtractNowContextAction({
selectedPackageIds: ["pkg-1", "pkg-2"],
selectedItemIds: [],
packages: {
"pkg-1": pkg("pkg-1", ["extracted"]),
"pkg-2": pkg("pkg-2", ["queued"])
},
items
})).toBeNull();
});
it("keeps retrying a failed child that belongs to a persisted manual extraction repair", () => {
const failed = item("failed", "pkg-1", "failed", "Download fehlgeschlagen");
const packageEntry = {
...pkg("pkg-1", ["failed"]),
manualExtractionPending: true,
manualExtractionRepairItemIds: ["failed"]
};
expect(buildExtractNowContextAction({
contextItemId: "failed",
selectedPackageIds: [],
selectedItemIds: ["failed"],
packages: { "pkg-1": packageEntry },
items: { failed }
})).toEqual({
label: "Jetzt entpacken",
request: { packageIds: [], itemIds: ["failed"] },
targetCount: 1
});
});
});