Repository navigation
feat(desktop):add Linux disgnostics integration - #2343
Conversation
|
|
||
| #![cfg(target_os = "macos")] | ||
| // These integration tests exercise the shared Unix process-group implementation. | ||
| #![cfg(any(target_os = "macos", target_os = "linux"))] |
There was a problem hiding this comment.
[P1] 这个 head 上 desktop-validation / linux 已经因为本行新开启的用例而失败,desktop 门禁不可能变绿
desktop-validation / linux(run 41202491377 / job 124541552585,2026-10-31T12:48:20Z)在 cargo test --locked --manifest-path src-tauri/Cargo.toml 这一步失败,失败用例正是加上 target_os = "linux" 之后才被编译进来的 tests/macos_diagnostics.rs::shutdown_cancels_the_next_check_after_a_completed_check:
- 日志:
test shutdown_cancels_the_next_check_after_a_completed_check ... FAILED,test result: FAILED. 2 passed; 1 failed; 0 ignored ... finished in 10.01s,panicked at tests/macos_diagnostics.rs:196:9: first check did not start; - 同文件另两条(
registered_launcher_is_verified_and_projected_without_private_output、shutdown_terminates_inflight_launcher_and_descendants_and_closes_admission)在本平台上通过,说明「按 sha256 校验后执行临时副本 + 私有进程组清理」这条链路在 Linux 可用,失败只集中在这条用例自己的夹具; - 该用例用脚本
else分支里的touch first当「首次检查已开始」的信号,10 s 内该文件没有出现,也就是首次service status --json调用没有走到写标记那一步; - 其后
pnpm ipc:check、Set up Python fixture tooling、Install locked Server test dependencies、Build Server wheel、Qualify the disposable checkout、Build native Linux diagnostic acceptance client、Test native diagnostics with isolated real Linux CLI、打包与上传全部skipped,本轮新增的 Linux 真实 CLI 验收没有任何执行证据。
.github/ci-paths.toml 的 desktop suite 只认 desktop-validation 这一个汇总 job,它现在是红的。
建议:先在 Linux 上本地复现该夹具,确认首次调用为什么没有产生标记(版本分支输出、current_dir 与脚本里的绝对路径、或 Group 清理时序都可能相关),改到稳定通过后再开 cfg;如果这条用例的语义确实只对 macOS 成立,就让它保留 #![cfg(target_os = "macos")],不要用整体开启来换覆盖数。
There was a problem hiding this comment.
[P1 已闭合] desktop-validation / linux 现在通过,且根因修在流程层而不是断言层
275e17a2 上 40 个 check run 全 success、无 pending,desktop-validation / linux 已绿。两处改动指向我上一轮看到的 first check did not start(tests/macos_diagnostics.rs 旧 :196)的真实原因:
diagnostics.rs先把快照写到0o500后关闭文件(新增sync_all(),并让File在块作用域内 drop)再交给diagnostic_process::run;diagnostic_process_macos.rs对spawn()的ETXTBSY做最多 20 次、每次 5 ms 的重试,之后才SafeError::NotFound。
即 Linux 上刚写完的可执行文件立即 spawn 会撞 ETXTBSY(macOS 不报),所以上一轮的红不是断言过严。
测试重写也没有放宽强度:仍要求首次检查完整完成并留下 marker(first.exists()),二次检查必须写 pid 并进入长跑分支,shutdown() 之后用 /bin/ps -o stat= 断言进程已消失或成 Z。脚本侧把 touch 换成 : >、sleep 换成 /bin/sleep 只消除了对 PATH 解析的依赖。
There was a problem hiding this comment.
Thanks for the detailed investigation.
Fixed in commit 275e17a. The root cause was a Linux ETXTBSY race when spawning the verified executable immediately after creating it. The snapshot is now fully written,synced, and closed before execution, and Linux retries transient ETXTBSY errors before returning failure.
The test assertions remain strict: the first check must complete and create its marker, the second check must enter the long-running branch, and shutdown must clean up the child process. The Linux desktop-validation job now passes.
| .any(|v| v.field == "registration" && v.status == "not_installed") | ||
| ); | ||
| assert_eq!(integrations.hosts.len(), 10); | ||
| assert!(service.items.iter().any(|v| v.field == "registration")); |
There was a problem hiding this comment.
[P2] 为了在 Linux 上通过而放宽的这两条断言,同时削弱了 Windows 侧的真实 CLI 资格探针
改动前是本 PR 想替换的两条硬断言:assert!(... any(|v| v.field == "registration" && v.status == "not_installed")) 与 assert_eq!(integrations.hosts.len(), 10);改动后只剩「存在名为 registration 的字段」和「hosts 非空」。
这个 example 由两处共用:desktop.yml 的 windows job(Check fixture qualification regressions 里 cargo build ... --example server_probe --example diagnostic_cli_probe,以及 Test native diagnostics with isolated real CLI)和本 PR 新增的 Linux 步骤。因此 Windows 侧静默失去两条校验:
service status --json的registration取值不再被断言:CLI 在未安装状态下返回installed或invalid也会通过;- 集成诊断的宿主数量不再被断言:
DiagnosticKind::Integrations固定传 10 个宿主名,投影只回 1 个宿主也能通过。
影响是 desktop-validation / windows 的「真实 CLI 输出与适配器契约一致」退化为「输出里有个字段名」,而这条路径正是 diagnostics.rs::project 的字段白名单与 cli_version_from_output 之外唯一的行为证据。
建议按平台给出期望值,而不是两平台一起放宽:Linux 侧显式列 allowed 的 support/registration 取值(例如 support ∈ {supported, unsupported},registration ∈ {installed, not_installed, unknown})并从宿主清单断言集合相等;Windows 侧保留原来的 not_installed 与 10 个宿主。
There was a problem hiding this comment.
[P2 已闭合] 断言改为按平台给期望值,Windows 侧强度恢复
diagnostic_cli_probe.rs 现在按平台分支:
#[cfg(windows)]:恢复原始硬断言——registration必须是not_installed,integrations.hosts.len() == 10;#[cfg(target_os = "linux")]:support∈ {supported,unsupported}、registration∈ {installed,not_installed,unknown},宿主列表排序后与 10 个具体主机名逐项相等。
两侧都不再是上一版的「字段存在 / 非空」,所以共用探针没有为了 Linux 变绿而削弱 Windows 的资格判定。
There was a problem hiding this comment.
Thanks for catching this regression.
Fixed in commit 275e17a. The Windows probe now restores the original strict assertions: the registration status must be not_installed, and the integrations report must contain exactly 10 hosts.
Linux now has separate platform-specific assertions for the supported registration states and the complete expected host set, so the Linux compatibility differences no longer weaken Windows validation.
| ) -> Result<crate::diagnostics::DiagnosticReport, SafeError> { | ||
| authorize_window(window.label())?; | ||
| #[cfg(any(windows, target_os = "macos"))] | ||
| #[cfg(any(windows, target_os = "macos", target_os = "linux"))] |
There was a problem hiding this comment.
[P2] Linux 上已经暴露了本机诊断 IPC,但 desktop/README.md 与 README.zh.md 没有登记 Linux 的注册路径
本行让 Linux 构建也走 LocalDiagnostics,注册文件位置由 lib.rs 的 DiagnosticHost::new(app.path().app_data_dir().ok()) 决定(diagnostic-cli.json)。而 desktop/README.md 的 “Local CLI diagnostics” 只给了 Windows 的 %APPDATA%/com.powercontext.desktop.preview/diagnostic-cli.json,macOS 段落只给了 ~/Library/Application Support/com.powercontext.desktop.preview/,两侧都没有 XDG 下的对应位置,也没有说明 Linux 同样要求:文件名必须是 powercontext、路径必须绝对、sha256 为 64 位、source 必须为 explicit_local_installation。
实际影响:在 deb 预览包里打开 Settings → 本机诊断时,因为 execute() 打开注册文件失败直接返回 SafeError::NotFound,用户既拿不到诊断结果,也无从知道要往哪里放这个 JSON——Windows 与 macOS 都已经写明路径,只有新开的 Linux 没有。
建议在 desktop/README.md:131-147 的 “Local CLI diagnostics” 与 desktop/README.zh.md 同步补一段 Linux 说明(注册路径按 app_data_dir() 的 XDG 解析给出,并说明 helpers 在私有进程组中运行、超时与输出上限与另两个平台相同)。desktop/README.md:147 现在只写了 “Helpers run hidden in an owned Windows Job”,对 POSIX 两个平台都不成立。
There was a problem hiding this comment.
[P2 已闭合] 两份 README 都补了 Linux 注册路径
desktop/README.md 与 desktop/README.zh.md 的诊断注册小节各自新增一段,写清 $XDG_DATA_HOME/com.powercontext.desktop.preview/diagnostic-cli.json、XDG_DATA_HOME 未设置时回落到 ~/.local/share/com.powercontext.desktop.preview/diagnostic-cli.json,以及可执行文件名是 powercontext(不是 powercontext.exe)、source 必须是 explicit_local_installation。两份语言版本同步落地,NotFound 的排查路径现在可循。
There was a problem hiding this comment.
Thanks for pointing out the missing Linux documentation.
Fixed in commit 275e17a. Both desktop/README.md and desktop/README.zh.md now document the Linux registration path:
$XDG_DATA_HOME/com.powercontext.desktop.preview/diagnostic-cli.json
They also document the fallback path when XDG_DATA_HOME is unset, the required powercontext executable name, the absolute-path and SHA-256 requirements, source:"explicit_local_installation", and the Linux/macOS private process-group cleanup behavior.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed 275e17a. One correctness issue remains in the newly enabled Linux integrations diagnostics; see the inline reproduction. The real CLI output and the unchanged Rust projector were exercised independently. This was not installed Kimi host or packaged Desktop acceptance.
| ) -> Result<crate::diagnostics::DiagnosticReport, SafeError> { | ||
| authorize_window(window.label())?; | ||
| #[cfg(any(windows, target_os = "macos"))] | ||
| #[cfg(any(windows, target_os = "macos", target_os = "linux"))] |
There was a problem hiding this comment.
[P2] Accept configured Kimi diagnostics before enabling the Linux path
With a configured Kimi plugin, the current CLI emits hosts["kimi-code"].checks.profile (cli/kimi_code.py:384), but the shared diagnostics::project allowlist rejects that field. I reproduced the fixed ten-host doctor command at this head using an isolated home with the tracked plugin and its configuration: it returned valid exit-1 JSON, but project(Integrations, stdout, 1) returned InvalidResponse. Removing only profile made the same ten-host report project successfully. Thus the newly enabled Linux integrations check loses the entire report for this ordinary configuration. The new real-CLI fixture uses an empty home and misses this branch. Align the safe projection vocabulary with the current CLI and cover a configured plugin in acceptance. The projector is shared with Windows/macOS, so the same fix should apply there too.
There was a problem hiding this comment.
Thanks for the detailed reproduction.
Addressed in the latest commit.
- Added
profileto the diagnostics projector’s allowlisted check fields. - Added a Rust regression test covering a configured
kimi-codehost with aprofilecheck. - Updated the real CLI acceptance fixture to create an isolated Kimi installation with the tracked plugin and
fullprofile. - Added an assertion in
diagnostic_cli_probethat the configured Kimiprofilecheck survives projection. - Preserved the existing strict Windows assertions.
The shared projector is used by Windows, macOS, and Linux, so the fix applies consistently across all supported platforms.
knqiufan
left a comment
There was a problem hiding this comment.
Reviewed ee34988. Please address the bounded-registration/shutdown failure and the Linux acceptance flag described inline. The FIFO failure was reproduced through the shared Unix implementation on macOS; the Linux artifact was inspected separately.
| #[cfg(windows)] | ||
| use std::os::windows::fs::OpenOptionsExt; | ||
| use std::{io::Read, time::Duration}; | ||
| let file = std::fs::File::open(registration).map_err(|_| SafeError::NotFound)?; |
There was a problem hiding this comment.
[P2] Reject non-regular registration files without blocking shutdown
The executable FIFO is now rejected, but a FIFO at the documented app-data diagnostic-cli.json path blocks this earlier File::open before parsing, executable verification, or any subprocess deadline. The 16 KiB read cap does not bound this wait. Aborting the caller cannot release the worker, so LocalDiagnostics::shutdown() keeps waiting for completion. I reproduced this through the public interface on the shared Unix implementation on macOS: after cancellation, shutdown still did not return at an external 3-second timeout; the newly enabled Linux path uses the same call. Apply bounded, non-blocking file-type validation to the registration read too, and cover this distinct invalid-input case.
There was a problem hiding this comment.
Thanks for catching this additional issue.
Fixed the registration-file path as well: it now validates that diagnostic-cli.json is a regular file before opening, uses O_NONBLOCK on Unix, and performs a second file-type check after opening to cover replacement races.
FIFO and other non-regular registration files now return CompatibilityUnverified without blocking diagnostic execution or LocalDiagnostics::shutdown(). I also added a regression test covering this case.
hidb4ai
left a comment
There was a problem hiding this comment.
Re-reviewed the Linux diagnostics changes and replayed the configured Kimi output that previously failed projection. The profile check now survives the safe projection, and the FIFO registration and executable regression tests pass. No new database tables or API/IPC commands are introduced.
Which issue or RFC does this PR close?
Related to #2110
This PR implements the 08-B Linux diagnostics workstream. It does not close #2110 because the issue also contains the separate 08-E workstream.
Rationale for this change
Linux Desktop needs a safe way to run the registered PowerContext CLI for local service and integration diagnostics.
The diagnostic process must not allow arbitrary renderer commands, arbitrary executable paths, or unbounded child processes. Linux should reuse the reviewed native diagnostics and process-management boundaries while preserving the existing Windows and macOS behavior.
What changes are included in this PR?
local_diagnosticsIPC command on Linux.serviceandintegrationsoperations.fetch_updateAPI withtry_updateindesktop/src-tauri/src/session_observations.rs. This is a maintenance-only compatibility fix with no behavior change; it is unrelated to the Linux diagnostics implementation and removes a warning from the current Rust toolchain.Are there any user-facing changes?
Yes.
On supported Linux Desktop environments, users can run the fixed local service and integration diagnostics through the trusted Desktop UI.
Diagnostic failures are returned as structured safe results. Missing or unavailable local tools do not expose raw process output and do not disable remote Server operations.
No public Server API or persisted data format is changed.
The
fetch_updatetotry_updatechange is internal only and has no user-facing behavior change.How was this change tested?
Local validation on Ubuntu 24.04:
cargo test --locked --manifest-path desktop/src-tauri/Cargo.tomlcargo clippy --locked --manifest-path desktop/src-tauri/Cargo.toml --all-targets -- -D warningscargo fmt --manifest-path desktop/src-tauri/Cargo.toml --checkpnpm --dir desktop lintpnpm --dir desktop typecheckpnpm --dir desktop testpnpm --dir desktop buildgit diff --checkpassed.Fork CI validation:
The Main workflow's unrelated upgrade-artifact matrix job failed at
Freeze distributions and resolve the source matrix once; the downstream Upgrade release gate failed as a consequence. The Desktop validation workflow passed on all four platforms.AI usage statement
This PR was developed with OpenAI Codex powered by GPT-5. The generated changes were reviewed, tested locally on Ubuntu 24.04, and validated through the fork's GitHub Actions workflows.