From 96e958e1781b83113491a457d9d92edc1959c100 Mon Sep 17 00:00:00 2001 From: stevenjj33 <75509501+stevenjj33@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:54:09 +0800 Subject: [PATCH] test(webui): select the tab's current identity in the two-page row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new tab lands its first load after the tab was opened, and the provider reads that landing as a replaced page: the generation moves with it, so the identity `open_tab` answered with is already a generation behind by the time the row uses it. The service refuses such an identity and says what to do about it — select the target again — so the row reads the identity the service holds for the tab, selects that one, and watches that one. --- .../isolated-chromium-two-pages.test.ts | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/webui/test/integration/isolated-chromium-two-pages.test.ts b/packages/webui/test/integration/isolated-chromium-two-pages.test.ts index 0948a7412..a66376619 100644 --- a/packages/webui/test/integration/isolated-chromium-two-pages.test.ts +++ b/packages/webui/test/integration/isolated-chromium-two-pages.test.ts @@ -538,8 +538,8 @@ describe.skipIf(!available)("the browser service, streaming two pages of one Chr "open_tab", { url: pageUrl("second page") }, ); - const second = opened.result as WebuiBrowserTargetId; - expect(second.targetId).not.toBe(first!.targetId); + const secondTab = opened.result as WebuiBrowserTargetId; + expect(secondTab.targetId).not.toBe(first!.targetId); const firstFrames: WebuiBrowserImageFrame[] = []; const secondFrames: WebuiBrowserImageFrame[] = []; @@ -565,16 +565,34 @@ describe.skipIf(!available)("the browser service, streaming two pages of one Chr await repaint(); await waitFor(() => firstFrames.length > 0, "a picture of the first page"); + // The page behind a new tab lands its first load after the tab was + // opened, and the provider reads that landing as a replaced page: the + // generation moves with it, and the identity `open_tab` answered with is a + // generation behind by the time the row gets to use it. The service + // refuses such an identity and says what to do about it — select the + // target again — so the row reads the identity the service holds for the + // tab, selects that one, and watches that one. + let second: WebuiBrowserTargetId | undefined; + await waitFor(async () => { + const listed = await service.listTargets("isolated-chromium", "run-1"); + const current = listed.targets.find( + (candidate) => candidate.id.targetId === secondTab.targetId, + ); + if (!current) return false; + await service.selectTarget(current.id, "run-1"); + second = current.id; + return true; + }, "the second page to become the run's selection"); + const secondStream = (async () => { for await (const frame of service.watchFrames( "isolated-chromium", - second, + second!, controller.signal, )) { secondFrames.push(frame); } })(); - await service.selectTarget(second, "run-1"); await repaint(); await waitFor(() => secondFrames.length > 0, "a picture of the second page"); @@ -585,7 +603,7 @@ describe.skipIf(!available)("the browser service, streaming two pages of one Chr expect(secondFrames.length).toBeGreaterThan(0); // Neither stream received the other page's picture. expect(firstFrames.every((frame) => frame.target.targetId === first!.targetId)).toBe(true); - expect(secondFrames.every((frame) => frame.target.targetId === second.targetId)).toBe(true); + expect(secondFrames.every((frame) => frame.target.targetId === secondTab.targetId)).toBe(true); }); });