fix: serialize every download start through lifecycle

Route full, package, and item starts through a shared typed start request lifecycle. Preserve targeted scopes while a stop drains, publish pending-start state consistently, and dispatch the accepted request only after the old work has settled.

Add package and item regression coverage and update the notification lifecycle assertion to the pending/drain contract.
This commit is contained in:
Sucukdeluxe
2026-08-22 12:20:33 +02:00
parent 7f3030ecc5
commit ae2691319d
3 changed files with 180 additions and 57 deletions
+4 -2
View File
@@ -664,11 +664,13 @@ describe("authoritative run completion", () => {
const packageB = addPackage(session, ["queued"], "follow-up-package");
await manager.start();
expect(session.running).toBe(true);
expect(state.runPackageIds).toEqual(new Set([packageB.id]));
expect(session.running).toBe(false);
expect(manager.getSnapshot().lifecycle).toMatchObject({ phase: "stopping", pendingStart: true });
releasePostProcess();
await latePostProcess;
await vi.waitFor(() => expect(manager.getSnapshot().lifecycle).toMatchObject({ phase: "running", pendingStart: false }));
expect(state.runPackageIds).toEqual(new Set([packageB.id]));
await flushNotifications();
expect(events.filter((event) => event.type === "package_completed")).toHaveLength(0);
expect(history).toHaveLength(0);