From fdf6a2f0c21de3e1525eb5466fe13e4786b0c65e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 17:53:05 +0000 Subject: [PATCH 1/7] =?UTF-8?q?Fix=20spelling=20errors:=20ISO=5FLable=20?= =?UTF-8?q?=E2=86=92=20ISO=5FLabel=20and=20other=20typos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Flickdm <8979761+Flickdm@users.noreply.github.com> --- scripts/windows/Make2023BootableMedia.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/windows/Make2023BootableMedia.ps1 b/scripts/windows/Make2023BootableMedia.ps1 index ba1fb19..2b513a6 100644 --- a/scripts/windows/Make2023BootableMedia.ps1 +++ b/scripts/windows/Make2023BootableMedia.ps1 @@ -73,7 +73,7 @@ function Show-Usage { } function Show-ADK-Req { - Write-Host "This script requires the Windows ADK be installed on the system. Avalable at http://aka.ms/adk" -ForegroundColor Red + Write-Host "This script requires the Windows ADK be installed on the system. Available at http://aka.ms/adk" -ForegroundColor Red Write-Host "After install, open an admin-elevated 'Deploy and Imaging Tools Environment' command prompt provided with the ADK." -ForegroundColor Red Write-Host "Then run PowerShell from this command prompt and you should be good to go.`r`n" -ForegroundColor Red } @@ -227,7 +227,7 @@ function Initialize-MediaPaths { $localMediaPath = ($mountResult | Get-Volume).DriveLetter + ":" # Retrieve the volume label from the mounted ISO to be used later if a new ISO is created - $global:ISO_Lable = (Get-Volume -DriveLetter ($mountResult | Get-Volume).DriveLetter).FileSystemLabel + $global:ISO_Label = (Get-Volume -DriveLetter ($mountResult | Get-Volume).DriveLetter).FileSystemLabel } else { @@ -714,15 +714,15 @@ function Create-ISOMedia { Write-Host "Writing 'Windows UEFI CA 2023' bootable ISO media at location [$ISOPath]" -ForegroundColor Blue - # If $ISOLable is not set, then defualt to "WINDOWS2023PCAISO" - if (-not $global:ISO_Lable) { - $global:ISO_Lable = "WINDOWS2023PCAISO" + # If $ISOLabel is not set, then default to "WINDOWS2023PCAISO" + if (-not $global:ISO_Label) { + $global:ISO_Label = "WINDOWS2023PCAISO" } # Generate a timestamp string in the following format: mm/dd/yyyy,hh:mm:ss $timestamp = Get-Date -Format "MM/dd/yyyy,HH:mm:ss" - $runCommand = "-l$global:ISO_Lable -t$timestamp -bootdata:2#p0,e,b$global:Temp_Media_To_Update_Path\boot\etfsboot.com#pEF,e,b$global:Temp_Media_To_Update_Path\efi\microsoft\boot\efisys_ex.bin -u2 -udfver102 -o $global:Temp_Media_To_Update_Path $ISOPath" + $runCommand = "-l$global:ISO_Label -t$timestamp -bootdata:2#p0,e,b$global:Temp_Media_To_Update_Path\boot\etfsboot.com#pEF,e,b$global:Temp_Media_To_Update_Path\efi\microsoft\boot\efisys_ex.bin -u2 -udfver102 -o $global:Temp_Media_To_Update_Path $ISOPath" Write-Dbg-Host "Running: $global:oscdimg_exe $runCommand" try { From 91c1bd03c3d6824e73a9d4e47017573092f8086e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 18:11:31 +0000 Subject: [PATCH 2/7] Add comprehensive test scripts for PowerShell spelling corrections validation Co-authored-by: Flickdm <8979761+Flickdm@users.noreply.github.com> --- scripts/README_PowerShell_Tests.md | 58 ++++ .../test_Make2023BootableMedia_spelling.ps1 | 309 ++++++++++++++++++ 2 files changed, 367 insertions(+) create mode 100644 scripts/README_PowerShell_Tests.md create mode 100644 scripts/test_Make2023BootableMedia_spelling.ps1 diff --git a/scripts/README_PowerShell_Tests.md b/scripts/README_PowerShell_Tests.md new file mode 100644 index 0000000..3377112 --- /dev/null +++ b/scripts/README_PowerShell_Tests.md @@ -0,0 +1,58 @@ +# PowerShell Script Validation Tests + +This directory contains test scripts to validate PowerShell scripts in the repository. + +## test_Make2023BootableMedia_spelling.ps1 + +This test script validates the spelling corrections made to `Make2023BootableMedia.ps1` as part of issue #220. + +### Purpose + +The script performs comprehensive automated static analysis tests to ensure that spelling corrections introduce no adverse effects to the PowerShell script functionality. + +### Test Categories + +1. **PowerShell Syntax Validation** - Ensures the script parses correctly +2. **Variable Consistency Checks** - Verifies all `ISO_Label` variables use consistent spelling +3. **Function Definition Integrity** - Confirms all key functions are present +4. **Parameter Block Validation** - Validates parameter definitions +5. **Critical Variable Usage** - Checks that critical variables are used correctly +6. **Spelling Correction Verification** - Confirms specific spelling fixes +7. **Script Loading Tests** - Verifies the script can be loaded without errors + +### Usage + +```powershell +# Run from the scripts directory +cd scripts +pwsh -File test_Make2023BootableMedia_spelling.ps1 + +# Or specify a custom path to the script being tested +pwsh -File test_Make2023BootableMedia_spelling.ps1 -ScriptPath "path\to\Make2023BootableMedia.ps1" +``` + +### Expected Results + +When all tests pass, you should see: +- โœ… 15 tests passed +- โŒ 0 tests failed +- ๐ŸŽ‰ Success message confirming no adverse effects + +### What the Tests Validate + +The tests specifically validate the following fixes from issue #220: + +- **Variable Name Consistency**: Ensures all instances of `$global:ISO_Lable` have been corrected to `$global:ISO_Label` +- **Spelling Corrections**: Verifies "Avalable" โ†’ "Available", "defualt" โ†’ "default" +- **Comment Corrections**: Confirms comment spelling has been fixed +- **Functional Integrity**: Ensures the corrections don't break script functionality + +### Requirements + +- PowerShell 5.1 or later (PowerShell Core recommended) +- The `Make2023BootableMedia.ps1` script must be present in the expected location + +### Exit Codes + +- `0`: All tests passed +- `1`: One or more tests failed \ No newline at end of file diff --git a/scripts/test_Make2023BootableMedia_spelling.ps1 b/scripts/test_Make2023BootableMedia_spelling.ps1 new file mode 100644 index 0000000..da8f6eb --- /dev/null +++ b/scripts/test_Make2023BootableMedia_spelling.ps1 @@ -0,0 +1,309 @@ +#Requires -Version 5.1 + +<# +.SYNOPSIS + Test script to validate spelling corrections in Make2023BootableMedia.ps1 + +.DESCRIPTION + This script performs automated static analysis tests to ensure that the spelling + corrections made to Make2023BootableMedia.ps1 introduce no adverse effects. + + Tests include: + - PowerShell syntax validation + - Variable consistency checks (ISO_Label vs ISO_Lable) + - Function definition integrity + - Parameter block validation + - Critical variable usage validation + - Spelling correction verification + - Script loading tests + +.NOTES + Created to validate fixes for issue #220 - "Lable" misspelling +#> + +param( + [Parameter(Mandatory=$false)] + [string]$ScriptPath = "$PSScriptRoot\windows\Make2023BootableMedia.ps1" +) + +# Test results tracking +$script:TestResults = @() +$script:TestsPassed = 0 +$script:TestsFailed = 0 + +function Write-TestResult { + param( + [string]$TestName, + [bool]$Passed, + [string]$Details = "" + ) + + $result = [PSCustomObject]@{ + TestName = $TestName + Passed = $Passed + Details = $Details + Timestamp = Get-Date + } + + $script:TestResults += $result + + if ($Passed) { + $script:TestsPassed++ + Write-Host "โœ… PASS: $TestName" -ForegroundColor Green + if ($Details) { + Write-Host " $Details" -ForegroundColor Gray + } + } else { + $script:TestsFailed++ + Write-Host "โŒ FAIL: $TestName" -ForegroundColor Red + if ($Details) { + Write-Host " $Details" -ForegroundColor Yellow + } + } +} + +function Test-PowerShellSyntax { + Write-Host "`n๐Ÿ” Testing PowerShell syntax validation..." -ForegroundColor Cyan + + try { + $scriptContent = Get-Content -Path $ScriptPath -Raw + $tokens = $null + $errors = $null + + # Parse the PowerShell script + [System.Management.Automation.Language.Parser]::ParseInput( + $scriptContent, + [ref]$tokens, + [ref]$errors + ) | Out-Null + + if ($errors.Count -eq 0) { + Write-TestResult "PowerShell Syntax Validation" $true "Script parses without syntax errors" + } else { + $errorDetails = ($errors | ForEach-Object { "$($_.Message) at line $($_.Extent.StartLineNumber)" }) -join "; " + Write-TestResult "PowerShell Syntax Validation" $false "Syntax errors found: $errorDetails" + } + } catch { + Write-TestResult "PowerShell Syntax Validation" $false "Exception during parsing: $($_.Exception.Message)" + } +} + +function Test-VariableConsistency { + Write-Host "`n๐Ÿ” Testing variable consistency..." -ForegroundColor Cyan + + $scriptContent = Get-Content -Path $ScriptPath -Raw + + # Check for the old misspelled variable name + $oldVariableMatches = [regex]::Matches($scriptContent, '\$global:ISO_Lable', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) + + if ($oldVariableMatches.Count -eq 0) { + Write-TestResult "Variable Consistency - No ISO_Lable" $true "No instances of misspelled 'ISO_Lable' found" + } else { + Write-TestResult "Variable Consistency - No ISO_Lable" $false "Found $($oldVariableMatches.Count) instances of misspelled 'ISO_Lable'" + } + + # Check for the correct variable name + $newVariableMatches = [regex]::Matches($scriptContent, '\$global:ISO_Label', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) + + if ($newVariableMatches.Count -ge 4) { + Write-TestResult "Variable Consistency - ISO_Label Present" $true "Found $($newVariableMatches.Count) instances of correctly spelled 'ISO_Label'" + } else { + Write-TestResult "Variable Consistency - ISO_Label Present" $false "Expected at least 4 instances of 'ISO_Label', found $($newVariableMatches.Count)" + } + + # Check for other misspellings that were fixed + $availableCheck = $scriptContent -notmatch "Avalable" + Write-TestResult "Spelling - Available" $availableCheck "Verified 'Avalable' has been corrected to 'Available'" + + $defaultCheck = $scriptContent -notmatch "defualt" + Write-TestResult "Spelling - Default" $defaultCheck "Verified 'defualt' has been corrected to 'default'" +} + +function Test-FunctionDefinitionIntegrity { + Write-Host "`n๐Ÿ” Testing function definition integrity..." -ForegroundColor Cyan + + try { + $scriptContent = Get-Content -Path $ScriptPath -Raw + + # Extract function definitions using regex + $functionMatches = [regex]::Matches($scriptContent, 'function\s+([A-Za-z-_]+)\s*\{', [System.Text.RegularExpressions.RegexOptions]::Multiline) + + # Core functions that should be present (not exhaustive, just key ones) + $expectedFunctions = @( + 'Get-TS', + 'Show-Usage', + 'Show-ADK-Req', + 'Write-Dbg-Host', + 'Initialize-MediaPaths', + 'Create-USBMedia', + 'Create-ISOMedia' + ) + + $foundFunctions = $functionMatches | ForEach-Object { $_.Groups[1].Value } + $missingFunctions = $expectedFunctions | Where-Object { $_ -notin $foundFunctions } + + if ($missingFunctions.Count -eq 0) { + Write-TestResult "Function Definition Integrity" $true "All key functions found (tested $($expectedFunctions.Count) core functions)" + } else { + Write-TestResult "Function Definition Integrity" $false "Missing functions: $($missingFunctions -join ', ')" + } + + # Check that we found a reasonable number of functions (should be at least 10) + if ($foundFunctions.Count -ge 10) { + Write-TestResult "Function Count" $true "Found $($foundFunctions.Count) function definitions" + } else { + Write-TestResult "Function Count" $false "Only found $($foundFunctions.Count) function definitions, expected at least 10" + } + + } catch { + Write-TestResult "Function Definition Integrity" $false "Exception during function analysis: $($_.Exception.Message)" + } +} + +function Test-ParameterBlockValidation { + Write-Host "`n๐Ÿ” Testing parameter block validation..." -ForegroundColor Cyan + + try { + $scriptContent = Get-Content -Path $ScriptPath -Raw + + # Check for param block at the beginning + $paramBlockFound = $scriptContent -match '(?s)param\s*\([^)]+\)' + + if ($paramBlockFound) { + Write-TestResult "Parameter Block Present" $true "Parameter block found in script" + } else { + Write-TestResult "Parameter Block Present" $false "Parameter block not found" + } + + # Check for expected parameters + $expectedParams = @('MediaPath', 'TargetType', 'ISOPath', 'USBDrive', 'FileSystem', 'NewMediaPath', 'StagingDir') + $missingParams = @() + + foreach ($param in $expectedParams) { + if ($scriptContent -notmatch "\[\s*Parameter[^]]*\]\s*\[\s*string\s*\]\s*\`$$param") { + $missingParams += $param + } + } + + if ($missingParams.Count -eq 0) { + Write-TestResult "Parameter Definitions" $true "All expected parameters found" + } else { + Write-TestResult "Parameter Definitions" $false "Missing parameters: $($missingParams -join ', ')" + } + + } catch { + Write-TestResult "Parameter Block Validation" $false "Exception during parameter validation: $($_.Exception.Message)" + } +} + +function Test-ScriptLoading { + Write-Host "`n๐Ÿ” Testing script loading..." -ForegroundColor Cyan + + try { + # Test that the script can be dot-sourced without errors + # We'll do this in a separate PowerShell process to avoid affecting current session + $testScript = @" +try { + . '$ScriptPath' + Write-Output "SUCCESS" +} catch { + Write-Output "ERROR: `$(`$_.Exception.Message)" +} +"@ + + $result = pwsh -Command $testScript + + if ($result -eq "SUCCESS") { + Write-TestResult "Script Loading" $true "Script can be dot-sourced without errors" + } else { + Write-TestResult "Script Loading" $false "Script loading failed: $result" + } + + } catch { + Write-TestResult "Script Loading" $false "Exception during script loading test: $($_.Exception.Message)" + } +} + +function Test-CriticalVariableUsage { + Write-Host "`n๐Ÿ” Testing critical variable usage..." -ForegroundColor Cyan + + $scriptContent = Get-Content -Path $ScriptPath -Raw + + # Check that ISO_Label is used in the oscdimg command line + $oscdimgLineFound = $scriptContent -match "runCommand.*-l\`$global:ISO_Label" + + if ($oscdimgLineFound) { + Write-TestResult "Critical Variable Usage - oscdimg" $true "ISO_Label variable correctly used in oscdimg command" + } else { + Write-TestResult "Critical Variable Usage - oscdimg" $false "ISO_Label variable not found in oscdimg command line" + } + + # Check that ISO_Label is set from the volume label + $volumeLabelAssignment = $scriptContent -match "\`$global:ISO_Label = \(Get-Volume" + + if ($volumeLabelAssignment) { + Write-TestResult "Critical Variable Usage - Assignment" $true "ISO_Label variable correctly assigned from volume label" + } else { + Write-TestResult "Critical Variable Usage - Assignment" $false "ISO_Label assignment from volume label not found" + } +} + +function Test-SpecificSpellingCorrections { + Write-Host "`n๐Ÿ” Testing specific spelling corrections..." -ForegroundColor Cyan + + $scriptContent = Get-Content -Path $ScriptPath -Raw + + # Test for specific line fixes mentioned in the issue + $corrections = @{ + "Available (not Avalable)" = "Available.*http://aka.ms/adk" + "default (not defualt)" = "# If.*ISOLabel.*not set.*then default" + "ISOLabel (not ISOLable) in comment" = "# If.*ISOLabel.*not set" + } + + foreach ($correctionName in $corrections.Keys) { + $pattern = $corrections[$correctionName] + $found = $scriptContent -match $pattern + + Write-TestResult "Spelling Correction - $correctionName" $found "Verified spelling correction is present" + } +} + +# Main test execution +function Run-AllTests { + Write-Host "๐Ÿงช Starting validation tests for Make2023BootableMedia.ps1 spelling corrections" -ForegroundColor Magenta + Write-Host "Script path: $ScriptPath" -ForegroundColor Gray + + if (-not (Test-Path $ScriptPath)) { + Write-Host "โŒ ERROR: Script not found at $ScriptPath" -ForegroundColor Red + return + } + + # Run all tests + Test-PowerShellSyntax + Test-VariableConsistency + Test-FunctionDefinitionIntegrity + Test-ParameterBlockValidation + Test-CriticalVariableUsage + Test-SpecificSpellingCorrections + Test-ScriptLoading + + # Summary + Write-Host "`n๐Ÿ“Š Test Summary:" -ForegroundColor Magenta + Write-Host "โœ… Passed: $script:TestsPassed" -ForegroundColor Green + Write-Host "โŒ Failed: $script:TestsFailed" -ForegroundColor Red + Write-Host "๐Ÿ“‹ Total: $($script:TestsPassed + $script:TestsFailed)" -ForegroundColor Cyan + + if ($script:TestsFailed -eq 0) { + Write-Host "`n๐ŸŽ‰ All tests passed! The spelling corrections introduce no adverse effects." -ForegroundColor Green + return 0 + } else { + Write-Host "`nโš ๏ธ Some tests failed. Please review the results above." -ForegroundColor Yellow + return 1 + } +} + +# Execute tests if script is run directly +if ($MyInvocation.InvocationName -ne '.') { + $exitCode = Run-AllTests + exit $exitCode +} \ No newline at end of file From dc220126db3913175cd8d1e75819e6b2ef9298a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 18:16:12 +0000 Subject: [PATCH 3/7] Add PR gate workflow to validate Make2023BootableMedia.ps1 changes Co-authored-by: Flickdm <8979761+Flickdm@users.noreply.github.com> --- .../validate-make2023bootablemedia.yml | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/validate-make2023bootablemedia.yml diff --git a/.github/workflows/validate-make2023bootablemedia.yml b/.github/workflows/validate-make2023bootablemedia.yml new file mode 100644 index 0000000..a039e1c --- /dev/null +++ b/.github/workflows/validate-make2023bootablemedia.yml @@ -0,0 +1,76 @@ +# This workflow validates the Make2023BootableMedia.ps1 script for spelling corrections +# and ensures no adverse effects are introduced by changes to the script. +# +# It runs comprehensive static analysis tests including: +# - PowerShell syntax validation +# - Variable consistency checks +# - Function definition integrity +# - Parameter block validation +# - Critical variable usage validation +# - Spelling correction verification +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent + +name: Validate Make2023BootableMedia.ps1 + +on: + pull_request: + paths: + - 'scripts/windows/Make2023BootableMedia.ps1' + branches: [ "main" ] + push: + paths: + - 'scripts/windows/Make2023BootableMedia.ps1' + branches: [ "main" ] + +jobs: + validate-script: + name: Validate PowerShell Script + runs-on: windows-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run PowerShell validation tests + shell: pwsh + run: | + Write-Host "Running validation tests for Make2023BootableMedia.ps1..." -ForegroundColor Cyan + + # Run the test script + $testScript = "scripts/test_Make2023BootableMedia_spelling.ps1" + $scriptToTest = "scripts/windows/Make2023BootableMedia.ps1" + + if (-not (Test-Path $testScript)) { + Write-Host "โŒ Test script not found at $testScript" -ForegroundColor Red + exit 1 + } + + if (-not (Test-Path $scriptToTest)) { + Write-Host "โŒ Target script not found at $scriptToTest" -ForegroundColor Red + exit 1 + } + + Write-Host "โœ… Found test script: $testScript" -ForegroundColor Green + Write-Host "โœ… Found target script: $scriptToTest" -ForegroundColor Green + + # Execute the validation tests + $exitCode = & $testScript -ScriptPath $scriptToTest + + if ($exitCode -eq 0) { + Write-Host "๐ŸŽ‰ All validation tests passed!" -ForegroundColor Green + } else { + Write-Host "โŒ Validation tests failed with exit code: $exitCode" -ForegroundColor Red + exit $exitCode + } + + - name: Report test results + if: always() + shell: pwsh + run: | + if ($LASTEXITCODE -eq 0) { + Write-Host "::notice title=Validation Complete::All PowerShell validation tests passed successfully" + } else { + Write-Host "::error title=Validation Failed::PowerShell validation tests failed. Please review the script changes." + } \ No newline at end of file From d86b55dcb7ef32445eba4b8f4168db92bb76ff9d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 18:32:46 +0000 Subject: [PATCH 4/7] Fix GitHub action to properly fail when tests fail and improve script loading test Co-authored-by: Javagedes <24388509+Javagedes@users.noreply.github.com> --- .../validate-make2023bootablemedia.yml | 3 +- .../test_Make2023BootableMedia_spelling.ps1 | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/validate-make2023bootablemedia.yml b/.github/workflows/validate-make2023bootablemedia.yml index a039e1c..d5faf2e 100644 --- a/.github/workflows/validate-make2023bootablemedia.yml +++ b/.github/workflows/validate-make2023bootablemedia.yml @@ -56,7 +56,8 @@ jobs: Write-Host "โœ… Found target script: $scriptToTest" -ForegroundColor Green # Execute the validation tests - $exitCode = & $testScript -ScriptPath $scriptToTest + & $testScript -ScriptPath $scriptToTest + $exitCode = $LASTEXITCODE if ($exitCode -eq 0) { Write-Host "๐ŸŽ‰ All validation tests passed!" -ForegroundColor Green diff --git a/scripts/test_Make2023BootableMedia_spelling.ps1 b/scripts/test_Make2023BootableMedia_spelling.ps1 index da8f6eb..ac282a2 100644 --- a/scripts/test_Make2023BootableMedia_spelling.ps1 +++ b/scripts/test_Make2023BootableMedia_spelling.ps1 @@ -200,12 +200,28 @@ function Test-ScriptLoading { Write-Host "`n๐Ÿ” Testing script loading..." -ForegroundColor Cyan try { - # Test that the script can be dot-sourced without errors - # We'll do this in a separate PowerShell process to avoid affecting current session + # Test that the script can be parsed and its functions loaded without errors + # We'll do this by checking if the script can be parsed successfully + # without trying to execute it (since it has mandatory parameters) $testScript = @" try { - . '$ScriptPath' - Write-Output "SUCCESS" + # Parse the script content to check for syntax errors and load functions + `$scriptContent = Get-Content '$ScriptPath' -Raw + `$scriptBlock = [ScriptBlock]::Create(`$scriptContent) + + # Test if we can invoke the script block in a way that doesn't trigger parameter prompts + # We'll use the -WhatIf pattern or check for function definitions + if (`$scriptBlock) { + # Check if key functions are defined after parsing + `$functions = `$scriptBlock.Ast.FindAll({param(`$node) `$node -is [System.Management.Automation.Language.FunctionDefinitionAst]}, `$true) + if (`$functions.Count -gt 0) { + Write-Output "SUCCESS: Script parsed and `$(`$functions.Count) functions found" + } else { + Write-Output "ERROR: Script parsed but no functions found" + } + } else { + Write-Output "ERROR: Failed to create script block" + } } catch { Write-Output "ERROR: `$(`$_.Exception.Message)" } @@ -213,8 +229,8 @@ try { $result = pwsh -Command $testScript - if ($result -eq "SUCCESS") { - Write-TestResult "Script Loading" $true "Script can be dot-sourced without errors" + if ($result -like "SUCCESS:*") { + Write-TestResult "Script Loading" $true "Script can be parsed and functions loaded: $($result -replace 'SUCCESS: ', '')" } else { Write-TestResult "Script Loading" $false "Script loading failed: $result" } From 46fda860bbd07da59258299a39585055232363c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 23:55:30 +0000 Subject: [PATCH 5/7] Add missing newlines at end of workflow and test files Co-authored-by: makubacki <21320094+makubacki@users.noreply.github.com> --- .github/workflows/validate-make2023bootablemedia.yml | 2 +- scripts/test_Make2023BootableMedia_spelling.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-make2023bootablemedia.yml b/.github/workflows/validate-make2023bootablemedia.yml index d5faf2e..d9eab17 100644 --- a/.github/workflows/validate-make2023bootablemedia.yml +++ b/.github/workflows/validate-make2023bootablemedia.yml @@ -74,4 +74,4 @@ jobs: Write-Host "::notice title=Validation Complete::All PowerShell validation tests passed successfully" } else { Write-Host "::error title=Validation Failed::PowerShell validation tests failed. Please review the script changes." - } \ No newline at end of file + } diff --git a/scripts/test_Make2023BootableMedia_spelling.ps1 b/scripts/test_Make2023BootableMedia_spelling.ps1 index ac282a2..bb7dad1 100644 --- a/scripts/test_Make2023BootableMedia_spelling.ps1 +++ b/scripts/test_Make2023BootableMedia_spelling.ps1 @@ -322,4 +322,4 @@ function Run-AllTests { if ($MyInvocation.InvocationName -ne '.') { $exitCode = Run-AllTests exit $exitCode -} \ No newline at end of file +} From f9ee4e43e8ae093b94f8eec5a02c15796e320dc3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Jun 2025 17:09:45 +0000 Subject: [PATCH 6/7] Remove redundant 'Report test results' step from workflow Co-authored-by: Javagedes <24388509+Javagedes@users.noreply.github.com> --- .github/workflows/validate-make2023bootablemedia.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/validate-make2023bootablemedia.yml b/.github/workflows/validate-make2023bootablemedia.yml index d9eab17..a4601cc 100644 --- a/.github/workflows/validate-make2023bootablemedia.yml +++ b/.github/workflows/validate-make2023bootablemedia.yml @@ -65,13 +65,3 @@ jobs: Write-Host "โŒ Validation tests failed with exit code: $exitCode" -ForegroundColor Red exit $exitCode } - - - name: Report test results - if: always() - shell: pwsh - run: | - if ($LASTEXITCODE -eq 0) { - Write-Host "::notice title=Validation Complete::All PowerShell validation tests passed successfully" - } else { - Write-Host "::error title=Validation Failed::PowerShell validation tests failed. Please review the script changes." - } From f78a80c7adae4e632d58e95f6b0435e1e2a620b5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:47:28 +0000 Subject: [PATCH 7/7] Remove PR gate workflow and test files as requested Co-authored-by: Flickdm <8979761+Flickdm@users.noreply.github.com> --- .../validate-make2023bootablemedia.yml | 67 ---- scripts/README_PowerShell_Tests.md | 58 ---- .../test_Make2023BootableMedia_spelling.ps1 | 325 ------------------ 3 files changed, 450 deletions(-) delete mode 100644 .github/workflows/validate-make2023bootablemedia.yml delete mode 100644 scripts/README_PowerShell_Tests.md delete mode 100644 scripts/test_Make2023BootableMedia_spelling.ps1 diff --git a/.github/workflows/validate-make2023bootablemedia.yml b/.github/workflows/validate-make2023bootablemedia.yml deleted file mode 100644 index a4601cc..0000000 --- a/.github/workflows/validate-make2023bootablemedia.yml +++ /dev/null @@ -1,67 +0,0 @@ -# This workflow validates the Make2023BootableMedia.ps1 script for spelling corrections -# and ensures no adverse effects are introduced by changes to the script. -# -# It runs comprehensive static analysis tests including: -# - PowerShell syntax validation -# - Variable consistency checks -# - Function definition integrity -# - Parameter block validation -# - Critical variable usage validation -# - Spelling correction verification -# -# Copyright (c) Microsoft Corporation. -# SPDX-License-Identifier: BSD-2-Clause-Patent - -name: Validate Make2023BootableMedia.ps1 - -on: - pull_request: - paths: - - 'scripts/windows/Make2023BootableMedia.ps1' - branches: [ "main" ] - push: - paths: - - 'scripts/windows/Make2023BootableMedia.ps1' - branches: [ "main" ] - -jobs: - validate-script: - name: Validate PowerShell Script - runs-on: windows-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Run PowerShell validation tests - shell: pwsh - run: | - Write-Host "Running validation tests for Make2023BootableMedia.ps1..." -ForegroundColor Cyan - - # Run the test script - $testScript = "scripts/test_Make2023BootableMedia_spelling.ps1" - $scriptToTest = "scripts/windows/Make2023BootableMedia.ps1" - - if (-not (Test-Path $testScript)) { - Write-Host "โŒ Test script not found at $testScript" -ForegroundColor Red - exit 1 - } - - if (-not (Test-Path $scriptToTest)) { - Write-Host "โŒ Target script not found at $scriptToTest" -ForegroundColor Red - exit 1 - } - - Write-Host "โœ… Found test script: $testScript" -ForegroundColor Green - Write-Host "โœ… Found target script: $scriptToTest" -ForegroundColor Green - - # Execute the validation tests - & $testScript -ScriptPath $scriptToTest - $exitCode = $LASTEXITCODE - - if ($exitCode -eq 0) { - Write-Host "๐ŸŽ‰ All validation tests passed!" -ForegroundColor Green - } else { - Write-Host "โŒ Validation tests failed with exit code: $exitCode" -ForegroundColor Red - exit $exitCode - } diff --git a/scripts/README_PowerShell_Tests.md b/scripts/README_PowerShell_Tests.md deleted file mode 100644 index 3377112..0000000 --- a/scripts/README_PowerShell_Tests.md +++ /dev/null @@ -1,58 +0,0 @@ -# PowerShell Script Validation Tests - -This directory contains test scripts to validate PowerShell scripts in the repository. - -## test_Make2023BootableMedia_spelling.ps1 - -This test script validates the spelling corrections made to `Make2023BootableMedia.ps1` as part of issue #220. - -### Purpose - -The script performs comprehensive automated static analysis tests to ensure that spelling corrections introduce no adverse effects to the PowerShell script functionality. - -### Test Categories - -1. **PowerShell Syntax Validation** - Ensures the script parses correctly -2. **Variable Consistency Checks** - Verifies all `ISO_Label` variables use consistent spelling -3. **Function Definition Integrity** - Confirms all key functions are present -4. **Parameter Block Validation** - Validates parameter definitions -5. **Critical Variable Usage** - Checks that critical variables are used correctly -6. **Spelling Correction Verification** - Confirms specific spelling fixes -7. **Script Loading Tests** - Verifies the script can be loaded without errors - -### Usage - -```powershell -# Run from the scripts directory -cd scripts -pwsh -File test_Make2023BootableMedia_spelling.ps1 - -# Or specify a custom path to the script being tested -pwsh -File test_Make2023BootableMedia_spelling.ps1 -ScriptPath "path\to\Make2023BootableMedia.ps1" -``` - -### Expected Results - -When all tests pass, you should see: -- โœ… 15 tests passed -- โŒ 0 tests failed -- ๐ŸŽ‰ Success message confirming no adverse effects - -### What the Tests Validate - -The tests specifically validate the following fixes from issue #220: - -- **Variable Name Consistency**: Ensures all instances of `$global:ISO_Lable` have been corrected to `$global:ISO_Label` -- **Spelling Corrections**: Verifies "Avalable" โ†’ "Available", "defualt" โ†’ "default" -- **Comment Corrections**: Confirms comment spelling has been fixed -- **Functional Integrity**: Ensures the corrections don't break script functionality - -### Requirements - -- PowerShell 5.1 or later (PowerShell Core recommended) -- The `Make2023BootableMedia.ps1` script must be present in the expected location - -### Exit Codes - -- `0`: All tests passed -- `1`: One or more tests failed \ No newline at end of file diff --git a/scripts/test_Make2023BootableMedia_spelling.ps1 b/scripts/test_Make2023BootableMedia_spelling.ps1 deleted file mode 100644 index bb7dad1..0000000 --- a/scripts/test_Make2023BootableMedia_spelling.ps1 +++ /dev/null @@ -1,325 +0,0 @@ -#Requires -Version 5.1 - -<# -.SYNOPSIS - Test script to validate spelling corrections in Make2023BootableMedia.ps1 - -.DESCRIPTION - This script performs automated static analysis tests to ensure that the spelling - corrections made to Make2023BootableMedia.ps1 introduce no adverse effects. - - Tests include: - - PowerShell syntax validation - - Variable consistency checks (ISO_Label vs ISO_Lable) - - Function definition integrity - - Parameter block validation - - Critical variable usage validation - - Spelling correction verification - - Script loading tests - -.NOTES - Created to validate fixes for issue #220 - "Lable" misspelling -#> - -param( - [Parameter(Mandatory=$false)] - [string]$ScriptPath = "$PSScriptRoot\windows\Make2023BootableMedia.ps1" -) - -# Test results tracking -$script:TestResults = @() -$script:TestsPassed = 0 -$script:TestsFailed = 0 - -function Write-TestResult { - param( - [string]$TestName, - [bool]$Passed, - [string]$Details = "" - ) - - $result = [PSCustomObject]@{ - TestName = $TestName - Passed = $Passed - Details = $Details - Timestamp = Get-Date - } - - $script:TestResults += $result - - if ($Passed) { - $script:TestsPassed++ - Write-Host "โœ… PASS: $TestName" -ForegroundColor Green - if ($Details) { - Write-Host " $Details" -ForegroundColor Gray - } - } else { - $script:TestsFailed++ - Write-Host "โŒ FAIL: $TestName" -ForegroundColor Red - if ($Details) { - Write-Host " $Details" -ForegroundColor Yellow - } - } -} - -function Test-PowerShellSyntax { - Write-Host "`n๐Ÿ” Testing PowerShell syntax validation..." -ForegroundColor Cyan - - try { - $scriptContent = Get-Content -Path $ScriptPath -Raw - $tokens = $null - $errors = $null - - # Parse the PowerShell script - [System.Management.Automation.Language.Parser]::ParseInput( - $scriptContent, - [ref]$tokens, - [ref]$errors - ) | Out-Null - - if ($errors.Count -eq 0) { - Write-TestResult "PowerShell Syntax Validation" $true "Script parses without syntax errors" - } else { - $errorDetails = ($errors | ForEach-Object { "$($_.Message) at line $($_.Extent.StartLineNumber)" }) -join "; " - Write-TestResult "PowerShell Syntax Validation" $false "Syntax errors found: $errorDetails" - } - } catch { - Write-TestResult "PowerShell Syntax Validation" $false "Exception during parsing: $($_.Exception.Message)" - } -} - -function Test-VariableConsistency { - Write-Host "`n๐Ÿ” Testing variable consistency..." -ForegroundColor Cyan - - $scriptContent = Get-Content -Path $ScriptPath -Raw - - # Check for the old misspelled variable name - $oldVariableMatches = [regex]::Matches($scriptContent, '\$global:ISO_Lable', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) - - if ($oldVariableMatches.Count -eq 0) { - Write-TestResult "Variable Consistency - No ISO_Lable" $true "No instances of misspelled 'ISO_Lable' found" - } else { - Write-TestResult "Variable Consistency - No ISO_Lable" $false "Found $($oldVariableMatches.Count) instances of misspelled 'ISO_Lable'" - } - - # Check for the correct variable name - $newVariableMatches = [regex]::Matches($scriptContent, '\$global:ISO_Label', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) - - if ($newVariableMatches.Count -ge 4) { - Write-TestResult "Variable Consistency - ISO_Label Present" $true "Found $($newVariableMatches.Count) instances of correctly spelled 'ISO_Label'" - } else { - Write-TestResult "Variable Consistency - ISO_Label Present" $false "Expected at least 4 instances of 'ISO_Label', found $($newVariableMatches.Count)" - } - - # Check for other misspellings that were fixed - $availableCheck = $scriptContent -notmatch "Avalable" - Write-TestResult "Spelling - Available" $availableCheck "Verified 'Avalable' has been corrected to 'Available'" - - $defaultCheck = $scriptContent -notmatch "defualt" - Write-TestResult "Spelling - Default" $defaultCheck "Verified 'defualt' has been corrected to 'default'" -} - -function Test-FunctionDefinitionIntegrity { - Write-Host "`n๐Ÿ” Testing function definition integrity..." -ForegroundColor Cyan - - try { - $scriptContent = Get-Content -Path $ScriptPath -Raw - - # Extract function definitions using regex - $functionMatches = [regex]::Matches($scriptContent, 'function\s+([A-Za-z-_]+)\s*\{', [System.Text.RegularExpressions.RegexOptions]::Multiline) - - # Core functions that should be present (not exhaustive, just key ones) - $expectedFunctions = @( - 'Get-TS', - 'Show-Usage', - 'Show-ADK-Req', - 'Write-Dbg-Host', - 'Initialize-MediaPaths', - 'Create-USBMedia', - 'Create-ISOMedia' - ) - - $foundFunctions = $functionMatches | ForEach-Object { $_.Groups[1].Value } - $missingFunctions = $expectedFunctions | Where-Object { $_ -notin $foundFunctions } - - if ($missingFunctions.Count -eq 0) { - Write-TestResult "Function Definition Integrity" $true "All key functions found (tested $($expectedFunctions.Count) core functions)" - } else { - Write-TestResult "Function Definition Integrity" $false "Missing functions: $($missingFunctions -join ', ')" - } - - # Check that we found a reasonable number of functions (should be at least 10) - if ($foundFunctions.Count -ge 10) { - Write-TestResult "Function Count" $true "Found $($foundFunctions.Count) function definitions" - } else { - Write-TestResult "Function Count" $false "Only found $($foundFunctions.Count) function definitions, expected at least 10" - } - - } catch { - Write-TestResult "Function Definition Integrity" $false "Exception during function analysis: $($_.Exception.Message)" - } -} - -function Test-ParameterBlockValidation { - Write-Host "`n๐Ÿ” Testing parameter block validation..." -ForegroundColor Cyan - - try { - $scriptContent = Get-Content -Path $ScriptPath -Raw - - # Check for param block at the beginning - $paramBlockFound = $scriptContent -match '(?s)param\s*\([^)]+\)' - - if ($paramBlockFound) { - Write-TestResult "Parameter Block Present" $true "Parameter block found in script" - } else { - Write-TestResult "Parameter Block Present" $false "Parameter block not found" - } - - # Check for expected parameters - $expectedParams = @('MediaPath', 'TargetType', 'ISOPath', 'USBDrive', 'FileSystem', 'NewMediaPath', 'StagingDir') - $missingParams = @() - - foreach ($param in $expectedParams) { - if ($scriptContent -notmatch "\[\s*Parameter[^]]*\]\s*\[\s*string\s*\]\s*\`$$param") { - $missingParams += $param - } - } - - if ($missingParams.Count -eq 0) { - Write-TestResult "Parameter Definitions" $true "All expected parameters found" - } else { - Write-TestResult "Parameter Definitions" $false "Missing parameters: $($missingParams -join ', ')" - } - - } catch { - Write-TestResult "Parameter Block Validation" $false "Exception during parameter validation: $($_.Exception.Message)" - } -} - -function Test-ScriptLoading { - Write-Host "`n๐Ÿ” Testing script loading..." -ForegroundColor Cyan - - try { - # Test that the script can be parsed and its functions loaded without errors - # We'll do this by checking if the script can be parsed successfully - # without trying to execute it (since it has mandatory parameters) - $testScript = @" -try { - # Parse the script content to check for syntax errors and load functions - `$scriptContent = Get-Content '$ScriptPath' -Raw - `$scriptBlock = [ScriptBlock]::Create(`$scriptContent) - - # Test if we can invoke the script block in a way that doesn't trigger parameter prompts - # We'll use the -WhatIf pattern or check for function definitions - if (`$scriptBlock) { - # Check if key functions are defined after parsing - `$functions = `$scriptBlock.Ast.FindAll({param(`$node) `$node -is [System.Management.Automation.Language.FunctionDefinitionAst]}, `$true) - if (`$functions.Count -gt 0) { - Write-Output "SUCCESS: Script parsed and `$(`$functions.Count) functions found" - } else { - Write-Output "ERROR: Script parsed but no functions found" - } - } else { - Write-Output "ERROR: Failed to create script block" - } -} catch { - Write-Output "ERROR: `$(`$_.Exception.Message)" -} -"@ - - $result = pwsh -Command $testScript - - if ($result -like "SUCCESS:*") { - Write-TestResult "Script Loading" $true "Script can be parsed and functions loaded: $($result -replace 'SUCCESS: ', '')" - } else { - Write-TestResult "Script Loading" $false "Script loading failed: $result" - } - - } catch { - Write-TestResult "Script Loading" $false "Exception during script loading test: $($_.Exception.Message)" - } -} - -function Test-CriticalVariableUsage { - Write-Host "`n๐Ÿ” Testing critical variable usage..." -ForegroundColor Cyan - - $scriptContent = Get-Content -Path $ScriptPath -Raw - - # Check that ISO_Label is used in the oscdimg command line - $oscdimgLineFound = $scriptContent -match "runCommand.*-l\`$global:ISO_Label" - - if ($oscdimgLineFound) { - Write-TestResult "Critical Variable Usage - oscdimg" $true "ISO_Label variable correctly used in oscdimg command" - } else { - Write-TestResult "Critical Variable Usage - oscdimg" $false "ISO_Label variable not found in oscdimg command line" - } - - # Check that ISO_Label is set from the volume label - $volumeLabelAssignment = $scriptContent -match "\`$global:ISO_Label = \(Get-Volume" - - if ($volumeLabelAssignment) { - Write-TestResult "Critical Variable Usage - Assignment" $true "ISO_Label variable correctly assigned from volume label" - } else { - Write-TestResult "Critical Variable Usage - Assignment" $false "ISO_Label assignment from volume label not found" - } -} - -function Test-SpecificSpellingCorrections { - Write-Host "`n๐Ÿ” Testing specific spelling corrections..." -ForegroundColor Cyan - - $scriptContent = Get-Content -Path $ScriptPath -Raw - - # Test for specific line fixes mentioned in the issue - $corrections = @{ - "Available (not Avalable)" = "Available.*http://aka.ms/adk" - "default (not defualt)" = "# If.*ISOLabel.*not set.*then default" - "ISOLabel (not ISOLable) in comment" = "# If.*ISOLabel.*not set" - } - - foreach ($correctionName in $corrections.Keys) { - $pattern = $corrections[$correctionName] - $found = $scriptContent -match $pattern - - Write-TestResult "Spelling Correction - $correctionName" $found "Verified spelling correction is present" - } -} - -# Main test execution -function Run-AllTests { - Write-Host "๐Ÿงช Starting validation tests for Make2023BootableMedia.ps1 spelling corrections" -ForegroundColor Magenta - Write-Host "Script path: $ScriptPath" -ForegroundColor Gray - - if (-not (Test-Path $ScriptPath)) { - Write-Host "โŒ ERROR: Script not found at $ScriptPath" -ForegroundColor Red - return - } - - # Run all tests - Test-PowerShellSyntax - Test-VariableConsistency - Test-FunctionDefinitionIntegrity - Test-ParameterBlockValidation - Test-CriticalVariableUsage - Test-SpecificSpellingCorrections - Test-ScriptLoading - - # Summary - Write-Host "`n๐Ÿ“Š Test Summary:" -ForegroundColor Magenta - Write-Host "โœ… Passed: $script:TestsPassed" -ForegroundColor Green - Write-Host "โŒ Failed: $script:TestsFailed" -ForegroundColor Red - Write-Host "๐Ÿ“‹ Total: $($script:TestsPassed + $script:TestsFailed)" -ForegroundColor Cyan - - if ($script:TestsFailed -eq 0) { - Write-Host "`n๐ŸŽ‰ All tests passed! The spelling corrections introduce no adverse effects." -ForegroundColor Green - return 0 - } else { - Write-Host "`nโš ๏ธ Some tests failed. Please review the results above." -ForegroundColor Yellow - return 1 - } -} - -# Execute tests if script is run directly -if ($MyInvocation.InvocationName -ne '.') { - $exitCode = Run-AllTests - exit $exitCode -}