|
| 1 | +# Reproduce corrupt DOCX failure locally: create a truncated file and run conversion. |
| 2 | +# The CI failure was: "End of Central Directory record could not be found" when opening a DOCX (ZIP). |
| 3 | +$ErrorActionPreference = 'Stop' |
| 4 | +Import-Module (Join-Path $PSScriptRoot '..' 'AwakeCoding.OpenSpecs') -Force |
| 5 | + |
| 6 | +$workDir = Join-Path $env:TEMP "openspecs-repro-$(Get-Date -Format 'yyyyMMddHHmmss')" |
| 7 | +New-Item -ItemType Directory -Path $workDir -Force | Out-Null |
| 8 | +$downloadsDir = Join-Path $workDir 'downloads' |
| 9 | +$convertedDir = Join-Path $workDir 'converted' |
| 10 | +New-Item -ItemType Directory -Path $downloadsDir -Force | Out-Null |
| 11 | +New-Item -ItemType Directory -Path $convertedDir -Force | Out-Null |
| 12 | + |
| 13 | +Write-Host "Work dir: $workDir" |
| 14 | + |
| 15 | +# Option 1: Download one real DOCX then truncate it to simulate corruption |
| 16 | +Write-Host "Downloading one spec (MS-NVGREE) to get a valid DOCX..." |
| 17 | +$null = Get-OpenSpecCatalog | Where-Object { $_.ProtocolId -eq 'MS-NVGREE' } | |
| 18 | + Save-OpenSpecDocument -Format DOCX -OutputPath $downloadsDir -Force |
| 19 | + |
| 20 | +$goodDocx = Get-ChildItem -LiteralPath $downloadsDir -Filter '*.docx' | Select-Object -First 1 |
| 21 | +if (-not $goodDocx) { |
| 22 | + Write-Error "No DOCX downloaded" |
| 23 | + exit 1 |
| 24 | +} |
| 25 | + |
| 26 | +# Create a corrupt copy (truncate so ZIP EOCD is missing) |
| 27 | +$corruptPath = Join-Path $downloadsDir 'CORRUPT-[MS-TEST].docx' |
| 28 | +$bytes = [System.IO.File]::ReadAllBytes($goodDocx.FullName) |
| 29 | +$truncatedSize = [Math]::Max(100, [int]($bytes.Length * 0.3)) |
| 30 | +[System.IO.File]::WriteAllBytes($corruptPath, $bytes[0..($truncatedSize-1)]) |
| 31 | +Write-Host "Created truncated (corrupt) file: $corruptPath ($truncatedSize bytes)" |
| 32 | + |
| 33 | +# Run conversion: should hit "End of Central Directory record could not be found" |
| 34 | +Write-Host "Converting (expect failure for corrupt file, then success for good file)..." |
| 35 | +$results = @( |
| 36 | + [pscustomobject]@{ Path = $corruptPath; ProtocolId = 'MS-TEST' }, |
| 37 | + [pscustomobject]@{ Path = $goodDocx.FullName; ProtocolId = 'MS-NVGREE' } |
| 38 | +) |
| 39 | +$conversionResults = $results | Convert-OpenSpecToMarkdown -OutputPath $convertedDir -Force |
| 40 | + |
| 41 | +Write-Host "`nConversion results:" |
| 42 | +$conversionResults | Format-Table ProtocolId, Status, Error -AutoSize |
| 43 | + |
| 44 | +$failed = $conversionResults | Where-Object { $_.Status -eq 'Failed' } |
| 45 | +$converted = $conversionResults | Where-Object { $_.Status -eq 'Converted' } |
| 46 | +if ($failed -and $failed.ProtocolId -eq 'MS-TEST' -and $converted -and $converted.ProtocolId -eq 'MS-NVGREE') { |
| 47 | + Write-Host "`nRepro succeeded: corrupt file failed gracefully, good file converted." |
| 48 | +} else { |
| 49 | + Write-Host "`nUnexpected: Failed=$($failed.ProtocolId) Converted=$($converted.ProtocolId)" |
| 50 | +} |
| 51 | + |
| 52 | +Remove-Item -LiteralPath $workDir -Recurse -Force -ErrorAction SilentlyContinue |
| 53 | +Write-Host "`nDone. Cleaned up $workDir" |
0 commit comments