diff --git a/packages/core/test/plugin/provider-opencode.test.ts b/packages/core/test/plugin/provider-opencode.test.ts index dba781f0a20..152099b000c 100644 --- a/packages/core/test/plugin/provider-opencode.test.ts +++ b/packages/core/test/plugin/provider-opencode.test.ts @@ -41,6 +41,20 @@ const noRemoteConfig = HttpClient.make((request) => Effect.succeed(HttpClientResponse.fromWeb(request, new Response(null, { status: 404 }))), ) +// Periodic Console checks run on TestClock, but a loopback request takes real time that `drain` does not wait for. +// Calling the server's handler in-process keeps each check within `drain`. +const inProcess = (server: { fetch: (request: Request) => Response | Promise }) => + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make((request) => + HttpClientRequest.toWeb(request).pipe( + Effect.orDie, + Effect.flatMap((web) => Effect.promise(async () => server.fetch(web))), + Effect.map((response) => HttpClientResponse.fromWeb(request, response)), + ), + ), + ) + function consoleServer(orgID: string | null | undefined, unavailable = false) { const config: { authorization: string | null; orgID: string | null }[] = [] const requests: string[] = [] @@ -602,7 +616,7 @@ describe("OpencodePlugin", () => { yield* websearch.transform(() => { rebuilds.websearch++ }) - yield* addPlugin() + yield* addPlugin().pipe(inProcess(server)) yield* drain const initial = { ...rebuilds } expect(state.requests).toBe(1) @@ -723,6 +737,7 @@ describe("OpencodePlugin", () => { }), }), ), + inProcess(server), ) yield* drain @@ -857,7 +872,7 @@ describe("OpencodePlugin", () => { metadata: { server: server.url.origin, orgID: "org_acme", orgName: "Acme" }, }), }) - yield* addPlugin() + yield* addPlugin().pipe(inProcess(server)) yield* drain expect(managed.current()).toEqual({ statements: [sudo], organization: "Acme" }) @@ -930,7 +945,7 @@ describe("OpencodePlugin", () => { rebuilds.count++ }) const alpha = yield* account("org_alpha", "Alpha") - yield* addPlugin() + yield* addPlugin().pipe(inProcess(server)) yield* drain const initial = rebuilds.count expect(state.requests).toBe(1) @@ -1027,7 +1042,7 @@ describe("OpencodePlugin", () => { metadata: { server: `${server.url.origin}/console`, orgID: "org_acme", orgName: "Acme" }, }), }) - yield* addPlugin() + yield* addPlugin().pipe(inProcess(server)) yield* drain expect(yield* status()).toBeUndefined() @@ -1140,7 +1155,7 @@ describe("OpencodePlugin", () => { integrationID: Integration.ID.make("opencode"), value: Credential.Key.make({ type: "key", key: "secret", metadata: { server: server.url.origin } }), }) - yield* addPlugin() + yield* addPlugin().pipe(inProcess(server)) yield* drain for (const body of [ @@ -1257,7 +1272,7 @@ describe("OpencodePlugin", () => { }) const status = () => integrations.get(Integration.ID.make("opencode")).pipe(Effect.map((item) => item?.connections[0]?.status)) - yield* addPlugin() + yield* addPlugin().pipe(inProcess(server)) yield* drain expect(yield* status()).toEqual({ status: "needs_auth", message: "Reconnect OpenCode Console to continue" }) diff --git a/packages/tui/test/component/session-tabs-mouse.test.tsx b/packages/tui/test/component/session-tabs-mouse.test.tsx index 592f9cb23db..839a3a977f6 100644 --- a/packages/tui/test/component/session-tabs-mouse.test.tsx +++ b/packages/tui/test/component/session-tabs-mouse.test.tsx @@ -144,7 +144,9 @@ test("keeps consecutive close controls fixed across overflow window changes", as await app.waitForFrame((frame) => Array.from(frame.split("\n")[0] ?? "")[11] === "✕") await app.mockMouse.click(11, 0) - await app.waitForFrame((frame) => items().length === 4 && Array.from(frame.split("\n")[0] ?? "")[11] === "✕") + await app.waitForFrame( + (frame) => !frame.includes("Third") && items().length === 4 && Array.from(frame.split("\n")[0] ?? "")[11] === "✕", + ) await app.mockMouse.click(11, 0) expect(closed).toEqual(["third", "fourth"]) diff --git a/packages/tui/test/context/session-tabs.test.tsx b/packages/tui/test/context/session-tabs.test.tsx index 56c52c5b098..c2be5163911 100644 --- a/packages/tui/test/context/session-tabs.test.tsx +++ b/packages/tui/test/context/session-tabs.test.tsx @@ -286,7 +286,15 @@ test("loads location metadata when an open session moves", async () => { const setup = await renderSessionTabs("first") try { - await wait(() => setup.locations.includes(directory) && setup.vcsLocations.includes(directory)) + // server.connected loads the default location on its own, so also wait for the session and its tab: + // a move that arrives before either has loaded is dropped. + await wait( + () => + setup.data.session.get("first") !== undefined && + setup.tabs.tabs().some((tab) => tab.sessionID === "first") && + setup.locations.includes(directory) && + setup.vcsLocations.includes(directory), + ) setup.emit({ id: "evt_moved", created: 1,