#!/usr/bin/env bash
# Unit checks for RsshSessionProvisioner + RsshBastionProvisioner (no DB).
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
export CRASHES_CONFIG="${CRASHES_CONFIG:-$ROOT/config/config.example.php}"

php -r '
require "'"$ROOT"'/src/bootstrap.php";
$alloc = RsshSessionProvisioner::allocate("test-session-abc");
assert($alloc["username"] !== "");
assert($alloc["remote_bind_port"] >= 18000);
assert($alloc["local_forward_port"] === 8022);
$cmds = RsshBastionProvisioner::operatorCommands([
    "rssh_username" => $alloc["username"],
    "rssh_remote_port" => $alloc["remote_bind_port"],
]);
assert(isset($cmds["shell"]));
assert(str_contains($cmds["shell"], (string) $alloc["remote_bind_port"]));
echo "OK RsshSessionProvisioner + operatorCommands\n";
'

echo "All RSSH PHP unit checks passed."
