Private/Test-KadenIncompleteTransaction.ps1

function Test-KadenIncompleteTransaction {
    <#
    .SYNOPSIS
        Report whether a child repository has a transaction journal that did not complete.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [string]$ChildRoot
    )

    $txnRoot = Join-Path $ChildRoot (Join-Path '.kaden' 'transactions')
    if (-not (Test-Path -LiteralPath $txnRoot)) {
        return $false
    }

    $journals = @(Get-ChildItem -LiteralPath $txnRoot -Recurse -Filter 'journal.json' -File -ErrorAction SilentlyContinue)
    foreach ($journalFile in $journals) {
        try {
            $doc = Get-Content -LiteralPath $journalFile.FullName -Raw | ConvertFrom-Json
        }
        catch {
            return $true
        }
        if ([string]$doc.status -ne 'completed') {
            return $true
        }
    }

    return $false
}