Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, describe, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Layer from "effect/Layer";
6import * as PlatformError from "effect/PlatformError";
7
8import * as DesktopAssets from "./DesktopAssets.ts";
9import * as DesktopConfig from "./DesktopConfig.ts";
10import * as DesktopEnvironment from "./DesktopEnvironment.ts";
11
12const environmentLayer = DesktopEnvironment.layer({
13 dirname: "/repo/apps/desktop/dist-electron",
14 homeDirectory: "/Users/alice",
15 platform: "darwin",
16 processArch: "arm64",
17 appVersion: "1.2.3",
18 appPath: "/Applications/T3 Code.app/Contents/Resources/app.asar",
19 isPackaged: true,
20 resourcesPath: "/Applications/T3 Code.app/Contents/Resources",
21 runningUnderArm64Translation: false,
22}).pipe(Layer.provide(Layer.mergeAll(NodeServices.layer, DesktopConfig.layerTest({}))));
23
24describe("DesktopAssets", () => {
25 it.effect("preserves the failed asset candidate and filesystem cause", () =>
26 Effect.gen(function* () {
27 const fileName = "custom.bin";
28 const candidatePath = "/repo/apps/desktop/resources/custom.bin";
29 const cause = PlatformError.systemError({
30 _tag: "PermissionDenied",
31 module: "FileSystem",
32 method: "exists",
33 pathOrDescriptor: candidatePath,
34 description: "private filesystem diagnostic",
35 });
36 const fileSystemLayer = FileSystem.layerNoop({
37 exists: (path) => (path === candidatePath ? Effect.fail(cause) : Effect.succeed(false)),
38 });
39 const assetsLayer = DesktopAssets.layer.pipe(
40 Layer.provide(Layer.merge(fileSystemLayer, environmentLayer)),
41 );
42 const assets = yield* DesktopAssets.DesktopAssets.pipe(Effect.provide(assetsLayer));
43
44 const error = yield* assets.resolveResourcePath(fileName).pipe(Effect.flip);
45
46 assert.instanceOf(error, DesktopAssets.DesktopAssetProbeError);
47 assert.equal(error.fileName, fileName);
48 assert.equal(error.candidatePath, candidatePath);
49 assert.strictEqual(error.cause, cause);
50 assert.equal(
51 error.message,
52 `Failed to probe desktop asset "${fileName}" at ${candidatePath}.`,
53 );
54 assert.notInclude(error.message, "private filesystem diagnostic");
55 }),
56 );
57});