11// @effect -diagnostics nodeBuiltinImport:off - plain local servers stand in for LAN services.
22import * as NodeServices from "@effect/platform-node/NodeServices" ;
3- import { describe , expect , it } from "@effect/vitest" ;
3+ import { assert , describe , expect , it } from "@effect/vitest" ;
44import { EnvironmentId , ProviderInstanceId , ThreadId } from "@t3tools/contracts" ;
55import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
66import * as HostProcess from "@t3tools/shared/HostProcess" ;
77import * as Deferred from "effect/Deferred" ;
88import * as Effect from "effect/Effect" ;
9+ import * as Exit from "effect/Exit" ;
910import * as Base64 from "effect/encoding/Base64" ;
1011import * as Fiber from "effect/Fiber" ;
1112import * as FileSystem from "effect/FileSystem" ;
@@ -19,6 +20,7 @@ import * as NodeURL from "node:url";
1920import { resolveAttachmentPathById } from "../attachmentStore.ts" ;
2021import * as ServerConfig from "../config.ts" ;
2122import * as HtmlRender from "./HtmlRender.ts" ;
23+ import { HtmlRenderBrowserError } from "./headlessChrome.ts" ;
2224import * as PreviewBrowser from "../preview/PreviewBrowser.ts" ;
2325
2426const TEST_BROWSER_ENV = "T3CODE_TEST_HEADLESS_SHELL" ;
@@ -287,6 +289,33 @@ describe("HtmlRender", () => {
287289 } ) ,
288290 ) ;
289291
292+ // Windows reports ENOENT asynchronously for this path instead of throwing ENOTDIR.
293+ describe . skipIf ( HostProcess . Platform . defaultValue ( ) === "win32" ) (
294+ "when the browser spawn throws synchronously" ,
295+ ( ) => {
296+ it . live ( "reports a typed preview error" , ( ) =>
297+ Effect . gen ( function * ( ) {
298+ const fileSystem = yield * FileSystem . FileSystem ;
299+ const path = yield * Path . Path ;
300+ const file = yield * fileSystem . makeTempFileScoped ( { prefix : "t3-browser-spawn-" } ) ;
301+ const outcome = yield * HtmlRender . HtmlRender . use ( ( htmlRender ) =>
302+ htmlRender . preview ( { html : "<p>x</p>" } ) . pipe ( Effect . flip ) ,
303+ ) . pipe (
304+ Effect . provide ( layerHtmlRender ( path . join ( file , "chrome-headless-shell" ) ) ) ,
305+ Effect . exit ,
306+ ) ;
307+ assert ( Exit . isSuccess ( outcome ) , "Expected a typed preview error." ) ;
308+ const error = outcome . value ;
309+ expect ( error ) . toBeInstanceOf ( HtmlRenderBrowserError ) ;
310+ expect ( error . message ) . toBe (
311+ "Headless Chrome could not render the page: the browser could not be started." ,
312+ ) ;
313+ expect ( error ) . toMatchObject ( { cause : { code : "ENOTDIR" } } ) ;
314+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
315+ ) ;
316+ } ,
317+ ) ;
318+
290319 it . live ( "keeps every local file but the page itself out of the browser" , ( ctx ) =>
291320 Effect . gen ( function * ( ) {
292321 const executable = ( yield * HostProcess . Environment ) [ TEST_BROWSER_ENV ] ;
0 commit comments