|
1 | | -import { PrimaryConnectionTarget } from "@t3tools/client-runtime/connection"; |
| 1 | +import { BearerConnectionTarget, PrimaryConnectionTarget } from "@t3tools/client-runtime/connection"; |
2 | 2 | import type { EnvironmentCatalogState } from "@t3tools/client-runtime/state/connections"; |
3 | 3 | import type { EnvironmentShellState } from "@t3tools/client-runtime/state/shell"; |
4 | 4 | import { EnvironmentId } from "@t3tools/contracts"; |
@@ -34,37 +34,67 @@ function catalogState(environmentIds: readonly EnvironmentId[]): EnvironmentCata |
34 | 34 | environmentIds.map((environmentId) => [ |
35 | 35 | environmentId, |
36 | 36 | { |
37 | | - target: new PrimaryConnectionTarget({ |
38 | | - environmentId, |
39 | | - label: environmentId, |
40 | | - httpBaseUrl: `https://${environmentId}.example.test`, |
41 | | - wsBaseUrl: `wss://${environmentId}.example.test`, |
42 | | - }), |
| 37 | + target: |
| 38 | + environmentId === LOCAL |
| 39 | + ? new PrimaryConnectionTarget({ |
| 40 | + environmentId, |
| 41 | + label: environmentId, |
| 42 | + httpBaseUrl: `https://${environmentId}.example.test`, |
| 43 | + wsBaseUrl: `wss://${environmentId}.example.test`, |
| 44 | + }) |
| 45 | + : new BearerConnectionTarget({ |
| 46 | + environmentId, |
| 47 | + connectionId: environmentId, |
| 48 | + label: environmentId, |
| 49 | + }), |
43 | 50 | profile: Option.none(), |
44 | 51 | }, |
45 | 52 | ]), |
46 | 53 | ), |
47 | 54 | }; |
48 | 55 | } |
49 | 56 |
|
50 | | -function makeHarness() { |
| 57 | +function makeHarness(requiresPrimaryEnvironment = true) { |
51 | 58 | const catalog = Atom.make<EnvironmentCatalogState>({ isReady: false, entries: new Map() }); |
52 | 59 | const shells = Atom.family((_environmentId: EnvironmentId) => |
53 | 60 | Atom.make<EnvironmentShellState>(shellState("empty")), |
54 | 61 | ); |
55 | 62 | const ready = createAllEnvironmentProjectSnapshotsReadyAtom({ |
56 | 63 | catalogValueAtom: catalog, |
57 | 64 | shellStateValueAtom: shells, |
| 65 | + requiresPrimaryEnvironment, |
58 | 66 | }); |
59 | 67 | const registry = AtomRegistry.make(); |
60 | 68 | return { catalog, shells, ready, registry }; |
61 | 69 | } |
62 | 70 |
|
63 | 71 | describe("project snapshot readiness", () => { |
64 | | - it("does not clear a saved scope before catalog loading finishes", () => { |
| 72 | + it("does not clear a saved scope while the ready catalog is still empty", () => { |
65 | 73 | const { catalog, ready, registry } = makeHarness(); |
66 | 74 | expect(registry.get(ready)).toBe(false); |
67 | 75 | registry.set(catalog, catalogState([])); |
| 76 | + expect(registry.get(ready)).toBe(false); |
| 77 | + registry.dispose(); |
| 78 | + }); |
| 79 | + |
| 80 | + it("waits for primary discovery even if a persisted remote is already live", () => { |
| 81 | + const { catalog, shells, ready, registry } = makeHarness(); |
| 82 | + registry.set(catalog, catalogState([REMOTE])); |
| 83 | + registry.set(shells(REMOTE), shellState("live")); |
| 84 | + expect(registry.get(ready)).toBe(false); |
| 85 | + |
| 86 | + registry.set(catalog, catalogState([LOCAL, REMOTE])); |
| 87 | + expect(registry.get(ready)).toBe(false); |
| 88 | + registry.set(shells(LOCAL), shellState("live")); |
| 89 | + expect(registry.get(ready)).toBe(true); |
| 90 | + registry.dispose(); |
| 91 | + }); |
| 92 | + |
| 93 | + it("allows a hosted client to load projects without a primary environment", () => { |
| 94 | + const { catalog, shells, ready, registry } = makeHarness(false); |
| 95 | + registry.set(catalog, catalogState([REMOTE])); |
| 96 | + expect(registry.get(ready)).toBe(false); |
| 97 | + registry.set(shells(REMOTE), shellState("live")); |
68 | 98 | expect(registry.get(ready)).toBe(true); |
69 | 99 | registry.dispose(); |
70 | 100 | }); |
|
0 commit comments