@@ -568,6 +568,49 @@ describe("server-channels auto restart", () => {
|
568 | 568 | expect(hoisted.sleepWithAbort.mock.calls[0]?.[0]).toBe(10); |
569 | 569 | }); |
570 | 570 | |
| 571 | +it("lets explicit starts win after a manual timeout during recovery stop", async () => { |
| 572 | +const releaseFirstTask = createDeferred(); |
| 573 | +let startCount = 0; |
| 574 | +const startAccount = vi.fn(async ({ abortSignal }: { abortSignal: AbortSignal }) => { |
| 575 | +startCount += 1; |
| 576 | +abortSignal.addEventListener("abort", () => {}, { once: true }); |
| 577 | +if (startCount === 1) { |
| 578 | +await releaseFirstTask.promise; |
| 579 | +return; |
| 580 | +} |
| 581 | +await new Promise<void>(() => {}); |
| 582 | +}); |
| 583 | +installTestRegistry( |
| 584 | +createTestPlugin({ |
| 585 | + startAccount, |
| 586 | +}), |
| 587 | +); |
| 588 | +const manager = createManager(); |
| 589 | + |
| 590 | +await manager.startChannels(); |
| 591 | +const recoveryStopTask = manager.stopChannel("discord", DEFAULT_ACCOUNT_ID, { |
| 592 | +manual: false, |
| 593 | +}); |
| 594 | +await vi.advanceTimersByTimeAsync(5_000); |
| 595 | +await recoveryStopTask; |
| 596 | + |
| 597 | +const manualStopTask = manager.stopChannel("discord", DEFAULT_ACCOUNT_ID); |
| 598 | +await vi.advanceTimersByTimeAsync(5_000); |
| 599 | +await manualStopTask; |
| 600 | +await manager.startChannel("discord", DEFAULT_ACCOUNT_ID); |
| 601 | +releaseFirstTask.resolve(); |
| 602 | +await waitForMicrotaskCondition( |
| 603 | +() => startAccount.mock.calls.length === 2, |
| 604 | +"expected explicit start to clear manual stop and restart after old task exits", |
| 605 | +); |
| 606 | + |
| 607 | +const account = manager.getRuntimeSnapshot().channelAccounts.discord?.[DEFAULT_ACCOUNT_ID]; |
| 608 | +expect(account?.running).toBe(true); |
| 609 | +expect(account?.restartPending).toBe(false); |
| 610 | +expect(manager.isManuallyStopped("discord", DEFAULT_ACCOUNT_ID)).toBe(false); |
| 611 | +expect(hoisted.sleepWithAbort).not.toHaveBeenCalled(); |
| 612 | +}); |
| 613 | + |
571 | 614 | it("marks enabled/configured when account descriptors omit them", () => { |
572 | 615 | installTestRegistry( |
573 | 616 | createTestPlugin({ |
|