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

Function run

e2e/desktop-packaged/supervised-attach.test.ts:351–415  ·  view source on GitHub ↗
(runDir: string)

Source from the content-addressed store, hash-verified

349}
350
351const run = async (runDir: string) => {
352 const home = mkdtempSync(join(tmpdir(), "executor-pkg-attach-"));
353 const dataDir = join(home, ".executor");
354 const manifestPath = join(dataDir, "server-control", "server.json");
355 const port = await freePort();
356
357 let daemon: ChildProcess | undefined;
358 let app: PackagedApp | undefined;
359 let stepIndex = 0;
360
361 try {
362 const started = await startSupervisedDaemon(
363 {
364 ...process.env,
365 HOME: home,
366 EXECUTOR_SUPERVISED: "1",
367 EXECUTOR_DATA_DIR: dataDir,
368 EXECUTOR_AUTH_TOKEN: "packaged-attach-film",
369 EXECUTOR_CLIENT: "desktop",
370 },
371 port,
372 );
373 daemon = started.child;
374 expect(started.ready, `supervised daemon became ready; stderr:\n${started.stderr}`).toBe(true);
375 await waitForHttp(`http://127.0.0.1:${port}/`, { timeoutMs: 30_000 });
376
377 const daemonManifest = JSON.parse(readFileSync(manifestPath, "utf8")) as Manifest;
378 expect(daemonManifest.kind, "the bundled executor advertises itself as cli-daemon").toBe(
379 "cli-daemon",
380 );
381 const daemonPid = daemonManifest.pid;
382
383 // Launch the PACKAGED bundle directly. `app.isPackaged` is true, so boot()
384 // runs the supervised attach path; CDP drives the real renderer.
385 app = await launchPackaged(home);
386 const page = app.cdp;
387 const step = async (label: string, body: () => Promise<void>) => {
388 await body();
389 stepIndex += 1;
390 const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, "-");
391 await page.screenshot(join(runDir, `${String(stepIndex).padStart(2, "0")}-${slug}.png`));
392 };
393
394 // The console only renders once the app has a live connection AND the bearer
395 // it injects is accepted by the gated daemon — so reaching it proves both the
396 // attach and the bearer wiring through the packaged session layer.
397 await step("packaged app boots into the bearer-gated console", async () => {
398 await page.waitForText("Settings", 120_000);
399 });
400
401 // Proof it ATTACHED, not spawned: the manifest is untouched — same pid, still
402 // cli-daemon. A managed sidecar would have rewritten it to "desktop-sidecar".
403 await step("server manifest still names the supervised daemon", async () => {
404 const after = JSON.parse(readFileSync(manifestPath, "utf8")) as Manifest;
405 expect(after.kind, "still the supervised daemon (not a desktop sidecar)").toBe("cli-daemon");
406 expect(after.pid, "the packaged app attached to our daemon, not a new sidecar").toBe(
407 daemonPid,
408 );

Callers 2

Calls 7

waitForHttpFunction · 0.90
freePortFunction · 0.70
startSupervisedDaemonFunction · 0.70
launchPackagedFunction · 0.70
stepFunction · 0.70
closePackagedFunction · 0.70
stopProcessFunction · 0.70

Tested by

no test coverage detected