MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / run

Function run

e2e/desktop-vm/artifact-external-link.test.ts:97–152  ·  view source on GitHub ↗
(runDir: string)

Source from the content-addressed store, hash-verified

95};
96
97const run = async (runDir: string) => {
98 const cdp = await CdpPage.connect(await pageWsUrl(Number(cdpPort)));
99 try {
100 await cdp.command("Runtime.enable");
101 await cdp.command("Page.enable");
102
103 // Film the guest while we drive it, so the recording shows the browser
104 // coming to the front when the link opens.
105 const recording = recordGuestScreen(
106 guestIp as string,
107 recSeconds,
108 join(runDir, "session.mp4"),
109 os,
110 );
111
112 // Wait for the console to load before we do anything with it.
113 await cdp.waitForText("Integrations", 60_000).catch(() => cdp.waitForText("Settings", 60_000));
114
115 const hostAddress = await hostAddressFromGuest(guestIp as string);
116 expect(hostAddress, "the guest reported the host address it routes through").toMatch(
117 /^\d+\.\d+\.\d+\.\d+$/,
118 );
119
120 const probe = await listenForOpen(hostAddress);
121 try {
122 const pagesBefore = await pageTargetCount();
123
124 // The same call the console makes when a `target="_blank"` link is
125 // clicked (see packages/react/src/api/shell-host.ts). We run it directly
126 // here — the click-to-open path is already covered by the cloud e2e, and
127 // what we care about on desktop is what Electron does with this call.
128 await cdp.command("Runtime.evaluate", {
129 expression: `window.open(${JSON.stringify(probe.url)}, "_blank", "noopener,noreferrer")`,
130 });
131
132 const fetcherUserAgent = await probe.waitForOpen(15_000);
133 await sleep(1500);
134 const pagesAfter = await pageTargetCount();
135
136 writeFileSync(join(runDir, "01-link-opened-externally.png"), await cdp.screenshot());
137
138 expect(fetcherUserAgent, "the desktop handed the link to the system browser").not.toBeNull();
139 expect(
140 fetcherUserAgent ?? "",
141 "the OS browser fetched the link, not an in-app Electron window",
142 ).not.toContain("Electron");
143 expect(pagesAfter, "the app opened no in-app browser window for the link").toBe(pagesBefore);
144 } finally {
145 probe.close();
146 }
147
148 await recording;
149 } finally {
150 cdp.close();
151 }
152};
153
154if (!cdpPort || !guestIp || os === "windows") {

Callers 1

Calls 8

pageWsUrlFunction · 0.90
recordGuestScreenFunction · 0.90
sleepFunction · 0.90
hostAddressFromGuestFunction · 0.85
listenForOpenFunction · 0.85
pageTargetCountFunction · 0.85
connectMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected