@@ -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" , ( ) =>
@@ -308,7 +335,10 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
308335 } ) ,
309336 ) ;
310337
311- const error = yield * materializeCodexShadowHome ( layout ) . pipe ( Effect . flip ) ;
338+ const error = yield * materializeCodexShadowHome ( layout ) . pipe (
339+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
340+ Effect . flip ,
341+ ) ;
312342
313343 expect ( error ) . toBeInstanceOf ( CodexShadowHomeEntryConflictError ) ;
314344 expect ( error ) . toMatchObject ( {
@@ -323,5 +353,63 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
323353 ) ;
324354 } ) ,
325355 ) ;
356+
357+ it . effect ( "links shared directories as junctions when Windows refuses symlinks" , ( ) =>
358+ Effect . gen ( function * ( ) {
359+ const fileSystem = yield * FileSystem . FileSystem ;
360+ const path = yield * Path . Path ;
361+ const sharedHome = yield * makeTempDir ( "t3code-codex-shared-" ) ;
362+ const shadowRoot = yield * makeTempDir ( "t3code-codex-shadow-root-" ) ;
363+ const shadowHome = path . join ( shadowRoot , "shadow" ) ;
364+ yield * fileSystem . makeDirectory ( path . join ( sharedHome , "sessions" ) ) ;
365+
366+ const layout = yield * resolveCodexHomeLayout (
367+ decodeCodexSettings ( {
368+ homePath : sharedHome ,
369+ shadowHomePath : shadowHome ,
370+ } ) ,
371+ ) ;
372+
373+ yield * onWindowsWithoutSymlinks ( materializeCodexShadowHome ( layout ) ) ;
374+ // A second pass finds the junctions already in place.
375+ yield * onWindowsWithoutSymlinks ( materializeCodexShadowHome ( layout ) ) ;
376+ yield * writeTextFile ( path . join ( shadowHome , "sessions" , "rollout.jsonl" ) , "{}\n" ) ;
377+
378+ expect ( yield * fileSystem . readLink ( path . join ( shadowHome , "sessions" ) ) ) . toBe (
379+ path . join ( sharedHome , "sessions" ) ,
380+ ) ;
381+ expect ( yield * fileSystem . exists ( path . join ( sharedHome , "sessions" , "rollout.jsonl" ) ) ) . toBe (
382+ true ,
383+ ) ;
384+ } ) ,
385+ ) ;
386+
387+ it . effect ( "keeps shared files local when Windows refuses symlinks" , ( ) =>
388+ Effect . gen ( function * ( ) {
389+ const fileSystem = yield * FileSystem . FileSystem ;
390+ const path = yield * Path . Path ;
391+ const sharedHome = yield * makeTempDir ( "t3code-codex-shared-" ) ;
392+ const shadowRoot = yield * makeTempDir ( "t3code-codex-shadow-root-" ) ;
393+ const shadowHome = path . join ( shadowRoot , "shadow" ) ;
394+ yield * writeTextFile ( path . join ( sharedHome , "config.toml" ) , 'model = "gpt-5-codex"\n' ) ;
395+ yield * writeTextFile ( path . join ( sharedHome , "installation_id" ) , "shared\n" ) ;
396+ // Codex created its own copy after an earlier pass could not link the shared one.
397+ yield * writeTextFile ( path . join ( shadowHome , "installation_id" ) , "shadow\n" ) ;
398+
399+ const layout = yield * resolveCodexHomeLayout (
400+ decodeCodexSettings ( {
401+ homePath : sharedHome ,
402+ shadowHomePath : shadowHome ,
403+ } ) ,
404+ ) ;
405+
406+ yield * onWindowsWithoutSymlinks ( materializeCodexShadowHome ( layout ) ) ;
407+
408+ expect ( yield * fileSystem . exists ( path . join ( shadowHome , "config.toml" ) ) ) . toBe ( false ) ;
409+ expect ( yield * fileSystem . readFileString ( path . join ( shadowHome , "installation_id" ) ) ) . toBe (
410+ "shadow\n" ,
411+ ) ;
412+ } ) ,
413+ ) ;
326414 } ) ;
327415} ) ;
0 commit comments