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 @@ -404,6 +404,7 @@ test('replaces a conflicting supervised Host with the requested active-work poli
resolveManagedDeploymentAuthority: async () => ({
kind: 'active',
lifecycleMode: 'supervised',
deploymentRoot: join(base, 'deployment'),
target: {
schemaVersion: 2,
serviceId: rootId,
Expand Down Expand Up @@ -513,14 +514,14 @@ test('does not persist recoverable setup authority before Desktop ownership comm
assert.equal(setupCalls, 0);
});

test('adopts committed managed authority from a released handoff without replaying setup', async (t) => {
test('adopts a released handoff through its existing legacy operator', async (t) => {
const base = await mkdtemp(join(tmpdir(), 'maka-local-remote-access-prestart-'));
t.after(() => rm(base, { recursive: true, force: true }));
const clientDataRoot = join(base, 'client');
const rootPath = join(clientDataRoot, 'workspaces', 'default');
const rootId = 'a'.repeat(64);
const deploymentId = '22222222-2222-4222-8222-222222222222';
const installedOperator = testOperator(join(base, 'installed', 'operator.mjs'));
const deploymentRoot = join(base, 'installed');
await mkdir(rootPath, { recursive: true });
await writeFile(
join(clientDataRoot, 'runtime-host-local-service.json'),
Expand All @@ -543,10 +544,11 @@ test('adopts committed managed authority from a released handoff without replayi
resolveManagedDeploymentAuthority: async () => ({
kind: 'active',
lifecycleMode: 'supervised',
deploymentRoot,
target: {
schemaVersion: 2,
serviceId: rootId,
operator: installedOperator,
operator: testOperator(join(deploymentRoot, 'operator.mjs')),
rootPath,
rootId,
deploymentId,
Expand All @@ -570,7 +572,10 @@ test('adopts committed managed authority from a released handoff without replayi
schemaVersion: 2,
state: 'managed',
serviceId: rootId,
operator: installedOperator,
operator: {
kind: 'legacy_posix_executable',
executablePath: join(deploymentRoot, 'operator'),
},
rootPath,
rootId,
deploymentId,
Expand Down
23 changes: 17 additions & 6 deletions apps/desktop/src/main/runtime-host-local-remote-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type LocalManagedDeploymentAuthority =
| {
readonly kind: 'active';
readonly lifecycleMode: 'on_demand' | 'supervised';
readonly deploymentRoot: string;
readonly target: LocalServiceTarget;
}
| { readonly kind: 'transition' };
Expand Down Expand Up @@ -205,6 +206,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
return {
kind: 'active',
lifecycleMode: authority.record.lifecycle.mode,
deploymentRoot: authority.record.deploymentRoot,
target: requireServiceTarget(
{
schemaVersion: 2,
Expand All @@ -223,15 +225,24 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
});

const adoptCommittedSetup = async (
setup: LocalServiceSetupPending,
setup: LocalServiceSetupPending | LocalServiceLegacyHandoff,
): Promise<
| { readonly kind: 'absent' | 'transition' }
| { readonly kind: 'managed'; readonly managed: LocalServiceManaged }
> => {
const authority = await resolveManagedDeploymentAuthority(setup.rootId);
if (!authority) return { kind: 'absent' };
if (authority.kind === 'transition') return authority;
const managed = managedLifecycle(authority.target);
const target =
setup.schemaVersion === 1
? {
...authority.target,
operator: createRuntimeHostLegacyPosixOperatorCommand(
join(authority.deploymentRoot, 'operator'),
),
}
: authority.target;
const managed = managedLifecycle(target);
await writeDocument(lifecyclePath, managed);
return { kind: 'managed', managed };
};
Expand Down Expand Up @@ -472,7 +483,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
| { readonly kind: 'complete'; readonly managed: LocalServiceManaged }
> => {
const pending = pendingSetup(legacy);
const authority = await adoptCommittedSetup(pending);
const authority = await adoptCommittedSetup(legacy);
if (authority.kind === 'managed') {
return { kind: 'complete', managed: authority.managed };
}
Expand All @@ -487,7 +498,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
);
if (retirement.kind === 'active_tasks') return { kind: 'active_tasks' };
if (retirement.kind === 'not_owned') {
const raced = await adoptCommittedSetup(pending);
const raced = await adoptCommittedSetup(legacy);
if (raced.kind === 'managed') {
return { kind: 'complete', managed: raced.managed };
}
Expand Down Expand Up @@ -857,7 +868,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
const pending = await readLifecycle(lifecyclePath, input.rootPath, input.rootId);
if (pending?.state !== 'setupPending' && pending?.state !== 'handoff') return false;
const current = pendingSetup(pending);
const authority = await adoptCommittedSetup(current);
const authority = await adoptCommittedSetup(pending);
if (authority.kind === 'absent') return false;
if (authority.kind === 'managed') return true;
if (pending.state === 'handoff') await writeDocument(lifecyclePath, current);
Expand All @@ -882,7 +893,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
return;
}
if (lifecycle.state === 'handoff' || lifecycle.state === 'setupPending') {
const committed = await adoptCommittedSetup(pendingSetup(lifecycle));
const committed = await adoptCommittedSetup(lifecycle);
if (committed.kind === 'managed') return;
if (!supported(input.directPeerAvailable)) return;
if (lifecycle.state === 'handoff') await recoverLegacyHandoff(lifecycle);
Expand Down