build-edges.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Edge builder & validator for cockpit-primary-area-guardrails
  2. # Written by AI agent. Runs in PowerShell (Windows sandbox safe).
  3. param(
  4. [string]$EffortDir = ""
  5. )
  6. if (-not $EffortDir) {
  7. $EffortDir = Split-Path $PSScriptRoot -Parent
  8. }
  9. $TicketsDir = Join-Path $EffortDir "issues"
  10. $MapPath = Join-Path $EffortDir "map.md"
  11. Write-Host "Building native `Blocked by:` edges and validating ticket count..."
  12. # Declare expected tickets and their blocking edges
  13. $ExpectedTickets = @{
  14. "01-primary-area-config-contract.md" = "None"
  15. "02-camera-limit-numeric-contract.md" = "01"
  16. "03-camera-contract-composition-and-entry-state.md" = "01,02"
  17. "04-research-cesium-ground-fog-mechanisms.md" = "None"
  18. "05-research-overlay-rectangle-pop-mechanisms.md" = "None"
  19. "06-research-three-fog-shader-reuse.md" = "None"
  20. "07-fog-implementation-spec.md" = "01,04,06"
  21. "08-coarse-to-fine-transition-solution.md" = "01,05,07"
  22. }
  23. $ExpectedMapTaskCount = 8
  24. # Function to fix one ticket
  25. function Fix-Edge {
  26. param([string]$TicketPath)
  27. $TicketName = Split-Path $TicketPath -Leaf
  28. if (-not $ExpectedTickets.ContainsKey($TicketName)) {
  29. Write-Host "Unknown ticket: $TicketName"
  30. return $false
  31. }
  32. $ExpectedEdge = $ExpectedTickets[$TicketName]
  33. $EdgeLine = "Blocked by: $ExpectedEdge"
  34. $Content = Get-Content $TicketPath -Raw
  35. if ($Content -match "(?m)^Blocked by: .*$") {
  36. $Content = $Content -replace "(?m)^Blocked by: .*$", $EdgeLine
  37. } else {
  38. $Content = $EdgeLine + "`n`n" + $Content
  39. }
  40. $Content | Set-Content $TicketPath -Encoding UTF8 -NoNewline
  41. Write-Host " Fixed $TicketName : $EdgeLine"
  42. return $true
  43. }
  44. # Build edges
  45. $Success = $true
  46. foreach ($Ticket in Get-ChildItem $TicketsDir -Filter "*.md") {
  47. $Fixed = Fix-Edge $Ticket.FullName
  48. if (-not $Fixed) { $Success = $false }
  49. }
  50. # Validate count
  51. $ActualTicketCount = (Get-ChildItem $TicketsDir -Filter "*.md").Count
  52. if ($ActualTicketCount -ne $ExpectedMapTaskCount) {
  53. Write-Host "Ticket count mismatch: expected $ExpectedMapTaskCount, actual $ActualTicketCount"
  54. $Success = $false
  55. }
  56. # Validate each `Blocked by:`
  57. foreach ($Ticket in Get-ChildItem $TicketsDir -Filter "*.md") {
  58. $Content = Get-Content $Ticket.FullName -Raw
  59. if ($Content -match "(?m)^Blocked by: (.*?)$") {
  60. $Edge = $Matches[1]
  61. $Refs = $Edge -split "," | ForEach-Object { $_.Trim() }
  62. foreach ($Ref in $Refs) {
  63. if ($Ref -ne "None") {
  64. $Referenced = Get-ChildItem $TicketsDir -Filter "$Ref*.md"
  65. if (-not $Referenced) {
  66. Write-Host " Invalid reference in $($Ticket.Name): $Ref"
  67. $Success = $false
  68. }
  69. }
  70. }
  71. } else {
  72. Write-Host " Missing `Blocked by:` in $($Ticket.Name)"
  73. $Success = $false
  74. }
  75. }
  76. # Validate resolved research tickets (04 and 05 are resolved; 06 is open)
  77. $ResolvedResearch = @("04-research-cesium-ground-fog-mechanisms.md", "05-research-overlay-rectangle-pop-mechanisms.md")
  78. foreach ($Name in $ResolvedResearch) {
  79. $Ticket = Join-Path $TicketsDir $Name
  80. if (Test-Path $Ticket) {
  81. $Content = Get-Content $Ticket -Raw
  82. if ($Content -notmatch "(?m)^Status: resolved$") {
  83. Write-Host " Research ticket $Name not resolved"
  84. $Success = $false
  85. }
  86. } else {
  87. Write-Host " Missing research ticket $Name"
  88. $Success = $false
  89. }
  90. }
  91. if ($Success) {
  92. Write-Host "All edges built and validated successfully. Total tickets: $ActualTicketCount"
  93. } else {
  94. Write-Host "Validation failed. Please fix above issues."
  95. exit 1
  96. }