<# .SYNOPSIS Validate a project brief (draft or approved) and say where to resume the interview. .DESCRIPTION -Mode Draft (default for briefs whose status is "draft"): lists what is still missing, grouped by interview stage, plus any errors or conflicts, and prints the stage and questions to resume with. -Mode Approved: everything must be complete, approved and free of conflicts; this is the same check the generator runs before writing anything. Exit codes: 0 = valid for the chosen mode, 1 = not valid, 4 = conflicts present (constraints the user must choose between). .EXAMPLE pwsh -File tools/Test-FoundryBrief.ps1 drafts/my-game.json pwsh -File tools/Test-FoundryBrief.ps1 examples/traffic-control-64/brief.json -Mode Approved #> [CmdletBinding()] param( [Parameter(Mandatory, Position = 0)][string]$Path, [ValidateSet('Draft', 'Approved', 'Auto')][string]$Mode = 'Auto', [switch]$Json ) Import-Module (Join-Path $PSScriptRoot 'Foundry.psm1') -Force try { $full = (Resolve-Path -LiteralPath $Path).ProviderPath $brief = Read-FoundryJson $full } catch { Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor Red exit 1 } $schema = Join-Path $PSScriptRoot '../schema/project-brief.schema.json' $schemaOk = Test-Json -Path $full -SchemaFile $schema -ErrorAction SilentlyContinue if (-not $schemaOk) { Write-Host "SCHEMA: $Path does not match schema/project-brief.schema.json (wrong type or an unknown enum value). Details from the rule checks follow." -ForegroundColor Red } if ($Mode -eq 'Auto') { $Mode = if ($brief.status -eq 'approved') { 'Approved' } else { 'Draft' } } $result = Test-FoundryBrief -Brief $brief -Mode $Mode -BriefPath $full if ($Json) { $result | ConvertTo-Json -Depth 6 } else { Format-FoundryValidation $result | Write-Host } if ($result.Conflicts.Count) { exit 4 } if (-not $result.Valid -or -not $schemaOk) { exit 1 } exit 0