From ec1cd6250f809ce40e6bf6938a6d422ad90d27de Mon Sep 17 00:00:00 2001 From: NitroDiesel <228459919+NitroDiesel@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:55:04 +0800 Subject: [PATCH 1/2] Add an opt-in engine test run for one disposable USB drive The elevated engine and worker-pipe tests refused everything but virtual disks. They now also accept a removable USB drive whose exact serial is named in RUFUST_TEST_USB_SERIAL, and scripts/windows/usb-tests.ps1 checks the disk number, bus, and serial, runs them, and leaves the stick as FAT32. Not yet run on physical media. Co-Authored-By: Claude --- apps/rufust/src/helper_client/windows.rs | 12 ++- crates/rufust-helper/src/windows/vhd_tests.rs | 21 ++++- docs/WINDOWS.md | 6 ++ scripts/windows/usb-tests.ps1 | 80 +++++++++++++++++++ 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 scripts/windows/usb-tests.ps1 diff --git a/apps/rufust/src/helper_client/windows.rs b/apps/rufust/src/helper_client/windows.rs index 8fb73c5..2c980dd 100644 --- a/apps/rufust/src/helper_client/windows.rs +++ b/apps/rufust/src/helper_client/windows.rs @@ -375,7 +375,17 @@ mod tests { .into_iter() .find(|device| device.minor == number) .expect("the disk is attached"); - assert_eq!(identity.transport, "loop", "refusing a non-virtual disk"); + // A virtual disk, or the one removable USB drive named by serial + // (`scripts/windows/usb-tests.ps1`). + let named = std::env::var("RUFUST_TEST_USB_SERIAL").unwrap_or_default(); + assert!( + identity.transport == "loop" + || (identity.transport == "usb" + && identity.removable + && !identity.serial.is_empty() + && identity.serial == named), + "refusing a disk that is neither virtual nor the named USB drive" + ); let block = platform::to_block_device(&identity, &platform::volumes()); Some(HelperRequest { protocol_version: PROTOCOL_VERSION, diff --git a/crates/rufust-helper/src/windows/vhd_tests.rs b/crates/rufust-helper/src/windows/vhd_tests.rs index c52ded1..4d66f80 100644 --- a/crates/rufust-helper/src/windows/vhd_tests.rs +++ b/crates/rufust-helper/src/windows/vhd_tests.rs @@ -38,13 +38,28 @@ fn target(variable: &str) -> Option { .into_iter() .find(|device| device.minor == number) .expect("the disk is attached"); - assert_eq!( - identity.transport, "loop", - "refusing disk {number}: it is not a file-backed virtual disk" + assert!( + disposable(&identity), + "refusing disk {number}: it is neither a file-backed virtual disk nor the \ + removable USB drive whose serial is in RUFUST_TEST_USB_SERIAL" ); Some(identity) } +/// Virtual disks are always fair game. A physical disk qualifies only as a +/// removable USB drive whose exact serial the caller named, which is how +/// `scripts/windows/usb-tests.ps1` opts one disposable stick in. +fn disposable(identity: &DeviceIdentity) -> bool { + if identity.transport == "loop" { + return true; + } + let named = std::env::var("RUFUST_TEST_USB_SERIAL").unwrap_or_default(); + identity.transport == "usb" + && identity.removable + && !identity.serial.is_empty() + && identity.serial == named +} + fn request(identity: &DeviceIdentity, operation: HelperOperation) -> HelperRequest { let block = platform::to_block_device(identity, &platform::volumes()); HelperRequest { diff --git a/docs/WINDOWS.md b/docs/WINDOWS.md index d21453c..170148b 100644 --- a/docs/WINDOWS.md +++ b/docs/WINDOWS.md @@ -131,6 +131,12 @@ UEFI:NTFS, GPT UEFI, FAT32) from a synthetic ISO, run large FAT32 on a sparse 40 GiB disk, and drive the window's pipe launcher through a format and a cancellation. CI runs them on every push. +`scripts\windows\usb-tests.ps1 -DiskNumber N -Serial S` runs the same tests on +one disposable USB flash drive and erases it. The script and the tests refuse +any physical disk that is not a removable USB drive with exactly that serial +(`RUFUST_TEST_USB_SERIAL`). It has not been run on physical media yet; the +smoke-test gate below stays open until it has. + ## Packaging The release workflow builds two downloads: diff --git a/scripts/windows/usb-tests.ps1 b/scripts/windows/usb-tests.ps1 new file mode 100644 index 0000000..9f5b54a --- /dev/null +++ b/scripts/windows/usb-tests.ps1 @@ -0,0 +1,80 @@ +# End-to-end tests of the Windows disk engine on one disposable USB stick. +# +# EVERYTHING ON THE DRIVE IS DESTROYED. Run from an elevated PowerShell at the +# repository root, naming the drive by disk number and by serial: +# +# Get-Disk | Select-Object Number, FriendlyName, BusType, SerialNumber +# powershell -ExecutionPolicy Bypass -File scripts\windows\usb-tests.ps1 ` +# -DiskNumber 2 -Serial 000AEBFFD790BA60C30C0600 +# +# The script and the tests both refuse a disk that is not a removable USB +# drive with exactly that serial. It runs the `windows::vhd_tests` engine +# tests (every file system provider, raw/gzip/VHDX image writes with +# read-back, Windows installer media) and the desktop's worker-pipe tests +# (format and cancellation), then leaves the stick as one FAT32 volume. +# Drives over 32 GiB also run the large FAT32 test. + +param( + [Parameter(Mandatory = $true)] [int] $DiskNumber, + [Parameter(Mandatory = $true)] [string] $Serial, + [string] $Log +) + +$ErrorActionPreference = 'Stop' +if ($Log) { Start-Transcript -Path $Log -Force | Out-Null } + +try { + $principal = New-Object Security.Principal.WindowsPrincipal( + [Security.Principal.WindowsIdentity]::GetCurrent()) + if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + throw 'Run this script from an elevated (administrator) PowerShell.' + } + + $disk = Get-Disk -Number $DiskNumber + if ($disk.BusType -ne 'USB') { throw "Disk $DiskNumber is $($disk.BusType), not USB." } + if ($disk.SerialNumber.Trim() -ne $Serial) { + throw "Disk $DiskNumber has serial '$($disk.SerialNumber.Trim())', not '$Serial'." + } + if ($disk.IsBoot -or $disk.IsSystem) { throw "Disk $DiskNumber is a boot or system disk." } + Write-Host "Erasing and testing disk ${DiskNumber}: $($disk.FriendlyName), $([math]::Round($disk.Size / 1GB, 1)) GB" + + $work = Join-Path ([IO.Path]::GetTempPath()) ("rufust-usb-" + [Guid]::NewGuid()) + New-Item -ItemType Directory -Path $work | Out-Null + $source = Join-Path $work 'source.vhdx' + $script = Join-Path $work 'diskpart.txt' + Set-Content -Path $script -Encoding ascii -Value "create vdisk file=`"$source`" maximum=16 type=fixed" + $output = & diskpart.exe /s $script + if ($LASTEXITCODE -ne 0) { throw "diskpart failed:`n$($output -join "`n")" } + + $env:RUFUST_TEST_USB_SERIAL = $Serial + $env:RUFUST_TEST_DISK = "$DiskNumber" + $env:RUFUST_TEST_VHD_SOURCE = $source + if ($disk.Size -gt 33GB) { $env:RUFUST_TEST_LARGE_DISK = "$DiskNumber" } + + cargo build -p rufust-helper --locked + if ($LASTEXITCODE -ne 0) { throw 'build failed' } + cargo test -p rufust-helper --locked windows::vhd_tests -- --ignored --test-threads=1 + if ($LASTEXITCODE -ne 0) { throw 'engine tests failed on the USB drive' } + cargo test -p rufust --locked -- --ignored --test-threads=1 helper_client::windows::tests + if ($LASTEXITCODE -ne 0) { throw 'worker pipe tests failed on the USB drive' } + + # Leave the stick usable. + Clear-Disk -Number $DiskNumber -RemoveData -RemoveOEM -Confirm:$false + $style = (Get-Disk -Number $DiskNumber).PartitionStyle + if ($style -eq 'RAW') { Initialize-Disk -Number $DiskNumber -PartitionStyle MBR } + $size = [math]::Min((Get-Disk -Number $DiskNumber).LargestFreeExtent, 32GB - 1MB) + New-Partition -DiskNumber $DiskNumber -Size $size -AssignDriveLetter | + Format-Volume -FileSystem FAT32 -NewFileSystemLabel 'RUFUST' -Confirm:$false | Out-Null + Write-Host 'USB TESTS PASSED' +} +catch { + Write-Host "USB TESTS FAILED: $_" + throw +} +finally { + if ($work) { Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue } + foreach ($name in 'RUFUST_TEST_USB_SERIAL', 'RUFUST_TEST_DISK', 'RUFUST_TEST_VHD_SOURCE', 'RUFUST_TEST_LARGE_DISK') { + Remove-Item "Env:\$name" -ErrorAction SilentlyContinue + } + if ($Log) { Stop-Transcript | Out-Null } +} From 465b39dc4fff7f4e35c3a62cd26d9c2fe35b5cc1 Mon Sep 17 00:00:00 2001 From: NitroDiesel <228459919+NitroDiesel@users.noreply.github.com> Date: Sat, 14 Nov 2026 13:40:05 +0800 Subject: [PATCH 2/2] Record the first engine test run on a physical USB drive scripts/windows/usb-tests.ps1 passed on a 16 GB Kingston DataTraveler 101 G2 under Windows 11, with the shared engine loops merged in locally. Co-Authored-By: Claude --- docs/PROJECT_CONTEXT.md | 7 ++++--- docs/WINDOWS.md | 15 ++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/PROJECT_CONTEXT.md b/docs/PROJECT_CONTEXT.md index 1da8bf8..a4ca22b 100644 --- a/docs/PROJECT_CONTEXT.md +++ b/docs/PROJECT_CONTEXT.md @@ -317,9 +317,10 @@ included in 0.1.3. These are known follow-ups, not claims that the current release is broken: -- Windows: smoke-test on disposable physical USB media (flash drive and USB - SSD), boot-test Windows-built media, and Authenticode-sign the executable - and installer. See `WINDOWS.md`. +- Windows: the engine tests passed on a physical USB flash drive + (`scripts/windows/usb-tests.ps1`). Still open: a USB SSD and a drive over + 32 GB, unplugging during a write, boot-testing Windows-built media, and + Authenticode-signing the executable and installer. See `WINDOWS.md`. - Run a packaged, real-polkit smoke test on disposable physical USB media for formatting, raw writing, Windows media, verification, cancellation, and disconnect during write. Automated tests, loop-backed udisks2 tests, and diff --git a/docs/WINDOWS.md b/docs/WINDOWS.md index 170148b..6350d88 100644 --- a/docs/WINDOWS.md +++ b/docs/WINDOWS.md @@ -134,8 +134,12 @@ cancellation. CI runs them on every push. `scripts\windows\usb-tests.ps1 -DiskNumber N -Serial S` runs the same tests on one disposable USB flash drive and erases it. The script and the tests refuse any physical disk that is not a removable USB drive with exactly that serial -(`RUFUST_TEST_USB_SERIAL`). It has not been run on physical media yet; the -smoke-test gate below stays open until it has. +(`RUFUST_TEST_USB_SERIAL`). It passed on 2026-11-14 on a 16 GB Kingston +DataTraveler 101 G2 (USB 2.0 flash drive) under Windows 11: every file system +provider, raw, gzip, and VHDX image writes with read-back, Windows installer +media in all three layouts, and a format and a cancelled bad-block test +through the worker pipes. The drive is under 32 GB, so large FAT32 did not +run on it. ## Packaging @@ -160,9 +164,10 @@ Authenticode-signed yet, so SmartScreen may warn on first launch. ## Open gates -- A smoke test on disposable physical USB media (flash drive and USB SSD): - format, image write, Windows media, verification, cancellation, and - unplugging during a write. Virtual disks do not replace it. +- The rest of the physical-media smoke test: a USB SSD or hard disk, a drive + over 32 GB (large FAT32), a full bad-block pass, and unplugging during a + write. The flash-drive run above covers format, image write, Windows media, + verification, and cancellation. - Boot tests of Windows-built media in QEMU/OVMF and on hardware. - Authenticode signing of release executables and the installer. - ext2/3/4 and ReFS creation, drive capture, and the other features blocked