@@ -6,12 +6,10 @@ import * as NodePath from "node:path";
66import * as NodeServices from "@effect/platform-node/NodeServices" ;
77import { assert , it } from "@effect/vitest" ;
88import * as ConfigProvider from "effect/ConfigProvider" ;
9- import * as DateTime from "effect/DateTime" ;
109import * as Effect from "effect/Effect" ;
1110import * as Fiber from "effect/Fiber" ;
1211import * as FileSystem from "effect/FileSystem" ;
1312import * as Layer from "effect/Layer" ;
14- import * as Option from "effect/Option" ;
1513import * as Path from "effect/Path" ;
1614import * as Sink from "effect/Sink" ;
1715import * as Stream from "effect/Stream" ;
@@ -844,9 +842,10 @@ it.effect.skipIf(windowsHost)(
844842 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
845843) ;
846844
847- // The handler probe carries its own timeout so a wedged xdg-mime costs only
848- // the file manager and the scan still completes. Runs on the live clock so
849- // the probe's real timeout fires.
845+ // The handler probe carries its own timeout because the editor scan's outer
846+ // timeout in server.getConfig degrades to an EMPTY editor list: a wedged
847+ // xdg-mime must cost only the file manager, never the other editors. Runs on
848+ // the live clock so the probe's real timeout fires.
850849it . live . skipIf ( windowsHost ) ( "a stalled handler probe drops only the file manager" , ( ) =>
851850 Effect . gen ( function * ( ) {
852851 const fileSystem = yield * FileSystem . FileSystem ;
@@ -1076,24 +1075,17 @@ it.effect.skipIf(windowsHost)("ignores unusable app bundles and keeps PATH launc
10761075 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
10771076) ;
10781077
1079- // Stubbed stats answer for PATH directories too, and discovery checks a
1080- // directory's mtime before reusing its listing, so the stub carries one.
1081- const stubFileInfo = {
1082- type : "File" ,
1083- mtime : Option . some ( DateTime . toDateUtc ( DateTime . makeUnsafe ( 0 ) ) ) ,
1084- } as FileSystem . File . Info ;
1085-
10861078it . effect ( "memoizes editor discovery and refreshes after the cache window" , ( ) => {
10871079 let statCalls = 0 ;
1080+ const fileInfo = { type : "File" } as FileSystem . File . Info ;
10881081 const launcherLayer = ExternalLauncher . layer . pipe (
10891082 Layer . provide (
10901083 Layer . mergeAll (
10911084 FileSystem . layerNoop ( {
1092- readDirectory : ( ) => Effect . succeed ( [ "code.CMD" ] ) ,
10931085 stat : ( ) =>
10941086 Effect . sync ( ( ) => {
10951087 statCalls += 1 ;
1096- return stubFileInfo ;
1088+ return fileInfo ;
10971089 } ) ,
10981090 } ) ,
10991091 Path . layer ,
@@ -1148,13 +1140,13 @@ it.effect("memoizes editor discovery and refreshes after the cache window", () =
11481140// replayed it to every later connect for the whole TTL, so `server.getConfig`
11491141// failed and no client could reconnect until the server restarted.
11501142it . effect ( "rescans after an interrupted discovery instead of caching the interrupt" , ( ) => {
1143+ const fileInfo = { type : "File" } as FileSystem . File . Info ;
11511144 let blockFirstScan = true ;
11521145 let scans = 0 ;
11531146 const launcherLayer = ExternalLauncher . layer . pipe (
11541147 Layer . provide (
11551148 Layer . mergeAll (
11561149 FileSystem . layerNoop ( {
1157- readDirectory : ( ) => Effect . succeed ( [ "code.CMD" ] ) ,
11581150 // The first scan parks inside `stat` so the interrupt lands while
11591151 // discovery is in flight, which is what a client disconnecting
11601152 // mid-connect does to the shared effect.
@@ -1164,7 +1156,7 @@ it.effect("rescans after an interrupted discovery instead of caching the interru
11641156 if ( blockFirstScan ) {
11651157 return yield * Effect . never ;
11661158 }
1167- return stubFileInfo ;
1159+ return fileInfo ;
11681160 } ) ,
11691161 } ) ,
11701162 Path . layer ,
@@ -1207,94 +1199,6 @@ it.effect("rescans after an interrupted discovery instead of caching the interru
12071199 ) ;
12081200} ) ;
12091201
1210- // One Windows PATH directory listing `listed`. Every stat reports a file except
1211- // the ones `stalls` matches, which never resolve, like a probe wedged on a
1212- // slow disk or share. Each test passes its own PATH so the process-wide
1213- // command-resolution cache cannot leak results between tests.
1214- const stubbedWindowsDiscoveryLayer = ( input : {
1215- readonly pathDirectory : string ;
1216- readonly listed : ReadonlyArray < string > ;
1217- readonly stalls : ( filePath : string ) => boolean ;
1218- readonly onStat ?: ( ) => void ;
1219- } ) =>
1220- Layer . mergeAll (
1221- ExternalLauncher . layer . pipe (
1222- Layer . provide (
1223- Layer . mergeAll (
1224- FileSystem . layerNoop ( {
1225- readDirectory : ( ) => Effect . succeed ( [ ...input . listed ] ) ,
1226- stat : ( filePath ) => {
1227- input . onStat ?.( ) ;
1228- return input . stalls ( filePath ) ? Effect . never : Effect . succeed ( stubFileInfo ) ;
1229- } ,
1230- } ) ,
1231- Path . layer ,
1232- Layer . succeed (
1233- ChildProcessSpawner . ChildProcessSpawner ,
1234- ChildProcessSpawner . make ( ( ) => Effect . sync ( ( ) => makeMockDetachedHandle ( ) ) ) ,
1235- ) ,
1236- ) ,
1237- ) ,
1238- ) ,
1239- Layer . succeed ( HostProcessPlatform , "win32" ) ,
1240- ConfigProvider . layer (
1241- ConfigProvider . fromEnv ( { env : { PATH : input . pathDirectory , PATHEXT : ".EXE;.CMD" } } ) ,
1242- ) ,
1243- ) ;
1244-
1245- it . effect ( "returns the editors found when one probe outlives the scan budget" , ( ) =>
1246- Effect . gen ( function * ( ) {
1247- const launcher = yield * ExternalLauncher . ExternalLauncher ;
1248- const fiber = yield * Effect . forkChild ( launcher . resolveAvailableEditors ( ) ) ;
1249- yield * TestClock . adjust ( "4 seconds" ) ;
1250-
1251- // Trae stalls, but the editors on either side of it, including the file
1252- // manager probed last, are still reported.
1253- assert . deepEqual ( yield * Fiber . join ( fiber ) , [ "cursor" , "file-manager" ] ) ;
1254- } ) . pipe (
1255- Effect . provide (
1256- stubbedWindowsDiscoveryLayer ( {
1257- pathDirectory : "C:\\t3-editor-scan-budget-test" ,
1258- listed : [ "cursor.EXE" , "trae.EXE" , "explorer.EXE" ] ,
1259- stalls : ( filePath ) => filePath . includes ( "trae" ) ,
1260- } ) ,
1261- ) ,
1262- ) ,
1263- ) ;
1264-
1265- it . effect ( "keeps editors from the last complete scan when a rescan runs out of time" , ( ) => {
1266- let stallVscode = false ;
1267- let stats = 0 ;
1268- return Effect . gen ( function * ( ) {
1269- const launcher = yield * ExternalLauncher . ExternalLauncher ;
1270- assert . deepEqual ( yield * launcher . resolveAvailableEditors ( ) , [ "vscode" , "file-manager" ] ) ;
1271-
1272- // Past the discovery cache window, the rescan stalls on VS Code.
1273- yield * TestClock . adjust ( "61 seconds" ) ;
1274- stallVscode = true ;
1275- const fiber = yield * Effect . forkChild ( launcher . resolveAvailableEditors ( ) ) ;
1276- yield * TestClock . adjust ( "4 seconds" ) ;
1277- assert . deepEqual ( yield * Fiber . join ( fiber ) , [ "vscode" , "file-manager" ] ) ;
1278-
1279- // The incomplete scan was not cached, so the next call scans again.
1280- stallVscode = false ;
1281- const statsBeforeRescan = stats ;
1282- assert . deepEqual ( yield * launcher . resolveAvailableEditors ( ) , [ "vscode" , "file-manager" ] ) ;
1283- assert . isAbove ( stats , statsBeforeRescan ) ;
1284- } ) . pipe (
1285- Effect . provide (
1286- stubbedWindowsDiscoveryLayer ( {
1287- pathDirectory : "C:\\t3-editor-incomplete-rescan-test" ,
1288- listed : [ "code.CMD" , "explorer.EXE" ] ,
1289- stalls : ( filePath ) => stallVscode && filePath . includes ( "code" ) ,
1290- onStat : ( ) => {
1291- stats += 1 ;
1292- } ,
1293- } ) ,
1294- ) ,
1295- ) ;
1296- } ) ;
1297-
12981202it . effect ( "rejects unknown editors through the service API" , ( ) =>
12991203 Effect . gen ( function * ( ) {
13001204 const launcher = yield * ExternalLauncher . ExternalLauncher ;
0 commit comments