From d74868589d9ac80b737cb2593b73f865973b13e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Fri, 4 Dec 2026 05:39:40 -0700 Subject: [PATCH 1/7] fix(macos): give CoW clones their own SSH port forward CloneCoW built reims.CreateOpts without SSHPort even though the field and the --ssh-port argument both exist, so every CoW clone came up with no host SSH forward. MCP temporary sessions and any other clone then failed every SSH-based guest tool (guest_exec, guest_wait_ready, test_run) with a port that nothing listened on. Pick the next free port after the source VM's forward and pass it to create; a source without forwarding still yields a clone without one. Add TestCloneSSHPort for the selection logic. model: deepseek/deepseek-v4.1-flash agent: lead (DeepSeek Harness) --- changes/clone-ssh-port-forward.json | 7 +++++ internal/macos/macosdriver/clone.go | 35 +++++++++++++++++++++++- internal/macos/macosdriver/clone_test.go | 25 +++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 changes/clone-ssh-port-forward.json create mode 100644 internal/macos/macosdriver/clone_test.go diff --git a/changes/clone-ssh-port-forward.json b/changes/clone-ssh-port-forward.json new file mode 100644 index 0000000..50248d5 --- /dev/null +++ b/changes/clone-ssh-port-forward.json @@ -0,0 +1,7 @@ +{ + "group": "fixes", + "order": 0, + "authors": ["Nwflower"], + "zh": "修复克隆虚拟机没有主机 SSH 端口转发的问题。源虚拟机开启端口转发时,克隆出的虚拟机现在会占用源端口之后的一个空闲端口,因此 MCP 临时会话与克隆上的 SSH 相关工具(`guest_exec`、`guest_wait_ready`、`test_run` 等)可以正常连接客体。源虚拟机未开启转发时克隆仍不开启。", + "en": "Fix cloned VMs having no host SSH port forward. When the source VM forwards SSH, a clone now takes the next free port after the source port, so SSH-based guest tools such as `guest_exec`, `guest_wait_ready`, and `test_run` work on MCP temporary sessions and other clones. A source without forwarding still yields a clone without one." +} diff --git a/internal/macos/macosdriver/clone.go b/internal/macos/macosdriver/clone.go index ce2ad9b..1158b94 100644 --- a/internal/macos/macosdriver/clone.go +++ b/internal/macos/macosdriver/clone.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "net" "os" "path/filepath" "strings" @@ -22,6 +23,33 @@ import ( var _ driver.CloneDriver = (*ReimsMacOSDriver)(nil) var _ driver.CloneResultDriver = (*ReimsMacOSDriver)(nil) +// portInUse reports whether a TCP port is already bound on the loopback +// interface, so a clone picks a forward that will not collide. +func portInUse(port int) bool { + l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) + if err != nil { + return true + } + _ = l.Close() + return false +} + +// cloneSSHPort gives a clone a host SSH forward of its own. The source VM's +// forward is still bound, so reusing its number would fail to start, and a +// clone without a forward rejects every SSH-based guest tool. A source without +// forwarding stays without one. +func cloneSSHPort(sourcePort int, inUse func(int) bool) int { + if sourcePort <= 0 { + return 0 + } + for port := sourcePort + 1; port < 65535; port++ { + if !inUse(port) { + return port + } + } + return sourcePort + 1 +} + func (d *ReimsMacOSDriver) CloneCoWWithInfo(ctx context.Context, sourceName, cloneName string, stdout, stderr io.Writer) (driver.VMInfo, error) { cloneName = strings.TrimSpace(cloneName) if err := d.CloneCoW(ctx, sourceName, cloneName, stdout, stderr); err != nil { @@ -121,7 +149,12 @@ func (d *ReimsMacOSDriver) CloneCoW(ctx context.Context, sourceName, cloneName s if src.NetworkMode == "bridge" { network = true } - createOpts := reims.CreateOpts{Name: cloneName, SourceMode: "disk", Disk: overlayPath, DiskMode: "in-place", DiskController: src.DiskController, CPUs: src.CPUs, Memory: src.Memory, Graphics: src.Graphics, GPU: src.GPU, Resolution: src.Resolution, Displays: src.Displays, Capture: &capture, Audio: &audio, Network: &network, Logs: &logs, Start: false} + // The clone needs its own host SSH forward: an MCP test run starts it and + // reaches the guest over SSH, while the source VM's own forward is still + // bound. Reusing the source port would fail to start, and dropping the + // forward leaves the clone with no ssh_port so every guest tool fails. + // Keep forwarding on when the source has it and pick the next free port. + createOpts := reims.CreateOpts{Name: cloneName, SourceMode: "disk", Disk: overlayPath, DiskMode: "in-place", DiskController: src.DiskController, CPUs: src.CPUs, Memory: src.Memory, Graphics: src.Graphics, GPU: src.GPU, Resolution: src.Resolution, Displays: src.Displays, Capture: &capture, Audio: &audio, Network: &network, SSHPort: cloneSSHPort(src.SSHPort, portInUse), Logs: &logs, Start: false} if err := c.RegisterCoWClone(ctx, createOpts, stdout, stderr); err != nil { return err } diff --git a/internal/macos/macosdriver/clone_test.go b/internal/macos/macosdriver/clone_test.go new file mode 100644 index 0000000..7f0e609 --- /dev/null +++ b/internal/macos/macosdriver/clone_test.go @@ -0,0 +1,25 @@ +package macosdriver + +import "testing" + +func TestCloneSSHPort(t *testing.T) { + never := func(int) bool { return false } + all := func(int) bool { return true } + for _, tt := range []struct { + name string + sourcePort int + inUse func(int) bool + want int + }{ + {"source without forwarding stays off", 0, never, 0}, + {"next free port after the source", 2222, never, 2223}, + {"skips ports that are already bound", 2222, func(p int) bool { return p <= 2225 }, 2226}, + {"falls back when the range is exhausted", 65533, all, 65534}, + } { + t.Run(tt.name, func(t *testing.T) { + if got := cloneSSHPort(tt.sourcePort, tt.inUse); got != tt.want { + t.Fatalf("cloneSSHPort(%d) = %d, want %d", tt.sourcePort, got, tt.want) + } + }) + } +} From d5841f0f70382ae15225d3bba845fba5a084de32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Fri, 4 Dec 2026 05:54:38 -0700 Subject: [PATCH 2/7] feat(ui,app): polish update UX, speed units, and relocate moved VM registry --- ...ocate-vm-registry-on-data-root-switch.json | 7 + changes/ui-polish-update-cache-and-speed.json | 7 + frontend/scripts/test-tasks.mjs | 9 +- frontend/src/App.tsx | 18 +- frontend/src/components/AboutPage.tsx | 57 +++---- frontend/src/i18n/domains/settings.gen.ts | 24 +-- frontend/src/i18n/keys.gen.ts | 5 - frontend/src/lib/tasks.ts | 10 +- frontend/src/lib/useAppUpdate.ts | 22 ++- internal/app/app.go | 9 + internal/app/dataroot_flow.go | 18 ++ internal/app/dataroot_flow_test.go | 62 +++++++ internal/app/runtime_bindings.go | 83 +++++----- internal/app/setup.go | 10 +- internal/app/update_cache_test.go | 74 +++++++++ internal/macos/reims/registrations.go | 154 ++++++++++++++++-- internal/macos/reims/registrations_test.go | 117 +++++++++++++ internal/plugin/market.go | 2 +- locales/en-US/settings.json | 7 +- locales/zh-CN/settings.json | 17 +- 20 files changed, 578 insertions(+), 134 deletions(-) create mode 100644 changes/relocate-vm-registry-on-data-root-switch.json create mode 100644 changes/ui-polish-update-cache-and-speed.json create mode 100644 internal/app/update_cache_test.go create mode 100644 internal/macos/reims/registrations_test.go diff --git a/changes/relocate-vm-registry-on-data-root-switch.json b/changes/relocate-vm-registry-on-data-root-switch.json new file mode 100644 index 0000000..d74b559 --- /dev/null +++ b/changes/relocate-vm-registry-on-data-root-switch.json @@ -0,0 +1,7 @@ +{ + "group": "fixes", + "order": 0, + "authors": ["Nwflower"], + "zh": "修复手动移动数据目录并在设置或首启界面重新选择新目录后,因虚拟机注册表保留旧路径导致无法启动虚拟机的问题。", + "en": "Fix VMs failing to start after moving the data folder and reselecting its new location by updating stale paths in the VM registry." +} diff --git a/changes/ui-polish-update-cache-and-speed.json b/changes/ui-polish-update-cache-and-speed.json new file mode 100644 index 0000000..ab4fcef --- /dev/null +++ b/changes/ui-polish-update-cache-and-speed.json @@ -0,0 +1,7 @@ +{ + "group": "improvements", + "order": 0, + "authors": ["Nwflower"], + "zh": "下载速度低于 1 MB/s 时改以 KB/s 显示,精简关于页社区与更新通道文案,并将更新检查按通道缓存 5 分钟,切换更新通道时不再禁用控件。", + "en": "Display download speeds below 1 MB/s in KB/s, tighten About page and update channel copy, cache update checks per channel for 5 minutes, and keep the update channel selector interactive while switching." +} diff --git a/frontend/scripts/test-tasks.mjs b/frontend/scripts/test-tasks.mjs index cfdc483..28f5f47 100644 --- a/frontend/scripts/test-tasks.mjs +++ b/frontend/scripts/test-tasks.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict' import test from 'node:test' import { loadTestModule } from './load-test-module.mjs' -const { currentTask, findActiveOfflineTask, pruneFinishedTasks, upsertTask } = +const { currentTask, findActiveOfflineTask, pruneFinishedTasks, taskDetail, upsertTask } = await loadTestModule(`export * from './lib/tasks'`) const task = (id, overrides = {}) => ({ @@ -33,3 +33,10 @@ test('one installer download represents the VM creations waiting for it', () => primary: download, waitingVMs: ['vm one'], matchedIDs: ['download', 'vm'], }) }) + +test('taskDetail formats download speeds under 1 MB/s in KB/s', () => { + assert.equal(taskDetail(task('slow', { done: 5e6, total: 50e6, rate: 512e3 })), '5 MB / 50 MB · 512 KB/s') + assert.equal(taskDetail(task('tiny', { done: 1e6, total: 10e6, rate: 200 })), '1 MB / 10 MB · 1 KB/s') + assert.equal(taskDetail(task('fast', { done: 2e9, total: 10e9, rate: 12.5e6 })), '2.0 GB / 10.0 GB · 12.5 MB/s') + assert.equal(taskDetail(task('gig', { done: 2e9, total: 10e9, rate: 1.2e9 })), '2.0 GB / 10.0 GB · 1.2 GB/s') +}) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 4087668..870385a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -516,13 +516,25 @@ export const App: React.FC = () => { const setChannel = (alpha: boolean) => { api.SetRuntimeChannel(alpha ? 'alpha' : 'stable').then(() => refresh()).catch((e) => fail(tr('failGeneric'), e)) } + const appChannelSeqRef = useRef(0) const appUpdateChannel = state?.config.app_update_channel === 'alpha' || state?.config.app_update_channel === 'dev' ? state.config.app_update_channel : 'stable' const setAppUpdateChannel = async (ch: 'stable' | 'alpha' | 'dev') => { - await api.SetAppUpdateChannel(ch) - await refresh() - await update.recheck() + const seq = ++appChannelSeqRef.current + setState((prev) => (prev ? { ...prev, config: { ...prev.config, app_update_channel: ch } } : prev)) + try { + await api.SetAppUpdateChannel(ch) + } catch (e) { + if (appChannelSeqRef.current === seq) { + void refresh() + throw e + } + return + } + if (appChannelSeqRef.current !== seq) return + await update.recheck(false) + if (appChannelSeqRef.current === seq) void refresh() } const cancelTask = (id: string) => { api.CancelTask(id).catch((e) => fail(tr('failGeneric'), e)) } diff --git a/frontend/src/components/AboutPage.tsx b/frontend/src/components/AboutPage.tsx index 73e5684..38efb9a 100644 --- a/frontend/src/components/AboutPage.tsx +++ b/frontend/src/components/AboutPage.tsx @@ -43,7 +43,6 @@ export const AboutPage: React.FC = ({ }) => { const tr = (k: I18nKey, v?: Record) => t(locale, k, v) const [checkingUpdate, setCheckingUpdate] = useState(false) - const [switchingChannel, setSwitchingChannel] = useState(false) const [updateErr, setUpdateErr] = useState('') const [qqInstalled, setQQInstalled] = useState(null) const [openingQQ, setOpeningQQ] = useState(false) @@ -128,54 +127,53 @@ export const AboutPage: React.FC = ({ } const handleChannelChange = async (next: AppUpdateChannel) => { - if (next === appUpdateChannel || switchingChannel) return - setSwitchingChannel(true) + if (next === appUpdateChannel) return setUpdateErr('') try { await onAppUpdateChannel(next) } catch (e) { setUpdateErr(String(e).replace(/^Error:\s*/, '')) - } finally { - setSwitchingChannel(false) } } - const version = appVersion ?? appUpdate?.current ?? '' + const visibleUpdate = appUpdate && (!appUpdate.channel || appUpdate.channel === appUpdateChannel) ? appUpdate : null + const visiblePhase: UpdatePhase = visibleUpdate ? updatePhase : 'none' + const version = appVersion ?? visibleUpdate?.current ?? '' const pct = updateTask && updateTask.percent >= 0 ? Math.round(updateTask.percent) : null - const updateAvailableKey: I18nKey = appUpdate?.channel === 'dev' + const updateAvailableKey: I18nKey = visibleUpdate?.channel === 'dev' ? 'appUpdateAvailableDev' - : appUpdate?.channel === 'alpha' + : visibleUpdate?.channel === 'alpha' ? 'appUpdateAvailableAlpha' : 'appUpdateAvailable' let updateSub: React.ReactNode = null - if (updatePhase === 'downloading') { + if (visiblePhase === 'downloading') { updateSub = ( <> -
{tr('updateDownloadingSub', { v: appUpdate?.latest ?? '' })}{updateTask && taskDetail(updateTask) ? ` · ${taskDetail(updateTask)}` : ''}
+
{tr('updateDownloadingSub', { v: visibleUpdate?.latest ?? '' })}{updateTask && taskDetail(updateTask) ? ` · ${taskDetail(updateTask)}` : ''}