Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): html previews say how their browser exited #16872

Mergednkoynov(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/16872/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 81 additions and 1 deletion.

x
0 of 2 viewed, 2 left
58 additions and 0 deletionsapps/server/src/htmlRender/HtmlRender.test.tsModified
View file
@@ -56,6 +56,33 @@
​
const PNG_BYTES = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
​
+/**
+ * A stand-in browser that reads T3's first command off its debugging pipe,
+ * then runs `exit`. Reading it first keeps the pipe from resetting.
+ */
+const exitingBrowser = (exit: string) =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-exiting-browser-" });
+ const executable = path.join(directory, "chrome-headless-shell");
+ yield* fileSystem.writeFileString(
+ executable,
+ [
+ `#!${process.execPath}`,
+ `new (process.getBuiltinModule("node:net").Socket)({ fd: 3 }).on("data", (chunk) => { if (chunk.includes(0)) { ${exit} } });`,
+ ].join("\n"),
+ );
+ yield* fileSystem.chmod(executable, 0o755);
+ return executable;
+ });
+​
+const previewError = (executable: string) =>
+ Effect.gen(function* () {
+ const htmlRender = yield* HtmlRender.HtmlRender;
+ return yield* htmlRender.preview({ html: "<p>x</p>" }).pipe(Effect.flip);
+ }).pipe(Effect.provide(layerHtmlRender(executable)));