133 lines
5.0 KiB
PowerShell
133 lines
5.0 KiB
PowerShell
param(
|
|
[string]$ArtifactRoot = "",
|
|
[string]$TenantId = "tenant-demo-001",
|
|
[string]$UserId = "",
|
|
[string]$Username = "admin@example.com",
|
|
[string]$DisplayName = "formal-launch-governance-snapshot",
|
|
[string]$DatabaseUrl = "",
|
|
[ValidateSet("none", "sqlite_governance")]
|
|
[string]$BootstrapMode = "none"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function New-Utf8NoBomEncoding {
|
|
return New-Object System.Text.UTF8Encoding($false)
|
|
}
|
|
|
|
function Write-Utf8File {
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$Path,
|
|
[Parameter(Mandatory = $true)][AllowEmptyString()][string]$Text
|
|
)
|
|
[System.IO.File]::WriteAllText($Path, $Text, (New-Utf8NoBomEncoding))
|
|
}
|
|
|
|
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
|
$backendRoot = Join-Path $repoRoot "backend"
|
|
$pythonPath = Join-Path $backendRoot ".venv\Scripts\python.exe"
|
|
$helperPath = Join-Path $backendRoot "tools\formal_launch_governance_cli.py"
|
|
$timestamp = Get-Date -Format "yyyy-MM-ddTHH-mm-ss-fff"
|
|
|
|
if ([string]::IsNullOrWhiteSpace($ArtifactRoot)) {
|
|
$ArtifactRoot = Join-Path $repoRoot "project-docs\qa-artifacts\formal-launch-governance-db-state"
|
|
}
|
|
if (-not [System.IO.Path]::IsPathRooted($ArtifactRoot)) {
|
|
$ArtifactRoot = Join-Path $repoRoot $ArtifactRoot
|
|
}
|
|
$artifactDir = Join-Path $ArtifactRoot $timestamp
|
|
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null
|
|
|
|
$rawOutputPath = Join-Path $artifactDir "formal-launch-governance-db-state.raw.log"
|
|
$summaryJson = Join-Path $artifactDir "formal-launch-governance-db-state-summary.json"
|
|
$summaryMd = Join-Path $artifactDir "formal-launch-governance-db-state-summary.md"
|
|
|
|
if (-not (Test-Path "$HOME\.Codex\skills\gstack\bin")) {
|
|
throw "gstack is required for all AI-assisted work in this repo."
|
|
}
|
|
if (-not (Test-Path -LiteralPath $pythonPath)) {
|
|
throw "backend virtualenv python not found: $pythonPath"
|
|
}
|
|
if (-not (Test-Path -LiteralPath $helperPath)) {
|
|
throw "formal launch governance helper not found: $helperPath"
|
|
}
|
|
|
|
$args = @(
|
|
$helperPath,
|
|
"snapshot",
|
|
"--tenant-id", $TenantId,
|
|
"--username", $Username,
|
|
"--display-name", $DisplayName,
|
|
"--bootstrap-mode", $BootstrapMode
|
|
)
|
|
if (-not [string]::IsNullOrWhiteSpace($UserId)) {
|
|
$args += @("--user-id", $UserId)
|
|
}
|
|
if (-not [string]::IsNullOrWhiteSpace($DatabaseUrl)) {
|
|
$args += @("--database-url", $DatabaseUrl)
|
|
}
|
|
|
|
$previousErrorActionPreference = $ErrorActionPreference
|
|
$ErrorActionPreference = "Continue"
|
|
try {
|
|
$output = & $pythonPath @args 2>&1
|
|
$exitCode = $LASTEXITCODE
|
|
} finally {
|
|
$ErrorActionPreference = $previousErrorActionPreference
|
|
}
|
|
|
|
$outputText = ($output -join [Environment]::NewLine)
|
|
Write-Utf8File -Path $rawOutputPath -Text $outputText
|
|
|
|
$jsonLine = @($output | Where-Object { $_ -match '^\{' } | Select-Object -Last 1)
|
|
if ($jsonLine.Count -eq 0) {
|
|
throw "formal launch governance snapshot did not return JSON payload"
|
|
}
|
|
|
|
$payload = $jsonLine[-1] | ConvertFrom-Json
|
|
$status = ([string]$payload.status).ToUpperInvariant()
|
|
$payload | ConvertTo-Json -Depth 12 | Set-Content -Encoding UTF8 -Path $summaryJson
|
|
|
|
$approvalMetrics = $payload.data.approval_metrics
|
|
$summary = $payload.data.summary
|
|
|
|
$md = New-Object System.Collections.Generic.List[string]
|
|
$md.Add("# Formal Launch Governance DB State") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("- status: $status") | Out-Null
|
|
$md.Add("- tenant_id: $($payload.tenant_id)") | Out-Null
|
|
$md.Add("- generated_at: $($payload.generated_at)") | Out-Null
|
|
$md.Add("- artifact_dir: $artifactDir") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("## Summary") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("| metric | value |") | Out-Null
|
|
$md.Add("|---|---:|") | Out-Null
|
|
$md.Add("| total_assets | $($summary.total_assets) |") | Out-Null
|
|
$md.Add("| pending_assignments | $($summary.pending_assignments) |") | Out-Null
|
|
$md.Add("| in_review_assignments | $($summary.in_review_assignments) |") | Out-Null
|
|
$md.Add("| review_tasks | $($approvalMetrics.review_tasks) |") | Out-Null
|
|
$md.Add("| missing_reviewer_tasks | $($approvalMetrics.missing_reviewer_tasks) |") | Out-Null
|
|
$md.Add("| approved_review_tasks | $($approvalMetrics.approved_review_tasks) |") | Out-Null
|
|
$md.Add("| approved_materials | $($approvalMetrics.approved_materials) |") | Out-Null
|
|
$md.Add("| approved_templates | $($approvalMetrics.approved_templates) |") | Out-Null
|
|
$md.Add("| approved_knowledge_cards | $($approvalMetrics.approved_knowledge_cards) |") | Out-Null
|
|
$md.Add("| approved_review_rules | $($approvalMetrics.approved_review_rules) |") | Out-Null
|
|
$md.Add("| approved_clauses | $($approvalMetrics.approved_clauses) |") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("## Latest Release Batch") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
if ($null -ne $payload.data.latest_release_batch) {
|
|
$md.Add("- batch_name: $($payload.data.latest_release_batch.batch_name)") | Out-Null
|
|
$md.Add("- release_status: $($payload.data.latest_release_batch.status)") | Out-Null
|
|
} else {
|
|
$md.Add("- none") | Out-Null
|
|
}
|
|
Write-Utf8File -Path $summaryMd -Text ($md -join [Environment]::NewLine)
|
|
|
|
Write-Output "FORMAL_LAUNCH_GOVERNANCE_DB_STATE_$status $artifactDir"
|
|
|
|
if ($exitCode -ne 0 -or $status -eq "FAIL") {
|
|
exit 1
|
|
}
|