Skip to content

fix(cli): attach parent console on Windows so CLI output appears (#364) - #367

Merged
drmowinckels merged 1 commit into
mainfrom
fix/issue-364-windows-cli-console
Oct 5, 2026
Merged

drmowinckels merged 1 commit into
mainfrom
fix/issue-364-windows-cli-console

Conversation

@drmowinckels

Copy link
Copy Markdown
Owner

@drmowinckels — for review, not auto-merged (nightly triage opens issue PRs OPEN for a human).

Closes #364

Root cause

The release Windows binary is built with windows_subsystem = "windows" (src-tauri/src/main.rs:2) so the tray app doesn't flash a console. The side effect is that the process never attaches to the console it was invoked from, so every CLI code path — help, status/profile/settings, log, and the eprintln! argument-error path — writes to a closed handle and prints nothing. It was latent until Scoop packaging (#359) first put entracte on PATH.

What changed

  • cli.rs — extracted the argv dispatch that lived inline in main.rs into a pure cli::classify(argv) -> Invocation, with Invocation::produces_console_output() marking the paths that print (everything except the tray-app fall-through). Behaviour mirrors the old dispatch exactly (help/log recognised ahead of the parser; locally-runnable commands via IPC; parse errors print + exit 2; otherwise launch the app).
  • cli.rs — added #[cfg(windows)] attach_parent_console(), a thin AttachConsole(ATTACH_PARENT_PROCESS) wrapper. Per .github/AGENTS.md the pure decision is unit-tested on every OS and only the FFI line is uncovered (the sanctioned OS-FFI patch-coverage bypass).
  • main.rs — calls classify, then on Windows only attaches the console when produces_console_output() — never on Invocation::LaunchApp, so launching from Explorer still shows no console window.
  • Cargo.toml — added the Win32_System_Console feature to the already-present Windows-only windows-sys dependency (where AttachConsole/ATTACH_PARENT_PROCESS live).

Tests (ship with the code, same PR)

New un-gated tests in cli.rs covering every Invocation variant and both produces_console_output() outcomes:

  • classify_help_variants_are_help_and_print — help/-h/--help → Invocation::Help, prints.
  • classify_log_is_log_and_prints — log → Invocation::Log, prints.
  • classify_local_command_prints — status → Invocation::Local(Status), prints.
  • classify_quick_flags_are_local_and_print — --profile= → Invocation::Local(Quick), prints.
  • classify_parse_error_still_prints — unknown command → Invocation::ParseError, prints.
  • classify_no_command_launches_app_without_console — no args → Invocation::LaunchApp, does not attach a console (the guard that stops the Explorer-launch console flash).

Verification

Ran locally on Linux:

  • cargo fmt --check ✅
  • cargo clippy --all-targets -- -D warnings ✅
  • cargo test --lib — all cli tests pass (30/30, incl. the 6 new). The only suite failure is scheduler::commands::backup::tests::commit_stage_surfaces_metadata_error, which is unrelated to this change: it chmod 0o000s a dir and expects PermissionDenied, but this sandbox runs as root, which bypasses permission bits. It passes on CI's non-root runners.

Not verifiable from this Linux environment, left to CI / your check:

  • The Windows half (attach_parent_console + the windows-sys feature) only compiles on the Windows CI matrix leg — the same as all existing windows-sys FFI in this repo, none of which compiles on the Ubuntu leg. The feature name and AttachConsole/ATTACH_PARENT_PROCESS signatures were checked against the vendored windows-sys 0.59 source.
  • The runtime behaviour (output actually reaching the shell on Windows; no console flash on Explorer launch) is reasoned, not exercised here — worth a manual check on a Windows build before merge.
  • knip/cspell were N/A: this is a Rust-only diff, knip analyses TS, and cspell's glob is md,ts,tsx (not .rs), so neither result can change.

Residual risk / notes

🤖 Generated with Claude Code

https://claude.ai/code/session_0192uQGtxemm5efjCrjZs6Tn


Generated by Claude Code

The release Windows binary is built with `windows_subsystem = "windows"`,
which stops a console flashing on tray launch but also leaves the process
with no console attached — so every CLI path (`help`, `status`, `log`,
argument errors) wrote to a closed handle and printed nothing. Latent until
Scoop packaging (#359) first put `entracte` on PATH.

Extract the argv dispatch out of `main.rs` into a pure `cli::classify`
returning an `Invocation` enum, with `produces_console_output()` marking the
printing paths. On Windows only, attach to the parent console via
`AttachConsole(ATTACH_PARENT_PROCESS)` before those paths run, never on the
tray-app fall-through (that would flash a console on Explorer launch).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0192uQGtxemm5efjCrjZs6Tn
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🔍 Advisory audit report

These checks don't block merges — they surface drift in dependencies, licensing, and external links.

cargo-deny

✅ clean (advisories, bans, licenses, sources)

lychee (broken links)

✅ all links resolve

npm audit

✅ no high-severity vulnerabilities

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.72%. Comparing base (a941fe2) to head (c2f9bb5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #367      +/-   ##
==========================================
+ Coverage   89.69%   89.72%   +0.02%     
==========================================
  Files         147      147              
  Lines       25495    25542      +47     
  Branches      861      861              
==========================================
+ Hits        22868    22917      +49     
+ Misses       2601     2599       -2     
  Partials       26       26              
Flag Coverage Δ
frontend 90.39% <ø> (ø)
rust 89.64% <100.00%> (+0.02%) ⬆️
Components Coverage Δ
Frontend (TypeScript) 90.39% <ø> (ø)
Backend (Rust) 89.64% <100.00%> (+0.02%) ⬆️
Files with missing lines Coverage Δ
src-tauri/src/cli.rs 74.14% <100.00%> (+3.16%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

✅ Built and deployed for commit c2f9bb5ee0e825568a9f5cf08d8327914d43c40f.

Preview URL https://pr-367--entract.netlify.app
Build logs https://github.com/drmowinckels/entracte/actions/runs/36955902473

Posted by docs-preview.yml — updates in place on every push.

@drmowinckels
drmowinckels merged commit 8aa2864 into main Oct 5, 2026
12 checks passed
@drmowinckels
drmowinckels deleted the fix/issue-364-windows-cli-console branch October 5, 2026 07:35
drmowinckels added a commit that referenced this pull request Oct 5, 2026
#367 fixed `entracte help` / `status` printing into a closed handle on
Windows but shipped without a changelog entry, and #361's Scoop entry
had been carrying the caveat that those commands were still silent —
which that fix made untrue. Removing the stale caveat left the fix
undocumented, so record it on its own.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Windows CLI prints nothing: the GUI-subsystem binary never attaches to the console

2 participants