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
87 changes: 86 additions & 1 deletion apps/server/src/assets/AssetAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as PlatformError from "effect/PlatformError";

import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
import * as ServerConfig from "../config.ts";
Expand Down Expand Up @@ -85,7 +86,58 @@ describe("AssetAccess", () => {
},
workspaceRoot: root,
}).pipe(Effect.flip);
expect(error.message).toContain("relative to the project root");
expect(error.message).toBe("Workspace file path must be relative to the project root.");
expect(error).toMatchObject({
operation: "validate-workspace-path",
resource: {
_tag: "workspace-file",
threadId: "thread-1",
path: htmlPath,
},
});
expect(error.cause).toBeInstanceOf(WorkspacePaths.WorkspacePathOutsideRootError);
}).pipe(Effect.provide(testLayer)),
);

it.effect("preserves non-missing canonical path failures when issuing asset URLs", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const root = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-asset-permission-root-",
});
const htmlPath = path.join(root, "report.html");
yield* fileSystem.writeFileString(htmlPath, "<p>report</p>");
const cause = PlatformError.systemError({
_tag: "PermissionDenied",
module: "FileSystem",
method: "realPath",
pathOrDescriptor: htmlPath,
});
const failingFileSystem = FileSystem.FileSystem.of({
...fileSystem,
realPath: () => Effect.fail(cause),
});

const error = yield* issueAssetUrl({
resource: {
_tag: "workspace-file",
threadId: ThreadId.make("thread-1"),
path: htmlPath,
},
workspaceRoot: root,
}).pipe(Effect.provideService(FileSystem.FileSystem, failingFileSystem), Effect.flip);

expect(error.message).toBe("Failed to inspect the workspace asset.");
expect(error).toMatchObject({
operation: "inspect-workspace-asset",
resource: {
_tag: "workspace-file",
threadId: "thread-1",
path: htmlPath,
},
});
expect(error.cause).toBe(cause);
}).pipe(Effect.provide(testLayer)),
);

Expand Down Expand Up @@ -186,4 +238,37 @@ describe("AssetAccess", () => {
).toEqual({ kind: "project-favicon-fallback" });
}).pipe(Effect.provide(testLayer)),
);

it.effect("preserves structured project favicon resolution causes", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const root = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-asset-favicon-error-",
});
const platformCause = PlatformError.systemError({
_tag: "PermissionDenied",
module: "FileSystem",
method: "stat",
});
const resolutionCause = new ProjectFaviconResolver.ProjectFaviconResolutionError({
operation: "stat-candidate",
workspaceRoot: root,
relativePath: "favicon.svg",
cause: platformCause,
});
const resolver = ProjectFaviconResolver.ProjectFaviconResolver.of({
resolvePath: () => Effect.fail(resolutionCause),
});

const error = yield* issueAssetUrl({
resource: { _tag: "project-favicon", cwd: root },
}).pipe(
Effect.provideService(ProjectFaviconResolver.ProjectFaviconResolver, resolver),
Effect.flip,
);

expect(error.message).toBe("Failed to resolve project favicon.");
expect(error.cause).toBe(resolutionCause);
}).pipe(Effect.provide(testLayer)),
);
});
Loading
Loading