|
6 | 6 | AssetWorkspaceContextNotFoundError, |
7 | 7 | EnvironmentAuthorizationError, |
8 | 8 | EnvironmentId, |
| 9 | + type ProjectCloneSnapshot, |
| 10 | + ProjectId, |
9 | 11 | ThreadId, |
10 | 12 | WS_METHODS, |
11 | 13 | } from "@t3tools/contracts"; |
@@ -409,4 +411,94 @@ describe("project favicon URL cache", () => { |
409 | 411 | registry.dispose(); |
410 | 412 | } |
411 | 413 | }); |
| 414 | + |
| 415 | + const cloning: ProjectCloneSnapshot = { |
| 416 | + projectId: ProjectId.make("project-cloning"), |
| 417 | + remoteUrl: "[email protected]:octocat/app.git", |
| 418 | + destinationPath: "/workspace", |
| 419 | + repository: null, |
| 420 | + phase: "running", |
| 421 | + stage: "receiving", |
| 422 | + percent: 10, |
| 423 | + detail: null, |
| 424 | + error: null, |
| 425 | + startedAt: "2026-01-01T00:00:00.000Z", |
| 426 | + endedAt: null, |
| 427 | + sequence: 1, |
| 428 | + }; |
| 429 | + |
| 430 | + function mountClonedProjectFavicon(initialClones: ReadonlyArray<ProjectCloneSnapshot>) { |
| 431 | + const registry = AtomRegistry.make(); |
| 432 | + // Stands in for the server, which reports the icon missing until the clone lands. |
| 433 | + const server = { lookups: 0, landed: false }; |
| 434 | + const result = Atom.make(() => { |
| 435 | + server.lookups += 1; |
| 436 | + return AsyncResult.success({ |
| 437 | + expiresAt: 4_000_000_000_000, |
| 438 | + relativeUrl: server.landed |
| 439 | + ? "/api/assets/token-b/v1-icon.svg" |
| 440 | + : "/api/assets/token-a/project-favicon-missing", |
| 441 | + }); |
| 442 | + }); |
| 443 | + const clones = Atom.make(initialClones); |
| 444 | + const connection = Atom.make(Option.some({ httpBaseUrl: "https://remote.test" })); |
| 445 | + const favicon = createProjectFaviconUrlAtomFamily({ |
| 446 | + createUrl: () => result, |
| 447 | + preparedConnection: () => connection, |
| 448 | + projectClones: () => clones, |
| 449 | + })({ environmentId: EnvironmentId.make("remote"), cwd: "/workspace" }); |
| 450 | + const unmount = registry.mount(favicon); |
| 451 | + return { |
| 452 | + registry, |
| 453 | + server, |
| 454 | + clones, |
| 455 | + favicon, |
| 456 | + dispose: () => { |
| 457 | + unmount(); |
| 458 | + registry.dispose(); |
| 459 | + }, |
| 460 | + }; |
| 461 | + } |
| 462 | + |
| 463 | + it("asks for a cloned project's icon again once its clone lands", () => { |
| 464 | + const { registry, server, clones, favicon, dispose } = mountClonedProjectFavicon([cloning]); |
| 465 | + try { |
| 466 | + expect(registry.get(favicon)).toBe( |
| 467 | + "https://remote.test/api/assets/token-a/project-favicon-missing", |
| 468 | + ); |
| 469 | + // Progress, and another folder's clone landing, do not ask again. |
| 470 | + registry.set(clones, [ |
| 471 | + { ...cloning, percent: 80, sequence: 2 }, |
| 472 | + { |
| 473 | + ...cloning, |
| 474 | + projectId: ProjectId.make("project-other"), |
| 475 | + destinationPath: "/other", |
| 476 | + phase: "done", |
| 477 | + sequence: 3, |
| 478 | + }, |
| 479 | + ]); |
| 480 | + expect(server.lookups).toBe(1); |
| 481 | + |
| 482 | + server.landed = true; |
| 483 | + registry.set(clones, [{ ...cloning, phase: "done", sequence: 4 }]); |
| 484 | + expect(registry.get(favicon)).toBe("https://remote.test/api/assets/token-b/v1-icon.svg"); |
| 485 | + expect(server.lookups).toBe(2); |
| 486 | + } finally { |
| 487 | + dispose(); |
| 488 | + } |
| 489 | + }); |
| 490 | + |
| 491 | + it("asks again when the first clone list it sees already says done", () => { |
| 492 | + const { registry, server, clones, favicon, dispose } = mountClonedProjectFavicon([]); |
| 493 | + try { |
| 494 | + expect(registry.get(favicon)).toBe( |
| 495 | + "https://remote.test/api/assets/token-a/project-favicon-missing", |
| 496 | + ); |
| 497 | + server.landed = true; |
| 498 | + registry.set(clones, [{ ...cloning, phase: "done", sequence: 2 }]); |
| 499 | + expect(registry.get(favicon)).toBe("https://remote.test/api/assets/token-b/v1-icon.svg"); |
| 500 | + } finally { |
| 501 | + dispose(); |
| 502 | + } |
| 503 | + }); |
412 | 504 | }); |
0 commit comments