Skip to content

fix(media): add USB size and cache space safeguards#167

Merged
mchave3 merged 1 commit into
mainfrom
feat/usb-os-cache-safety
May 15, 2026
Merged

fix(media): add USB size and cache space safeguards#167
mchave3 merged 1 commit into
mainfrom
feat/usb-os-cache-safety

Conversation

@mchave3
Copy link
Copy Markdown
Collaborator

@mchave3 mchave3 commented May 15, 2026

Summary

Add USB media safety checks and deployment cache fallback behavior.

Reason

Foundry OSD should prevent creating boot media on USB keys smaller than 16 GB while still making the selected device and reason visible to the user. Foundry Deploy should avoid failing deployment downloads when the USB cache does not have enough free space.

Main changes

  • Keep small USB keys visible in Foundry OSD, but mark the USB target readiness row as a warning and block USB creation below 16 GB.
  • Add a final destructive-operation guard before USB formatting.
  • Fall back from USB cache to the target Windows partition cache for OS images and OEM driver packs when the USB cache has insufficient free space.
  • Add regression tests for OSD preflight/USB validation and Deploy payload cache fallback.

Testing notes

  • git diff --check
  • dotnet test src\Foundry.Core.Tests\Foundry.Core.Tests.csproj --no-restore -m:1 -nr:false (180 passed)
  • dotnet test src\Foundry.Deploy.Tests\Foundry.Deploy.Tests.csproj --no-restore -m:1 -nr:false (108 passed)
  • dotnet build src\Foundry\Foundry.csproj --no-restore -m:1 -nr:false (0 warnings, 0 errors)

@github-actions github-actions Bot added tests Test coverage or test infrastructure change ui User interface or XAML changes project: foundry Changes in the Foundry desktop application project: foundry-deploy Changes in the Foundry.Deploy deployment application project: foundry-core Changes in the Foundry.Core shared business logic library labels May 15, 2026
@mchave3 mchave3 self-assigned this May 15, 2026
@mchave3 mchave3 marked this pull request as ready for review May 15, 2026 23:39
Copilot AI review requested due to automatic review settings May 15, 2026 23:39
@mchave3 mchave3 merged commit a6ae18a into main May 15, 2026
9 checks passed
@mchave3 mchave3 deleted the feat/usb-os-cache-safety branch May 15, 2026 23:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds safety checks around USB boot media creation (minimum supported USB size) and improves deployment robustness by falling back to the target disk cache when the USB cache partition lacks free space, while adding regression coverage for both behaviors.

Changes:

  • OSD: Introduce a minimum USB disk size (16 GiB) as a blocking reason for USB creation while keeping the device visible in readiness UI.
  • Core: Add a final disk-safety guard in WinPeUsbMediaService to refuse targets below the minimum size.
  • Deploy: Add size-aware cache-root resolution that can fall back from USB cache to target cache; add tests covering fallback behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Foundry/ViewModels/StartMediaViewModel.cs Updates USB readiness row to show warning state/message when selected USB is below minimum size.
src/Foundry/Strings/fr-FR/Resources.resw Adds localized text for the new blocking reason.
src/Foundry/Strings/en-US/Resources.resw Adds localized text for the new blocking reason.
src/Foundry.Deploy/Services/Deployment/Steps/DownloadOperatingSystemImageStep.cs Uses size-aware cache-root resolution for OS image download.
src/Foundry.Deploy/Services/Deployment/Steps/DownloadDriverPackStep.cs Uses size-aware cache-root resolution for driver pack download.
src/Foundry.Deploy/Services/Deployment/DeploymentStepExecutionContext.cs Adds payload cache root fallback logic based on available free space.
src/Foundry.Deploy.Tests/DeploymentPayloadCacheFallbackTests.cs Adds tests validating USB-cache-to-target-cache fallback for OS/driver pack downloads.
src/Foundry.Core/Services/WinPe/WinPeUsbMediaService.cs Adds minimum USB size constant + disk safety validation guard.
src/Foundry.Core/Services/Media/MediaPreflightService.cs Adds preflight blocking reason for USB targets below minimum size.
src/Foundry.Core/Services/Media/MediaPreflightBlockingReason.cs Adds UsbTargetBelowMinimumSize enum value.
src/Foundry.Core.Tests/WinPe/WinPeUsbMediaServiceTests.cs Adds/adjusts tests for the new minimum-size disk safety validation.
src/Foundry.Core.Tests/Media/MediaPreflightServiceTests.cs Adds coverage ensuring small USB blocks USB creation but not ISO.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1406 to 1409
string description = isBelowMinimumSize
? GetBlockingReasonText(MediaPreflightBlockingReason.UsbTargetBelowMinimumSize)
: state == StartReadinessState.Ready
? FormatUsbCandidate(options.SelectedUsbDisk)
Comment on lines 20 to 24
protected override async Task<DeploymentStepResult> ExecuteLiveAsync(DeploymentStepExecutionContext context, CancellationToken cancellationToken)
{
string osDirectory = context.ResolveOperatingSystemCacheRoot();
string osDirectory = context.ResolveOperatingSystemCacheRoot(context.Request.OperatingSystem.SizeBytes);
Directory.CreateDirectory(osDirectory);
const string stepMessage = "Downloading OS image...";
Comment on lines 81 to 85
string driverPackDirectory = Path.Combine(
context.ResolveDriverPackCacheRoot(),
context.ResolveDriverPackCacheRoot(driverPack.SizeBytes),
DeploymentStepExecutionContext.SanitizePathSegment(driverPack.Manufacturer));
Directory.CreateDirectory(driverPackDirectory);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

project: foundry Changes in the Foundry desktop application project: foundry-core Changes in the Foundry.Core shared business logic library project: foundry-deploy Changes in the Foundry.Deploy deployment application tests Test coverage or test infrastructure change ui User interface or XAML changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants