mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-01 12:46:55 +00:00
Show Schedules when a saved host is still connecting (#11361)
* fix(schedules): show results while another host connects ## Problem An online host returning no schedules leaves the page loading indefinitely when another saved host is still connecting. The user cannot reach the empty state or create a schedule despite a successful response. ## Solution Return the available results, including an empty list, and include a warning for hosts still connecting. Preserve the initial connecting state when no host can answer and existing errors when every attempted request fails. * test(schedules): cover stalled hosts in the browser ## Problem The schedules spinner regression needs a user-visible check, and partial loading must not hide errors from the only connected host. ## Solution Exercise an isolated daemon alongside a stalled WebSocket connection in the existing schedules suite. Verify the empty state, warning, and creation button, capture both responsive layouts, and preserve failed-host coverage. * fix(schedules): keep host warnings consistent with fetched results ## Problem A host changing connection state during another request could lose its missing-results warning or gain a warning despite returning schedules. ## Solution Remember settling hosts when deciding which requests to send. Cover both connection transitions and express the browser regression through concise user-level helpers. * test(schedules): keep scenario mechanics in runtime fixtures ## Problem Host-specific branching inside test bodies obscures the behaviors being asserted and conflicts with the repository's test conventions. ## Solution Reuse the runtime fixture for failed responses and isolate connection transitions in a focused helper while preserving unconditional assertions. * test(schedules): assert the empty state and creation control Check the text and action the user sees when another host is still connecting. Co-authored-by: MarkA <agenore990@gmail.com> * fix(schedules): identify hosts that are still connecting Carry the reason for each partial result so the banner can distinguish a pending connection from a failed schedule request. --------- Co-authored-by: MarkA <agenore990@gmail.com> Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { createServer, type Socket } from "node:net";
|
||||
import { expect, test, type Page } from "../support/fixtures";
|
||||
import { gotoAppShell } from "../support/helpers/app";
|
||||
import { addScheduleHostAndReload, createScheduleHost } from "../support/helpers/schedule-host";
|
||||
@@ -141,6 +142,68 @@ async function findScheduleIdByName(workspace: SeededWorkspace, name: string): P
|
||||
return schedule.id;
|
||||
}
|
||||
|
||||
async function createConnectingHost() {
|
||||
const sockets = new Set<Socket>();
|
||||
// Accept TCP without completing the WebSocket handshake, like a stalled host.
|
||||
const server = createServer((socket) => {
|
||||
sockets.add(socket);
|
||||
socket.on("close", () => sockets.delete(socket));
|
||||
});
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.once("error", reject);
|
||||
server.listen(0, "127.0.0.1", resolve);
|
||||
});
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") throw new Error("Expected a TCP address");
|
||||
return {
|
||||
port: address.port,
|
||||
close: async () => {
|
||||
for (const socket of sockets) socket.destroy();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.close((error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function openSchedulesWithConnectingHost(
|
||||
page: Page,
|
||||
cleanupTasks: Array<() => Promise<void>>,
|
||||
): Promise<void> {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "schedule-partial-hosts-", git: false });
|
||||
cleanupTasks.push(() => workspace.cleanup());
|
||||
const stalledHost = await createConnectingHost();
|
||||
cleanupTasks.push(() => stalledHost.close());
|
||||
|
||||
await gotoAppShell(page);
|
||||
await waitForSidebarHydration(page);
|
||||
await page.goto(buildSchedulesRoute());
|
||||
await addScheduleHostAndReload({
|
||||
page,
|
||||
serverId: "stalled-schedule-host",
|
||||
label: "Connecting host",
|
||||
port: stalledHost.port,
|
||||
});
|
||||
}
|
||||
|
||||
async function expectPartialEmptySchedules(page: Page): Promise<void> {
|
||||
await expect(page.getByText("No active schedules", { exact: true })).toBeVisible();
|
||||
await expect(page.getByText("Connecting host: Still connecting", { exact: true })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "New schedule", exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
async function expectScheduleCreationAvailable(page: Page): Promise<void> {
|
||||
await openNewScheduleSheet(page);
|
||||
await page.getByRole("button", { name: "Cancel", exact: true }).click();
|
||||
await expect(page.getByTestId("schedule-form-sheet")).toHaveCount(0);
|
||||
}
|
||||
|
||||
test.describe("Schedules project target", () => {
|
||||
const cleanupTasks: Array<() => Promise<void>> = [];
|
||||
|
||||
@@ -151,6 +214,12 @@ test.describe("Schedules project target", () => {
|
||||
cleanupTasks.length = 0;
|
||||
});
|
||||
|
||||
test("shows empty schedules while another host is still connecting", async ({ page }) => {
|
||||
await openSchedulesWithConnectingHost(page, cleanupTasks);
|
||||
await expectPartialEmptySchedules(page);
|
||||
await expectScheduleCreationAvailable(page);
|
||||
});
|
||||
|
||||
test("dismisses the new schedule sheet without reopening", async ({ page }) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "schedule-sheet-dismiss-", git: false });
|
||||
cleanupTasks.push(() => workspace.cleanup());
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("schedule mutation cache updates", () => {
|
||||
const current: FetchAggregatedSchedulesResult = {
|
||||
status: "loaded",
|
||||
data: [schedule()],
|
||||
hostErrors: [],
|
||||
hostWarnings: [],
|
||||
};
|
||||
|
||||
const result = updateAggregatedSchedulesData(current, pauseSchedules);
|
||||
@@ -51,7 +51,7 @@ describe("schedule mutation cache updates", () => {
|
||||
expect(result).toEqual({
|
||||
status: "loaded",
|
||||
data: [schedule({ status: "paused" })],
|
||||
hostErrors: [],
|
||||
hostWarnings: [],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@ describe("schedule mutation cache updates", () => {
|
||||
const loaded: FetchAggregatedSchedulesResult = {
|
||||
status: "loaded",
|
||||
data: [schedule()],
|
||||
hostErrors: [],
|
||||
hostWarnings: [],
|
||||
};
|
||||
queryClient.setQueryData(connectingKey, connecting);
|
||||
queryClient.setQueryData(loadedKey, loaded);
|
||||
@@ -85,7 +85,7 @@ describe("schedule mutation cache updates", () => {
|
||||
expect(queryClient.getQueryData(loadedKey)).toEqual({
|
||||
status: "loaded",
|
||||
data: [schedule({ status: "paused" })],
|
||||
hostErrors: [],
|
||||
hostWarnings: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,14 +10,14 @@ import {
|
||||
schedulesQueryBaseKey,
|
||||
type AggregateLoadState,
|
||||
type AggregatedSchedule,
|
||||
type ScheduleHostError,
|
||||
type ScheduleHostWarning,
|
||||
type ScheduleHostInput,
|
||||
} from "@/schedules/aggregated-schedules";
|
||||
|
||||
export type {
|
||||
AggregateLoadState,
|
||||
AggregatedSchedule,
|
||||
ScheduleHostError,
|
||||
ScheduleHostWarning,
|
||||
} from "@/schedules/aggregated-schedules";
|
||||
|
||||
export function schedulesQueryKey(serverIds: readonly string[]) {
|
||||
@@ -26,7 +26,7 @@ export function schedulesQueryKey(serverIds: readonly string[]) {
|
||||
|
||||
export interface UseSchedulesResult {
|
||||
loadState: AggregateLoadState<AggregatedSchedule>;
|
||||
hostErrors: ScheduleHostError[];
|
||||
hostWarnings: ScheduleHostWarning[];
|
||||
isError: boolean;
|
||||
error: Error | null;
|
||||
refetch: () => void;
|
||||
@@ -65,7 +65,7 @@ export function useSchedules(): UseSchedulesResult {
|
||||
|
||||
return {
|
||||
loadState,
|
||||
hostErrors: query.data?.status === "loaded" ? query.data.hostErrors : [],
|
||||
hostWarnings: query.data?.status === "loaded" ? query.data.hostWarnings : [],
|
||||
isError: query.isError,
|
||||
error: query.error,
|
||||
refetch: () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ScheduleSummary } from "@getpaseo/protocol/schedule/types";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
ALL_SCHEDULE_HOSTS_FAILED_MESSAGE,
|
||||
fetchAggregatedSchedules,
|
||||
type ScheduleRuntime,
|
||||
type ScheduleRuntimeSnapshot,
|
||||
@@ -28,6 +29,8 @@ function makeSchedule(overrides: Partial<ScheduleSummary> = {}): ScheduleSummary
|
||||
function makeRuntime(input: {
|
||||
snapshots: Record<string, ScheduleRuntimeSnapshot | null>;
|
||||
schedules?: Record<string, ScheduleSummary[]>;
|
||||
errors?: Record<string, string>;
|
||||
beforeResponse?: () => Promise<void>;
|
||||
}): ScheduleRuntime {
|
||||
return {
|
||||
getSnapshot: (serverId) => input.snapshots[serverId] ?? null,
|
||||
@@ -37,12 +40,31 @@ function makeRuntime(input: {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
scheduleList: async () => ({ requestId: "test-request", schedules, error: null }),
|
||||
scheduleList: async () => {
|
||||
await input.beforeResponse?.();
|
||||
return { requestId: "test-request", schedules, error: input.errors?.[serverId] ?? null };
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function makeTransitionRuntime(initial: string, next: string, schedule: ScheduleSummary) {
|
||||
const snapshots: Record<string, ScheduleRuntimeSnapshot> = {
|
||||
"host-a": { connectionStatus: "online" },
|
||||
"host-b": { connectionStatus: initial },
|
||||
};
|
||||
return makeRuntime({
|
||||
snapshots,
|
||||
schedules: { "host-a": [], "host-b": [schedule] },
|
||||
beforeResponse: async () => {
|
||||
// Both hosts have been considered before the first response arrives.
|
||||
await Promise.resolve();
|
||||
snapshots["host-b"] = { connectionStatus: next };
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe("fetchAggregatedSchedules load state", () => {
|
||||
it("does not report loaded empty while known hosts are still connecting", async () => {
|
||||
const result = await fetchAggregatedSchedules({
|
||||
@@ -80,10 +102,10 @@ describe("fetchAggregatedSchedules load state", () => {
|
||||
}),
|
||||
});
|
||||
|
||||
expect(result).toEqual({ status: "loaded", data: [], hostErrors: [] });
|
||||
expect(result).toEqual({ status: "loaded", data: [], hostWarnings: [] });
|
||||
});
|
||||
|
||||
it("does not report loaded empty while another known host is still connecting", async () => {
|
||||
it("shows the empty result with a warning while another host is connecting", async () => {
|
||||
const result = await fetchAggregatedSchedules({
|
||||
hosts: [
|
||||
{ serverId: "host-a", serverName: "Host A" },
|
||||
@@ -100,7 +122,62 @@ describe("fetchAggregatedSchedules load state", () => {
|
||||
}),
|
||||
});
|
||||
|
||||
expect(result).toEqual({ status: "connecting" });
|
||||
expect(result).toEqual({
|
||||
status: "loaded",
|
||||
data: [],
|
||||
hostWarnings: [
|
||||
{
|
||||
serverId: "host-b",
|
||||
serverName: "Host B",
|
||||
reason: "connecting",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ initial: "connecting", next: "online", includedHosts: [], missingHosts: ["host-b"] },
|
||||
{ initial: "online", next: "connecting", includedHosts: ["host-b"], missingHosts: [] },
|
||||
])(
|
||||
"keeps warnings consistent when a host changes from $initial to $next",
|
||||
async ({ initial, next, includedHosts, missingHosts }) => {
|
||||
const schedule = makeSchedule();
|
||||
const result = await fetchAggregatedSchedules({
|
||||
hosts: [
|
||||
{ serverId: "host-a", serverName: "Host A" },
|
||||
{ serverId: "host-b", serverName: "Host B" },
|
||||
],
|
||||
runtime: makeTransitionRuntime(initial, next, schedule),
|
||||
});
|
||||
expect(result).toEqual({
|
||||
status: "loaded",
|
||||
data: includedHosts.map((serverId) => ({ ...schedule, serverId, serverName: "Host B" })),
|
||||
hostWarnings: missingHosts.map((serverId) => ({
|
||||
serverId,
|
||||
serverName: "Host B",
|
||||
reason: "connecting",
|
||||
})),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the error state when the only connected host fails", async () => {
|
||||
await expect(
|
||||
fetchAggregatedSchedules({
|
||||
hosts: [
|
||||
{ serverId: "host-a", serverName: "Host A" },
|
||||
{ serverId: "host-b", serverName: "Host B" },
|
||||
],
|
||||
runtime: makeRuntime({
|
||||
snapshots: {
|
||||
"host-a": { connectionStatus: "online" },
|
||||
"host-b": { connectionStatus: "connecting" },
|
||||
},
|
||||
schedules: { "host-a": [] },
|
||||
errors: { "host-a": "Schedule storage unavailable" },
|
||||
}),
|
||||
}),
|
||||
).rejects.toThrow(ALL_SCHEDULE_HOSTS_FAILED_MESSAGE);
|
||||
});
|
||||
|
||||
it("loads reachable host data when another known host is still connecting", async () => {
|
||||
@@ -124,7 +201,13 @@ describe("fetchAggregatedSchedules load state", () => {
|
||||
expect(result).toEqual({
|
||||
status: "loaded",
|
||||
data: [{ ...schedule, serverId: "host-a", serverName: "Host A" }],
|
||||
hostErrors: [],
|
||||
hostWarnings: [
|
||||
{
|
||||
serverId: "host-b",
|
||||
serverName: "Host B",
|
||||
reason: "connecting",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { ScheduleSummary } from "@getpaseo/protocol/schedule/types";
|
||||
import { toErrorMessage } from "@/utils/error-messages";
|
||||
|
||||
export const schedulesQueryBaseKey = ["schedules"] as const;
|
||||
|
||||
@@ -27,10 +26,8 @@ export interface AggregatedSchedule extends ScheduleSummary {
|
||||
serverName: string;
|
||||
}
|
||||
|
||||
export interface ScheduleHostError {
|
||||
serverId: string;
|
||||
serverName: string;
|
||||
message: string;
|
||||
export interface ScheduleHostWarning extends ScheduleHostInput {
|
||||
reason: "connecting" | "request-failed";
|
||||
}
|
||||
|
||||
export interface FetchAggregatedSchedulesConnectingResult {
|
||||
@@ -40,7 +37,7 @@ export interface FetchAggregatedSchedulesConnectingResult {
|
||||
export interface FetchAggregatedSchedulesResult {
|
||||
status: "loaded";
|
||||
data: AggregatedSchedule[];
|
||||
hostErrors: ScheduleHostError[];
|
||||
hostWarnings: ScheduleHostWarning[];
|
||||
}
|
||||
|
||||
export type FetchAggregatedSchedulesState =
|
||||
@@ -62,9 +59,9 @@ export interface FetchAggregatedSchedulesInput {
|
||||
* Connectivity is checked here at execution time, so explicit query refreshes
|
||||
* pick up the currently connected host set.
|
||||
*
|
||||
* Offline hosts are skipped. A connected host that fails contributes to
|
||||
* `hostErrors` (surfaced as a banner) while the rest still render; only when
|
||||
* every connected host fails do we throw so the screen shows a full error.
|
||||
* Offline hosts are skipped. Hosts that are still connecting or fail to load
|
||||
* schedules contribute warnings. If every request fails, the screen shows
|
||||
* a full error instead.
|
||||
*/
|
||||
export async function fetchAggregatedSchedules(
|
||||
input: FetchAggregatedSchedulesInput,
|
||||
@@ -82,8 +79,9 @@ export async function fetchAggregatedSchedules(
|
||||
}
|
||||
|
||||
const schedules: AggregatedSchedule[] = [];
|
||||
const hostErrors: ScheduleHostError[] = [];
|
||||
const hostWarnings: ScheduleHostWarning[] = [];
|
||||
let connectedAttempts = 0;
|
||||
let failedAttempts = 0;
|
||||
|
||||
await Promise.all(
|
||||
input.hosts.map(async (host) => {
|
||||
@@ -91,6 +89,9 @@ export async function fetchAggregatedSchedules(
|
||||
const isOnline = snapshot?.connectionStatus === "online";
|
||||
const client = input.runtime.getClient(host.serverId);
|
||||
if (!client || !isOnline) {
|
||||
if (isScheduleHostConnectionSettling(snapshot)) {
|
||||
hostWarnings.push({ ...host, reason: "connecting" });
|
||||
}
|
||||
return;
|
||||
}
|
||||
connectedAttempts += 1;
|
||||
@@ -102,25 +103,18 @@ export async function fetchAggregatedSchedules(
|
||||
for (const schedule of payload.schedules) {
|
||||
schedules.push({ ...schedule, serverId: host.serverId, serverName: host.serverName });
|
||||
}
|
||||
} catch (error) {
|
||||
hostErrors.push({
|
||||
serverId: host.serverId,
|
||||
serverName: host.serverName,
|
||||
message: toErrorMessage(error),
|
||||
});
|
||||
} catch {
|
||||
failedAttempts += 1;
|
||||
hostWarnings.push({ ...host, reason: "request-failed" });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
if (connectedAttempts > 0 && schedules.length === 0 && hostErrors.length === connectedAttempts) {
|
||||
if (connectedAttempts > 0 && failedAttempts === connectedAttempts) {
|
||||
throw new Error(ALL_SCHEDULE_HOSTS_FAILED_MESSAGE);
|
||||
}
|
||||
|
||||
if (schedules.length === 0 && hasSettlingHost) {
|
||||
return { status: "connecting" };
|
||||
}
|
||||
|
||||
return { status: "loaded", data: schedules, hostErrors };
|
||||
return { status: "loaded", data: schedules, hostWarnings };
|
||||
}
|
||||
|
||||
function isScheduleHostConnectionSettling(
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
useSchedules,
|
||||
type AggregateLoadState,
|
||||
type AggregatedSchedule,
|
||||
type ScheduleHostError,
|
||||
type ScheduleHostWarning,
|
||||
} from "@/hooks/use-schedules";
|
||||
import { getHostRuntimeStore, useHosts } from "@/runtime/host-runtime";
|
||||
import {
|
||||
@@ -63,7 +63,7 @@ export function SchedulesScreen(): ReactElement {
|
||||
}
|
||||
|
||||
function SchedulesScreenContent(): ReactElement {
|
||||
const { loadState, hostErrors, isError, refetch } = useSchedules();
|
||||
const { loadState, hostWarnings, isError, refetch } = useSchedules();
|
||||
const schedules = loadState.status === "loaded" ? loadState.data : EMPTY_SCHEDULES;
|
||||
const { agents } = useAggregatedAgents({ includeArchived: true });
|
||||
const { projects } = useProjects();
|
||||
@@ -169,7 +169,7 @@ function SchedulesScreenContent(): ReactElement {
|
||||
<SchedulesScreenBody
|
||||
rows={visibleRows}
|
||||
loadState={loadState}
|
||||
hostErrors={hostErrors}
|
||||
hostWarnings={hostWarnings}
|
||||
showLoadError={showLoadError}
|
||||
statusFilter={statusFilter}
|
||||
onStatusFilterChange={setStatusFilter}
|
||||
@@ -195,7 +195,7 @@ function SchedulesScreenContent(): ReactElement {
|
||||
function SchedulesScreenBody({
|
||||
rows,
|
||||
loadState,
|
||||
hostErrors,
|
||||
hostWarnings,
|
||||
showLoadError,
|
||||
statusFilter,
|
||||
onStatusFilterChange,
|
||||
@@ -209,7 +209,7 @@ function SchedulesScreenBody({
|
||||
}: {
|
||||
rows: ScheduleRowView[];
|
||||
loadState: AggregateLoadState<AggregatedSchedule>;
|
||||
hostErrors: ScheduleHostError[];
|
||||
hostWarnings: ScheduleHostWarning[];
|
||||
showLoadError: boolean;
|
||||
statusFilter: ScheduleBucket;
|
||||
onStatusFilterChange: (value: ScheduleBucket) => void;
|
||||
@@ -245,7 +245,7 @@ function SchedulesScreenBody({
|
||||
if (bodyState.kind === "empty") {
|
||||
return (
|
||||
<View style={styles.centered}>
|
||||
{hostErrors.length > 0 ? <ScheduleHostErrorsBanner errors={hostErrors} /> : null}
|
||||
{hostWarnings.length > 0 ? <ScheduleHostWarningsBanner warnings={hostWarnings} /> : null}
|
||||
<SchedulesEmptyState onCreate={onCreate} testID="schedules-empty" />
|
||||
</View>
|
||||
);
|
||||
@@ -294,7 +294,7 @@ function SchedulesScreenBody({
|
||||
keyboardShouldPersistTaps="handled"
|
||||
testID="schedules-list"
|
||||
>
|
||||
{hostErrors.length > 0 ? <ScheduleHostErrorsBanner errors={hostErrors} /> : null}
|
||||
{hostWarnings.length > 0 ? <ScheduleHostWarningsBanner warnings={hostWarnings} /> : null}
|
||||
{schedulesContent}
|
||||
</ScrollView>
|
||||
</View>
|
||||
@@ -334,13 +334,17 @@ function SchedulesEndedEmptyState(): ReactElement {
|
||||
);
|
||||
}
|
||||
|
||||
function ScheduleHostErrorsBanner({ errors }: { errors: ScheduleHostError[] }): ReactElement {
|
||||
function ScheduleHostWarningsBanner({
|
||||
warnings,
|
||||
}: {
|
||||
warnings: ScheduleHostWarning[];
|
||||
}): ReactElement {
|
||||
return (
|
||||
<View style={styles.errorsBannerWrap}>
|
||||
<View style={styles.errorsBanner} testID="schedules-host-errors">
|
||||
{errors.map((error) => (
|
||||
<Text key={error.serverId} style={styles.errorsBannerText}>
|
||||
{`${error.serverName}: Could not load schedules`}
|
||||
{warnings.map((warning) => (
|
||||
<Text key={warning.serverId} style={styles.errorsBannerText}>
|
||||
{`${warning.serverName}: ${warning.reason === "connecting" ? "Still connecting" : "Could not load schedules"}`}
|
||||
</Text>
|
||||
))}
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user