Skip to content

Commit 6974acc

Browse files
test(server): fold late preview timeout into existing host-retention test
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4a5509f commit 6974acc

1 file changed

Lines changed: 32 additions & 69 deletions

File tree

‎apps/server/src/mcp/PreviewAutomationBroker.test.ts‎

Lines changed: 32 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,78 +1427,41 @@ it.effect("rejects a routed action when its generation is evicted before deliver
14271427
),
14281428
);
14291429

1430-
it.effect.each(["navigate", "waitFor"] as const)(
1431-
"keeps the server browser available when %s reports its full operation timeout",
1432-
(operation) =>
1433-
Effect.scoped(
1434-
Effect.gen(function* () {
1435-
const broker = yield* makeBroker;
1436-
const received = yield* Deferred.make<void>();
1437-
const requests = requestsFrom(
1438-
yield* broker.connect(makeHost({ clientId: SERVER_BROWSER_AUTOMATION_CLIENT_ID }), {
1439-
preferred: true,
1440-
}),
1441-
);
1442-
yield* Stream.runForEach(requests, (request) =>
1443-
Effect.gen(function* () {
1444-
if (request.operation === operation) {
1445-
yield* Deferred.succeed(received, undefined);
1446-
// The browser starts its timer after delivery and needs time to return its error.
1447-
yield* Effect.sleep(request.timeoutMs + 50);
1448-
}
1449-
yield* broker.respond({
1450-
clientId: SERVER_BROWSER_AUTOMATION_CLIENT_ID,
1451-
connectionId: request.connectionId,
1452-
requestId: request.requestId,
1453-
...(request.operation === operation
1454-
? {
1455-
ok: false,
1456-
error: { _tag: "PreviewAutomationTimeoutError", message: "Page timed out" },
1457-
}
1458-
: { ok: true, result: "responsive" }),
1459-
});
1460-
}),
1461-
).pipe(Effect.forkScoped);
1462-
const timedOut = yield* broker
1463-
.invoke<void>({ scope, operation, input: {}, timeoutMs: 1_000 })
1464-
.pipe(Effect.flip, Effect.forkScoped);
1465-
yield* Deferred.await(received);
1466-
yield* TestClock.adjust(1_050);
1467-
expect(yield* Fiber.join(timedOut)).toMatchObject({
1468-
_tag: "PreviewAutomationTimeoutError",
1469-
remoteTag: "PreviewAutomationTimeoutError",
1470-
});
1471-
expect(yield* broker.invoke({ scope, operation: "snapshot", input: {} })).toBe(
1472-
"responsive",
1473-
);
1474-
}),
1475-
),
1476-
);
1477-
1478-
it.effect("keeps a host that responds with an operation timeout", () =>
1430+
it.effect("keeps a host whose operation timeout arrives just after the budget", () =>
14791431
Effect.scoped(
14801432
Effect.gen(function* () {
14811433
const broker = yield* makeBroker;
1482-
const connected = yield* Deferred.make<void>();
1483-
const events = yield* broker.connect(makeHost());
1484-
yield* Stream.runForEach(events, (event) => {
1485-
if (event.type === "connected") return Deferred.succeed(connected, undefined);
1486-
return broker.respond({
1487-
clientId: "client-1",
1488-
connectionId: event.connectionId,
1489-
requestId: event.request.requestId,
1490-
...(event.request.operation === "waitFor"
1491-
? {
1492-
ok: false,
1493-
error: { _tag: "PreviewAutomationTimeoutError", message: "Selector timed out" },
1494-
}
1495-
: { ok: true, result: "responsive" }),
1496-
});
1497-
}).pipe(Effect.forkScoped);
1498-
yield* Deferred.await(connected);
1499-
expect(
1500-
yield* broker.invoke<void>({ scope, operation: "waitFor", input: {} }).pipe(Effect.flip),
1501-
).toMatchObject({ _tag: "PreviewAutomationTimeoutError" });
1434+
const received = yield* Deferred.make<void>();
1435+
const requests = requestsFrom(yield* broker.connect(makeHost()));
1436+
yield* Stream.runForEach(requests, (request) =>
1437+
Effect.gen(function* () {
1438+
if (request.operation === "waitFor") {
1439+
yield* Deferred.succeed(received, undefined);
1440+
// The browser starts its own timer after delivery, so its timeout lands late.
1441+
yield* Effect.sleep(request.timeoutMs + 50);
1442+
}
1443+
yield* broker.respond({
1444+
clientId: "client-1",
1445+
connectionId: request.connectionId,
1446+
requestId: request.requestId,
1447+
...(request.operation === "waitFor"
1448+
? {
1449+
ok: false,
1450+
error: { _tag: "PreviewAutomationTimeoutError", message: "Selector timed out" },
1451+
}
1452+
: { ok: true, result: "responsive" }),
1453+
});
1454+
}),
1455+
).pipe(Effect.forkScoped);
1456+
const timedOut = yield* broker
1457+
.invoke<void>({ scope, operation: "waitFor", input: {}, timeoutMs: 1_000 })
1458+
.pipe(Effect.flip, Effect.forkScoped);
1459+
yield* Deferred.await(received);
1460+
yield* TestClock.adjust(1_050);
1461+
expect(yield* Fiber.join(timedOut)).toMatchObject({
1462+
_tag: "PreviewAutomationTimeoutError",
1463+
remoteTag: "PreviewAutomationTimeoutError",
1464+
});
15021465
expect(yield* broker.invoke({ scope, operation: "status", input: {} })).toBe("responsive");
15031466
}),
15041467
),

0 commit comments

Comments
 (0)