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
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,41 @@ test('quiesces reconnect and waits for the Host process before update install',
await owner.close();
});

test('quiesces Local reconnect while a managed service changes', async () => {
const current = candidateHarness({ lifecycleMode: 'service' });
const replacement = candidateHarness({
lifecycleMode: 'service',
hostEpoch: 'service-after',
});
let starts = 0;
let finishChange!: () => void;
const change = new Promise<void>((resolve) => {
finishChange = resolve;
});
const owner = await startRuntimeHostDesktopManager(
{} as DesktopRuntimeHostCandidateStartInput,
{
startCandidate: async () => {
starts += 1;
return ready(starts === 1 ? current.candidate : replacement.candidate);
},
},
);

const changing = owner.runManagedLocalHostChange(async () => {
current.disconnect();
await change;
});
await new Promise<void>((resolve) => setImmediate(resolve));
assert.equal(starts, 1);

finishChange();
await changing;
await owner.waitUntilReady('local', 'test-host-epoch');
assert.equal(starts, 2);
await owner.close();
});

test('waits through a reconnect gap before quiescing Host retirement', async () => {
const first = candidateHarness();
const replacement = candidateHarness({ disconnectOnPrepare: true });
Expand Down Expand Up @@ -531,6 +566,32 @@ test('replays pairing finalization after an unknown commit and reconnect', async
await manager.close();
});

test('reconnects after a pairing candidate becomes bound to this Client', async () => {
const local = candidateHarness({ hostId: 'host-a' });
const remoteHostId = 'a'.repeat(64);
const candidate = candidateHarness({
hostId: remoteHostId,
finalizeReconnectRequired: true,
});
const claimed = candidateHarness({ hostId: remoteHostId });
const queue = [local.candidate, candidate.candidate, claimed.candidate];
const manager = await startRuntimeHostDesktopManager(
{} as DesktopRuntimeHostCandidateStartInput,
{
startCandidate: async () => ready(queue.shift()!),
reconnectBackoff: { minMs: 0, maxMs: 0 },
},
);
await manager.enable(remoteTarget('office'));

await manager.finalizePairing('office');

assert.equal(candidate.finalizeCalls, 1);
assert.equal(candidate.closeCalls, 1);
assert.equal(manager.current('office')?.candidate, claimed.candidate);
await manager.close();
});

for (const dispatch of ['not_dispatched', 'dispatched'] as const) {
test(`replays ${dispatch} pairing finalization after connection loss`, async () => {
const local = candidateHarness({ hostId: 'host-a' });
Expand Down Expand Up @@ -1102,6 +1163,7 @@ function candidateHarness(
hostId?: string;
hostEpoch?: string;
finalizeFailures?: Error[];
finalizeReconnectRequired?: boolean;
disconnectOnFinalizeFailure?: boolean;
onPrepare?: (mode: string) => unknown | Promise<unknown>;
} = {},
Expand Down Expand Up @@ -1158,7 +1220,7 @@ function candidateHarness(
}
throw failure;
}
return {};
return { reconnectRequired: options.finalizeReconnectRequired ?? false };
},
},
botIncoming: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import assert from 'node:assert/strict';
import test from 'node:test';
import { runtimeHostLocalSetupCommand } from '../runtime-host-local-operator.js';

test('local setup installs one managed service for the Desktop root with Direct peer enabled', () => {
assert.deepEqual(
runtimeHostLocalSetupCommand({
packageSpecifier: 'maka-agent@0.2.0',
clientDataRoot: '/Users/ada/Library/Application Support/Maka',
rootPath: '/Users/ada/Library/Application Support/Maka/workspaces/default',
principalId: 'desktop-owner:pairing',
coordinationRelays: ['/dns4/discovery.example/udp/443/quic-v1'],
expectedTarget: {
serviceId: 'b'.repeat(64),
rootPath: '/Users/ada/Library/Application Support/Maka/workspaces/default',
rootId: 'a'.repeat(64),
},
}),
{
executable: 'npm',
args: [
'exec', '--yes', '--package', 'maka-agent@0.2.0', '--',
'maka', 'runtime-host', 'setup',
'--client-data-root', '/Users/ada/Library/Application Support/Maka',
'--root', '/Users/ada/Library/Application Support/Maka/workspaces/default',
'--principal', 'desktop-owner:pairing',
'--preset', 'desktop-client',
'--defer-pairing-commit',
'--bind-pairing-to-client',
'--enable-direct-peer',
'--expected-service-id', 'b'.repeat(64),
'--expected-root-path', '/Users/ada/Library/Application Support/Maka/workspaces/default',
'--expected-root-id', 'a'.repeat(64),
'--coordination-relay', '/dns4/discovery.example/udp/443/quic-v1',
'--json',
],
},
);
});
Loading
Loading