Add dockerized fake-agent for integration testing and live edge-broker smoke tests. Introduce agent CLI status command and report helpers. Add browser shell session handling for disconnected agents. Extend tests and improve token validation flow.

This commit is contained in:
Jeppe Bundgaard
2026-04-09 16:31:38 +02:00
parent 745e68aa4f
commit 2a0a3468c1
11 changed files with 955 additions and 44 deletions
@@ -16,7 +16,6 @@ function with_edge_gateway_server_state(array $server, callable $callback): void
$originalServer = $_SERVER;
$originalPublicApiUrl = getenv('EDGE_PUBLIC_API_URL');
$originalBrokerPublicUrl = getenv('EDGE_BROKER_PUBLIC_URL');
$originalBrokerPublicPort = getenv('EDGE_BROKER_PUBLIC_PORT');
$_SERVER = $server;
@@ -34,11 +33,6 @@ function with_edge_gateway_server_state(array $server, callable $callback): void
} else {
putenv('EDGE_BROKER_PUBLIC_URL=' . $originalBrokerPublicUrl);
}
if ($originalBrokerPublicPort === false) {
putenv('EDGE_BROKER_PUBLIC_PORT');
} else {
putenv('EDGE_BROKER_PUBLIC_PORT=' . $originalBrokerPublicPort);
}
}
}
@@ -51,13 +45,15 @@ it('builds install script urls with forwarded https scheme when proxied', functi
$script = $manager->buildInstallScript('abc123');
expect($manager->getApiBaseUrl())->toBe('https://api.truckwash.io:4433');
expect($manager->buildInstallTokenVerifyUrl('abc123'))->toBe('https://api.truckwash.io:4433/edge-agent/install-token/verify?token=abc123');
expect($manager->buildInstallScriptUrl('abc123'))->toBe('https://api.truckwash.io:4433/edge-agent/install.sh?token=abc123');
expect($manager->buildInstallCommand('abc123'))->toContain("https://api.truckwash.io:4433/edge-agent/install.sh?token=abc123");
expect($script)->toContain('curl -fsSL "https://api.truckwash.io:4433/edge-agent/install-token/verify?token=abc123" >/dev/null');
expect($script)->toContain('mkdir -p "$INSTALL_DIR"');
expect($script)->toContain('curl -fsSL "https://api.truckwash.io:4433/edge-agent/artifacts/package.json" -o "$INSTALL_DIR/package.json"');
expect($script)->toContain('curl -fsSL "https://api.truckwash.io:4433/edge-agent/artifacts/agent.mjs" -o "$INSTALL_DIR/agent.mjs"');
expect($script)->toContain('"apiUrl":"https://api.truckwash.io:4433"');
expect($script)->toContain('"brokerUrl":"https://api.truckwash.io:4300"');
expect($script)->toContain('"brokerUrl":"https://api.truckwash.io:4433"');
expect($script)->not->toContain('Undefined variable $INSTALL_DIR');
});
});
@@ -84,11 +80,11 @@ it('infers https for the staging api host when only the https port is present',
expect($manager->getApiBaseUrl())->toBe('https://api.truckwash.io:4433');
expect($script)->toContain('"apiUrl":"https://api.truckwash.io:4433"');
expect($script)->toContain('"brokerUrl":"https://api.truckwash.io:4300"');
expect($script)->toContain('"brokerUrl":"https://api.truckwash.io:4433"');
});
});
it('prefers EDGE_PUBLIC_API_URL when explicitly configured', function (): void {
it('prefers EDGE_PUBLIC_API_URL when explicitly configured and derives the broker from the api origin', function (): void {
with_edge_gateway_server_state([
'HTTP_HOST' => 'localhost',
'HTTP_X_FORWARDED_PROTO' => 'http',
@@ -98,16 +94,18 @@ it('prefers EDGE_PUBLIC_API_URL when explicitly configured', function (): void {
$manager = new EdgeGatewayManagerUrlHarness();
expect($manager->getApiBaseUrl())->toBe('https://edge.example.test/api');
expect($manager->getBrokerPublicUrl())->toBe('https://edge.example.test');
expect($manager->buildInstallScriptUrl('token-1'))->toBe('https://edge.example.test/api/edge-agent/install.sh?token=token-1');
expect($manager->buildBrowserShellWsUrl('token-1'))->toBe('wss://edge.example.test/ws/browser-shell?token=token-1');
});
});
it('normalizes public broker overrides to https and browser shell urls to wss', function (): void {
it('normalizes public broker overrides to https, strips paths, and browser shell urls to wss', function (): void {
with_edge_gateway_server_state([
'HTTP_HOST' => 'localhost',
'HTTP_X_FORWARDED_PROTO' => 'http',
], function (): void {
putenv('EDGE_BROKER_PUBLIC_URL=http://api.truckwash.io:4300');
putenv('EDGE_BROKER_PUBLIC_URL=http://api.truckwash.io:4300/edge-broker');
$manager = new EdgeGatewayManagerUrlHarness();
@@ -138,6 +136,7 @@ it('includes node-pty build prerequisites in the generated install script', func
$manager = new EdgeGatewayManagerUrlHarness();
$script = $manager->buildInstallScript('pty-token');
expect($script)->toMatch('/set -euo pipefail\s+curl -fsSL "https:\/\/api\.truckwash\.io:4433\/edge-agent\/install-token\/verify\?token=pty-token" >\/dev\/null\s+INSTALL_DIR=\/opt\/truckwash-edge-agent/');
expect($script)->toContain('apt-get install -y curl ca-certificates nodejs npm python3 make g++');
expect($script)->toContain('npm install --omit=dev');
});