mirror of
https://github.com/warmbly/warmbly.git
synced 2026-11-23 08:05:31 +00:00
feat: refresh visible mailbox health and error reports from current server evidence every minute and on stale tab return
This commit is contained in:
@@ -642,6 +642,8 @@ The Accounts list groups mailboxes as **Healthy** (sending normally), **Warming*
|
||||
|
||||
Repeated reports of the same error code count once toward the health score, at their highest unresolved severity, rather than making one problem look like several. The drawer groups identical reports while keeping different error details and sending versus sync failures separate. Connection titles name Gmail, Microsoft Outlook or the mail server. **Reported** shows the stored report time: connection and temporary provider-limit observations refresh it, while other error categories may retain their original report time. It is not proof of an ongoing outage.
|
||||
|
||||
While visible, the Accounts list and mailbox drawer refresh their health and error reports every minute as well as on relevant live events. Returning to a tab refreshes stale reports too. These reads show the server's latest recovery evidence; they do not reconnect a mailbox or retry a send. A failed status refresh does not count as recovery.
|
||||
|
||||
A later completed sync automatically clears earlier temporary sync errors. A provider-confirmed send clears earlier temporary sending errors, including provider throttling and quota warnings. Recovered reports no longer appear under **Needs attention** or reduce the health score. Older reports that do not identify which operation failed clear once both sending and sync have succeeded after the report; existing reports with that evidence are cleared on upgrade too. A newer failure remains visible, and simply waiting or completing a queued task does not count as recovery. Recoverable connection failures retry automatically while the mailbox is on; a connection warning alone is not a reason to reconnect. A temporary connection, server or throttling failure is not shown at all while the affected sync or sending has still succeeded within the last two hours, because the mailbox is working. It appears only when the failure lasts longer than that. Authentication, credential and policy errors retain their own instructions, and a switched-off mailbox must be switched back on before it can retry.
|
||||
|
||||
A send safety hold is different from a retryable connection failure. If Warmbly cannot confirm whether the provider accepted a message, sending pauses to avoid retrying a message that might already have been sent. The mailbox is shown as needing attention even without a separate connection warning, and its health details explain the hold. A successful inbox sync does not confirm a send. The hold clears on its own and no customer action is needed. After ten minutes Warmbly sets the uncertain email aside for good: a campaign email waits for confirmation for that one contact while the mailbox sends to everyone else, and a Unibox, placement-test or Warmbly Cloud send simply never runs again. A send that never reached the worker is handed back after 30 minutes so the step can go out fresh. A late confirmed result still updates the email automatically. Only legacy sends without durable execution authorization need provider-confirmed resolution. See [send safety](/development/send-safety/).
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
import type { PropsWithChildren } from "react";
|
||||
import { act, cleanup, renderHook } from "@testing-library/react";
|
||||
import { focusManager, QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import getAccountStatus from "@/lib/api/client/app/analytics/getAccountStatus";
|
||||
import getAccountStatuses from "@/lib/api/client/app/analytics/getAccountStatuses";
|
||||
import type AccountStatus from "@/lib/api/models/app/analytics/AccountStatus";
|
||||
import useAccountStatus from "./useAccountStatus";
|
||||
import useAccountStatuses from "./useAccountStatuses";
|
||||
|
||||
vi.mock("@/lib/api/client/app/analytics/getAccountStatus", () => ({ default: vi.fn() }));
|
||||
vi.mock("@/lib/api/client/app/analytics/getAccountStatuses", () => ({ default: vi.fn() }));
|
||||
|
||||
function mailbox(recovered: boolean): AccountStatus {
|
||||
return {
|
||||
id: "mailbox", email: "mailbox@example.test", provider: "smtp_imap", status: "active",
|
||||
last_synced_at: recovered ? new Date() : new Date(Date.now() - 3 * 60 * 60_000),
|
||||
health: { status: recovered ? "healthy" : "warning", score: recovered ? 100 : 80 },
|
||||
errors: recovered ? [] : [{
|
||||
id: "failure", error_code: "SERVER_UNREACHABLE", severity: "WARNING", operation: "sync",
|
||||
title: "Mail server sync connection failed", message: "Automatic retry", created_at: new Date(),
|
||||
}],
|
||||
daily_usage: { date: "2026-11-01", campaign_sent: 0, campaign_limit: 10 }, in_campaign: false,
|
||||
};
|
||||
}
|
||||
|
||||
function harness() {
|
||||
const client = new QueryClient({ defaultOptions: { queries: {
|
||||
retry: false, gcTime: Infinity, staleTime: 30_000, refetchOnWindowFocus: false,
|
||||
} } });
|
||||
const wrapper = ({ children }: PropsWithChildren) => <QueryClientProvider client={client}>{children}</QueryClientProvider>;
|
||||
const ids = ["mailbox"];
|
||||
const hook = renderHook(({ enabled }) => ({
|
||||
drawer: useAccountStatus(enabled ? "mailbox" : ""), list: useAccountStatuses(ids, { enabled }),
|
||||
}), { wrapper, initialProps: { enabled: true } });
|
||||
return { client, ...hook };
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.clearAllMocks();
|
||||
focusManager.setFocused(true);
|
||||
vi.mocked(getAccountStatus).mockResolvedValue(mailbox(false));
|
||||
vi.mocked(getAccountStatuses).mockResolvedValue([mailbox(false)]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
focusManager.setFocused(undefined);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("mailbox status freshness without realtime events", () => {
|
||||
it("replaces a recovered warning and its old success time in both open views", async () => {
|
||||
const { client, result, unmount } = harness();
|
||||
await act(() => vi.advanceTimersByTimeAsync(1));
|
||||
expect(result.current.drawer.data?.errors).toHaveLength(1);
|
||||
expect(result.current.list.data[0]?.errors).toHaveLength(1);
|
||||
|
||||
const recovered = mailbox(true);
|
||||
vi.mocked(getAccountStatus).mockResolvedValue(recovered);
|
||||
vi.mocked(getAccountStatuses).mockResolvedValue([recovered]);
|
||||
await act(() => vi.advanceTimersByTimeAsync(59_000));
|
||||
expect(getAccountStatus).toHaveBeenCalledTimes(1);
|
||||
expect(getAccountStatuses).toHaveBeenCalledTimes(1);
|
||||
await act(() => vi.advanceTimersByTimeAsync(1_001));
|
||||
expect(result.current.drawer.data?.errors).toEqual([]);
|
||||
expect(result.current.drawer.data?.last_synced_at).toEqual(recovered.last_synced_at);
|
||||
expect(result.current.list.data[0]?.errors).toEqual([]);
|
||||
expect(result.current.list.data[0]?.last_synced_at).toEqual(recovered.last_synced_at);
|
||||
unmount(); client.clear();
|
||||
});
|
||||
|
||||
it("retains a reported failure until the server confirms recovery, and stops after unmount", async () => {
|
||||
const { client, result, unmount } = harness();
|
||||
await act(() => vi.advanceTimersByTimeAsync(60_002));
|
||||
expect(getAccountStatus).toHaveBeenCalledTimes(2);
|
||||
expect(getAccountStatuses).toHaveBeenCalledTimes(2);
|
||||
expect(result.current.drawer.data?.errors).toHaveLength(1);
|
||||
expect(result.current.list.data[0]?.errors).toHaveLength(1);
|
||||
unmount();
|
||||
await act(() => vi.advanceTimersByTimeAsync(120_000));
|
||||
expect(getAccountStatus).toHaveBeenCalledTimes(2);
|
||||
expect(getAccountStatuses).toHaveBeenCalledTimes(2);
|
||||
client.clear();
|
||||
});
|
||||
|
||||
it("pauses periodic reads while hidden and refreshes immediately on return", async () => {
|
||||
const { client, result, unmount } = harness();
|
||||
await act(() => vi.advanceTimersByTimeAsync(1));
|
||||
act(() => focusManager.setFocused(false));
|
||||
const recovered = mailbox(true);
|
||||
vi.mocked(getAccountStatus).mockResolvedValue(recovered);
|
||||
vi.mocked(getAccountStatuses).mockResolvedValue([recovered]);
|
||||
await act(() => vi.advanceTimersByTimeAsync(60_001));
|
||||
expect(getAccountStatus).toHaveBeenCalledTimes(1);
|
||||
expect(getAccountStatuses).toHaveBeenCalledTimes(1);
|
||||
act(() => focusManager.setFocused(true));
|
||||
await act(() => vi.advanceTimersByTimeAsync(1));
|
||||
expect(result.current.drawer.data?.errors).toEqual([]);
|
||||
expect(result.current.list.data[0]?.errors).toEqual([]);
|
||||
unmount(); client.clear();
|
||||
});
|
||||
|
||||
it("keeps the last report when a refresh fails instead of assuming recovery", async () => {
|
||||
const { client, result, unmount } = harness();
|
||||
await act(() => vi.advanceTimersByTimeAsync(1));
|
||||
vi.mocked(getAccountStatus).mockRejectedValue(new Error("Status unavailable"));
|
||||
vi.mocked(getAccountStatuses).mockRejectedValue(new Error("Status unavailable"));
|
||||
await act(() => vi.advanceTimersByTimeAsync(60_001));
|
||||
expect(result.current.drawer.isError).toBe(true);
|
||||
expect(result.current.list.isError).toBe(true);
|
||||
expect(result.current.drawer.data?.errors).toHaveLength(1);
|
||||
expect(result.current.list.data[0]?.errors).toHaveLength(1);
|
||||
expect(result.current.list.observations[0]?.current).toBe(false);
|
||||
unmount(); client.clear();
|
||||
});
|
||||
|
||||
it("respects disabled status reads during timer and focus changes", async () => {
|
||||
const { client, rerender, unmount } = harness();
|
||||
await act(() => vi.advanceTimersByTimeAsync(1));
|
||||
rerender({ enabled: false });
|
||||
act(() => focusManager.setFocused(false));
|
||||
await act(() => vi.advanceTimersByTimeAsync(60_001));
|
||||
act(() => focusManager.setFocused(true));
|
||||
await act(() => vi.advanceTimersByTimeAsync(60_001));
|
||||
expect(getAccountStatus).toHaveBeenCalledTimes(1);
|
||||
expect(getAccountStatuses).toHaveBeenCalledTimes(1);
|
||||
unmount(); client.clear();
|
||||
});
|
||||
});
|
||||
@@ -6,5 +6,8 @@ export default function useAccountStatus(id: string) {
|
||||
queryKey: ["analytics", "accounts", id],
|
||||
queryFn: () => getAccountStatus(id),
|
||||
enabled: !!id,
|
||||
})
|
||||
// Routine recovery persists without a realtime event.
|
||||
refetchInterval: 60_000,
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ export default function useAccountStatuses(emailIds: string[], options?: { enabl
|
||||
queryKey: ["analytics", "accounts", "list", ids, sourceRevision],
|
||||
queryFn: ({ signal }: { signal: AbortSignal }) => getAccountStatuses(ids, signal),
|
||||
enabled: ids.length > 0 && enabled,
|
||||
// Routine recovery persists without a realtime event.
|
||||
refetchInterval: 60_000,
|
||||
refetchOnWindowFocus: true,
|
||||
})),
|
||||
[chunks, enabled, sourceRevision],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user