Skip to content

Commit c87e4e0

Browse files
committed
test(peer): keep reachability split layer coherent
Generated-by: Codex (gpt-5.6-sol)
1 parent 9be9eb3 commit c87e4e0

2 files changed

Lines changed: 88 additions & 35 deletions

File tree

apps/desktop/src/main/__tests__/runtime-host-local-remote-access.test.ts

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ test('enabling remote access hands the same root to one managed service before D
4949
routeHints: ['/ip4/192.0.2.1/udp/41000/quic-v1'],
5050
coordinationRelays: [],
5151
};
52-
const livePeer = {
53-
...peer,
54-
coordinationRelays: ['/dns4/relay.example/udp/443/quic-v1/p2p/12D3KooWrelay'],
55-
};
52+
const livePeer = peerReachability(
53+
peer.peerId,
54+
peer.routeHints,
55+
['/dns4/relay.example/udp/443/quic-v1/p2p/12D3KooWrelay'],
56+
);
5657
const manager = {
5758
async retireOwnedLocalHost() {
5859
retired = true;
@@ -142,7 +143,12 @@ test('enabling remote access hands the same root to one managed service before D
142143
assert.deepEqual(decodeRuntimeHostOwnerConnectionCode(result.connectionCode), {
143144
name: decodeRuntimeHostOwnerConnectionCode(result.connectionCode).name,
144145
rootId: 'a'.repeat(64),
145-
transport: { kind: 'libp2p-direct', ...livePeer },
146+
transport: {
147+
kind: 'libp2p-direct',
148+
peerId: livePeer.lease.peerId,
149+
routeHints: livePeer.lease.directRoutes,
150+
coordinationRelays: livePeer.lease.coordinationRoutes,
151+
},
146152
credential: 'pending-credential',
147153
});
148154
const lifecycle = JSON.parse(
@@ -166,10 +172,11 @@ test('shares the running Local Host endpoint instead of its persisted startup ro
166172
routeHints: ['/ip4/192.0.2.1/udp/41000/quic-v1'],
167173
coordinationRelays: [],
168174
};
169-
const livePeer = {
170-
...configuredPeer,
171-
coordinationRelays: ['/dns4/relay.example/udp/443/quic-v1/p2p/12D3KooWrelay'],
172-
};
175+
const livePeer = peerReachability(
176+
configuredPeer.peerId,
177+
configuredPeer.routeHints,
178+
['/dns4/relay.example/udp/443/quic-v1/p2p/12D3KooWrelay'],
179+
);
173180
const service = createDesktopLocalRuntimeHostRemoteAccess({
174181
ipcMain: { handle() {}, removeHandler() {} },
175182
clientDataRoot,
@@ -212,7 +219,12 @@ test('shares the running Local Host endpoint instead of its persisted startup ro
212219
const target = await service.createCollaborationConnectionTarget();
213220
assert.deepEqual(target, {
214221
name: target.name,
215-
transport: { kind: 'libp2p-direct', ...livePeer },
222+
transport: {
223+
kind: 'libp2p-direct',
224+
peerId: livePeer.lease.peerId,
225+
routeHints: livePeer.lease.directRoutes,
226+
coordinationRelays: livePeer.lease.coordinationRoutes,
227+
},
216228
});
217229
});
218230

@@ -964,6 +976,26 @@ async function writeManagedLifecycle(
964976
);
965977
}
966978

979+
function peerReachability(
980+
peerId: string,
981+
directRoutes: readonly string[],
982+
coordinationRoutes: readonly string[],
983+
) {
984+
return {
985+
lease: {
986+
version: 1 as const,
987+
peerId,
988+
revision: 1,
989+
issuedAt: 1,
990+
expiresAt: 2,
991+
directRoutes,
992+
coordinationRoutes,
993+
},
994+
publicKey: Buffer.from('public').toString('base64url'),
995+
signature: Buffer.from('signature').toString('base64url'),
996+
};
997+
}
998+
967999
function hostRegistration(
9681000
overrides: Partial<Pick<HostRegistration, 'rootId' | 'lifecycleMode'>> = {},
9691001
): HostRegistration {

apps/desktop/src/main/__tests__/runtime-host-profile-service.test.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -689,19 +689,12 @@ test('persists authenticated Owner routes imported through a connection code', a
689689
routeHints: ['/ip4/192.0.2.8/udp/44001/quic-v1'],
690690
coordinationRelays: ['/memory/stale-relay'],
691691
};
692-
const freshEndpoint = {
693-
lease: {
694-
version: 1 as const,
695-
peerId: staleTransport.peerId,
696-
revision: 2,
697-
issuedAt: 1,
698-
expiresAt: 2,
699-
directRoutes: ['/ip4/198.51.100.9/udp/44002/quic-v1'],
700-
coordinationRoutes: ['/memory/fresh-relay'],
701-
},
702-
publicKey: 'AA',
703-
signature: 'AA',
704-
};
692+
const freshEndpoint = peerReachability(
693+
staleTransport.peerId,
694+
2,
695+
['/ip4/198.51.100.9/udp/44002/quic-v1'],
696+
['/memory/fresh-relay'],
697+
);
705698
let observedIncarnation: string | undefined;
706699
const service = createDesktopRuntimeHostProfileService({
707700
clientDataRoot: root,
@@ -738,7 +731,12 @@ test('persists authenticated Owner routes imported through a connection code', a
738731
assert.equal(persisted.profileIncarnationId, observedIncarnation);
739732
assert.deepEqual(
740733
persisted.profile.kind === 'remote' ? persisted.profile.transport : undefined,
741-
{ kind: 'libp2p-direct', ...freshEndpoint },
734+
{
735+
kind: 'libp2p-direct',
736+
peerId: freshEndpoint.lease.peerId,
737+
routeHints: freshEndpoint.lease.directRoutes,
738+
coordinationRelays: freshEndpoint.lease.coordinationRoutes,
739+
},
742740
);
743741
const restarted = await resolveDesktopRuntimeHostStartup(root, { catalog });
744742
assert.deepEqual(restarted.remotes, [persisted]);
@@ -781,11 +779,12 @@ test("keeps a managed Direct route on the SSH profile credential authority", asy
781779
await managedServices.save(MANAGED_PROFILE, MANAGED_SERVICE);
782780
const startup = await resolveDesktopRuntimeHostStartup(root, { catalog });
783781
const activated: ResolvedRuntimeHostProfile[] = [];
784-
const livePeer = {
785-
peerId: "12D3KooWpeer",
786-
routeHints: ["/ip4/192.0.2.9/udp/44002/quic-v1"],
787-
coordinationRelays: ["/dns4/relay.example/udp/443/quic-v1/p2p/12D3KooWrelay"],
788-
};
782+
const livePeer = peerReachability(
783+
'12D3KooWpeer',
784+
2,
785+
['/ip4/192.0.2.9/udp/44002/quic-v1'],
786+
['/dns4/relay.example/udp/443/quic-v1/p2p/12D3KooWrelay'],
787+
);
789788
let exposeReadyState = false;
790789
const service = createDesktopRuntimeHostProfileService({
791790
clientDataRoot: root,
@@ -840,7 +839,12 @@ test("keeps a managed Direct route on the SSH profile credential authority", asy
840839
await service.resolveCollaborationConnectionTarget(MANAGED_PROFILE),
841840
{
842841
name: MANAGED_PROFILE.name,
843-
transport: { kind: "libp2p-direct", ...livePeer },
842+
transport: {
843+
kind: 'libp2p-direct',
844+
peerId: livePeer.lease.peerId,
845+
routeHints: livePeer.lease.directRoutes,
846+
coordinationRelays: livePeer.lease.coordinationRoutes,
847+
},
844848
},
845849
);
846850
exposeReadyState = false;
@@ -1689,11 +1693,7 @@ function ready(target: ResolvedRuntimeHostProfile): RuntimeHostDesktopTargetStat
16891693

16901694
function readyWithPeerEndpoint(
16911695
target: ResolvedRuntimeHostProfile,
1692-
peerEndpoint: {
1693-
readonly peerId: string;
1694-
readonly routeHints: readonly string[];
1695-
readonly coordinationRelays: readonly string[];
1696-
},
1696+
peerEndpoint: ReturnType<typeof peerReachability>,
16971697
): RuntimeHostDesktopTargetState {
16981698
return {
16991699
epoch: `epoch-${target.profile.id}`,
@@ -1708,6 +1708,27 @@ function readyWithPeerEndpoint(
17081708
};
17091709
}
17101710

1711+
function peerReachability(
1712+
peerId: string,
1713+
revision = 1,
1714+
directRoutes: readonly string[] = ['/ip4/192.0.2.8/udp/44001/quic-v1'],
1715+
coordinationRoutes: readonly string[] = [],
1716+
) {
1717+
return {
1718+
lease: {
1719+
version: 1 as const,
1720+
peerId,
1721+
revision,
1722+
issuedAt: 1,
1723+
expiresAt: 2,
1724+
directRoutes,
1725+
coordinationRoutes,
1726+
},
1727+
publicKey: Buffer.from('public').toString('base64url'),
1728+
signature: Buffer.from(`signature-${revision}`).toString('base64url'),
1729+
};
1730+
}
1731+
17111732
function unavailable(
17121733
target: ResolvedRuntimeHostProfile,
17131734
error: Error,

0 commit comments

Comments
 (0)