Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,45 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
});

describe("materializeCodexShadowHome", () => {
it.effect.skipIf(!symlinksSupported)(
"keeps Finder metadata local across repeated shadow home setup",
() =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const sharedHome = yield* makeTempDir("t3code-codex-shared-");
const shadowHome = yield* makeTempDir("t3code-codex-shadow-");
const sharedMetadata = path.join(sharedHome, ".DS_Store");
const shadowMetadata = path.join(shadowHome, ".DS_Store");

yield* writeTextFile(sharedMetadata, "shared Finder metadata");
yield* writeTextFile(shadowMetadata, "shadow Finder metadata");
yield* writeTextFile(path.join(shadowHome, "auth.json"), '{"shadow":true}\n');
const layout = yield* resolveCodexHomeLayout(
decodeCodexSettings({ homePath: sharedHome, shadowHomePath: shadowHome }),
);

yield* materializeCodexShadowHome(layout);
expect(yield* fileSystem.readFileString(shadowMetadata)).toBe("shadow Finder metadata");
yield* fileSystem.remove(shadowMetadata);
yield* materializeCodexShadowHome(layout);
expect(yield* fileSystem.exists(shadowMetadata)).toBe(false);

yield* writeTextFile(shadowMetadata, "shadow Finder metadata");
yield* materializeCodexShadowHome(layout);
yield* materializeCodexShadowHome(layout);

expect(yield* fileSystem.readFileString(sharedMetadata)).toBe("shared Finder metadata");
expect(yield* fileSystem.readFileString(shadowMetadata)).toBe("shadow Finder metadata");
expect(yield* fileSystem.readFileString(path.join(shadowHome, "auth.json"))).toBe(
'{"shadow":true}\n',
);
expect(yield* fileSystem.readLink(path.join(shadowHome, "sessions"))).toBe(
path.join(sharedHome, "sessions"),
);
}),
);

it.effect.skipIf(!symlinksSupported)(
"materializes a shadow home with shared state links and private auth",
() =>
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/provider/Drivers/CodexHomeLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const KNOWN_SHARED_DIRECTORIES = [
] as const;

const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "models_cache.json"]);
const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp"]);
// Finder maintains metadata separately for each directory, including shadow homes.
const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp", ".DS_Store"]);
// Codex creates these runtime locks itself when it starts in a shadow home before the shared
// home has one. They guard shared state, so a local copy is replaced with the shared link.
const REPLACEABLE_SHARED_RUNTIME_ENTRIES = new Set(["mcp-oauth-locks", ".sqlite-maintenance.lock"]);
Expand Down
Loading