Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] Preserve desktop user-data probe failures (#3304)

Julius Marminge515303edf2f8
diff --git a/apps/desktop/src/app/DesktopAppIdentity.test.ts b/apps/desktop/src/app/DesktopAppIdentity.test.ts
index 7c4c06eb6..3c95b266b 100644
--- a/apps/desktop/src/app/DesktopAppIdentity.test.ts
+++ b/apps/desktop/src/app/DesktopAppIdentity.test.ts
@@ -4,6 +4,7 @@ import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
+import * as PlatformError from "effect/PlatformError";
import type * as Electron from "electron";
@@ -105,6 +106,7 @@ const withIdentity = <A, E, R>(
readonly calls?: ElectronAppCalls;
readonly environment?: TestEnvironmentInput;
readonly legacyPathExists?: boolean;
+ readonly legacyPathProbeError?: PlatformError.PlatformError;
readonly packageJson?: string;
readonly pngIconPath?: Option.Option<string>;
} = {},
@@ -121,7 +123,11 @@ const withIdentity = <A, E, R>(
Layer.provideMerge(
FileSystem.layerNoop({
exists: (path) =>
- Effect.succeed(input.legacyPathExists === true && path.includes("T3 Code (Alpha)")),
+ input.legacyPathProbeError
+ ? Effect.fail(input.legacyPathProbeError)
+ : Effect.succeed(
+ input.legacyPathExists === true && path.includes("T3 Code (Alpha)"),
+ ),
readFileString: () =>
Effect.succeed(input.packageJson ?? '{"t3codeCommitHash":"abcdef1234567890"}'),
}),
@@ -147,6 +153,33 @@ describe("DesktopAppIdentity", () => {
),
);
+ it.effect("preserves failures while inspecting the legacy userData path", () => {
+ const legacyPath = "/Users/alice/Library/Application Support/T3 Code (Alpha)";
+ const cause = PlatformError.systemError({
+ _tag: "PermissionDenied",
+ module: "FileSystem",
+ method: "exists",
+ description: "permission denied",
+ pathOrDescriptor: legacyPath,
+ });
+
+ return withIdentity(
+ Effect.gen(function* () {
+ const identity = yield* DesktopAppIdentity.DesktopAppIdentity;
+ const error = yield* identity.resolveUserDataPath.pipe(Effect.flip);
+
+ assert.instanceOf(error, DesktopAppIdentity.DesktopUserDataPathResolutionError);
+ assert.equal(error.legacyPath, legacyPath);
+ assert.strictEqual(error.cause, cause);
+ assert.equal(
+ error.message,
+ `Failed to inspect legacy desktop user-data path at "${legacyPath}".`,
+ );
+ }),
+ { legacyPathProbeError: cause },
+ );
+ });
+
it.effect("configures app identity from the environment commit override", () => {
const calls: ElectronAppCalls = {
setAboutPanelOptions: [],
diff --git a/apps/desktop/src/app/DesktopAppIdentity.ts b/apps/desktop/src/app/DesktopAppIdentity.ts
index 2664581b1..385e69433 100644
--- a/apps/desktop/src/app/DesktopAppIdentity.ts
+++ b/apps/desktop/src/app/DesktopAppIdentity.ts
@@ -18,10 +18,22 @@ const AppPackageMetadata = Schema.Struct({
});
const decodeAppPackageMetadata = Schema.decodeEffect(Schema.fromJsonString(AppPackageMetadata));
+export class DesktopUserDataPathResolutionError extends Schema.TaggedErrorClass<DesktopUserDataPathResolutionError>()(
+ "DesktopUserDataPathResolutionError",
+ {
+ legacyPath: Schema.String,
+ cause: Schema.Defect(),
+ },
+) {
+ override get message(): string {
+ return `Failed to inspect legacy desktop user-data path at "${this.legacyPath}".`;
+ }
+}
+
export class DesktopAppIdentity extends Context.Service<
DesktopAppIdentity,
{
- readonly resolveUserDataPath: Effect.Effect<string>;
+ readonly resolveUserDataPath: Effect.Effect<string, DesktopUserDataPathResolutionError>;
readonly configure: Effect.Effect<void>;
}
>()("@t3tools/desktop/app/DesktopAppIdentity") {}
@@ -33,7 +45,7 @@ const normalizeCommitHash = (value: string): Option.Option<string> => {
: Option.none();
};
-const make = Effect.gen(function* () {
+export const make = Effect.gen(function* () {
const assets = yield* DesktopAssets.DesktopAssets;
const electronApp = yield* ElectronApp.ElectronApp;
const environment = yield* DesktopEnvironment.DesktopEnvironment;
@@ -83,9 +95,15 @@ const make = Effect.gen(function* () {
environment.appDataDirectory,
environment.legacyUserDataDirName,
);
- const legacyPathExists = yield* fileSystem
- .exists(legacyPath)
- .pipe(Effect.orElseSucceed(() => false));
+ const legacyPathExists = yield* fileSystem.exists(legacyPath).pipe(
+ Effect.mapError(
+ (cause) =>
+ new DesktopUserDataPathResolutionError({
+ legacyPath,
+ cause,
+ }),
+ ),
+ );
return legacyPathExists
? legacyPath
: environment.path.join(environment.appDataDirectory, environment.userDataDirName);