Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test: match CLI DPI settings in Windows discovery regression

Richie McIlroy93a178270806
diff --git a/.github/workflows/windows-targets.yml b/.github/workflows/windows-targets.yml
index f90d70fa2..490e808b2 100644
--- a/.github/workflows/windows-targets.yml
+++ b/.github/workflows/windows-targets.yml
@@ -25,12 +25,31 @@ jobs:
runs-on: windows-2022
timeout-minutes: 20
steps:
- - uses: actions/checkout@v4
- - uses: dtolnay/[email protected]
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
+ - uses: dtolnay/rust-toolchain@688313b0823df1393bcebb1b4add0438a6d36884
with:
components: clippy
- uses: ./.github/actions/setup-rust-cache
with:
target: x86_64-pc-windows-msvc
- run: cargo test --locked -p scap-targets --lib --test windows_targets -- --nocapture
+ - name: Compare discovery against the PR base
+ if: github.event_name == 'pull_request'
+ shell: pwsh
+ env:
+ BASE_SHA: ${{ github.event.pull_request.base.sha }}
+ run: |
+ $source = "crates/scap-targets/src/platform/win.rs"
+ $patchedSource = [System.IO.File]::ReadAllBytes($source)
+ try {
+ $baseline = git show "$($env:BASE_SHA):$source"
+ if ($LASTEXITCODE -ne 0) { throw "Could not load base Windows implementation" }
+ $baseline | Set-Content -Encoding utf8 $source
+ cargo test --locked -p scap-targets --test windows_targets -- --nocapture
+ $baselineExit = $LASTEXITCODE
+ "Base implementation discovery test exit code: $baselineExit (0 means this fixture already passed on the base)." | Add-Content $env:GITHUB_STEP_SUMMARY
+ } finally {
+ [System.IO.File]::WriteAllBytes($source, $patchedSource)
+ }
+ exit 0
- run: cargo clippy --locked -p scap-targets --all-targets -- -D warnings
diff --git a/crates/scap-targets/tests/windows_targets.rs b/crates/scap-targets/tests/windows_targets.rs
index 6ceebf3f4..79f260cba 100644
--- a/crates/scap-targets/tests/windows_targets.rs
+++ b/crates/scap-targets/tests/windows_targets.rs
@@ -10,10 +10,13 @@ use std::{
use windows::{
Win32::{
Foundation::HWND,
- UI::WindowsAndMessaging::{
- CreateWindowExW, DestroyWindow, DispatchMessageW, MSG, PM_REMOVE, PeekMessageW,
- SW_MINIMIZE, ShowWindow, TranslateMessage, WINDOW_EX_STYLE, WINDOW_STYLE, WS_CHILD,
- WS_EX_TOOLWINDOW, WS_OVERLAPPEDWINDOW, WS_POPUP, WS_VISIBLE,
+ UI::{
+ HiDpi::{PROCESS_PER_MONITOR_DPI_AWARE, SetProcessDpiAwareness},
+ WindowsAndMessaging::{
+ CreateWindowExW, DestroyWindow, DispatchMessageW, MSG, PM_REMOVE, PeekMessageW,
+ SW_MINIMIZE, ShowWindow, TranslateMessage, WINDOW_EX_STYLE, WINDOW_STYLE, WS_CHILD,
+ WS_EX_TOOLWINDOW, WS_OVERLAPPEDWINDOW, WS_POPUP, WS_VISIBLE,
+ },
},
},
core::w,
@@ -68,6 +71,9 @@ fn window_fixture_process() {
return;
}
+ unsafe { SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE) }
+ .expect("match CLI per-monitor DPI awareness");
+
let normal = TestWindow::new(WS_OVERLAPPEDWINDOW | WS_VISIBLE, WINDOW_EX_STYLE(0), None);
let popup = TestWindow::new(WS_POPUP | WS_VISIBLE, WINDOW_EX_STYLE(0), Some(normal.0));
let hidden = TestWindow::new(WS_OVERLAPPEDWINDOW, WINDOW_EX_STYLE(0), None);
@@ -105,6 +111,8 @@ fn window_fixture_process() {
#[test]
fn discovers_foreign_top_level_windows_and_preserves_target_filters() {
+ unsafe { SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE) }
+ .expect("match CLI per-monitor DPI awareness");
let mut fixture = FixtureProcess(
Command::new(std::env::current_exe().unwrap())
.args(["--exact", "window_fixture_process", "--nocapture"])