138 lines
4.9 KiB
PowerShell
138 lines
4.9 KiB
PowerShell
param(
|
|
[string]$SidecarExe = "runs/msglib-sidecar/MsgLibReadSidecar.exe",
|
|
[string]$SQLiteDllPath = $env:ISPHERE_MSGLIB_SQLITE_DLL,
|
|
[string]$DbPath = $env:ISPHERE_MSGLIB_DB,
|
|
[switch]$SkipBuild
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$repo = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")
|
|
$sidecarPath = Join-Path $repo $SidecarExe
|
|
|
|
function Invoke-SidecarJson([hashtable]$Request) {
|
|
$json = $Request | ConvertTo-Json -Depth 10 -Compress
|
|
$output = $json | & $sidecarPath
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "sidecar exited with code $LASTEXITCODE"
|
|
}
|
|
try {
|
|
return $output | ConvertFrom-Json
|
|
}
|
|
catch {
|
|
throw "sidecar output was not JSON: $output"
|
|
}
|
|
}
|
|
|
|
if (-not $SkipBuild) {
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $repo "scripts\build-msglib-sidecar.ps1") | Out-Host
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "build-msglib-sidecar.ps1 failed with exit code $LASTEXITCODE"
|
|
}
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $sidecarPath)) {
|
|
throw "sidecar not found: $sidecarPath"
|
|
}
|
|
|
|
$self = Invoke-SidecarJson @{
|
|
protocol = "isphere.msglib.v1"
|
|
request_id = "verify-self-check"
|
|
op = "self_check"
|
|
args = @{}
|
|
}
|
|
if (-not $self.ok -or $self.data.sidecar_name -ne "MsgLibReadSidecar" -or $self.data.process_bits -ne 32) {
|
|
throw "self_check failed: $($self | ConvertTo-Json -Depth 8 -Compress)"
|
|
}
|
|
|
|
$providerChecked = $false
|
|
$displaySources = $null
|
|
$displayEntitySummaries = @()
|
|
$messageSources = $null
|
|
$messageSourceSummaries = @()
|
|
if ($SQLiteDllPath -and $DbPath) {
|
|
if (-not (Test-Path -LiteralPath $SQLiteDllPath)) {
|
|
throw "SQLite DLL not found: $SQLiteDllPath"
|
|
}
|
|
if (-not (Test-Path -LiteralPath $DbPath)) {
|
|
throw "MsgLib DB not found: $DbPath"
|
|
}
|
|
$displaySources = Invoke-SidecarJson @{
|
|
protocol = "isphere.msglib.v1"
|
|
request_id = "verify-display-sources"
|
|
op = "display_sources"
|
|
args = @{
|
|
sqlite_dll_path = $SQLiteDllPath
|
|
db_path = $DbPath
|
|
password = "123"
|
|
include_counts = $true
|
|
max_tables = 64
|
|
}
|
|
}
|
|
if (-not $displaySources.ok -or -not $displaySources.data.metadata_only -or $displaySources.data.message_body_values_returned) {
|
|
throw "display_sources failed"
|
|
}
|
|
|
|
$messageSources = Invoke-SidecarJson @{
|
|
protocol = "isphere.msglib.v1"
|
|
request_id = "verify-message-sources"
|
|
op = "message_sources"
|
|
args = @{
|
|
sqlite_dll_path = $SQLiteDllPath
|
|
db_path = $DbPath
|
|
password = "123"
|
|
}
|
|
}
|
|
if (-not $messageSources.ok -or -not $messageSources.data.metadata_only -or -not $messageSources.data.read_only -or $messageSources.data.message_body_values_returned -or $messageSources.data.raw_rows_returned -or $messageSources.data.file_paths_returned) {
|
|
throw "message_sources failed"
|
|
}
|
|
foreach ($source in @($messageSources.data.message_sources)) {
|
|
$messageSourceSummaries += [ordered]@{
|
|
source = $source.source
|
|
table = $source.table
|
|
role = $source.role
|
|
available = $source.available
|
|
row_count = $source.row_count
|
|
}
|
|
}
|
|
|
|
foreach ($entityType in @("contacts", "groups")) {
|
|
$displayEntities = Invoke-SidecarJson @{
|
|
protocol = "isphere.msglib.v1"
|
|
request_id = "verify-display-entities-$entityType"
|
|
op = "display_entities"
|
|
args = @{
|
|
sqlite_dll_path = $SQLiteDllPath
|
|
db_path = $DbPath
|
|
password = "123"
|
|
entity_type = $entityType
|
|
limit = 5
|
|
}
|
|
}
|
|
if (-not $displayEntities.ok -or -not $displayEntities.data.metadata_only -or -not $displayEntities.data.read_only -or $displayEntities.data.message_body_values_returned -or $displayEntities.data.raw_rows_returned) {
|
|
throw "display_entities failed for $entityType"
|
|
}
|
|
$sourceTables = @($displayEntities.data.entities | ForEach-Object { $_.source_table } | Sort-Object -Unique)
|
|
$displayEntitySummaries += [ordered]@{
|
|
entity_type = $entityType
|
|
entity_count = @($displayEntities.data.entities).Count
|
|
source_tables = $sourceTables
|
|
}
|
|
}
|
|
$providerChecked = $true
|
|
}
|
|
|
|
[ordered]@{
|
|
ok = $true
|
|
sidecar = (Resolve-Path -LiteralPath $sidecarPath).Path
|
|
version = $self.data.sidecar_version
|
|
process_bits = $self.data.process_bits
|
|
provider_checked = $providerChecked
|
|
display_source_count = if ($displaySources) { $displaySources.data.display_sources.Count } else { 0 }
|
|
display_entity_summaries = $displayEntitySummaries
|
|
message_source_count = if ($messageSources) { $messageSources.data.message_sources.Count } else { 0 }
|
|
message_source_summaries = $messageSourceSummaries
|
|
message_body_values_returned = $false
|
|
raw_rows_returned = $false
|
|
file_paths_returned = $false
|
|
} | ConvertTo-Json -Depth 8 -Compress
|