fix(linux): start Hopper demo sessions headlessly

This commit is contained in:
morluto
2026-07-14 04:58:45 +08:00
parent 08d5b913b0
commit 75818d119e
18 changed files with 816 additions and 169 deletions
+43
View File
@@ -59,6 +59,21 @@ class SilentLauncher implements BridgeLauncher {
}
}
class ExitingLauncher implements BridgeLauncher {
constructor(readonly code: number) {}
launch() {
return Promise.resolve(
ok({
process: spawn(process.execPath, ["-e", `process.exit(${this.code})`], {
stdio: ["ignore", "ignore", "pipe"],
}),
ownsProcessLifetime: true,
}),
);
}
}
const clients: HopperClient[] = [];
const startClient = async () => {
const client = new HopperClient({
@@ -183,6 +198,34 @@ describe("HopperClient", () => {
expect(Date.now() - startedAt).toBeLessThan(500);
});
it("reports an owned launcher exit during bridge startup", async () => {
const client = new HopperClient({
launcher: new ExitingLauncher(78),
startupTimeoutMs: 10_000,
});
clients.push(client);
const startedAt = Date.now();
const result = await client.start();
expect(result.ok).toBe(false);
if (!result.ok)
expect(result.error).toMatchObject({
_tag: "HopperProcessError",
exitCode: 78,
});
expect(Date.now() - startedAt).toBeLessThan(500);
});
it("allows a short-lived launcher to hand off bridge startup", async () => {
const client = new HopperClient({
launcher: new ExitingLauncher(0),
startupTimeoutMs: 100,
});
clients.push(client);
const result = await client.start();
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error._tag).toBe("HopperTimeoutError");
});
it("ignores more than 1,024 late responses without corrupting the session", async () => {
const client = await startClient();
const timedOut = await Promise.all(