analyze_404_cause.ps1 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Count how many 404s are caused by @Profile("admin") exclusion
  2. # by checking if the same path exists in fs-admin-saas with admin profile
  3. # Read backend_mappings.txt which has the mapping info
  4. $mappings = Get-Content "d:\ylrz\saasadminui\backend_mappings.txt" -Encoding UTF8
  5. # Parse admin-profiled mappings
  6. $adminMappings = @{}
  7. $companyMappings = @{}
  8. foreach ($line in $mappings) {
  9. if ($line -match "^\s*(\S+)\s+=>\s+admin\s+\|") {
  10. $path = $Matches[1]
  11. $adminMappings[$path] = $line
  12. } elseif ($line -match "^\s*(\S+)\s+=>\s+company\s+\|") {
  13. $path = $Matches[1]
  14. $companyMappings[$path] = $line
  15. }
  16. }
  17. Write-Host "Admin-only mappings: $($adminMappings.Count)"
  18. Write-Host "Company mappings: $($companyMappings.Count)"
  19. # Read 404 results
  20. $content = Get-Content "d:\ylrz\saasadminui\api_test_v2_results.txt" -Raw
  21. $sections = $content -split "=== "
  22. $notFound = @()
  23. foreach ($section in $sections) {
  24. if ($section.StartsWith("404")) {
  25. $notFound = ($section -split "`n" | Where-Object { $_.Trim() -ne "" -and $_ -notmatch "^404" })
  26. }
  27. }
  28. # Filter GET/POST 404s only
  29. $meaningful404 = $notFound | Where-Object { $_ -match "^(GET|POST)\s+" }
  30. Write-Host "`nGET/POST 404 count: $($meaningful404.Count)"
  31. # Categorize each 404
  32. $profileExcluded = @()
  33. $pathMismatch = @()
  34. $trulyMissing = @()
  35. foreach ($line in $meaningful404) {
  36. if ($line -match "^\w+\s+(/\S+)(?:\s|\|)") {
  37. $path = $Matches[1]
  38. # Remove trailing /
  39. $cleanPath = $path.TrimEnd('/')
  40. if ($cleanPath -eq "") { $cleanPath = $path }
  41. # Check if this path exists in admin mappings
  42. $found = $false
  43. foreach ($key in $adminMappings.Keys) {
  44. if ($key.StartsWith($cleanPath) -or $cleanPath.StartsWith($key)) {
  45. $profileExcluded += "$line => ADMIN: $($adminMappings[$key])"
  46. $found = $true
  47. break
  48. }
  49. }
  50. if (-not $found) {
  51. # Check if similar path exists in company mappings
  52. $similar = $false
  53. foreach ($key in $companyMappings.Keys) {
  54. # Extract base module path
  55. if ($key -match "^/([^/]+)/" -and $cleanPath -match "^/([^/]+)/") {
  56. if ($Matches[1] -eq $Matches[2]) {
  57. # Same module - could be path mismatch
  58. break
  59. }
  60. }
  61. }
  62. $trulyMissing += $line
  63. }
  64. }
  65. }
  66. Write-Host "`n=== 404 Root Cause Analysis ==="
  67. Write-Host "Caused by @Profile('admin') exclusion: $($profileExcluded.Count)"
  68. Write-Host "Truly missing (no backend controller): $($trulyMissing.Count)"
  69. # Show profile-excluded details by module
  70. Write-Host "`n=== Profile-Excluded by Module ==="
  71. $peByMod = @{}
  72. foreach ($line in $profileExcluded) {
  73. if ($line -match "^\w+\s+/([^/]+)/") {
  74. $mod = $Matches[1]
  75. if (-not $peByMod.ContainsKey($mod)) { $peByMod[$mod] = 0 }
  76. $peByMod[$mod]++
  77. }
  78. }
  79. $peByMod.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
  80. # Show truly missing by module
  81. Write-Host "`n=== Truly Missing by Module ==="
  82. $tmByMod = @{}
  83. foreach ($line in $trulyMissing) {
  84. if ($line -match "^\w+\s+/([^/]+)/") {
  85. $mod = $Matches[1]
  86. if (-not $tmByMod.ContainsKey($mod)) { $tmByMod[$mod] = 0 }
  87. $tmByMod[$mod]++
  88. }
  89. }
  90. $tmByMod.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
  91. # Show sample profile-excluded 404s
  92. Write-Host "`n=== Sample Profile-Excluded 404s ==="
  93. $profileExcluded | Select-Object -First 20 | ForEach-Object { Write-Host " $_" }
  94. # Show sample truly missing 404s
  95. Write-Host "`n=== Sample Truly Missing 404s ==="
  96. $trulyMissing | Select-Object -First 20 | ForEach-Object { Write-Host " $_" }