Skip to content

feat(remote): 主机能力报告 WSL 互操作状态 windowsInterop,remote.connect 的会话带上它 (Refs 1lck/Lithe-IDEA#2231) - #172

Merged
xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-wsl-interop
Nov 22, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-wsl-interop

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联 Issue

1lck/Lithe-IDEA#2231(远程开发完整设计)S31:连接窗口显示 WSL 互操作状态,并明确 WSL 不是安全边界、不因此放宽信任。本 PR 是 Core 部分,桌面端显示在随后的桌面 Draft 里。

类型

  • feat:远端服务的主机能力新增可选字段 windowsInterop,remote.connect 返回的 session 带上它。旧服务端不发这个字段,客户端按"未知"处理,所以协议版本不变。不新增命令、错误码或日志事件。

判定方法

WSL 在 binfmt_misc 注册条目,Linux 程序才能启动 Windows 程序。条目文件第一行是 enabled 或 disabled。条目名有两个:

  • WSLInterop
  • WSLInterop-late:部分 WSL 版本在启用 systemd 的发行版上注册它(WSL 生成的 systemd-binfmt.service override 会重新注册),有时只剩这一个

两个可能同时存在,也可能只有一个。要手动关掉互操作,必须两个都关。

条目状态 windowsInterop
任意一个是 enabled true
有条目,但都不是 enabled false
一个都没有(不是 WSL、WSL 没注册、容器看不到、macOS 主机、旧服务端) 省略 / null

参考:microsoft/WSL#13449、wslutilities/wslu#319、microsoft/WSL#11471。

改动说明

crates/remote/src/protocol/methods.rs

  • HostCapabilities 新增 windows_interop: Option<bool>,带 #[serde(default, skip_serializing_if = "Option::is_none")],线上字段名为 windowsInterop。文档注释写明三种取值和"客户端只显示、不放宽信任(S31)"。
  • 新测试 windows_interop_is_omitted_unless_the_host_is_wsl:没有字段的 hello 解析为 None,序列化时也省略;true 和 false 原样往返。

crates/remote/src/server/platform/linux.rs

  • windows_interop() 读 /proc/sys/fs/binfmt_misc,逻辑在 windows_interop_in(directory) 里,测试可以换成临时目录。
  • 读不了的条目按不存在处理。
  • 新测试覆盖:只有 WSLInterop 开或关、只有 WSLInterop-late 开、一关一开、两个都关、第一行内容异常、只有别的解释器条目、目录不存在。

crates/remote/src/server/platform/macos.rs:windows_interop() 固定返回 None,和 Linux 函数签名相同。

crates/remote/src/server/platform/mod.rs:host_capabilities() 填入 host::windows_interop()。

crates/workspace/src/sessions.rs(只改连接结果):OpenedSession 新增 windows_interop,取自服务端的主机能力,序列化为 windowsInterop(不在 WSL 时为 null)。

contracts/remote-workspace-protocol-v1.md:"Host capabilities" 一节列出 windowsInterop,写明取值、什么时候省略,以及 WSL 不是安全边界。

contracts/rust-core-api.md:remote.connect 的 session 字段表加上 windowsInterop,说明它只用来显示。

验证

  • macOS arm64:
    • cargo test -p lithe-remote --all-features:lib 206 个和各集成测试全部通过
    • cargo test -p lithe-workspace:83 个全部通过
    • cargo clippy -p lithe-remote -p lithe-workspace --all-features --all-targets -- -D warnings:无告警
    • cargo fmt --all
  • Linux 代码(cfg(target_os = "linux")):
    • cargo clippy -p lithe-remote --no-default-features --features server --all-targets --target x86_64-unknown-linux-musl -- -D warnings:无告警
    • 交叉编译 musl 测试二进制,拷到 Windows 实机(原生 x86_64)的 WSL 发行版(x86_64,启用 systemd)里运行:lib 51 个全部通过,其中包括 3 个新测试
    • 同一台主机上只有 WSLInterop 一个条目,第一行是 enabled,和测试夹具格式一致
    • 跑完删掉了 WSL 和 Windows 两边的临时目录
  • --all-features 的 musl 交叉编译需要 musl C 编译器给 libsqlite3-sys,本机没有,留给 Linux CI。

@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 22, 2026 08:33
@xiaoyumuxi
xiaoyumuxi merged commit a5806bc into main Nov 22, 2026
11 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.

1 participant