Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/hip-moments-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
12 changes: 7 additions & 5 deletions src/session/broker/brokerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,16 @@ describe("Hunk session daemon client", () => {
messages.push(args.map((value) => String(value)).join(" "));
};

const client = new SessionBrokerClient(createRegistration(), createSnapshot());
const client = new SessionBrokerClient(createRegistration(), createSnapshot(), {
daemonStartupTimeoutMs: 100,
reconnectDelayMs: 10_000,
});

try {
client.start();
await waitUntil("initial session-daemon conflict warning", () => messages.length === 1);
await client.start();
expect(messages).toHaveLength(1);

client.start();
await Bun.sleep(2_000);
await client.start();

expect(messages).toHaveLength(1);
expect(messages[0]).toContain(
Expand Down
18 changes: 13 additions & 5 deletions src/session/broker/brokerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type SessionAppBridge<
Result = unknown,
> = SessionBrokerConnectionBridge<ServerMessage, Result>;

interface SessionBrokerClientTiming {
daemonStartupTimeoutMs?: number;
reconnectDelayMs?: number;
}

/** Keep one running app session registered with the local session broker daemon. */
export class SessionBrokerClient<
Info = unknown,
Expand All @@ -60,6 +65,7 @@ export class SessionBrokerClient<
constructor(
private registration: SessionRegistration<Info>,
private snapshot: SessionSnapshot<State>,
private timing: SessionBrokerClientTiming = {},
) {}

start() {
Expand All @@ -68,7 +74,7 @@ export class SessionBrokerClient<
}

if (this.startupPromise) {
return;
return this.startupPromise;
}

this.startupPromise = this.ensureDaemonAndConnect()
Expand All @@ -83,6 +89,8 @@ export class SessionBrokerClient<
.finally(() => {
this.startupPromise = null;
});

return this.startupPromise;
}

stop() {
Expand Down Expand Up @@ -119,15 +127,15 @@ export class SessionBrokerClient<
private async ensureDaemonAvailable(config: ResolvedSessionBrokerConfig) {
await ensureSessionBrokerAvailable({
config,
timeoutMs: DAEMON_STARTUP_TIMEOUT_MS,
timeoutMs: this.timing.daemonStartupTimeoutMs ?? DAEMON_STARTUP_TIMEOUT_MS,
});

const capabilities = await readHunkSessionDaemonCapabilities(config);
if (!capabilities) {
await this.restartIncompatibleDaemon(config);
await ensureSessionBrokerAvailable({
config,
timeoutMs: DAEMON_STARTUP_TIMEOUT_MS,
timeoutMs: this.timing.daemonStartupTimeoutMs ?? DAEMON_STARTUP_TIMEOUT_MS,
});

if (!(await readHunkSessionDaemonCapabilities(config))) {
Expand Down Expand Up @@ -205,7 +213,7 @@ export class SessionBrokerClient<
snapshot: this.snapshot,
bridge: this.bridge,
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
reconnectDelayMs: RECONNECT_DELAY_MS,
reconnectDelayMs: this.timing.reconnectDelayMs ?? RECONNECT_DELAY_MS,
resolveClose: (event) =>
this.isIncompatibleSessionClose(event)
? { reconnect: false, warning: INCOMPATIBLE_SESSION_CLOSE_MESSAGE }
Expand All @@ -216,7 +224,7 @@ export class SessionBrokerClient<
this.connection.start();
}

private scheduleReconnect(delayMs = RECONNECT_DELAY_MS) {
private scheduleReconnect(delayMs = this.timing.reconnectDelayMs ?? RECONNECT_DELAY_MS) {
if (this.reconnectTimer || this.stopped) {
return;
}
Expand Down
73 changes: 39 additions & 34 deletions src/ui/AppHost.interactions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ function createRapidViewportLoopBootstrap(): AppBootstrap {
function createMouseScrollSelectionBootstrap(): AppBootstrap {
const firstBeforeLines = createNumberedAssignmentLines(1, 12);
const secondBeforeLines = Array.from(
{ length: 90 },
{ length: 50 },
(_, index) => `export const line${String(index + 13).padStart(2, "0")} = ${index + 13};`,
);
const secondAfterLines = [...secondBeforeLines];

secondAfterLines[0] = "export const line13 = 1300;";
secondAfterLines[59] = "export const line72 = 7200;";
secondAfterLines[60] = "export const line73 = 7300;";
secondAfterLines[61] = "export const line74 = 7400;";
secondAfterLines[29] = "export const line42 = 4200;";
secondAfterLines[30] = "export const line43 = 4300;";
secondAfterLines[31] = "export const line44 = 4400;";

return createTestVcsAppBootstrap({
changesetId: "changeset:mouse-scroll-selection",
Expand Down Expand Up @@ -3220,25 +3220,26 @@ describe("App interactions", () => {
});

let snapshot = getLatestSnapshot();
for (let index = 0; index < 24; index += 1) {
for (let index = 0; index < 16; index += 1) {
await act(async () => {
await setup.mockMouse.scroll(120, 7, "down");
});
await flush(setup);

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) =>
currentSnapshot.selectedFilePath === "second.ts" &&
currentSnapshot.selectedHunkIndex === 1,
4,
);
snapshot = getLatestSnapshot();
if (snapshot?.selectedFilePath === "second.ts" && snapshot.selectedHunkIndex === 1) {
break;
}
}

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) =>
currentSnapshot.selectedFilePath === "second.ts" &&
currentSnapshot.selectedHunkIndex === 1,
4,
);
expect(snapshot).toMatchObject({
selectedFilePath: "second.ts",
selectedHunkIndex: 1,
Expand Down Expand Up @@ -3275,17 +3276,19 @@ describe("App interactions", () => {
});
await flush(setup);

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) => currentSnapshot.selectedFilePath === "second.ts",
4,
);
snapshot = getLatestSnapshot();
if (snapshot?.selectedFilePath === "second.ts") {
break;
}
}

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) => currentSnapshot.selectedFilePath === "second.ts",
4,
);

// Page-sized scrolling should move selection ownership into the later file. The exact hunk
// can vary with viewport handoff timing because the page jump may land near either visible
// hunk in second.ts on slower CI machines.
Expand All @@ -3299,17 +3302,18 @@ describe("App interactions", () => {
});
await flush(setup);

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) => currentSnapshot.selectedFilePath === "first.ts",
4,
);
snapshot = getLatestSnapshot();
if (snapshot?.selectedFilePath === "first.ts") {
break;
}
}

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) => currentSnapshot.selectedFilePath === "first.ts",
4,
);
expect(snapshot).toMatchObject({
selectedFilePath: "first.ts",
selectedHunkIndex: 0,
Expand Down Expand Up @@ -3340,25 +3344,26 @@ describe("App interactions", () => {
});

let snapshot = getLatestSnapshot();
for (let index = 0; index < 80; index += 1) {
for (let index = 0; index < 50; index += 1) {
await act(async () => {
await setup.mockInput.pressArrow("down");
});
await flush(setup);

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) =>
currentSnapshot.selectedFilePath === "second.ts" &&
currentSnapshot.selectedHunkIndex === 1,
4,
);
snapshot = getLatestSnapshot();
if (snapshot?.selectedFilePath === "second.ts" && snapshot.selectedHunkIndex === 1) {
break;
}
}

snapshot = await waitForSnapshot(
setup,
getLatestSnapshot,
(currentSnapshot) =>
currentSnapshot.selectedFilePath === "second.ts" &&
currentSnapshot.selectedHunkIndex === 1,
4,
);
expect(snapshot).toMatchObject({
selectedFilePath: "second.ts",
selectedHunkIndex: 1,
Expand Down
Loading
Loading