Add new tests for shell bridge and broker to handle structured failures and invalid session handling

- Add tests for shell bridge to validate structured error reporting on spawn failures.

- Add broker tests to ensure proper rejection of malformed browser shell upgrades without leaking sensitive tokens.

- Update `.env.example` with `EDGE_PUBLIC_BROKER_URL` for public access configuration.
This commit is contained in:
Jeppe Bundgaard
2026-04-28 09:00:12 +02:00
parent e93d3f30d2
commit 2aded0812a
10 changed files with 2699 additions and 13 deletions
@@ -169,6 +169,14 @@ it('assembles tasks, logs, statistics, operations, commands, and shell lifecycle
->and($commandResult['job']['status'] ?? null)
->toBe('COMPLETED');
$context['manager']->recordBrokerPresence(
$gatewayId,
'connected',
'broker-connection-1',
null,
['transport' => 'ws']
);
$shellSession = $context['manager']->createShellSession(
$gatewayId,
(int)$user['id'],
@@ -179,6 +187,8 @@ it('assembles tasks, logs, statistics, operations, commands, and shell lifecycle
);
$shellToken = (string)($shellSession['token'] ?? '');
expect($shellToken)->not->toBe('');
expect($shellSession['diagnostics']['broker_presence']['connection_id'] ?? null)
->toBe('broker-connection-1');
$validatedShell = $context['manager']->validateShellSessionToken($shellToken);
expect($validatedShell)->toHaveKey('status', 'PENDING');
@@ -189,12 +199,21 @@ it('assembles tasks, logs, statistics, operations, commands, and shell lifecycle
$closedShell = $context['manager']->closeShellSessionByToken(
$shellToken,
"edge-shell-output\n",
'agent_exit'
'agent_exit',
[
'message' => 'Integration shell completed.',
'code' => 0,
'stage' => 'shell_active',
]
);
expect($closedShell)
->toHaveKey('status', 'COMPLETED')
->and($closedShell['transcript'] ?? null)
->toBe("edge-shell-output\n");
->toBe("edge-shell-output\n")
->and($closedShell['metadata']['close_reason'] ?? null)
->toBe('agent_exit')
->and($closedShell['metadata']['close_stage'] ?? null)
->toBe('shell_active');
$context['manager']->appendGatewayLogEntry(
$gatewayId,
@@ -205,14 +224,6 @@ it('assembles tasks, logs, statistics, operations, commands, and shell lifecycle
['source' => 'integration']
);
$context['manager']->recordBrokerPresence(
$gatewayId,
'connected',
'broker-connection-1',
null,
['transport' => 'ws']
);
$context['manager']->recordTelemetryFromBroker($gatewayId, [
'status' => 'ONLINE',
'metadata' => [