Skip to content

fix(settings): 转发可指定/编辑主机;SSH config 主机可编辑;修正菜单锚定与连接池重指 - #175

Merged
flymysql merged 1 commit into
flymysql:mainfrom
Blz-Galaxy:fix/forward-host-and-alias-edit
Nov 19, 2026
Merged

flymysql merged 1 commit into
flymysql:mainfrom
Blz-Galaxy:fix/forward-host-and-alias-edit

Conversation

@Blz-Galaxy

@Blz-Galaxy Blz-Galaxy commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

这是什么

Fixes #174
修复转发无法指定主机、SSH config 新主机无法编辑设密码、「…」菜单不贴按钮、编辑当前机器后连接池仍连旧地址;并支持编辑已有转发。

改动

  • 转发可选主机:表单新增「主机」下拉,define 发送 machineId,服务端校验(未知 404);未连接主机可先定义,启动仍按机器隔离。
  • 已有转发可编辑:预填表单,运行中的先 stop→update→start;服务端对运行中改 bind 返回 409;编辑行高亮。
  • SSH config 主机与已保存机器统一「…」菜单,编辑可填密码;编辑器改用 formOpen 支持新增。
  • 菜单锚定:设置菜单 anchorRef、右键 anchorPoint,并保留 getAnchorRect 兼容旧宿主。依据 DSH 2c990f0b14(rc.2 起改 CSS anchor)。
  • 保存当前机器后 applyActiveMachine() 重指连接池,失败 poolWarning;非当前机器不抢占。

验证

新增 forwards-host-ui / forwards-lifecycle / machine-edit-pool 用例(池回归测试未修复时失败)。全量:1550 用例,1537 通过,0 失败,12 跳过,1 cancelled(既有 fake-ssh-host-key)。node check.mjs 通过;README 双语同步。

…menus

Three gaps made "my new host cannot carry a forward" unavoidable:

1. The add-forward form had no host field. `define` tagged whichever machine
   happened to be connected, so a host that was not connected yet could never
   be given a tunnel. The form now lists saved machines (current one marked
   当前, default) and sends `machineId`; the route validates it against the
   registry (unknown id = 404) and still defaults to the active machine when
   the field is absent. Defining for a non-connected host is allowed — it
   becomes startable once that host connects — while starting still refuses
   to tunnel through the wrong connection.

2. An existing forward could only be deleted and re-added. Each row now has
   编辑: the form is prefilled, 添加转发 becomes 保存修改 (+ 取消), and
   `POST /forwards {action:'update'}` accepts a partial patch for direction,
   ports, target and owning host. A LIVE tunnel keeps its old bind, so the
   client stops it, patches the record and starts it again; the route also
   refuses bind changes on an active forward (409) while still allowing the
   自动重连 toggle. While editing, the picked row stays identifiable (tinted
   row, left accent, 编辑中 badge), the form scrolls into view, and the
   highlight clears on save/cancel.

3. A host added to ~/.ssh/config rendered as a probe-only row: only SAVED
   machines had the `...` menu, so a new host had no edit entry and no place
   to type its login password. The discovered row now exposes the same `...`
   menu (编辑 opens the machine form prefilled as an alias: useSshConfig +
   openssh backend, password field included). The entry no longer changes
   shape after the first save.

The `...` menu also has to OPEN AT THE BUTTON. DSH 0.2.2-alpha.2 replaced the
old `getAnchorRect` prop with CSS anchors (`anchorRef` / `anchorPoint`), and a
menu given only the old rect is silently placed elsewhere — which is why the
编辑/删除 popup (and the explorer's right-click menu) appeared away from the
pointer. Both APIs are passed now (a host ignores the one it does not know),
the settings menu is right-aligned under its trigger and returns focus to it;
the explorer menu is pointer-anchored with `contextual` spacing.

Saving an EDITED machine now re-points the live pool. The settings save path
used to write the registry only; the pool keeps the target it was APPLIED with
and forwards.start()/rw_* dial through it, so after changing a machine's host
the page showed the new address while 启动 still connected to the old one
("ssh: connect to host <old>: Host is down"). A save of the CURRENT machine now
runs applyActiveMachine (setTarget keeps the live connection when no identity
field changed) and reports `poolWarning` if re-pointing fails; saving a standby
machine never hijacks the active connection.

Supporting changes: the machine editor is keyed on explicit `formOpen` state
(a new record has no id yet). A host half that predates these fields cannot be
trusted: the old `define` silently tags the active machine and the old
`update` stores only autoStart. The client compares what it asked for with
what came back, removes a mis-attached definition / restores the previous
forward, and asks for a restart instead of showing a silent success.

Tests: route tests for host validation, forward editing (including the 409
while running) and the pool re-point (RED without the fix: the pool stayed on
the old address), plus real-render UI tests for the host select, forward
editing/restart, the edited-row highlight, the discovered-host menu, menu
anchoring and both stale-host guards. READMEs updated (zh/en).
@flymysql

Copy link
Copy Markdown
Owner

验证完成:1550 tests / 1527 pass / 0 fail / 23 skipped;CI 与 Agent native/PTC(0.2.0/0.2.1/0.2.2)、macOS、Windows 全绿。首次运行两个 native 失败在 search/highlighted-editor 的浏览器 e2e(.xterm 文本超时、highlighted-editor-web-e2e.mjs:164),与本 PR 触碰的转发/菜单路径无关,重跑全绿,判为环境抖动。

对“菜单同时传新旧两套 anchor”做了独立核对:本机 0.2.1-rc.5 的宿主 Menu 只解构 anchor 与 getAnchorRect(无 anchorRef/anchorPoint),未知 props 被忽略,且 getAnchorRect 优先取用 —— 所以这个超集写法对旧宿主不会造成错位,方向是对的。相应地,我上一批加的“禁止出现 anchorPoint”不变量在本 PR 里被改成“必须保留 getAnchorRect + 允许 anchorRef/anchorPoint”,这个放宽是合理的:旧宿主靠 rect,新宿主靠 ref/point,两边都不能丢。

服务端校验也确认到位:define/update 对显式 machineId 走注册表校验(未知 404),运行中改 bind 返回 409,machineId 列入 bind 变更集合;保存当前机器才 applyActiveMachine() 重指连接池,非当前机器不抢占,失败以 poolWarning 回传而不是静默。

新增 7 条 UI 用例带 24 处真实点击/输入,不是读 props 的假绿。

感谢 @Blz-Galaxy 把四个问题一次讲清楚,并且把“未连接主机也能先存转发”的边界也考虑进去了。

@flymysql flymysql left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

服务端校验、运行中 bind 保护、连接池重指范围与兼容旧宿主的菜单锚定都已核对,测试为真实交互。approve.

@flymysql
flymysql merged commit bc7036a into flymysql:main Nov 19, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 端口转发无法指定主机;SSH config 新主机无法编辑设密码;菜单与连接池问题

2 participants