fix(test): align AgentCommandControllerIT with current spec

Two drifts corrected:
- registerAgent helper missing required environmentId (spec: 400 if absent).
- sendGroupCommand is now synchronous request-reply: returns 200 with an
  aggregated CommandGroupResponse {success,total,responded,responses,timedOut}
  — no longer 202 with {targetCount,commandIds}. Updated assertions and name.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-21 21:18:14 +02:00
parent 7436a37b99
commit 97a6b2e010

View File

@@ -42,6 +42,7 @@ class AgentCommandControllerIT extends AbstractPostgresIT {
{
"instanceId": "%s",
"applicationId": "%s",
"environmentId": "default",
"version": "1.0.0",
"routeIds": ["route-1"],
"capabilities": {}
@@ -77,7 +78,7 @@ class AgentCommandControllerIT extends AbstractPostgresIT {
}
@Test
void sendGroupCommand_returns202WithTargetCount() throws Exception {
void sendGroupCommand_returns200WithAggregateReplies() throws Exception {
String group = "cmd-it-group-" + UUID.randomUUID().toString().substring(0, 8);
registerAgent("agent-g1-" + group, "Group Agent 1", group);
registerAgent("agent-g2-" + group, "Group Agent 2", group);
@@ -86,17 +87,20 @@ class AgentCommandControllerIT extends AbstractPostgresIT {
{"type": "deep-trace", "payload": {"correlationId": "group-trace-1"}}
""";
// Group dispatch is synchronous request-reply with a 10s deadline; returns
// 200 with the aggregated reply set (total/responded/timedOut). Neither agent
// holds an SSE connection in this test, so both time out but are counted.
ResponseEntity<String> response = restTemplate.postForEntity(
"/api/v1/agents/groups/" + group + "/commands",
new HttpEntity<>(commandJson, securityHelper.authHeaders(operatorJwt)),
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
JsonNode body = objectMapper.readTree(response.getBody());
assertThat(body.get("targetCount").asInt()).isEqualTo(2);
assertThat(body.get("commandIds").isArray()).isTrue();
assertThat(body.get("commandIds").size()).isEqualTo(2);
assertThat(body.get("total").asInt()).isEqualTo(2);
assertThat(body.get("timedOut").isArray()).isTrue();
assertThat(body.get("timedOut").size()).isEqualTo(2);
}
@Test