fix(runtimes): consolidate local machine by device name

Fixes #3333
This commit is contained in:
DENG
2026-05-28 11:49:44 +08:00
committed by GitHub
parent 4864831721
commit ec5874db96
2 changed files with 70 additions and 1 deletions

View File

@@ -157,6 +157,67 @@ describe("runtime machine grouping", () => {
});
});
it("treats a runtime with the local device name as the current machine", () => {
const machines = buildRuntimeMachines(
[
makeRuntime({
daemon_id: "legacy-hostname",
name: "Claude (My Laptop)",
device_info: "My Laptop · claude 1.0.0",
}),
],
{
now: NOW,
localDaemonId: "daemon-uuid",
localMachineName: "my laptop",
ensureLocalMachine: true,
},
);
expect(machines).toHaveLength(1);
expect(machines[0]).toMatchObject({
title: "my laptop",
section: "local",
isCurrent: true,
daemonId: "legacy-hostname",
});
});
it("does not treat a cloud runtime with the local device name as current", () => {
const machines = buildRuntimeMachines(
[
makeRuntime({
id: "cloud-1",
daemon_id: null,
runtime_mode: "cloud",
provider: "codex",
name: "Codex (My Laptop)",
device_info: "My Laptop · codex 1.0.0",
}),
],
{
now: NOW,
localDaemonId: "daemon-uuid",
localMachineName: "my laptop",
ensureLocalMachine: true,
},
);
expect(machines).toHaveLength(2);
const cloud = machines.find((m) => m.id === "cloud:device:My Laptop");
expect(cloud).toMatchObject({
title: "My Laptop",
section: "cloud",
isCurrent: false,
});
const local = machines.find((m) => m.isCurrent);
expect(local).toMatchObject({
title: "my laptop",
section: "local",
runtimes: [],
});
});
it("keeps cloud runtimes as cloud workers when they have no daemon", () => {
const machines = buildRuntimeMachines(
[

View File

@@ -174,7 +174,15 @@ function finalizeRuntimeMachine(
const first = runtimes[0];
const providerNames = Array.from(new Set(runtimes.map((r) => r.provider))).sort();
const isCurrent =
!!options.localDaemonId && draft.daemonId === options.localDaemonId;
(!!options.localDaemonId && draft.daemonId === options.localDaemonId) ||
(draft.mode === "local" &&
!!options.localMachineName &&
(draft.daemonId?.toLowerCase() === options.localMachineName.toLowerCase() ||
runtimes.some(
(r) =>
runtimeDeviceName(r)?.toLowerCase() ===
options.localMachineName?.toLowerCase(),
)));
const title = machineTitle(runtimes, {
isCurrent,
localMachineName: options.localMachineName,