@@ -78,6 +78,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
7878 readonly body ?: Stream . Stream < Uint8Array > ;
7979 readonly wait ?: Duration . Input ;
8080 readonly unsupported ?: boolean ;
81+ readonly env ?: NodeJS . ProcessEnv ;
8182 } = { } ,
8283) {
8384 const fs = yield * FileSystem . FileSystem ;
@@ -103,6 +104,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
103104 } ) . pipe (
104105 Effect . provideService ( HostProcess . Platform , hostPlatform ) ,
105106 Effect . provideService ( HostProcess . Architecture , "x64" ) ,
107+ Effect . provideService ( HostProcess . Environment , options . env ?? { } ) ,
106108 Effect . provideService (
107109 HttpClient . HttpClient ,
108110 HttpClient . make ( ( request ) =>
@@ -121,6 +123,67 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
121123} ) ;
122124
123125it . layer ( NodeServices . layer ) ( "PreviewBrowser" , ( it ) => {
126+ it . effect ( "uses a configured browser without downloading the bundled shell" , ( ) =>
127+ Effect . gen ( function * ( ) {
128+ const fs = yield * FileSystem . FileSystem ;
129+ const path = yield * Path . Path ;
130+ const directory = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-custom-browser-test-" } ) ;
131+ const configured = path . join ( directory , "custom Chrome" ) ;
132+ yield * fs . writeFileString ( configured , "#!/bin/sh\n" ) ;
133+ yield * fs . chmod ( configured , 0o755 ) ;
134+ const { browser, requests } = yield * makeHarness ( {
135+ env : { T3CODE_SERVER_BROWSER_EXECUTABLE : ` ${ configured } ` } ,
136+ } ) ;
137+
138+ expect ( yield * browser . installed ) . toEqual ( Option . some ( configured ) ) ;
139+ expect ( yield * browser . executable ) . toBe ( configured ) ;
140+ expect ( requests ) . toEqual ( [ ] ) ;
141+ } ) ,
142+ ) ;
143+
144+ it . effect . each ( [
145+ { name : "missing" } ,
146+ { name : "directory" } ,
147+ { name : "relative" } ,
148+ ...( hostPlatform === "win32" ? [ ] : [ { name : "non-executable" } ] ) ,
149+ ] ) ( "rejects a $name browser override without downloading a fallback" , ( testCase ) =>
150+ Effect . gen ( function * ( ) {
151+ const fs = yield * FileSystem . FileSystem ;
152+ const path = yield * Path . Path ;
153+ const directory = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-custom-browser-test-" } ) ;
154+ const configured =
155+ testCase . name === "relative"
156+ ? "relative-browser"
157+ : testCase . name === "directory"
158+ ? directory
159+ : path . join ( directory , "missing-browser" ) ;
160+ if ( testCase . name === "non-executable" ) {
161+ yield * fs . writeFileString ( configured , "#!/bin/sh\n" ) ;
162+ yield * fs . chmod ( configured , 0o644 ) ;
163+ }
164+ const { browser, requests } = yield * makeHarness ( {
165+ env : { T3CODE_SERVER_BROWSER_EXECUTABLE : configured } ,
166+ } ) ;
167+
168+ expect ( yield * browser . installed ) . toEqual ( Option . none ( ) ) ;
169+ const error = yield * browser . executable . pipe ( Effect . flip ) ;
170+ expect ( error . _tag ) . toBe ( "PreviewBrowserInstallError" ) ;
171+ expect ( error . message ) . toContain ( "T3CODE_SERVER_BROWSER_EXECUTABLE" ) ;
172+ expect ( requests ) . toEqual ( [ ] ) ;
173+ } ) ,
174+ ) ;
175+
176+ it . effect ( "treats a blank override as the bundled browser" , ( ) =>
177+ Effect . gen ( function * ( ) {
178+ const { browser, requests } = yield * makeHarness ( {
179+ env : { T3CODE_SERVER_BROWSER_EXECUTABLE : " " } ,
180+ } ) ;
181+
182+ expect ( yield * browser . executable ) . toContain ( executableName ) ;
183+ expect ( requests ) . toHaveLength ( 1 ) ;
184+ } ) ,
185+ ) ;
186+
124187 it . effect ( "installs a verified download with its file modes and then reuses it" , ( ) =>
125188 Effect . gen ( function * ( ) {
126189 const { browser, fs, path, installRoot, requests } = yield * makeHarness ( ) ;
0 commit comments