Repository navigation
refactor(platform): 平台规则改为数据,平台专属测试移到 lithe-platform-tests - #48
Merged
Merged
Conversation
- 新增 lithe-platform crate:Platform { Unix, Windows } 与 Platform::HOST,
路径包含判断、斜杠路径、Windows 保留设备名、owner-only 权限、可执行位、
隐藏控制台窗口、batch 参数转义统一成按平台参数计算的函数
- LSP 进程在所有平台都放进 ProcessTree:macOS/Linux 终止或释放语言服务器时
一并结束它启动的子进程(旧代码下子进程会存活);Unix 语言服务器进入独立
进程组,终端 Ctrl-C 不再直接传给它
- Git 路径校验统一使用同一份保留名规则,新增拒绝 CONIN$/CONOUT$
- 补丁指纹无条件计入文件模式,Windows 打开远程 Unix 工作区时结果一致
- SSH Connection::close 调整关闭顺序,Unix 下不再固定等满 2 秒
- 新增 lithe-platform-tests 包:fixture 程序代替 shell 命令,迁入
git-host/tests/process.rs,并新增 LSP 进程树、Windows batch 参数、权限、
Git 可执行文件解析的真实系统测试
- 顺手修复 shared/plugins/sdk/e2e 中原有的 clippy needless-borrow 报错
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 05:02
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
无。来自平台专属代码通用化的讨论:能用数据表达的平台差异改成按
Platform参数计算,只能在真实系统上验证的测试移到单独的测试包。类型
refactor(含两处行为修复,见下)
改动点
新增
lithe-platformcrate(平台规则即数据)Platform { Unix, Windows }与Platform::HOST,以及is_windows、executable_name、null_device。paths:relative_path_contains(按平台决定是否忽略大小写和分隔符)、slash_separated、native_path_from_bytes。names:is_reserved_device_name、is_portable_windows_component。Windows 保留设备名只保留这一份(CON/PRN/AUX/NUL/CONIN$/CONOUT$/COM1–9/COM¹²³/LPT…),原来git/src/repository.rs和project-generators/src/archive.rs各有一份(git 那份缺 CONIN$/CONOUT$),现在都改为调用它。fs:OWNER_ONLY_FILE_MODE、OWNER_ONLY_DIRECTORY_MODE、owner_only_file、directory_mode、restrict_directory_to_owner、unix_mode、has_execute_bit、is_launchable_file、add_execute_bits等。调用方不用再写#[cfg(unix)]。process:CREATE_NO_WINDOW、hide_console_window、verbatim_argument、exit_status_from_code。这样纯规则函数能在任意一台机器上测两个平台的分支。各 crate 里原先
#[cfg(windows)]的单元测试大多改成了Platform::Windows/Platform::Unix参数化测试,macOS 和 Linux 上也会跑。行为修复与调整
ProcessTree(lsp-transport/src/process.rs):dispose先回收根进程,再tree.terminate。原因是 Unix 进程组里未回收的僵尸根进程仍算存活,已有测试a_unix_tree_ends_only_once_its_root_is_reaped验证了这一点。BatchLaunch:Windows 上.cmd/.bat的命令行拼接集中到一处。lithe-platform的保留名规则,因此新增拒绝CONIN$、CONOUT$。git/src/patch_exchange.rs):改为无条件计入文件模式。原来 Windows 上不计入,Windows 打开远程 Unix 工作区时会和 Unix 端算出的结果不一致。Connection::close(workspace/src/sessions.rs):原来先tree.terminate(2s)再 kill/wait 根进程;Unix 进程组把未回收的根进程算作存活,所以每次关闭都要等满 2 秒超时。现在先tree.kill()立即结束整棵树,再 kill/wait 回收根进程,最后tree.terminate(2s)只等可能残留的子进程。新增
lithe-platform-tests包(平台专属测试单独存放)src/bin/lithe-platform-fixture.rs:测试用的 fixture 程序,取代原来依赖的sh/cmd命令和sleep。共有 hold、parent、failure、stream、echo-arguments 五种模式。tests/platform/:所有测试编进同一个测试二进制。process_tree.rs:从git-host/tests/process.rs迁入并重写。覆盖增量输出取消、非零退出保留输出、终止整棵进程树、Unix 根进程未回收时的超时,以及 Windows 上释放 Job 即结束进程树。lsp_process.rs:语言服务器 terminate/dispose 时结束子进程。Windows 另有 batch 启动脚本的测试:带空格的路径和& % ! ^ ( ) "等元字符要原样传到程序;终止脚本时要连它启动的程序一起结束。permissions.rs:Unix 上的 owner-only 文件和目录权限、可执行位;Windows 上没有 mode 时的行为。git_executable.rs:Windows 上解析出的路径使用正斜杠(从git-host/src/configuration.rs迁入);Unix 上文件有可执行位后才会被采用。cargo test -p lithe-platform -p lithe-platform-tests。其他
shared/plugins/sdk/e2e/plugin_sdk/mod.rs:修复原有的 clippyneedless_borrow报错(listing(&package)改为listing(package)),这个报错和本次改动无关,但会挡住clippy -D warnings。仍保留
cfg的地方(有意不改)lithe-remote服务端的平台适配器,以及它本身就分平台的测试。git-host的平台模块(Unix 进程组和 Windows Job Object 的实现本身)。project-generators/archive.rs的 reparse point 检查和 share_mode 断言。验证
macOS(aarch64)上执行:
cargo test --workspace:2049 个通过,0 个失败。cargo test -p lithe-platform-tests:集成测试 9 个、单元测试 2 个全部通过,用时 0.51 秒。之后检查过,没有残留的 fixture 进程。cargo fmt --all --check。cargo clippy --workspace --all-targets --all-features -D warnings。cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc -D warnings:只用默认 features。--all-features会打开lithe-remote的serverfeature,它依赖的trashcrate 在 Windows 上本来就编不过(E0070);服务端只支持 Linux 和 macOS,这个问题在本次改动前就存在。cargo clippy --workspace --all-targets --all-features --target x86_64-unknown-linux-musl -D warnings。scripts/rust-core/verify-rust-core-comments.sh。node scripts/logging/generate-log-events.mjs --check。node shared/plugins/scripts/verify-docs.mjs。write-stable-tests的稳定性检查verify-test-stability.mjs。已知限制
x86_64-pc-windows-msvc的 clippy 交叉检查。合入前需要在 Windows 上跑一次cargo test -p lithe-platform -p lithe-platform-tests,重点看 batch 参数测试和 Job Object 测试。background_git_processes_do_not_create_windows_console检查的是常量标志位。它已经删掉,没有换成行为测试,因为没有 Windows 环境可以验证“确实没有弹出控制台窗口”。hide_console_window目前也没有单元测试(CommandExt::creation_flags设置后无法从Command读回),只能在 Windows 上确认。cargo test的 CI,以上结果都来自本地运行。