mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(core): extract shared pagination helper, reject maxResults=0 (#2343)
Closes #2339, #2340. ListResult<T> and its paginate()/encode()/decode() helpers existed as five near-identical private copies (BedrockAgentCoreGatewayService, BedrockAgentCoreIdentityService, BedrockAgentCoreMemoryService, BedrockAgentCoreControlService's three list methods, and MskService), not the two originally scoped in #2340 - the ListResult<T> record was already shared within bedrockagentcorecontrol, which is what earlier scoping missed. Extracts core.common.Pagination + PaginatedResult<T> and migrates every one of them, deleting both now-unused per-service ListResult model classes. Every duplicate collapsed "maxResults omitted" and "maxResults=0" onto the same primitive int, defaulting both to the full page instead of rejecting the explicit zero the way AWS's MaxResults min:1 constraint requires (confirmed against botocore's real kafka and verified live: botocore itself refuses to send MaxResults=0 client-side). Pagination.paginate/parseMaxResults take a boxed Integer so the two cases are distinguishable, and every migrated service now rejects 0 with its own existing error code (ValidationException for the bedrockagentcorecontrol services, BadRequestException for MSK) - the fix lands once, not five times. Also carries over the MskController fix from #2336: an Integer-typed @QueryParam converts before the resource method runs, so a non-numeric maxResults was a bare 404 instead of an AWS-shaped 400. Every migrated REST controller now binds maxResults as a String and calls Pagination.parseMaxResults, closing the same gap in BedrockAgentCoreGatewayController/ControlController/MemoryController that MSK already had fixed.
This commit is contained in:
1 parent
1cc97d57c1
commit
25b46e28ad
18 files changed
+215
-338
No files matched your search
+16
-8
@@ -3,12 +3,12 @@ package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntime;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntimeEndpoint;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntimeVersion;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.ListResult;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -109,7 +109,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
void listReturnsCreatedRuntimes() {
|
||||
create("agentA");
|
||||
create("agentB");
|
||||
ListResult<AgentRuntime> result = service.listAgentRuntimes(0, null, REGION);
|
||||
PaginatedResult<AgentRuntime> result = service.listAgentRuntimes(null, null, REGION);
|
||||
assertEquals(2, result.items().size());
|
||||
assertNull(result.nextToken());
|
||||
}
|
||||
@@ -119,10 +119,10 @@ class BedrockAgentCoreControlServiceTest {
|
||||
create("agentA");
|
||||
create("agentB");
|
||||
create("agentC");
|
||||
ListResult<AgentRuntime> page1 = service.listAgentRuntimes(2, null, REGION);
|
||||
PaginatedResult<AgentRuntime> page1 = service.listAgentRuntimes(2, null, REGION);
|
||||
assertEquals(2, page1.items().size());
|
||||
assertTrue(page1.nextToken() != null);
|
||||
ListResult<AgentRuntime> page2 = service.listAgentRuntimes(2, page1.nextToken(), REGION);
|
||||
PaginatedResult<AgentRuntime> page2 = service.listAgentRuntimes(2, page1.nextToken(), REGION);
|
||||
assertEquals(1, page2.items().size());
|
||||
assertNull(page2.nextToken());
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
String token = null;
|
||||
int pages = 0;
|
||||
do {
|
||||
ListResult<AgentRuntimeVersion> page = service.listAgentRuntimeVersions(id, 5, token, REGION);
|
||||
PaginatedResult<AgentRuntimeVersion> page = service.listAgentRuntimeVersions(id, 5, token, REGION);
|
||||
page.items().forEach(v -> seen.add(v.getVersion()));
|
||||
token = page.nextToken();
|
||||
assertTrue(++pages <= 5, "pagination did not terminate (cycled)");
|
||||
@@ -183,7 +183,15 @@ class BedrockAgentCoreControlServiceTest {
|
||||
@Test
|
||||
void listRejectsMalformedNextToken() {
|
||||
assertEquals(400, assertThrows(AwsException.class,
|
||||
() -> service.listAgentRuntimes(0, "!!!not-base64!!!", REGION)).getHttpStatus());
|
||||
() -> service.listAgentRuntimes(null, "!!!not-base64!!!", REGION)).getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRejectsZeroMaxResults() {
|
||||
// AWS declares MaxResults with a minimum of 1; 0 is a real out-of-range value, not a
|
||||
// synonym for "omitted" (that's represented by null instead).
|
||||
assertEquals(400, assertThrows(AwsException.class,
|
||||
() -> service.listAgentRuntimes(0, null, REGION)).getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,7 +202,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
AgentRuntime b = service.createAgentRuntime("myAgent", artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "d", null, null, null, "tok-1", REGION);
|
||||
assertEquals(a.getAgentRuntimeId(), b.getAgentRuntimeId());
|
||||
assertEquals(1, service.listAgentRuntimes(0, null, REGION).items().size());
|
||||
assertEquals(1, service.listAgentRuntimes(null, null, REGION).items().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,7 +231,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
// Not visible or gettable from a different region.
|
||||
assertTrue(service.listAgentRuntimes(0, null, "us-west-2").items().isEmpty());
|
||||
assertTrue(service.listAgentRuntimes(null, null, "us-west-2").items().isEmpty());
|
||||
assertEquals(404, assertThrows(AwsException.class,
|
||||
() -> service.getAgentRuntime(id, "us-west-2")).getHttpStatus());
|
||||
// Same id resolves in its own region.
|
||||
|
||||
+9
@@ -61,4 +61,13 @@ class BedrockAgentCorePaginationIntegrationTest {
|
||||
assertEquals(collected.size(), new HashSet<>(collected).size(), "duplicate items across pages");
|
||||
assertTrue(collected.containsAll(mine), "a created runtime was dropped by pagination");
|
||||
}
|
||||
|
||||
// AWS declares MaxResults with a minimum of 1; 0 is real out-of-range input, not a
|
||||
// synonym for "omitted" (an absent query param instead).
|
||||
@Test
|
||||
void listRuntimesRejectsZeroMaxResults() {
|
||||
given().contentType("application/json").queryParam("maxResults", 0)
|
||||
.when().post("/runtimes/")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
}
|
||||
+9
@@ -270,6 +270,15 @@ class MskControllerIntegrationTest {
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
// AWS declares MaxResults with a minimum of 1; 0 is real out-of-range input, not a
|
||||
// synonym for "omitted" (that's an absent query param instead).
|
||||
@Test
|
||||
void listConfigurationsRejectsZeroMaxResults() {
|
||||
given()
|
||||
.when().get("/v1/configurations?maxResults=0")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
// maxResults is bound as a raw String and parsed by hand rather than @QueryParam
|
||||
// Integer specifically because a non-numeric value for an Integer-typed @QueryParam
|
||||
// fails RESTEasy Reactive's own conversion before the method body runs, and its
|
||||
|
||||
@@ -6,9 +6,9 @@ import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.services.msk.model.ClusterState;
|
||||
import io.github.hectorvent.floci.services.msk.model.ConfigurationState;
|
||||
import io.github.hectorvent.floci.services.msk.model.ListResult;
|
||||
import io.github.hectorvent.floci.services.msk.model.MskCluster;
|
||||
import io.github.hectorvent.floci.services.msk.model.MskConfiguration;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -153,7 +153,7 @@ class MskServiceTest {
|
||||
void listConfigurations() {
|
||||
mskService.createConfiguration("config-1", "desc", List.of("3.6.0"), "props");
|
||||
mskService.createConfiguration("config-2", "desc", List.of("3.6.0"), "props");
|
||||
List<MskConfiguration> configurations = mskService.listConfigurations(0, null).items();
|
||||
List<MskConfiguration> configurations = mskService.listConfigurations(null, null).items();
|
||||
assertEquals(2, configurations.size());
|
||||
}
|
||||
|
||||
@@ -163,11 +163,11 @@ class MskServiceTest {
|
||||
mskService.createConfiguration("config-2", "desc", List.of("3.6.0"), "props");
|
||||
mskService.createConfiguration("config-3", "desc", List.of("3.6.0"), "props");
|
||||
|
||||
ListResult<MskConfiguration> firstPage = mskService.listConfigurations(2, null);
|
||||
PaginatedResult<MskConfiguration> firstPage = mskService.listConfigurations(2, null);
|
||||
assertEquals(2, firstPage.items().size());
|
||||
assertNotNull(firstPage.nextToken());
|
||||
|
||||
ListResult<MskConfiguration> secondPage = mskService.listConfigurations(2, firstPage.nextToken());
|
||||
PaginatedResult<MskConfiguration> secondPage = mskService.listConfigurations(2, firstPage.nextToken());
|
||||
assertEquals(1, secondPage.items().size());
|
||||
assertNull(secondPage.nextToken());
|
||||
}
|
||||
@@ -177,9 +177,17 @@ class MskServiceTest {
|
||||
assertThrows(AwsException.class, () -> mskService.listConfigurations(101, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listConfigurationsRejectsZeroMaxResults() {
|
||||
// AWS declares MaxResults with a minimum of 1; 0 is a real out-of-range value, not a
|
||||
// synonym for "omitted" (that's represented by null instead).
|
||||
AwsException ex = assertThrows(AwsException.class, () -> mskService.listConfigurations(0, null));
|
||||
assertEquals("BadRequestException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listConfigurationsRejectsInvalidNextToken() {
|
||||
assertThrows(AwsException.class, () -> mskService.listConfigurations(0, "not-a-valid-token!!"));
|
||||
assertThrows(AwsException.class, () -> mskService.listConfigurations(null, "not-a-valid-token!!"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,7 +195,7 @@ class MskServiceTest {
|
||||
MskConfiguration configuration = mskService.createConfiguration(
|
||||
"test-config", "desc", List.of("3.6.0"), "props");
|
||||
mskService.deleteConfiguration(configuration.getArn());
|
||||
assertTrue(mskService.listConfigurations(0, null).items().isEmpty());
|
||||
assertTrue(mskService.listConfigurations(null, null).items().isEmpty());
|
||||
}
|
||||
|
||||
// StorageBackend persists this model via plain Jackson serialization (PersistentStorage,
|
||||
|
||||
Reference in new issue
Block a user