#!/usr/bin/env nu
# test-all.nu - Master test runner for provisioning tests
#
# Runs all provisioning tests and provides comprehensive report
#
# Usage: nu tests/provisioning/test-all.nu

def main [] {
    print ""
    print "╔══════════════════════════════════════════════════╗"
    print "║  syntaxis Provisioning Test Suite                ║"
    print "╚══════════════════════════════════════════════════╝"
    print ""

    let mut results = []
    let mut failed = false

    # Test 1: Presets validation
    print "Running preset tests..."
    try {
        nu tests/provisioning/test-presets.nu
        $results = ($results | append {name: "Presets", status: "PASS"})
        print "✓ Presets tests passed"
    } catch { |err|
        $results = ($results | append {name: "Presets", status: "FAIL", error: ($err | to string)})
        $failed = true
        print $"✗ Presets tests failed: ($err)"
    }

    print ""

    # Test 2: provctl detection
    print "Running provctl detection tests..."
    try {
        nu tests/provisioning/test-detect-provctl.nu
        $results = ($results | append {name: "provctl Detection", status: "PASS"})
        print "✓ provctl detection tests passed"
    } catch { |err|
        $results = ($results | append {name: "provctl Detection", status: "FAIL", error: ($err | to string)})
        $failed = true
        print $"✗ provctl detection tests failed: ($err)"
    }

    print ""

    # Summary
    print "╔══════════════════════════════════════════════════╗"
    print "║  Test Summary                                    ║"
    print "╚══════════════════════════════════════════════════╝"
    print ""

    for result in $results {
        if ($result.status == "PASS") {
            print $"  ✓ ($result.name): PASS"
        } else {
            print $"  ✗ ($result.name): FAIL"
            if ($result | has "error") {
                print $"    Error: ($result.error)"
            }
        }
    }

    let pass_count = ($results | where status == "PASS" | length)
    let fail_count = ($results | where status == "FAIL" | length)
    let total = ($results | length)

    print ""
    print $"Results: ($pass_count)/($total) test suites passed"

    if $failed {
        print ""
        print "⚠️  Some tests failed"
        exit 1
    } else {
        print ""
        print "🎉 All tests passed!"
    }
}

if ($nu.invocation-dir == (pwd)) {
    main
}
