<?php
/**
 * One-off verification for libs/host_resources.php.
 * Run on staging/prod: php /docker/whp/web/scripts/test-host-resources.php
 * (or whatever path the libs file ends up at; this loads it relatively)
 */

require_once(__DIR__ . '/../web-files/libs/host_resources.php');

$cores = whp_host_cpu_cores();
$mem_mb = whp_host_memory_mb();

printf("CPU cores: %d\n", $cores);
printf("Memory MB: %d (%.2f GB)\n", $mem_mb, $mem_mb / 1024);

// Sanity bounds — anything outside is almost certainly a parse bug
if ($cores < 1 || $cores > 256) {
    fprintf(STDERR, "FAIL: cores out of sane bounds (1-256)\n");
    exit(1);
}
if ($mem_mb < 512 || $mem_mb > 4 * 1024 * 1024) {  // 512MB - 4TB
    fprintf(STDERR, "FAIL: memory out of sane bounds (512MB-4TB)\n");
    exit(1);
}

// Static-cache check — second call should return identical values
if (whp_host_cpu_cores() !== $cores || whp_host_memory_mb() !== $mem_mb) {
    fprintf(STDERR, "FAIL: static cache changed between calls\n");
    exit(1);
}

echo "OK\n";
