@@ -3,9 +3,11 @@ import { describe, expect, it } from "@effect/vitest";
33import * as Effect from "effect/Effect" ;
44import * as FileSystem from "effect/FileSystem" ;
55import * as Path from "effect/Path" ;
6+ import * as PlatformError from "effect/PlatformError" ;
67import * as Schema from "effect/Schema" ;
78
89import { CodexSettings } from "@t3tools/contracts" ;
10+ import * as HostProcess from "@t3tools/shared/HostProcess" ;
911import {
1012 CodexShadowHomeEntryConflictError ,
1113 CodexShadowHomePathConflictError ,
@@ -38,6 +40,31 @@ const writeTextFile = Effect.fn("CodexHomeLayout.test.writeTextFile")(function*
3840 yield * fileSystem . writeFileString ( filePath , contents ) ;
3941} ) ;
4042
43+ // Windows without Developer Mode: every symlink fails with EPERM, as Effect reports it there.
44+ const onWindowsWithoutSymlinks = < A , E , R > ( effect : Effect . Effect < A , E , R > ) =>
45+ Effect . gen ( function * ( ) {
46+ const fileSystem = yield * FileSystem . FileSystem ;
47+ const refusingFileSystem = FileSystem . FileSystem . of ( {
48+ ...fileSystem ,
49+ symlink : ( _target , link ) =>
50+ Effect . fail (
51+ PlatformError . systemError ( {
52+ _tag : "Unknown" ,
53+ module : "FileSystem" ,
54+ method : "symlink" ,
55+ pathOrDescriptor : link ,
56+ cause : Object . assign ( new Error ( "EPERM: operation not permitted, symlink" ) , {
57+ code : "EPERM" ,
58+ } ) ,
59+ } ) ,
60+ ) ,
61+ } ) ;
62+ return yield * effect . pipe (
63+ Effect . provideService ( FileSystem . FileSystem , refusingFileSystem ) ,
64+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
65+ ) ;
66+ } ) ;
67+
4168it . layer ( NodeServices . layer ) ( "CodexHomeLayout" , ( it ) => {
4269 describe ( "resolveCodexHomeLayout" , ( ) => {
4370 it . effect ( "uses the shared home for continuation and the shadow home for runtime" , ( ) =>
@@ -348,7 +375,10 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
348375 } ) ,
349376 ) ;
350377
351- const error = yield * materializeCodexShadowHome ( layout ) . pipe ( Effect . flip ) ;
378+ const error = yield * materializeCodexShadowHome ( layout ) . pipe (
379+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
380+ Effect . flip ,
381+ ) ;
352382
353383 expect ( error ) . toBeInstanceOf ( CodexShadowHomeEntryConflictError ) ;
354384 expect ( error ) . toMatchObject ( {
@@ -363,5 +393,63 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
363393 ) ;
364394 } ) ,
365395 ) ;
396+
397+ it . effect ( "links shared directories as junctions when Windows refuses symlinks" , ( ) =>
398+ Effect . gen ( function * ( ) {
399+ const fileSystem = yield * FileSystem . FileSystem ;
400+ const path = yield * Path . Path ;
401+ const sharedHome = yield * makeTempDir ( "t3code-codex-shared-" ) ;
402+ const shadowRoot = yield * makeTempDir ( "t3code-codex-shadow-root-" ) ;
403+ const shadowHome = path . join ( shadowRoot , "shadow" ) ;
404+ yield * fileSystem . makeDirectory ( path . join ( sharedHome , "sessions" ) ) ;
405+
406+ const layout = yield * resolveCodexHomeLayout (
407+ decodeCodexSettings ( {
408+ homePath : sharedHome ,
409+ shadowHomePath : shadowHome ,
410+ } ) ,
411+ ) ;
412+
413+ yield * onWindowsWithoutSymlinks ( materializeCodexShadowHome ( layout ) ) ;
414+ // A second pass finds the junctions already in place.
415+ yield * onWindowsWithoutSymlinks ( materializeCodexShadowHome ( layout ) ) ;
416+ yield * writeTextFile ( path . join ( shadowHome , "sessions" , "rollout.jsonl" ) , "{}\n" ) ;
417+
418+ expect ( yield * fileSystem . readLink ( path . join ( shadowHome , "sessions" ) ) ) . toBe (
419+ path . join ( sharedHome , "sessions" ) ,
420+ ) ;
421+ expect ( yield * fileSystem . exists ( path . join ( sharedHome , "sessions" , "rollout.jsonl" ) ) ) . toBe (
422+ true ,
423+ ) ;
424+ } ) ,
425+ ) ;
426+
427+ it . effect ( "keeps shared files local when Windows refuses symlinks" , ( ) =>
428+ Effect . gen ( function * ( ) {
429+ const fileSystem = yield * FileSystem . FileSystem ;
430+ const path = yield * Path . Path ;
431+ const sharedHome = yield * makeTempDir ( "t3code-codex-shared-" ) ;
432+ const shadowRoot = yield * makeTempDir ( "t3code-codex-shadow-root-" ) ;
433+ const shadowHome = path . join ( shadowRoot , "shadow" ) ;
434+ yield * writeTextFile ( path . join ( sharedHome , "config.toml" ) , 'model = "gpt-5-codex"\n' ) ;
435+ yield * writeTextFile ( path . join ( sharedHome , "installation_id" ) , "shared\n" ) ;
436+ // Codex created its own copy after an earlier pass could not link the shared one.
437+ yield * writeTextFile ( path . join ( shadowHome , "installation_id" ) , "shadow\n" ) ;
438+
439+ const layout = yield * resolveCodexHomeLayout (
440+ decodeCodexSettings ( {
441+ homePath : sharedHome ,
442+ shadowHomePath : shadowHome ,
443+ } ) ,
444+ ) ;
445+
446+ yield * onWindowsWithoutSymlinks ( materializeCodexShadowHome ( layout ) ) ;
447+
448+ expect ( yield * fileSystem . exists ( path . join ( shadowHome , "config.toml" ) ) ) . toBe ( false ) ;
449+ expect ( yield * fileSystem . readFileString ( path . join ( shadowHome , "installation_id" ) ) ) . toBe (
450+ "shadow\n" ,
451+ ) ;
452+ } ) ,
453+ ) ;
366454 } ) ;
367455} ) ;
0 commit comments