Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - tests inject swaps at the native open boundary.
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as NodeHttpPlatform from "@effect/platform-node/NodeHttpPlatform";
4import * as NodeFSP from "node:fs/promises";
5import { AssetPreviewTypeValidationError, ThreadId } from "@t3tools/contracts";
6import { PROJECT_FAVICON_FALLBACK_MARKER } from "@t3tools/shared/projectFavicon";
7import { describe, expect, it } from "@effect/vitest";
8import * as Crypto from "effect/Crypto";
9import * as Effect from "effect/Effect";
10import * as FileSystem from "effect/FileSystem";
11import * as Layer from "effect/Layer";
12import * as Path from "effect/Path";
13import * as PlatformError from "effect/PlatformError";
14import * as TestClock from "effect/testing/TestClock";
15import { HttpServerResponse } from "effect/unstable/http";
16import { vi } from "vite-plus/test";
17
18import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
19import * as ServerConfig from "../config.ts";
20import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
21import * as T3ProjectFileLoader from "../project/T3ProjectFileLoader.ts";
22import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
23import { assetFileResponse } from "../http.ts";
24import { ASSET_ROUTE_PREFIX, issueAssetUrl, resolveAsset } from "./AssetAccess.ts";
25import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
26import { openMediaFile } from "./MediaFile.ts";
27import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
28
29vi.mock("node:fs/promises", async (importOriginal) => {
30 const actual = await importOriginal<typeof NodeFSP>();
31 return { ...actual, open: vi.fn(actual.open), realpath: vi.fn(actual.realpath) };
32});
33
34const configLayer = ServerConfig.ServerConfig.layerTest(process.cwd(), {
35 prefix: "t3-asset-access-test-",
36});
37const testLayer = Layer.mergeAll(
38 NodeHttpPlatform.layer,
39 configLayer,
40 WorkspacePaths.layer,
41 ProjectFaviconResolver.layer.pipe(
42 Layer.provide(WorkspacePaths.layer),
43 Layer.provide(T3ProjectFileLoader.layer),
44 ),
45 NativeAppIconResolver.layer.pipe(Layer.provide(configLayer)),
46 ServerSecretStore.layer.pipe(Layer.provide(configLayer)),
47).pipe(Layer.provideMerge(NodeServices.layer));
48
49describe("AssetAccess", () => {
50 it.effect("issues exact URLs for media and browser documents outside the workspace", () =>
51 Effect.gen(function* () {
52 const fs = yield* FileSystem.FileSystem;
53 const path = yield* Path.Path;
54 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-root-" });
55 const outside = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-outside-" });
56 for (const [name, mimeType] of [
57 ["screenshot.png", "image/png"],
58 ["recording.mp4", "video/mp4"],
59 ["recording.webm", "video/webm"],
60 ["report.html", "text/html"],
61 ["report.pdf", "application/pdf"],
62 ] as const) {
63 const filePath = path.join(outside, name);
64 yield* fs.writeFileString(filePath, "media");
65 const canonicalFile = yield* fs.realPath(filePath);
66 const result = yield* issueAssetUrl({
67 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
68 workspaceRoot: root,
69 });
70 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
71 const separator = suffix.indexOf("/");
72 const token = suffix.slice(0, separator);
73 expect(yield* resolveAsset(token, suffix.slice(separator + 1))).toMatchObject({
74 kind: "file",
75 path: canonicalFile,
76 mimeType,
77 });
78 yield* fs.writeFileString(path.join(outside, "sibling.png"), "private sibling");
79 expect(yield* resolveAsset(token, "sibling.png")).toBeNull();
80 expect(yield* resolveAsset(token, `../${name}`)).toBeNull();
81 expect(yield* resolveAsset(`${token}tampered`, name)).toBeNull();
82 }
83 }).pipe(Effect.provide(testLayer)),
84 );
85
86 it.effect("reports pixel dimensions from an image header and nothing for other files", () =>
87 Effect.gen(function* () {
88 const fs = yield* FileSystem.FileSystem;
89 const path = yield* Path.Path;
90 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-dimensions-" });
91 const png = Uint8Array.from([
92 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13, 0x49, 0x48, 0x44, 0x52, 0, 0,
93 0x06, 0x40, 0, 0, 0x03, 0x84,
94 ]);
95 yield* fs.writeFile(path.join(root, "shot.png"), png);
96 yield* fs.writeFileString(path.join(root, "clip.mp4"), "video");
97 yield* fs.writeFileString(path.join(root, "broken.png"), "not a png");
98 const issue = (name: string) =>
99 issueAssetUrl({
100 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: name },
101 workspaceRoot: root,
102 });
103
104 expect((yield* issue("shot.png")).imageDimensions).toEqual({ width: 1600, height: 900 });
105 expect((yield* issue("clip.mp4")).imageDimensions).toBeUndefined();
106 expect((yield* issue("broken.png")).imageDimensions).toBeUndefined();
107 }).pipe(Effect.provide(testLayer)),
108 );
109
110 it.effect("resolves relative media paths from the thread workspace, including outside it", () =>
111 Effect.gen(function* () {
112 const fs = yield* FileSystem.FileSystem;
113 const path = yield* Path.Path;
114 const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-relative-" });
115 const root = path.join(directory, "workspace");
116 yield* fs.makeDirectory(root);
117 for (const relativePath of ["screenshot.png", "../recording.mp4"]) {
118 const filePath = path.resolve(root, relativePath);
119 yield* fs.writeFileString(filePath, "media");
120 const result = yield* issueAssetUrl({
121 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: relativePath },
122 workspaceRoot: root,
123 });
124 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
125 const separator = suffix.indexOf("/");
126 expect(
127 yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)),
128 ).toMatchObject({
129 kind: "file",
130 path: yield* fs.realPath(filePath),
131 });
132 }
133 }).pipe(Effect.provide(testLayer)),
134 );
135
136 it.effect.skipIf(!symlinksSupported)(
137 "rejects non-previewable files, disguised targets, and directories",
138 () =>
139 Effect.gen(function* () {
140 const fs = yield* FileSystem.FileSystem;
141 const path = yield* Path.Path;
142 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-validation-" });
143 for (const name of ["report.md", "secret.txt", "secret.%70ng", "secret.png#private.txt"]) {
144 const filePath = path.join(root, name);
145 yield* fs.writeFileString(filePath, "not media");
146 const error = yield* issueAssetUrl({
147 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
148 }).pipe(Effect.flip);
149 expect(error).toBeInstanceOf(AssetPreviewTypeValidationError);
150 }
151 const disguisedPath = path.join(root, "disguised.png");
152 yield* fs.symlink(path.join(root, "secret.txt"), disguisedPath);
153 const disguisedError = yield* issueAssetUrl({
154 resource: {
155 _tag: "media-file",
156 threadId: ThreadId.make("thread-1"),
157 path: disguisedPath,
158 },
159 }).pipe(Effect.flip);
160 expect(disguisedError).toBeInstanceOf(AssetPreviewTypeValidationError);
161 const directoryPath = path.join(root, "directory.png");
162 yield* fs.makeDirectory(directoryPath);
163 const directoryError = yield* issueAssetUrl({
164 resource: {
165 _tag: "media-file",
166 threadId: ThreadId.make("thread-1"),
167 path: directoryPath,
168 },
169 }).pipe(Effect.flip);
170 expect(directoryError._tag).toBe("AssetWorkspaceAssetNotFoundError");
171 }).pipe(Effect.provide(testLayer)),
172 );
173
174 it.effect.skipIf(!symlinksSupported)(
175 "binds media URLs to the canonical target and rejects symlink substitution",
176 () =>
177 Effect.gen(function* () {
178 const fs = yield* FileSystem.FileSystem;
179 const path = yield* Path.Path;
180 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-symlink-" });
181 const filePath = path.join(root, "actual.svg");
182 const aliasPath = path.join(root, "alias.png");
183 const replacementPath = path.join(root, "other.svg");
184 yield* fs.writeFileString(filePath, "<svg/>");
185 yield* fs.writeFileString(replacementPath, "<svg>private</svg>");
186 yield* fs.symlink(filePath, aliasPath);
187 const canonicalFile = yield* fs.realPath(filePath);
188 const result = yield* issueAssetUrl({
189 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: aliasPath },
190 });
191 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
192 const separator = suffix.indexOf("/");
193 const token = suffix.slice(0, separator);
194 const name = suffix.slice(separator + 1);
195 const expected = { kind: "file", path: canonicalFile, mimeType: "image/svg+xml" };
196 expect(yield* resolveAsset(token, name)).toMatchObject(expected);
197 yield* fs.remove(aliasPath);
198 yield* fs.symlink(replacementPath, aliasPath);
199 expect(yield* resolveAsset(token, name)).toMatchObject(expected);
200 yield* fs.remove(filePath);
201 yield* fs.symlink(replacementPath, filePath);
202 expect(yield* resolveAsset(token, name)).toBeNull();
203 }).pipe(Effect.provide(testLayer)),
204 );
205
206 it.effect.skipIf(!symlinksSupported)(
207 "keeps full and partial responses bound to the file opened during resolution",
208 () =>
209 Effect.gen(function* () {
210 const fs = yield* FileSystem.FileSystem;
211 const path = yield* Path.Path;
212 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-file-" });
213 const filePath = path.join(root, "recording.mp4");
214 const savedPath = path.join(root, "saved.mp4");
215 const secretPath = path.join(root, "secret.txt");
216 yield* fs.writeFileString(filePath, "0123456789");
217 yield* fs.writeFileString(secretPath, "private information");
218 const result = yield* issueAssetUrl({
219 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
220 });
221 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
222 const separator = suffix.indexOf("/");
223 for (const [range, expected, status] of [
224 [undefined, "0123456789", 200],
225 ["bytes=2-5", "2345", 206],
226 ] as const) {
227 const asset = yield* resolveAsset(
228 suffix.slice(0, separator),
229 suffix.slice(separator + 1),
230 );
231 if (!asset) throw new Error("Expected a resolved media file");
232
233 yield* fs.rename(filePath, savedPath);
234 yield* fs.symlink(secretPath, filePath);
235 const response = HttpServerResponse.toWeb(yield* assetFileResponse(asset, range));
236 expect(response.status).toBe(status);
237 expect(response.headers.get("content-length")).toBe(String(expected.length));
238 expect(yield* Effect.promise(() => response.text())).toBe(expected);
239 yield* fs.remove(filePath);
240 yield* fs.rename(savedPath, filePath);
241 }
242 }).pipe(Effect.provide(testLayer)),
243 );
244
245 it.effect.skipIf(!symlinksSupported)(
246 "rejects a symlink swapped in after canonical validation but before open",
247 () =>
248 Effect.gen(function* () {
249 const fs = yield* FileSystem.FileSystem;
250 const path = yield* Path.Path;
251 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-race-" });
252 const filePath = path.join(root, "recording.mp4");
253 const secretPath = path.join(root, "secret.txt");
254 yield* fs.writeFileString(filePath, "video");
255 yield* fs.writeFileString(secretPath, "secret");
256 const canonicalPath = yield* fs.realPath(filePath);
257 const result = yield* issueAssetUrl({
258 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
259 });
260 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
261 const separator = suffix.indexOf("/");
262 const swappingFileSystem = FileSystem.FileSystem.of({
263 ...fs,
264 stat: Effect.fn(function* (requestedPath) {
265 const info = yield* fs.stat(requestedPath);
266 if (requestedPath === canonicalPath) {
267 yield* fs.remove(filePath);
268 yield* fs.symlink(secretPath, filePath);
269 }
270 return info;
271 }),
272 });
273 expect(
274 yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)).pipe(
275 Effect.provideService(FileSystem.FileSystem, swappingFileSystem),
276 ),
277 ).toBeNull();
278 }).pipe(Effect.provide(testLayer)),
279 );
280
281 it.effect.skipIf(!symlinksSupported)(
282 "closes a descriptor rejected when its path changes during open",
283 () =>
284 Effect.gen(function* () {
285 const fs = yield* FileSystem.FileSystem;
286 const path = yield* Path.Path;
287 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-rejected-" });
288 const filePath = path.join(root, "recording.mp4");
289 const secretPath = path.join(root, "secret.txt");
290 yield* fs.writeFileString(filePath, "video");
291 yield* fs.writeFileString(secretPath, "secret");
292 const canonicalPath = yield* fs.realPath(filePath);
293 const originalOpen = (yield* Effect.promise(() =>
294 vi.importActual<typeof NodeFSP>("node:fs/promises"),
295 )).open;
296 let opened: NodeFSP.FileHandle | undefined;
297 const openSpy = vi.mocked(NodeFSP.open).mockImplementation(async (target, flags, mode) => {
298 const handle = await originalOpen(target, flags, mode);
299 if (target === canonicalPath) {
300 opened = handle;
301 await NodeFSP.unlink(filePath);
302 await NodeFSP.symlink(secretPath, filePath);
303 }
304 return handle;
305 });
306 yield* Effect.addFinalizer(() =>
307 Effect.sync(() => openSpy.mockImplementation(originalOpen)),
308 );
309 expect(yield* openMediaFile(canonicalPath)).toBeNull();
310 expect(opened).toBeDefined();
311 expect(opened?.fd).toBe(-1);
312 }).pipe(Effect.provide(testLayer)),
313 );
314
315 it.effect.skipIf(!symlinksSupported)(
316 "rejects an ancestor symlink race even when canonical path rechecks would pass",
317 () =>
318 Effect.gen(function* () {
319 const fs = yield* FileSystem.FileSystem;
320 const path = yield* Path.Path;
321 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-parent-race-" });
322 const publicDirectory = path.join(root, "public");
323 const privateDirectory = path.join(root, "private");
324 yield* fs.makeDirectory(publicDirectory);
325 yield* fs.makeDirectory(privateDirectory);
326 const filePath = path.join(publicDirectory, "recording.mp4");
327 yield* fs.writeFileString(filePath, "public video");
328 yield* fs.writeFileString(path.join(privateDirectory, "recording.mp4"), "private video");
329 const canonicalPath = yield* fs.realPath(filePath);
330 const result = yield* issueAssetUrl({
331 resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
332 });
333 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
334 const separator = suffix.indexOf("/");
335 const native = yield* Effect.promise(() =>
336 vi.importActual<typeof NodeFSP>("node:fs/promises"),
337 );
338 const savedDirectory = path.join(root, "saved");
339 const realpathSpy = vi.mocked(NodeFSP.realpath).mockImplementationOnce(async () => {
340 // A pathname-only guard can see the original parents during realpath,
341 // but the private file during both lstat calls and open.
342 await native.unlink(publicDirectory);
343 await native.rename(savedDirectory, publicDirectory);
344 const canonical = await native.realpath(canonicalPath);
345 await native.rename(publicDirectory, savedDirectory);
346 await native.symlink(privateDirectory, publicDirectory, "junction");
347 return canonical;
348 });
349 yield* Effect.addFinalizer(() =>
350 Effect.sync(() => realpathSpy.mockReset().mockImplementation(native.realpath)),
351 );
352 const swappingFileSystem = FileSystem.FileSystem.of({
353 ...fs,
354 realPath: Effect.fn(function* (requestedPath) {
355 const canonical = yield* fs.realPath(requestedPath);
356 if (requestedPath === canonicalPath) {
357 yield* fs.rename(publicDirectory, savedDirectory);
358 yield* Effect.promise(() =>
359 NodeFSP.symlink(privateDirectory, publicDirectory, "junction"),
360 );
361 }
362 return canonical;
363 }),
364 });
365 expect(
366 yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)).pipe(
367 Effect.provideService(FileSystem.FileSystem, swappingFileSystem),
368 ),
369 ).toBeNull();
370 }).pipe(Effect.provide(testLayer)),
371 );
372
373 it.effect("keeps in-place edits readable but requires a new URL after atomic replacement", () =>
374 Effect.gen(function* () {
375 const fs = yield* FileSystem.FileSystem;
376 const path = yield* Path.Path;
377 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-replacement-" });
378 const filePath = path.join(root, "recording.mp4");
379 yield* fs.writeFileString(filePath, "original");
380 const input = {
381 resource: {
382 _tag: "media-file" as const,
383 threadId: ThreadId.make("thread-1"),
384 path: filePath,
385 },
386 };
387 const original = yield* issueAssetUrl(input);
388 const suffix = original.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
389 const separator = suffix.indexOf("/");
390 const token = suffix.slice(0, separator);
391 const name = suffix.slice(separator + 1);
392 yield* fs.writeFileString(filePath, "in-place edit");
393 const edited = yield* resolveAsset(token, name);
394 if (!edited) throw new Error("Expected the edited media file");
395 const editedResponse = HttpServerResponse.toWeb(yield* assetFileResponse(edited));
396 expect(yield* Effect.promise(() => editedResponse.text())).toBe("in-place edit");
397
398 const replacement = path.join(root, "replacement.mp4");
399 yield* fs.writeFileString(replacement, "replacement");
400 yield* fs.rename(replacement, filePath);
401 expect(yield* resolveAsset(token, name)).toBeNull();
402
403 const renewed = yield* issueAssetUrl(input);
404 const renewedSuffix = renewed.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
405 const renewedSeparator = renewedSuffix.indexOf("/");
406 const renewedAsset = yield* resolveAsset(
407 renewedSuffix.slice(0, renewedSeparator),
408 renewedSuffix.slice(renewedSeparator + 1),
409 );
410 if (!renewedAsset) throw new Error("Expected the replacement media file");
411 const renewedResponse = HttpServerResponse.toWeb(yield* assetFileResponse(renewedAsset));
412 expect(yield* Effect.promise(() => renewedResponse.text())).toBe("replacement");
413 yield* fs.remove(filePath);
414 expect(
415 yield* resolveAsset(
416 renewedSuffix.slice(0, renewedSeparator),
417 renewedSuffix.slice(renewedSeparator + 1),
418 ),
419 ).toBeNull();
420 }).pipe(Effect.provide(testLayer)),
421 );
422
423 it.effect("issues workspace URLs that resolve the entry file and sibling assets", () =>
424 Effect.gen(function* () {
425 const fileSystem = yield* FileSystem.FileSystem;
426 const path = yield* Path.Path;
427 const root = yield* fileSystem.makeTempDirectoryScoped({
428 prefix: "t3-asset-workspace-",
429 });
430 const htmlPath = path.join(root, "report.html");
431 const cssPath = path.join(root, "report.css");
432 yield* fileSystem.writeFileString(htmlPath, '<link rel="stylesheet" href="report.css">');
433 yield* fileSystem.writeFileString(cssPath, "body { color: red; }");
434 yield* fileSystem.writeFileString(path.join(root, ".env"), "SECRET=value");
435 const canonicalHtmlPath = yield* fileSystem.realPath(htmlPath);
436 const canonicalCssPath = yield* fileSystem.realPath(cssPath);
437
438 const result = yield* issueAssetUrl({
439 resource: {
440 _tag: "workspace-file",
441 threadId: ThreadId.make("thread-1"),
442 path: htmlPath,
443 },
444 workspaceRoot: root,
445 });
446 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
447 const separatorIndex = suffix.indexOf("/");
448 const token = suffix.slice(0, separatorIndex);
449
450 expect(yield* resolveAsset(token, "report.html")).toEqual({
451 kind: "file",
452 path: canonicalHtmlPath,
453 });
454 expect(yield* resolveAsset(token, "report.css")).toEqual({
455 kind: "file",
456 path: canonicalCssPath,
457 });
458 expect(yield* resolveAsset(token, "../secret.txt")).toBeNull();
459 expect(yield* resolveAsset(token, ".env")).toBeNull();
460 expect(yield* resolveAsset(`${token}tampered`, "report.html")).toBeNull();
461 }).pipe(Effect.provide(testLayer)),
462 );
463
464 it.effect("rejects workspace files outside the authorized root", () =>
465 Effect.gen(function* () {
466 const fileSystem = yield* FileSystem.FileSystem;
467 const path = yield* Path.Path;
468 const root = yield* fileSystem.makeTempDirectoryScoped({
469 prefix: "t3-asset-root-",
470 });
471 const outside = yield* fileSystem.makeTempDirectoryScoped({
472 prefix: "t3-asset-outside-",
473 });
474 const htmlPath = path.join(outside, "report.html");
475 yield* fileSystem.writeFileString(htmlPath, "<p>outside</p>");
476
477 const error = yield* issueAssetUrl({
478 resource: {
479 _tag: "workspace-file",
480 threadId: ThreadId.make("thread-1"),
481 path: htmlPath,
482 },
483 workspaceRoot: root,
484 }).pipe(Effect.flip);
485 expect(error.message).toBe("Workspace file path must be relative to the project root.");
486 expect(error).toMatchObject({
487 _tag: "AssetWorkspacePathValidationError",
488 resource: {
489 _tag: "workspace-file",
490 threadId: "thread-1",
491 path: htmlPath,
492 },
493 });
494 expect(error.cause).toBeInstanceOf(WorkspacePaths.WorkspacePathOutsideRootError);
495 }).pipe(Effect.provide(testLayer)),
496 );
497
498 it.effect("issues draft workspace URLs without a thread", () =>
499 Effect.gen(function* () {
500 const fileSystem = yield* FileSystem.FileSystem;
501 const path = yield* Path.Path;
502 const root = yield* fileSystem.makeTempDirectoryScoped({
503 prefix: "t3-asset-draft-",
504 });
505 const htmlPath = path.join(root, "report.html");
506 const cssPath = path.join(root, "report.css");
507 yield* fileSystem.writeFileString(htmlPath, '<link rel="stylesheet" href="report.css">');
508 yield* fileSystem.writeFileString(cssPath, "body { color: red; }");
509 const canonicalHtmlPath = yield* fileSystem.realPath(htmlPath);
510 const canonicalCssPath = yield* fileSystem.realPath(cssPath);
511
512 const result = yield* issueAssetUrl({
513 resource: { _tag: "draft-workspace-file", cwd: root, path: "report.html" },
514 workspaceRoot: root,
515 });
516 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
517 const separatorIndex = suffix.indexOf("/");
518 const token = suffix.slice(0, separatorIndex);
519
520 expect(yield* resolveAsset(token, "report.html")).toEqual({
521 kind: "file",
522 path: canonicalHtmlPath,
523 });
524 expect(yield* resolveAsset(token, "report.css")).toEqual({
525 kind: "file",
526 path: canonicalCssPath,
527 });
528 expect(yield* resolveAsset(token, "../secret.txt")).toBeNull();
529 }).pipe(Effect.provide(testLayer)),
530 );
531
532 it.effect("serves absolute draft media files exactly, wherever they live", () =>
533 Effect.gen(function* () {
534 const fileSystem = yield* FileSystem.FileSystem;
535 const path = yield* Path.Path;
536 const root = yield* fileSystem.makeTempDirectoryScoped({
537 prefix: "t3-asset-draft-root-",
538 });
539 const outside = yield* fileSystem.makeTempDirectoryScoped({
540 prefix: "t3-asset-draft-outside-",
541 });
542 const clipPath = path.join(outside, "clip.mp4");
543 yield* fileSystem.writeFileString(clipPath, "video");
544 const canonicalClipPath = yield* fileSystem.realPath(clipPath);
545
546 const result = yield* issueAssetUrl({
547 resource: { _tag: "draft-workspace-file", cwd: root, path: clipPath },
548 workspaceRoot: root,
549 });
550 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
551 const separatorIndex = suffix.indexOf("/");
552 const token = suffix.slice(0, separatorIndex);
553
554 expect(yield* resolveAsset(token, "clip.mp4")).toMatchObject({
555 kind: "file",
556 path: canonicalClipPath,
557 mimeType: "video/mp4",
558 });
559 expect(yield* resolveAsset(token, "other.mp4")).toBeNull();
560 }).pipe(Effect.provide(testLayer)),
561 );
562
563 it.effect("falls back to the resource cwd for relative draft paths", () =>
564 Effect.gen(function* () {
565 const fileSystem = yield* FileSystem.FileSystem;
566 const path = yield* Path.Path;
567 const root = yield* fileSystem.makeTempDirectoryScoped({
568 prefix: "t3-asset-draft-fallback-",
569 });
570 const htmlPath = path.join(root, "report.html");
571 yield* fileSystem.writeFileString(htmlPath, "<p>draft</p>");
572 const canonicalHtmlPath = yield* fileSystem.realPath(htmlPath);
573
574 const result = yield* issueAssetUrl({
575 resource: { _tag: "draft-workspace-file", cwd: root, path: "report.html" },
576 });
577 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
578 const separatorIndex = suffix.indexOf("/");
579 const token = suffix.slice(0, separatorIndex);
580
581 expect(yield* resolveAsset(token, "report.html")).toEqual({
582 kind: "file",
583 path: canonicalHtmlPath,
584 });
585 }).pipe(Effect.provide(testLayer)),
586 );
587
588 it.effect("preserves non-missing canonical path failures when issuing asset URLs", () =>
589 Effect.gen(function* () {
590 const fileSystem = yield* FileSystem.FileSystem;
591 const path = yield* Path.Path;
592 const root = yield* fileSystem.makeTempDirectoryScoped({
593 prefix: "t3-asset-permission-root-",
594 });
595 const htmlPath = path.join(root, "report.html");
596 yield* fileSystem.writeFileString(htmlPath, "<p>report</p>");
597 const cause = PlatformError.systemError({
598 _tag: "PermissionDenied",
599 module: "FileSystem",
600 method: "realPath",
601 pathOrDescriptor: htmlPath,
602 });
603 const failingFileSystem = FileSystem.FileSystem.of({
604 ...fileSystem,
605 realPath: () => Effect.fail(cause),
606 });
607
608 const error = yield* issueAssetUrl({
609 resource: {
610 _tag: "workspace-file",
611 threadId: ThreadId.make("thread-1"),
612 path: htmlPath,
613 },
614 workspaceRoot: root,
615 }).pipe(Effect.provideService(FileSystem.FileSystem, failingFileSystem), Effect.flip);
616
617 expect(error.message).toBe("Failed to inspect the workspace asset.");
618 expect(error).toMatchObject({
619 _tag: "AssetWorkspaceAssetInspectionError",
620 resource: {
621 _tag: "workspace-file",
622 threadId: "thread-1",
623 path: htmlPath,
624 },
625 });
626 expect(error.cause).toBe(cause);
627 }).pipe(Effect.provide(testLayer)),
628 );
629
630 it.effect("issues exact workspace URLs for image previews", () =>
631 Effect.gen(function* () {
632 const fileSystem = yield* FileSystem.FileSystem;
633 const path = yield* Path.Path;
634 const root = yield* fileSystem.makeTempDirectoryScoped({
635 prefix: "t3-asset-image-workspace-",
636 });
637 const assetsDirectory = path.join(root, "assets");
638 const imagePath = path.join(assetsDirectory, "icon.png");
639 const siblingPath = path.join(assetsDirectory, "other.png");
640 yield* fileSystem.makeDirectory(assetsDirectory, { recursive: true });
641 yield* fileSystem.writeFile(imagePath, new Uint8Array([137, 80, 78, 71]));
642 yield* fileSystem.writeFile(siblingPath, new Uint8Array([137, 80, 78, 71]));
643 const canonicalImagePath = yield* fileSystem.realPath(imagePath);
644
645 const result = yield* issueAssetUrl({
646 resource: {
647 _tag: "workspace-file",
648 threadId: ThreadId.make("thread-1"),
649 path: imagePath,
650 },
651 workspaceRoot: root,
652 });
653 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
654 const separatorIndex = suffix.indexOf("/");
655 const token = suffix.slice(0, separatorIndex);
656
657 expect(yield* resolveAsset(token, "icon.png")).toEqual({
658 kind: "file",
659 path: canonicalImagePath,
660 });
661 expect(yield* resolveAsset(token, "other.png")).toBeNull();
662 expect(yield* resolveAsset(token, "../icon.png")).toBeNull();
663 }).pipe(Effect.provide(testLayer)),
664 );
665
666 it.effect("issues exact attachment capabilities by attachment id", () =>
667 Effect.gen(function* () {
668 const config = yield* ServerConfig.ServerConfig;
669 const fileSystem = yield* FileSystem.FileSystem;
670 const path = yield* Path.Path;
671 const attachmentId = "thread-1-00000000-0000-4000-8000-000000000001";
672 const attachmentPath = path.join(config.attachmentsDir, `${attachmentId}.png`);
673 yield* fileSystem.makeDirectory(config.attachmentsDir, { recursive: true });
674 yield* fileSystem.writeFile(attachmentPath, new Uint8Array([1, 2, 3]));
675
676 const result = yield* issueAssetUrl({
677 resource: { _tag: "attachment", attachmentId },
678 });
679 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
680 const separatorIndex = suffix.indexOf("/");
681 const token = suffix.slice(0, separatorIndex);
682
683 expect(yield* resolveAsset(token, "ignored.png")).toEqual({
684 kind: "file",
685 path: attachmentPath,
686 });
687 }).pipe(Effect.provide(testLayer)),
688 );
689
690 it.effect("serves video attachments inline", () =>
691 Effect.gen(function* () {
692 const config = yield* ServerConfig.ServerConfig;
693 const fileSystem = yield* FileSystem.FileSystem;
694 const path = yield* Path.Path;
695 const attachmentId = "thread-1-00000000-0000-4000-8000-000000000001-mp4";
696 const attachmentPath = path.join(config.attachmentsDir, `${attachmentId}.mp4`);
697 yield* fileSystem.makeDirectory(config.attachmentsDir, { recursive: true });
698 yield* fileSystem.writeFile(attachmentPath, new Uint8Array([1, 2, 3]));
699
700 const result = yield* issueAssetUrl({
701 resource: {
702 _tag: "attachment",
703 attachmentId,
704 fileName: "demo.mp4",
705 mimeType: 'video/mp4; codecs="avc1.42E01E"',
706 },
707 });
708 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
709 const separatorIndex = suffix.indexOf("/");
710
711 expect(
712 yield* resolveAsset(suffix.slice(0, separatorIndex), suffix.slice(separatorIndex + 1)),
713 ).toEqual({
714 kind: "file",
715 path: attachmentPath,
716 fileName: "demo.mp4",
717 mimeType: "video/mp4",
718 });
719 }).pipe(Effect.provide(testLayer)),
720 );
721 it.effect("issues signed native application icon capabilities", () =>
722 Effect.gen(function* () {
723 const result = yield* issueAssetUrl({
724 resource: {
725 _tag: "native-app-icon",
726 app: { _tag: "app-id", appId: "com.example.Editor" },
727 },
728 });
729
730 expect(result.relativeUrl).toMatch(
731 new RegExp(`^${ASSET_ROUTE_PREFIX}/[^/]+/native-app-icon\\.png$`, "u"),
732 );
733 expect(result.expiresAt).toBeGreaterThan(0);
734 }).pipe(Effect.provide(testLayer)),
735 );
736
737 it.effect("serves document attachments inline when a viewer requests it", () =>
738 Effect.gen(function* () {
739 const config = yield* ServerConfig.ServerConfig;
740 const fileSystem = yield* FileSystem.FileSystem;
741 const path = yield* Path.Path;
742 const attachmentId = "thread-1-00000000-0000-4000-8000-000000000001-pdf";
743 const attachmentPath = path.join(config.attachmentsDir, `${attachmentId}.pdf`);
744 yield* fileSystem.makeDirectory(config.attachmentsDir, { recursive: true });
745 yield* fileSystem.writeFile(attachmentPath, new Uint8Array([1, 2, 3]));
746
747 const result = yield* issueAssetUrl({
748 resource: {
749 _tag: "attachment",
750 attachmentId,
751 fileName: "report.pdf",
752 mimeType: "application/pdf",
753 disposition: "inline",
754 },
755 });
756 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
757 const separatorIndex = suffix.indexOf("/");
758
759 expect(
760 yield* resolveAsset(suffix.slice(0, separatorIndex), suffix.slice(separatorIndex + 1)),
761 ).toEqual({
762 kind: "file",
763 path: attachmentPath,
764 fileName: "report.pdf",
765 mimeType: "application/pdf",
766 });
767 }).pipe(Effect.provide(testLayer)),
768 );
769
770 it.effect("serves audio previews with their stored format and keeps saving explicit", () =>
771 Effect.gen(function* () {
772 const config = yield* ServerConfig.ServerConfig;
773 const fileSystem = yield* FileSystem.FileSystem;
774 const path = yield* Path.Path;
775 const attachmentId = "thread-1-00000000-0000-4000-8000-000000000003-wav";
776 const attachmentPath = path.join(config.attachmentsDir, `${attachmentId}.wav`);
777 yield* fileSystem.makeDirectory(config.attachmentsDir, { recursive: true });
778 yield* fileSystem.writeFile(attachmentPath, new Uint8Array([1, 2, 3]));
779 for (const disposition of ["inline", "attachment"] as const) {
780 const result = yield* issueAssetUrl({
781 resource: {
782 _tag: "attachment",
783 attachmentId,
784 fileName: "recording.wav",
785 mimeType: "application/octet-stream",
786 disposition,
787 },
788 });
789 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
790 const separatorIndex = suffix.indexOf("/");
791 expect(
792 yield* resolveAsset(suffix.slice(0, separatorIndex), suffix.slice(separatorIndex + 1)),
793 ).toEqual({
794 kind: "file",
795 path: attachmentPath,
796 fileName: "recording.wav",
797 mimeType: disposition === "inline" ? "audio/wav" : "application/octet-stream",
798 ...(disposition === "attachment" ? { download: true } : {}),
799 });
800 }
801 }).pipe(Effect.provide(testLayer)),
802 );
803
804 it.effect("keeps inline requests for other attachment types as downloads", () =>
805 Effect.gen(function* () {
806 const config = yield* ServerConfig.ServerConfig;
807 const fileSystem = yield* FileSystem.FileSystem;
808 const path = yield* Path.Path;
809 const attachmentId = "thread-1-00000000-0000-4000-8000-000000000002-zip";
810 const attachmentPath = path.join(config.attachmentsDir, `${attachmentId}.zip`);
811 yield* fileSystem.makeDirectory(config.attachmentsDir, { recursive: true });
812 yield* fileSystem.writeFile(attachmentPath, new Uint8Array([1, 2, 3]));
813
814 const result = yield* issueAssetUrl({
815 resource: {
816 _tag: "attachment",
817 attachmentId,
818 fileName: "archive.zip",
819 mimeType: "text/html",
820 disposition: "inline",
821 },
822 });
823 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
824 const separatorIndex = suffix.indexOf("/");
825
826 expect(
827 yield* resolveAsset(suffix.slice(0, separatorIndex), suffix.slice(separatorIndex + 1)),
828 ).toMatchObject({ kind: "file", path: attachmentPath, download: true });
829 }).pipe(Effect.provide(testLayer)),
830 );
831 it.effect("issues project favicon capabilities with a signed fallback", () =>
832 Effect.gen(function* () {
833 const fileSystem = yield* FileSystem.FileSystem;
834 const path = yield* Path.Path;
835 const root = yield* fileSystem.makeTempDirectoryScoped({
836 prefix: "t3-asset-favicon-",
837 });
838 const faviconPath = path.join(root, "favicon.svg");
839 const initialFavicon = "<svg>a</svg>";
840 const updatedFavicon = "<svg>b</svg>";
841 expect(updatedFavicon).toHaveLength(initialFavicon.length);
842 yield* fileSystem.writeFileString(faviconPath, initialFavicon);
843 const canonicalFaviconPath = yield* fileSystem.realPath(faviconPath);
844
845 const faviconResult = yield* issueAssetUrl({
846 resource: { _tag: "project-favicon", cwd: root },
847 });
848 expect(faviconResult.sourcePath).toBe("favicon.svg");
849 expect(faviconResult.relativeUrl).toMatch(/\/v[0-9a-f]{64}-favicon\.svg$/);
850 expect(
851 yield* issueAssetUrl({
852 resource: { _tag: "project-favicon", cwd: root },
853 }),
854 ).toEqual(faviconResult);
855 const faviconSuffix = faviconResult.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
856 const faviconSeparatorIndex = faviconSuffix.indexOf("/");
857 expect(
858 yield* resolveAsset(
859 faviconSuffix.slice(0, faviconSeparatorIndex),
860 faviconSuffix.slice(faviconSeparatorIndex + 1),
861 ),
862 ).toEqual({ kind: "file", path: canonicalFaviconPath });
863
864 yield* fileSystem.writeFileString(faviconPath, updatedFavicon);
865 const updatedFaviconResult = yield* issueAssetUrl({
866 resource: { _tag: "project-favicon", cwd: root },
867 });
868 expect(
869 updatedFaviconResult.relativeUrl.slice(updatedFaviconResult.relativeUrl.lastIndexOf("/")),
870 ).not.toBe(faviconResult.relativeUrl.slice(faviconResult.relativeUrl.lastIndexOf("/")));
871
872 yield* fileSystem.remove(faviconPath);
873 const fallbackResult = yield* issueAssetUrl({
874 resource: { _tag: "project-favicon", cwd: root },
875 });
876 expect(fallbackResult.relativeUrl.endsWith(`/${PROJECT_FAVICON_FALLBACK_MARKER}`)).toBe(true);
877 expect(fallbackResult.sourcePath).toBeUndefined();
878 const fallbackSuffix = fallbackResult.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
879 const fallbackSeparatorIndex = fallbackSuffix.indexOf("/");
880 expect(
881 yield* resolveAsset(
882 fallbackSuffix.slice(0, fallbackSeparatorIndex),
883 fallbackSuffix.slice(fallbackSeparatorIndex + 1),
884 ),
885 ).toBeNull();
886 }).pipe(Effect.provide(testLayer)),
887 );
888
889 it.effect("issues project favicon capabilities for a saved override", () =>
890 Effect.gen(function* () {
891 const fileSystem = yield* FileSystem.FileSystem;
892 const path = yield* Path.Path;
893 const root = yield* fileSystem.makeTempDirectoryScoped({
894 prefix: "t3-asset-favicon-override-",
895 });
896 yield* fileSystem.makeDirectory(path.join(root, "brand"));
897 yield* fileSystem.writeFileString(path.join(root, "brand", "custom.svg"), "<svg />");
898 yield* fileSystem.writeFileString(path.join(root, "favicon.svg"), "<svg>auto</svg>");
899
900 const result = yield* issueAssetUrl({
901 resource: { _tag: "project-favicon", cwd: root },
902 projectFaviconPath: "brand/custom.svg",
903 });
904
905 expect(result.sourcePath).toBe(path.join("brand", "custom.svg"));
906 expect(result.relativeUrl).toMatch(/\/v[0-9a-f]{64}-custom\.svg$/);
907 }).pipe(Effect.provide(testLayer)),
908 );
909
910 it.effect("issues an exact capability for a saved favicon outside the workspace", () =>
911 Effect.gen(function* () {
912 const fileSystem = yield* FileSystem.FileSystem;
913 const path = yield* Path.Path;
914 const root = yield* fileSystem.makeTempDirectoryScoped({
915 prefix: "t3-asset-favicon-workspace-",
916 });
917 const pictures = yield* fileSystem.makeTempDirectoryScoped({
918 prefix: "t3-asset-favicon-pictures-",
919 });
920 const externalPath = path.join(pictures, "custom.png");
921 const siblingPath = path.join(pictures, "sibling.png");
922 yield* fileSystem.writeFile(externalPath, new Uint8Array([1, 2, 3]));
923 yield* fileSystem.writeFile(siblingPath, new Uint8Array([4, 5, 6]));
924 const canonicalPath = yield* fileSystem.realPath(externalPath);
925 const canonicalSiblingPath = yield* fileSystem.realPath(siblingPath);
926
927 const result = yield* issueAssetUrl({
928 resource: { _tag: "project-favicon", cwd: root },
929 projectFaviconPath: externalPath,
930 });
931 const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
932 const separatorIndex = suffix.indexOf("/");
933
934 expect(result.sourcePath).toBe(externalPath);
935 expect(result.relativeUrl).toMatch(/\/v[0-9a-f]{64}-custom\.png$/);
936 expect(
937 yield* resolveAsset(suffix.slice(0, separatorIndex), suffix.slice(separatorIndex + 1)),
938 ).toEqual({ kind: "file", path: canonicalPath });
939 const tamperedSuffixResult = yield* resolveAsset(
940 suffix.slice(0, separatorIndex),
941 "sibling.png",
942 );
943 expect(tamperedSuffixResult).toEqual({ kind: "file", path: canonicalPath });
944 expect(tamperedSuffixResult).not.toEqual({ kind: "file", path: canonicalSiblingPath });
945 }).pipe(Effect.provide(testLayer)),
946 );
947
948 it.effect("ignores a client favicon path hint", () =>
949 Effect.gen(function* () {
950 const fileSystem = yield* FileSystem.FileSystem;
951 const path = yield* Path.Path;
952 const root = yield* fileSystem.makeTempDirectoryScoped({
953 prefix: "t3-asset-favicon-hint-",
954 });
955 yield* fileSystem.makeDirectory(path.join(root, "brand"));
956 yield* fileSystem.writeFileString(path.join(root, "brand", "hint.svg"), "<svg>hint</svg>");
957 yield* fileSystem.writeFileString(path.join(root, "brand", "saved.svg"), "<svg>saved</svg>");
958
959 const result = yield* issueAssetUrl({
960 resource: { _tag: "project-favicon", cwd: root, path: "brand/hint.svg" },
961 projectFaviconPath: "brand/saved.svg",
962 });
963
964 expect(result.sourcePath).toBe(path.join("brand", "saved.svg"));
965 expect(result.relativeUrl).toMatch(/\/v[0-9a-f]{64}-saved\.svg$/);
966 }).pipe(Effect.provide(testLayer)),
967 );
968
969 it.effect("keeps automatic favicon resolution separate from a saved override", () =>
970 Effect.gen(function* () {
971 const fileSystem = yield* FileSystem.FileSystem;
972 const path = yield* Path.Path;
973 const root = yield* fileSystem.makeTempDirectoryScoped({
974 prefix: "t3-asset-favicon-automatic-",
975 });
976 yield* fileSystem.makeDirectory(path.join(root, "brand"));
977 yield* fileSystem.writeFileString(path.join(root, "brand", "saved.svg"), "<svg>saved</svg>");
978 yield* fileSystem.writeFileString(path.join(root, "favicon.svg"), "<svg>automatic</svg>");
979
980 const result = yield* issueAssetUrl({
981 resource: { _tag: "project-favicon", cwd: root },
982 });
983
984 expect(result.sourcePath).toBe("favicon.svg");
985 expect(result.relativeUrl).toMatch(/\/v[0-9a-f]{64}-favicon\.svg$/);
986 }).pipe(Effect.provide(testLayer)),
987 );
988
989 it.effect("rejects a resolved project favicon with a non-image extension", () =>
990 Effect.gen(function* () {
991 const fileSystem = yield* FileSystem.FileSystem;
992 const path = yield* Path.Path;
993 const root = yield* fileSystem.makeTempDirectoryScoped({
994 prefix: "t3-asset-favicon-type-",
995 });
996 yield* fileSystem.writeFileString(path.join(root, "secret.txt"), "not an image");
997
998 const error = yield* issueAssetUrl({
999 resource: { _tag: "project-favicon", cwd: root },
1000 projectFaviconPath: "secret.txt",
1001 }).pipe(Effect.flip);
1002
1003 expect(error).toBeInstanceOf(AssetPreviewTypeValidationError);
1004 }).pipe(Effect.provide(testLayer)),
1005 );
1006
1007 it.effect("buckets project favicon expiry after content hashing", () =>
1008 Effect.gen(function* () {
1009 const crypto = yield* Crypto.Crypto;
1010 const fileSystem = yield* FileSystem.FileSystem;
1011 const path = yield* Path.Path;
1012 const root = yield* fileSystem.makeTempDirectoryScoped({
1013 prefix: "t3-asset-favicon-expiry-",
1014 });
1015 yield* fileSystem.writeFileString(path.join(root, "favicon.svg"), "<svg />");
1016
1017 const bucketMs = 30 * 60 * 1000;
1018 yield* TestClock.setTime(bucketMs - 1);
1019 const crossingCrypto = Crypto.make({
1020 randomBytes: (size) => new Uint8Array(size),
1021 digest: (algorithm, data) =>
1022 TestClock.adjust("2 millis").pipe(Effect.andThen(crypto.digest(algorithm, data))),
1023 });
1024 const result = yield* issueAssetUrl({
1025 resource: { _tag: "project-favicon", cwd: root },
1026 }).pipe(Effect.provideService(Crypto.Crypto, crossingCrypto));
1027
1028 expect(result.expiresAt).toBe(3 * bucketMs);
1029 }).pipe(Effect.provide(testLayer)),
1030 );
1031
1032 it.effect("preserves structured project favicon resolution causes", () =>
1033 Effect.gen(function* () {
1034 const fileSystem = yield* FileSystem.FileSystem;
1035 const root = yield* fileSystem.makeTempDirectoryScoped({
1036 prefix: "t3-asset-favicon-error-",
1037 });
1038 const platformCause = PlatformError.systemError({
1039 _tag: "PermissionDenied",
1040 module: "FileSystem",
1041 method: "stat",
1042 });
1043 const resolutionCause = new ProjectFaviconResolver.ProjectFaviconResolutionError({
1044 operation: "stat-candidate",
1045 workspaceRoot: root,
1046 relativePath: "favicon.svg",
1047 cause: platformCause,
1048 });
1049 const resolver = ProjectFaviconResolver.ProjectFaviconResolver.of({
1050 resolvePath: () => Effect.fail(resolutionCause),
1051 });
1052
1053 const error = yield* issueAssetUrl({
1054 resource: { _tag: "project-favicon", cwd: root },
1055 }).pipe(
1056 Effect.provideService(ProjectFaviconResolver.ProjectFaviconResolver, resolver),
1057 Effect.flip,
1058 );
1059
1060 expect(error.message).toBe("Failed to resolve project favicon.");
1061 expect(error._tag).toBe("AssetProjectFaviconResolutionError");
1062 expect(error.cause).toBe(resolutionCause);
1063 }).pipe(Effect.provide(testLayer)),
1064 );
1065});