perf(studio): stream nitro repair progress over SSE and allow cancelling
This commit is contained in:
1 parent
ba81d16f00
commit
9d571e0c29
4 files changed
+249
-26
No files matched your search
@@ -88,6 +88,7 @@ vi.mock("node:fs", async (orig) => {
|
||||
import {
|
||||
autoCleanFakeNitros,
|
||||
deleteNitroCleanupFiles,
|
||||
type NitroRepairProgress,
|
||||
repairBrokenNitros,
|
||||
scanFakeBrokenNitros,
|
||||
} from "@/lib/services/nitro-cleanup";
|
||||
@@ -471,4 +472,59 @@ describe("repairBrokenNitros", () => {
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.errors[0]).toMatch(/could not re-obtain/);
|
||||
});
|
||||
|
||||
it("reports per-bundle progress while re-downloading", async () => {
|
||||
getTargetsFn.mockResolvedValue({
|
||||
nitroDir: "/a/nitro",
|
||||
swfDir: "/a/swf",
|
||||
iconDir: "/a/icons",
|
||||
mirrorDirs: [],
|
||||
});
|
||||
readFileFn.mockResolvedValue(Buffer.from("nitro-data"));
|
||||
parseNitroBundle.mockReturnValue({});
|
||||
downloadFileFn.mockResolvedValue({ ok: true, size: 100 });
|
||||
|
||||
const events: NitroRepairProgress[] = [];
|
||||
const result = await repairBrokenNitros(["a.nitro", "b.nitro"], {
|
||||
onProgress: (progress) => events.push(progress),
|
||||
});
|
||||
|
||||
expect(result.repaired).toBe(2);
|
||||
expect(events).toHaveLength(2);
|
||||
expect(events.map((e) => e.completed).sort()).toEqual([1, 2]);
|
||||
expect(events[events.length - 1]).toMatchObject({
|
||||
total: 2,
|
||||
ok: 2,
|
||||
failed: 0,
|
||||
});
|
||||
expect(events[0].total).toBe(2);
|
||||
});
|
||||
|
||||
it("counts successes and failures in repair progress", async () => {
|
||||
getTargetsFn.mockResolvedValue({
|
||||
nitroDir: "/a/nitro",
|
||||
swfDir: "/a/swf",
|
||||
iconDir: "/a/icons",
|
||||
mirrorDirs: [],
|
||||
});
|
||||
readFileFn.mockResolvedValue(Buffer.from("nitro-data"));
|
||||
parseNitroBundle.mockReturnValue({});
|
||||
downloadFileFn.mockImplementation(async (url: string) => ({
|
||||
ok: url.includes("a.nitro"),
|
||||
size: 100,
|
||||
error: url.includes("b.nitro") ? "HTTP 404" : undefined,
|
||||
}));
|
||||
|
||||
const events: NitroRepairProgress[] = [];
|
||||
await repairBrokenNitros(["a.nitro", "b.nitro"], {
|
||||
onProgress: (progress) => events.push(progress),
|
||||
});
|
||||
|
||||
expect(events.map((e) => e.completed).sort()).toEqual([1, 2]);
|
||||
expect(events[events.length - 1]).toMatchObject({
|
||||
total: 2,
|
||||
ok: 1,
|
||||
failed: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user