mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(bedrockagentcore): emulate the AgentCore control plane and InvokeAgentRuntime stub (#2316)
* docs(bedrockagentcore): add AgentCore emulation design + upgrade path
* feat(bedrockagentcore): add agent runtime CRUD control plane
Implements the bedrock-agentcore-control runtime registry (Phase 1):
Create/Get/List/Update/Delete AgentRuntime plus ListAgentRuntimeVersions,
with immutable version snapshots, cursor pagination, and ISO-8601 timestamps.
- REST-JSON controller + service + reflection-safe models
- ServiceRegistry descriptor + EmulatorConfig toggle
- Unit + RestAssured integration tests
- AWS SDK v2 compatibility test (sdk-test-java)
- Service docs page
Refs lex00/floci#2
* feat(bedrockagentcore): add agent runtime endpoints
Phase 2: Create/Get/Update/Delete/List AgentRuntimeEndpoint under
/runtimes/{id}/runtime-endpoints/, with a DEFAULT endpoint auto-created per
runtime and agentEndpoint/<uuid> ARNs. RestAssured + SDK v2 compat tests.
Refs lex00/floci#3
* feat(bedrockagentcore): add InvokeAgentRuntime data-plane stub
Phase 3: POST /runtimes/{agentRuntimeArn}/invocations returns a fixed,
configurable canned response ({"output":"yes"}) and echoes the runtime
session id. Opaque payload is never parsed; streaming is not emulated.
Separate stateless bedrock-agentcore service. RestAssured + SDK v2 compat tests.
Refs lex00/floci#4
* feat(bedrockagentcore): add tagging and workload identity
Phase 4:
- TagResource/UntagResource/ListTagsForResource for runtime ARNs via a
TagHandler on the shared /tags/{arn} route
- Workload identity RPC CRUD (POST /identities/<Op>); each runtime auto-creates
a resolvable workload identity
- Workload-identity timestamps are epoch-seconds (unixTimestamp), distinct from
the runtime ISO-8601 timestamps
RestAssured + SDK v2 compat tests.
Refs lex00/floci#5
* feat(bedrockagentcore): add gateway and memory primitives
Phase 5 (optional): metadata-only CRUD registries.
- Gateways (POST /gateways/) + gateway targets, standard REST
- Memory (POST /memories/create, GET /memories/{id}/details, ...), action-suffix
- Gateway timestamps are ISO-8601; memory timestamps are epoch seconds
RestAssured + SDK v2 compat tests.
Refs lex00/floci#6
* fix(bedrockagentcore): correctness fixes from adversarial audit
- Fix ListAgentRuntimeVersions pagination cycling for >=10 versions: sort by
the pagination cursor and zero-pad the version cursor (closes #7)
- Capture authorizerConfiguration/protocolConfiguration in version snapshots so
GetAgentRuntime?version returns the requested version's config (closes #8)
- Support tagging AgentCore gateways (AWS-taggable): add tags to Gateway,
dispatch the TagHandler by ARN resource type, store tags on CreateGateway;
non-taggable AgentCore ARNs now 400 (closes #9)
- Validate maxResults range (1..N) across all list operations (closes #12)
Adds regression tests: version-pagination multi-page, version-config snapshot,
gateway tag round-trip (REST + SDK), unsupported-ARN 400, maxResults + malformed
nextToken validation, and an HTTP-level multi-page pagination test.
Refs lex00/floci#14
* feat(bedrockagentcore): clientToken idempotency, invoke existence flag, config docs
- clientToken idempotency for Runtime/Endpoint/Memory create+delete (lenient:
same token returns the existing resource; completed-delete tokens tracked
in-memory so a replayed delete returns 202 not 404) (closes #10)
- InvokeAgentRuntime existence check behind floci.services.bedrock-agent-core
.validate-runtime-exists (default false, preserving permissive behavior);
when on, unknown runtime ARNs return ResourceNotFoundException (closes #11)
- Document that YAML config keys are hyphenated (bedrock-agent-core-control),
distinct from the reported service name (closes #13)
Adds unit tests (create/delete idempotency), a TestProfile integration test for
the existence flag, and an SDK v2 idempotency compat test.
Refs lex00/floci#10 lex00/floci#11 lex00/floci#13
* ci: trigger fork pipeline dry-run
* test(bedrockagentcore): add persistence, region-isolation, concurrency and boundary coverage
Closes the structural test gaps from the audit (issue #14):
- Persistence-across-restart: full AgentRuntime (JsonNode config, Instants,
version snapshots, endpoints, tags, env vars) round-trips through
PersistentStorage to disk and reloads intact
- Region isolation: a runtime is invisible/ungettable from another region
- Concurrency: concurrent creates all persist (no dropped inserts)
- Endpoint version retargeting, gateway + target update, duplicate-name 409,
and memory eventExpiryDuration boundaries (2/3/365/366)
Refs lex00/floci#14
* fix(bedrockagentcore): validate endpoint versions and the identity in a tagging ARN
createEndpoint and updateEndpoint stored agentRuntimeVersion without resolving
it against the runtime, so a version that was never published produced a READY
endpoint whose generated runtime ARN resolves to nothing. Both now reject one
the runtime has not published.
Tag operations resolved a resource from the ARN's id suffix alone, so an ARN
naming another account or region but a local id reached the local runtime or
gateway and could read or change its tags. The shared tag dispatch now checks
both fields against the request, which covers runtimes and gateways in one
place, and reports not found rather than a validation error so the response
does not confirm what sits behind the foreign identity.
This commit is contained in:
1 parent
6b14999974
commit
4e6e6df06d
43 files changed
+5405
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcore;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class BedrockAgentCoreInvokeIntegrationTest {
|
||||
|
||||
private static final String ARN =
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/abcdef12-3456-7890-abcd-ef1234567890:1";
|
||||
private static final String SESSION_ID = "session-0000000000000000000000000000abc";
|
||||
private static final String SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id";
|
||||
|
||||
@Test
|
||||
void invokeReturnsCannedBodyAndEchoesSession() {
|
||||
given()
|
||||
.header(SESSION_HEADER, SESSION_ID)
|
||||
.contentType("application/json")
|
||||
.body("{\"prompt\":\"anything\"}")
|
||||
.when().post("/runtimes/" + ARN + "/invocations")
|
||||
.then().statusCode(200)
|
||||
.header(SESSION_HEADER, SESSION_ID)
|
||||
.body("output", equalTo("yes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeAcceptsLargeUnparsedPayload() {
|
||||
byte[] big = new byte[1_000_000];
|
||||
java.util.Arrays.fill(big, (byte) 'x');
|
||||
given()
|
||||
.contentType("application/octet-stream")
|
||||
.body(big)
|
||||
.when().post("/runtimes/" + ARN + "/invocations")
|
||||
.then().statusCode(200)
|
||||
.body("output", equalTo("yes"));
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcore;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Verifies the opt-in existence check (issue #11). With
|
||||
* {@code validate-runtime-exists=true}, invoking an unknown runtime ARN returns 404
|
||||
* while invoking a real runtime's ARN still returns the canned body.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(BedrockAgentCoreInvokeValidateIntegrationTest.ValidateProfile.class)
|
||||
class BedrockAgentCoreInvokeValidateIntegrationTest {
|
||||
|
||||
public static class ValidateProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("floci.services.bedrock-agent-core.validate-runtime-exists", "true");
|
||||
}
|
||||
}
|
||||
|
||||
private static final String CREATE = """
|
||||
{
|
||||
"agentRuntimeName": "invAgent",
|
||||
"agentRuntimeArtifact": {"containerConfiguration": {"containerUri": "x:latest"}},
|
||||
"networkConfiguration": {"networkMode": "PUBLIC"},
|
||||
"roleArn": "arn:aws:iam::000000000000:role/agent"
|
||||
}""";
|
||||
|
||||
@Test
|
||||
void invokeKnownRuntimeSucceeds() {
|
||||
String arn = given().contentType("application/json").body(CREATE)
|
||||
.when().put("/runtimes/")
|
||||
.then().statusCode(202)
|
||||
.extract().path("agentRuntimeArn");
|
||||
|
||||
given().contentType("application/json").body("{}")
|
||||
.when().post("/runtimes/" + arn + "/invocations")
|
||||
.then().statusCode(200)
|
||||
.body("output", equalTo("yes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeUnknownRuntimeReturns404() {
|
||||
String unknown =
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/00000000-0000-0000-0000-000000000000:1";
|
||||
given().contentType("application/json").body("{}")
|
||||
.when().post("/runtimes/" + unknown + "/invocations")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreControlIntegrationTest {
|
||||
|
||||
private static final String CREATE_BODY = """
|
||||
{
|
||||
"agentRuntimeName": "itAgent",
|
||||
"agentRuntimeArtifact": {"containerConfiguration": {"containerUri": "x:latest"}},
|
||||
"networkConfiguration": {"networkMode": "PUBLIC"},
|
||||
"roleArn": "arn:aws:iam::000000000000:role/agent",
|
||||
"description": "v1"
|
||||
}""";
|
||||
|
||||
private static final String UPDATE_BODY = """
|
||||
{
|
||||
"agentRuntimeArtifact": {"containerConfiguration": {"containerUri": "x:v2"}},
|
||||
"networkConfiguration": {"networkMode": "PUBLIC"},
|
||||
"roleArn": "arn:aws:iam::000000000000:role/agent",
|
||||
"description": "v2"
|
||||
}""";
|
||||
|
||||
private static String runtimeId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createReturns202WithArn() {
|
||||
runtimeId = given().contentType("application/json").body(CREATE_BODY)
|
||||
.when().put("/runtimes/")
|
||||
.then().statusCode(202)
|
||||
.body("agentRuntimeId", matchesPattern("itAgent-[a-zA-Z0-9]{10}"))
|
||||
.body("agentRuntimeVersion", equalTo("1"))
|
||||
.body("status", equalTo("READY"))
|
||||
.body("agentRuntimeArn", containsString(":bedrock-agentcore:"))
|
||||
.body("agentRuntimeArn", containsString(":agent/"))
|
||||
.body("workloadIdentityDetails.workloadIdentityArn", notNullValue())
|
||||
.extract().path("agentRuntimeId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getReturnsRuntime() {
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/")
|
||||
.then().statusCode(200)
|
||||
.body("agentRuntimeName", equalTo("itAgent"))
|
||||
.body("agentRuntimeVersion", equalTo("1"))
|
||||
.body("description", equalTo("v1"))
|
||||
.body("agentRuntimeArtifact.containerConfiguration.containerUri", equalTo("x:latest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listReturnsRuntime() {
|
||||
given().contentType("application/json")
|
||||
.when().post("/runtimes/")
|
||||
.then().statusCode(200)
|
||||
.body("agentRuntimes.agentRuntimeId", hasItem(runtimeId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void updateBumpsVersion() {
|
||||
given().contentType("application/json").body(UPDATE_BODY)
|
||||
.when().put("/runtimes/" + runtimeId + "/")
|
||||
.then().statusCode(202)
|
||||
.body("agentRuntimeVersion", equalTo("2"))
|
||||
.body("lastUpdatedAt", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getOldVersionReturnsSnapshot() {
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/?version=1")
|
||||
.then().statusCode(200)
|
||||
.body("agentRuntimeVersion", equalTo("1"))
|
||||
.body("description", equalTo("v1"))
|
||||
.body("agentRuntimeArtifact.containerConfiguration.containerUri", equalTo("x:latest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void listVersionsReturnsBoth() {
|
||||
given().contentType("application/json")
|
||||
.when().post("/runtimes/" + runtimeId + "/versions/")
|
||||
.then().statusCode(200)
|
||||
.body("agentRuntimes.agentRuntimeVersion", hasItem("1"))
|
||||
.body("agentRuntimes.agentRuntimeVersion", hasItem("2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void deleteReturns202Deleting() {
|
||||
given().contentType("application/json")
|
||||
.when().delete("/runtimes/" + runtimeId + "/")
|
||||
.then().statusCode(202)
|
||||
.body("agentRuntimeId", equalTo(runtimeId))
|
||||
.body("status", equalTo("DELETING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void getAfterDeleteReturns404() {
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void createWithInvalidNameReturns400() {
|
||||
given().contentType("application/json")
|
||||
.body("{\"agentRuntimeName\":\"1bad\",\"agentRuntimeArtifact\":{},\"networkConfiguration\":{},\"roleArn\":\"r\"}")
|
||||
.when().put("/runtimes/")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
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.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;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class BedrockAgentCoreControlServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private BedrockAgentCoreControlService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new BedrockAgentCoreControlService(
|
||||
new InMemoryStorage<>(), new RegionResolver(REGION, "000000000000"));
|
||||
}
|
||||
|
||||
private ObjectNode artifact() {
|
||||
ObjectNode node = mapper.createObjectNode();
|
||||
node.putObject("containerConfiguration").put("containerUri", "123456789012.dkr.ecr/x:latest");
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode network() {
|
||||
ObjectNode node = mapper.createObjectNode();
|
||||
node.put("networkMode", "PUBLIC");
|
||||
return node;
|
||||
}
|
||||
|
||||
private AgentRuntime create(String name) {
|
||||
return service.createAgentRuntime(name, artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "desc", null, null, null, null, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGeneratesIdArnAndVersion() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
assertTrue(rt.getAgentRuntimeId().matches("myAgent-[a-zA-Z0-9]{10}"), rt.getAgentRuntimeId());
|
||||
assertEquals(1, rt.getLatestVersion());
|
||||
assertEquals("READY", rt.getStatus());
|
||||
assertTrue(rt.getWorkloadIdentityArn().contains(":bedrock-agentcore:"));
|
||||
assertTrue(service.arn(rt, "1", REGION)
|
||||
.matches("arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/[0-9a-f-]{36}:1"),
|
||||
service.arn(rt, "1", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsInvalidName() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> create("1bad-name"));
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsMissingRequiredFields() {
|
||||
assertThrows(AwsException.class, () -> service.createAgentRuntime("ok", null, network(),
|
||||
"arn:aws:iam::000000000000:role/agent", null, null, null, null, null, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBumpsVersionAndKeepsHistory() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
|
||||
AgentRuntime updated = service.updateAgentRuntime(id, artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent2", "v2", null, null, null, REGION);
|
||||
assertEquals(2, updated.getLatestVersion());
|
||||
assertEquals(2, updated.getVersions().size());
|
||||
assertTrue(service.resolveVersion(updated, "1").getRoleArn().endsWith("role/agent"));
|
||||
assertTrue(service.resolveVersion(updated, "2").getRoleArn().endsWith("role/agent2"));
|
||||
assertEquals("2", service.resolveVersion(updated, null).getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUnknownThrows404() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.getAgentRuntime("missing-abcdefghij", REGION));
|
||||
assertEquals(404, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveUnknownVersionThrows404() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.resolveVersion(rt, "9"));
|
||||
assertEquals(404, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listReturnsCreatedRuntimes() {
|
||||
create("agentA");
|
||||
create("agentB");
|
||||
ListResult<AgentRuntime> result = service.listAgentRuntimes(0, null, REGION);
|
||||
assertEquals(2, result.items().size());
|
||||
assertNull(result.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPaginatesWithToken() {
|
||||
create("agentA");
|
||||
create("agentB");
|
||||
create("agentC");
|
||||
ListResult<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);
|
||||
assertEquals(1, page2.items().size());
|
||||
assertNull(page2.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listVersionsPaginatesPastNineVersionsWithoutCycling() {
|
||||
// Regression for the numeric-sort / lexicographic-cursor pagination bug (issue #7).
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
service.updateAgentRuntime(id, artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "d", null, null, null, REGION);
|
||||
}
|
||||
// 12 versions ("1".."12"). Page with maxResults=5 and follow the cursor.
|
||||
Set<String> seen = new HashSet<>();
|
||||
String token = null;
|
||||
int pages = 0;
|
||||
do {
|
||||
ListResult<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)");
|
||||
} while (token != null);
|
||||
assertEquals(12, seen.size());
|
||||
assertTrue(seen.contains("10") && seen.contains("11") && seen.contains("12"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionSnapshotCapturesAuthorizerAndProtocolConfig() {
|
||||
// Regression for the version-config leak (issue #8).
|
||||
ObjectNode authA = mapper.createObjectNode();
|
||||
authA.putObject("customJWTAuthorizer").put("discoveryUrl", "A");
|
||||
ObjectNode authB = mapper.createObjectNode();
|
||||
authB.putObject("customJWTAuthorizer").put("discoveryUrl", "B");
|
||||
|
||||
AgentRuntime rt = service.createAgentRuntime("myAgent", artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "d", null, authA, null, null, REGION);
|
||||
String id = rt.getAgentRuntimeId();
|
||||
service.updateAgentRuntime(id, artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "d", null, authB, null, REGION);
|
||||
|
||||
AgentRuntime fresh = service.getAgentRuntime(id, REGION);
|
||||
assertEquals("A", service.resolveVersion(fresh, "1").getAuthorizerConfiguration()
|
||||
.path("customJWTAuthorizer").path("discoveryUrl").asText());
|
||||
assertEquals("B", service.resolveVersion(fresh, "2").getAuthorizerConfiguration()
|
||||
.path("customJWTAuthorizer").path("discoveryUrl").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRejectsOutOfRangeMaxResults() {
|
||||
create("agentA");
|
||||
assertEquals(400, assertThrows(AwsException.class,
|
||||
() -> service.listAgentRuntimes(101, null, REGION)).getHttpStatus());
|
||||
assertEquals(400, assertThrows(AwsException.class,
|
||||
() -> service.listAgentRuntimes(-1, null, REGION)).getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRejectsMalformedNextToken() {
|
||||
assertEquals(400, assertThrows(AwsException.class,
|
||||
() -> service.listAgentRuntimes(0, "!!!not-base64!!!", REGION)).getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createIsIdempotentByClientToken() {
|
||||
// Regression for issue #10.
|
||||
AgentRuntime a = service.createAgentRuntime("myAgent", artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "d", null, null, null, "tok-1", REGION);
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteIsIdempotentByClientToken() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
assertEquals("DELETING", service.deleteAgentRuntime(id, "del-1", REGION).getStatus());
|
||||
// Replayed delete with the same token succeeds instead of 404.
|
||||
assertEquals("DELETING", service.deleteAgentRuntime(id, "del-1", REGION).getStatus());
|
||||
// A different token against the now-missing id still 404s.
|
||||
assertEquals(404, assertThrows(AwsException.class,
|
||||
() -> service.deleteAgentRuntime(id, "other", REGION)).getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesAndReportsDeleting() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
AgentRuntime deleted = service.deleteAgentRuntime(id, null, REGION);
|
||||
assertEquals("DELETING", deleted.getStatus());
|
||||
assertThrows(AwsException.class, () -> service.getAgentRuntime(id, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimesAreIsolatedByRegion() {
|
||||
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());
|
||||
assertEquals(404, assertThrows(AwsException.class,
|
||||
() -> service.getAgentRuntime(id, "us-west-2")).getHttpStatus());
|
||||
// Same id resolves in its own region.
|
||||
assertEquals(id, service.getAgentRuntime(id, REGION).getAgentRuntimeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentCreatesAllPersist() throws InterruptedException {
|
||||
int n = 32;
|
||||
ExecutorService pool = Executors.newFixedThreadPool(8);
|
||||
AtomicInteger failures = new AtomicInteger();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final int idx = i;
|
||||
pool.submit(() -> {
|
||||
try {
|
||||
create("agent" + idx);
|
||||
} catch (RuntimeException e) {
|
||||
failures.incrementAndGet();
|
||||
}
|
||||
});
|
||||
}
|
||||
pool.shutdown();
|
||||
assertTrue(pool.awaitTermination(30, TimeUnit.SECONDS), "tasks did not finish");
|
||||
assertEquals(0, failures.get());
|
||||
assertEquals(n, service.listAgentRuntimes(100, null, REGION).items().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointRetargetsToRequestedVersion() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
service.updateAgentRuntime(id, artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", "v2", null, null, null, REGION);
|
||||
|
||||
AgentRuntimeEndpoint ep = service.createEndpoint(id, "prod", "2", "prod ep", null, REGION);
|
||||
assertEquals("2", ep.getTargetVersion());
|
||||
assertEquals("2", ep.getLiveVersion());
|
||||
|
||||
AgentRuntimeEndpoint retargeted = service.updateEndpoint(id, "prod", "1", null, REGION);
|
||||
assertEquals("1", retargeted.getTargetVersion());
|
||||
assertEquals("1", service.getEndpoint(id, "prod", REGION).getTargetVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateEndpointNameConflicts() {
|
||||
AgentRuntime rt = create("myAgent");
|
||||
String id = rt.getAgentRuntimeId();
|
||||
service.createEndpoint(id, "prod", null, null, null, REGION);
|
||||
assertEquals(409, assertThrows(AwsException.class,
|
||||
() -> service.createEndpoint(id, "prod", null, null, null, REGION)).getHttpStatus());
|
||||
// The auto-created DEFAULT endpoint also conflicts.
|
||||
assertEquals(409, assertThrows(AwsException.class,
|
||||
() -> service.createEndpoint(id, "DEFAULT", null, null, null, REGION)).getHttpStatus());
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreEndpointIntegrationTest {
|
||||
|
||||
private static final String CREATE_RUNTIME = """
|
||||
{
|
||||
"agentRuntimeName": "epAgent",
|
||||
"agentRuntimeArtifact": {"containerConfiguration": {"containerUri": "x:latest"}},
|
||||
"networkConfiguration": {"networkMode": "PUBLIC"},
|
||||
"roleArn": "arn:aws:iam::000000000000:role/agent"
|
||||
}""";
|
||||
|
||||
private static String runtimeId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void setupRuntimeHasDefaultEndpoint() {
|
||||
runtimeId = given().contentType("application/json").body(CREATE_RUNTIME)
|
||||
.when().put("/runtimes/")
|
||||
.then().statusCode(202)
|
||||
.extract().path("agentRuntimeId");
|
||||
|
||||
// The DEFAULT endpoint is auto-created with the runtime.
|
||||
given().contentType("application/json")
|
||||
.when().post("/runtimes/" + runtimeId + "/runtime-endpoints/")
|
||||
.then().statusCode(200)
|
||||
.body("runtimeEndpoints.name", hasItem("DEFAULT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createEndpoint() {
|
||||
given().contentType("application/json")
|
||||
.body("{\"name\":\"prod\",\"agentRuntimeVersion\":\"1\",\"description\":\"prod ep\"}")
|
||||
.when().put("/runtimes/" + runtimeId + "/runtime-endpoints/")
|
||||
.then().statusCode(202)
|
||||
.body("endpointName", equalTo("prod"))
|
||||
.body("targetVersion", equalTo("1"))
|
||||
.body("status", equalTo("READY"))
|
||||
.body("agentRuntimeEndpointArn", containsString(":agentEndpoint/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createEndpointOnAnUnpublishedVersionIsRejected() {
|
||||
// Storing the version unchecked produced a READY endpoint whose generated runtime ARN
|
||||
// resolves to nothing.
|
||||
given().contentType("application/json")
|
||||
.body("{\"name\":\"ghost\",\"agentRuntimeVersion\":\"99\"}")
|
||||
.when().put("/runtimes/" + runtimeId + "/runtime-endpoints/")
|
||||
.then().statusCode(400);
|
||||
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/runtime-endpoints/ghost/")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getEndpoint() {
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(200)
|
||||
.body("name", equalTo("prod"))
|
||||
.body("targetVersion", equalTo("1"))
|
||||
.body("description", equalTo("prod ep"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void listEndpoints() {
|
||||
given().contentType("application/json")
|
||||
.when().post("/runtimes/" + runtimeId + "/runtime-endpoints/")
|
||||
.then().statusCode(200)
|
||||
.body("runtimeEndpoints.name", hasItem("prod"))
|
||||
.body("runtimeEndpoints.name", hasItem("DEFAULT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void updateEndpointToAnUnpublishedVersionIsRejected() {
|
||||
given().contentType("application/json").body("{\"agentRuntimeVersion\":\"99\"}")
|
||||
.when().put("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(400);
|
||||
|
||||
// The endpoint keeps the version it had rather than pointing at one that does not exist.
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(200)
|
||||
.body("targetVersion", equalTo("1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void updateEndpointRetargetsVersion() {
|
||||
given().contentType("application/json").body("{\"description\":\"prod v2\"}")
|
||||
.when().put("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(202);
|
||||
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(200)
|
||||
.body("description", equalTo("prod v2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteEndpoint() {
|
||||
given().contentType("application/json")
|
||||
.when().delete("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(202)
|
||||
.body("status", equalTo("DELETING"));
|
||||
|
||||
given().contentType("application/json")
|
||||
.when().get("/runtimes/" + runtimeId + "/runtime-endpoints/prod/")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void createEndpointOnMissingRuntime404() {
|
||||
given().contentType("application/json").body("{\"name\":\"x\"}")
|
||||
.when().put("/runtimes/missing-abcdefghij/runtime-endpoints/")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreGatewayIntegrationTest {
|
||||
|
||||
private static final String CREATE = """
|
||||
{"name":"myGateway","authorizerType":"AWS_IAM","roleArn":"arn:aws:iam::000000000000:role/gw"}""";
|
||||
|
||||
private static String gatewayId;
|
||||
private static String targetId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createGateway() {
|
||||
gatewayId = given().contentType("application/json").body(CREATE)
|
||||
.when().post("/gateways/")
|
||||
.then().statusCode(202)
|
||||
.body("gatewayId", notNullValue())
|
||||
.body("gatewayArn", containsString(":gateway/"))
|
||||
.body("status", equalTo("READY"))
|
||||
.body("workloadIdentityDetails.workloadIdentityArn", notNullValue())
|
||||
.extract().path("gatewayId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getAndListGateway() {
|
||||
given().when().get("/gateways/" + gatewayId + "/")
|
||||
.then().statusCode(200)
|
||||
.body("name", equalTo("myGateway"))
|
||||
.body("protocolType", equalTo("MCP"));
|
||||
|
||||
given().when().get("/gateways/")
|
||||
.then().statusCode(200)
|
||||
.body("items.gatewayId", hasItem(gatewayId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createAndGetTarget() {
|
||||
targetId = given().contentType("application/json")
|
||||
.body("{\"name\":\"t1\",\"targetConfiguration\":{\"mcp\":{\"lambda\":{}}}}")
|
||||
.when().post("/gateways/" + gatewayId + "/targets/")
|
||||
.then().statusCode(202)
|
||||
.body("targetId", notNullValue())
|
||||
.body("gatewayArn", containsString(":gateway/"))
|
||||
.extract().path("targetId");
|
||||
|
||||
given().when().get("/gateways/" + gatewayId + "/targets/" + targetId + "/")
|
||||
.then().statusCode(200)
|
||||
.body("targetId", equalTo(targetId))
|
||||
.body("targetConfiguration.mcp.lambda", notNullValue());
|
||||
|
||||
given().when().get("/gateways/" + gatewayId + "/targets/")
|
||||
.then().statusCode(200)
|
||||
.body("items.targetId", hasItem(targetId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void updateGatewayAndTarget() {
|
||||
given().contentType("application/json")
|
||||
.body("{\"name\":\"myGateway\",\"authorizerType\":\"AWS_IAM\","
|
||||
+ "\"roleArn\":\"arn:aws:iam::000000000000:role/gw2\",\"description\":\"updated gw\"}")
|
||||
.when().put("/gateways/" + gatewayId + "/")
|
||||
.then().statusCode(202);
|
||||
given().when().get("/gateways/" + gatewayId + "/")
|
||||
.then().statusCode(200)
|
||||
.body("roleArn", equalTo("arn:aws:iam::000000000000:role/gw2"))
|
||||
.body("description", equalTo("updated gw"));
|
||||
|
||||
given().contentType("application/json")
|
||||
.body("{\"targetConfiguration\":{\"mcp\":{\"lambda\":{\"arn\":\"x\"}}},\"description\":\"t2\"}")
|
||||
.when().put("/gateways/" + gatewayId + "/targets/" + targetId + "/")
|
||||
.then().statusCode(202);
|
||||
given().when().get("/gateways/" + gatewayId + "/targets/" + targetId + "/")
|
||||
.then().statusCode(200)
|
||||
.body("description", equalTo("t2"))
|
||||
.body("targetConfiguration.mcp.lambda.arn", equalTo("x"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void deleteTargetAndGateway() {
|
||||
given().when().delete("/gateways/" + gatewayId + "/targets/" + targetId + "/")
|
||||
.then().statusCode(202)
|
||||
.body("status", equalTo("DELETING"));
|
||||
|
||||
given().when().delete("/gateways/" + gatewayId + "/")
|
||||
.then().statusCode(202)
|
||||
.body("status", equalTo("DELETING"));
|
||||
|
||||
given().when().get("/gateways/" + gatewayId + "/")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreMemoryIntegrationTest {
|
||||
|
||||
private static String memoryId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createMemory() {
|
||||
memoryId = given().contentType("application/json")
|
||||
.body("{\"name\":\"myMemory\",\"eventExpiryDuration\":30}")
|
||||
.when().post("/memories/create")
|
||||
.then().statusCode(202)
|
||||
.body("memory.id", notNullValue())
|
||||
.body("memory.name", equalTo("myMemory"))
|
||||
.body("memory.status", equalTo("ACTIVE"))
|
||||
.body("memory.arn", containsString(":memory/"))
|
||||
.extract().path("memory.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getAndListMemory() {
|
||||
given().when().get("/memories/" + memoryId + "/details")
|
||||
.then().statusCode(200)
|
||||
.body("memory.name", equalTo("myMemory"))
|
||||
.body("memory.eventExpiryDuration", equalTo(30));
|
||||
|
||||
given().contentType("application/json").body("{}")
|
||||
.when().post("/memories/")
|
||||
.then().statusCode(200)
|
||||
.body("memories.id", hasItem(memoryId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void updateMemory() {
|
||||
given().contentType("application/json").body("{\"description\":\"updated\"}")
|
||||
.when().put("/memories/" + memoryId + "/update")
|
||||
.then().statusCode(202)
|
||||
.body("memory.description", equalTo("updated"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void deleteMemory() {
|
||||
given().when().delete("/memories/" + memoryId + "/delete")
|
||||
.then().statusCode(202)
|
||||
.body("status", equalTo("DELETING"));
|
||||
|
||||
given().when().get("/memories/" + memoryId + "/details")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void createMemoryRequiresExpiry() {
|
||||
given().contentType("application/json").body("{\"name\":\"noExpiry\"}")
|
||||
.when().post("/memories/create")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void eventExpiryDurationBoundaries() {
|
||||
// In range (3..365) → accepted.
|
||||
for (int v : new int[]{3, 365}) {
|
||||
given().contentType("application/json")
|
||||
.body("{\"name\":\"memOk" + v + "\",\"eventExpiryDuration\":" + v + "}")
|
||||
.when().post("/memories/create").then().statusCode(202);
|
||||
}
|
||||
// Out of range → 400.
|
||||
for (int v : new int[]{2, 366}) {
|
||||
given().contentType("application/json")
|
||||
.body("{\"name\":\"memBad" + v + "\",\"eventExpiryDuration\":" + v + "}")
|
||||
.when().post("/memories/create").then().statusCode(400);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class BedrockAgentCorePaginationIntegrationTest {
|
||||
|
||||
private static String body(String name) {
|
||||
return "{\"agentRuntimeName\":\"" + name + "\","
|
||||
+ "\"agentRuntimeArtifact\":{\"containerConfiguration\":{\"containerUri\":\"x:latest\"}},"
|
||||
+ "\"networkConfiguration\":{\"networkMode\":\"PUBLIC\"},"
|
||||
+ "\"roleArn\":\"arn:aws:iam::000000000000:role/agent\"}";
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRuntimesPaginatesWithoutDuplicatesOrGaps() {
|
||||
// Exercises the HTTP-level nextToken round-trip (controller <-> service cursor).
|
||||
Set<String> mine = new HashSet<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String name = "pageAgent" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
String id = given().contentType("application/json").body(body(name))
|
||||
.when().put("/runtimes/")
|
||||
.then().statusCode(202)
|
||||
.extract().path("agentRuntimeId");
|
||||
mine.add(id);
|
||||
}
|
||||
|
||||
List<String> collected = new ArrayList<>();
|
||||
String token = null;
|
||||
int pages = 0;
|
||||
do {
|
||||
var req = given().contentType("application/json").queryParam("maxResults", 2);
|
||||
if (token != null) {
|
||||
req = req.queryParam("nextToken", token);
|
||||
}
|
||||
ExtractableResponse<Response> resp = req.when().post("/runtimes/")
|
||||
.then().statusCode(200).extract();
|
||||
List<String> ids = resp.path("agentRuntimes.agentRuntimeId");
|
||||
if (ids != null) {
|
||||
collected.addAll(ids);
|
||||
assertTrue(ids.size() <= 2, "page exceeded maxResults");
|
||||
}
|
||||
token = resp.path("nextToken");
|
||||
assertTrue(++pages < 200, "pagination did not terminate");
|
||||
} while (token != null);
|
||||
|
||||
// No duplicates across pages, and every runtime we created appears exactly once.
|
||||
assertEquals(collected.size(), new HashSet<>(collected).size(), "duplicate items across pages");
|
||||
assertTrue(collected.containsAll(mine), "a created runtime was dropped by pagination");
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Persistence-across-restart coverage: writes a fully-populated agent runtime through
|
||||
* {@link PersistentStorage} to disk and reloads it into a fresh instance (a simulated
|
||||
* restart), verifying that JsonNode config blobs, {@code Instant} timestamps, version
|
||||
* snapshots, endpoints, tags, and env vars all survive serialization. This is the path
|
||||
* exercised by {@code persistent}/{@code hybrid}/{@code wal} storage modes and native image.
|
||||
*/
|
||||
class BedrockAgentCorePersistenceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void agentRuntimeSurvivesPersistentStorageRoundTrip(@TempDir Path dir) {
|
||||
BedrockAgentCoreControlService svc = new BedrockAgentCoreControlService(
|
||||
new InMemoryStorage<>(), new RegionResolver(REGION, "000000000000"));
|
||||
|
||||
ObjectNode artifact = mapper.createObjectNode();
|
||||
artifact.putObject("containerConfiguration").put("containerUri", "x:latest");
|
||||
ObjectNode network = mapper.createObjectNode();
|
||||
network.put("networkMode", "PUBLIC");
|
||||
ObjectNode authorizer = mapper.createObjectNode();
|
||||
authorizer.putObject("customJWTAuthorizer").put("discoveryUrl", "https://issuer/.well-known");
|
||||
|
||||
AgentRuntime created = svc.createAgentRuntime("persistAgent", artifact, network,
|
||||
"arn:aws:iam::000000000000:role/agent", "v1", Map.of("K", "V"),
|
||||
authorizer, null, null, REGION);
|
||||
String id = created.getAgentRuntimeId();
|
||||
svc.updateAgentRuntime(id, artifact, network,
|
||||
"arn:aws:iam::000000000000:role/agent", "v2", null, authorizer, null, REGION);
|
||||
svc.createEndpoint(id, "prod", "1", "prod ep", null, REGION);
|
||||
AgentRuntime before = svc.getAgentRuntime(id, REGION);
|
||||
svc.tagByArn(REGION, svc.arn(before, "1", REGION), Map.of("env", "prod"));
|
||||
before = svc.getAgentRuntime(id, REGION);
|
||||
|
||||
// Write to disk, then reload into a brand-new backend (simulated restart).
|
||||
Path file = dir.resolve("bedrock-agentcore-runtimes.json");
|
||||
TypeReference<Map<String, AgentRuntime>> ref = new TypeReference<>() {};
|
||||
PersistentStorage<String, AgentRuntime> writer = new PersistentStorage<>(file, ref);
|
||||
writer.put("runtime:" + REGION + ":" + id, before);
|
||||
writer.flush();
|
||||
|
||||
PersistentStorage<String, AgentRuntime> reader = new PersistentStorage<>(file, ref);
|
||||
reader.load();
|
||||
AgentRuntime loaded = reader.get("runtime:" + REGION + ":" + id).orElseThrow();
|
||||
|
||||
assertEquals("persistAgent", loaded.getAgentRuntimeName());
|
||||
assertEquals(2, loaded.getLatestVersion());
|
||||
assertEquals(2, loaded.getVersions().size());
|
||||
assertNotNull(loaded.getCreatedAt());
|
||||
// JsonNode config blobs survive.
|
||||
assertEquals("x:latest", loaded.getAgentRuntimeArtifact()
|
||||
.path("containerConfiguration").path("containerUri").asText());
|
||||
assertEquals("https://issuer/.well-known", loaded.getAuthorizerConfiguration()
|
||||
.path("customJWTAuthorizer").path("discoveryUrl").asText());
|
||||
// Per-version snapshot JsonNode survives.
|
||||
assertNotNull(loaded.getVersions().get(0).getAgentRuntimeArtifact());
|
||||
// Env vars + tags + endpoints (DEFAULT + prod) survive.
|
||||
assertEquals("V", loaded.getEnvironmentVariables().get("K"));
|
||||
assertEquals("prod", loaded.getTags().get("env"));
|
||||
assertEquals(2, loaded.getEndpoints().size());
|
||||
assertTrue(loaded.getEndpoints().stream().anyMatch(e -> "prod".equals(e.getName())));
|
||||
assertTrue(loaded.getEndpoints().stream().anyMatch(e -> "DEFAULT".equals(e.getName())));
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreTaggingIdentityIntegrationTest {
|
||||
|
||||
private static final String CREATE_RUNTIME = """
|
||||
{
|
||||
"agentRuntimeName": "tagAgent",
|
||||
"agentRuntimeArtifact": {"containerConfiguration": {"containerUri": "x:latest"}},
|
||||
"networkConfiguration": {"networkMode": "PUBLIC"},
|
||||
"roleArn": "arn:aws:iam::000000000000:role/agent"
|
||||
}""";
|
||||
|
||||
private static String runtimeArn;
|
||||
private static String workloadIdentityArn;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createRuntimeCapturesArns() {
|
||||
var resp = given().contentType("application/json").body(CREATE_RUNTIME)
|
||||
.when().put("/runtimes/")
|
||||
.then().statusCode(202)
|
||||
.body("workloadIdentityDetails.workloadIdentityArn", notNullValue())
|
||||
.extract();
|
||||
runtimeArn = resp.path("agentRuntimeArn");
|
||||
workloadIdentityArn = resp.path("workloadIdentityDetails.workloadIdentityArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void tagUntagRoundTrip() {
|
||||
given().contentType("application/json").body("{\"tags\":{\"env\":\"prod\"}}")
|
||||
.when().post("/tags/" + runtimeArn)
|
||||
.then().statusCode(204);
|
||||
|
||||
given().when().get("/tags/" + runtimeArn)
|
||||
.then().statusCode(200)
|
||||
.body("tags.env", equalTo("prod"));
|
||||
|
||||
given().when().delete("/tags/" + runtimeArn + "?tagKeys=env")
|
||||
.then().statusCode(204);
|
||||
|
||||
given().when().get("/tags/" + runtimeArn)
|
||||
.then().statusCode(200)
|
||||
.body("tags.env", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void aForeignAccountOrRegionInTheArnDoesNotReachTheLocalResource() {
|
||||
// Both services resolve from the id suffix alone, so without an identity check these
|
||||
// reach the same local runtime and expose its tags through someone else's ARN.
|
||||
String foreignAccount = runtimeArn.replace(":000000000000:", ":111111111111:");
|
||||
String foreignRegion = runtimeArn.replace(":us-east-1:", ":eu-west-1:");
|
||||
|
||||
given().when().get("/tags/" + foreignAccount).then().statusCode(404);
|
||||
given().when().get("/tags/" + foreignRegion).then().statusCode(404);
|
||||
|
||||
given().contentType("application/json").body("{\"tags\":{\"env\":\"stolen\"}}")
|
||||
.when().post("/tags/" + foreignAccount)
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void workloadIdentityCrud() {
|
||||
given().contentType("application/json").body("{\"name\":\"wid_test_1\"}")
|
||||
.when().post("/identities/CreateWorkloadIdentity")
|
||||
.then().statusCode(201)
|
||||
.body("name", equalTo("wid_test_1"))
|
||||
.body("workloadIdentityArn", notNullValue());
|
||||
|
||||
given().contentType("application/json").body("{\"name\":\"wid_test_1\"}")
|
||||
.when().post("/identities/GetWorkloadIdentity")
|
||||
.then().statusCode(200)
|
||||
.body("name", equalTo("wid_test_1"));
|
||||
|
||||
given().contentType("application/json").body("{}")
|
||||
.when().post("/identities/ListWorkloadIdentities")
|
||||
.then().statusCode(200)
|
||||
.body("workloadIdentities.name", hasItem("wid_test_1"));
|
||||
|
||||
given().contentType("application/json").body("{\"name\":\"wid_test_1\"}")
|
||||
.when().post("/identities/DeleteWorkloadIdentity")
|
||||
.then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void runtimeWorkloadIdentityResolves() {
|
||||
String name = workloadIdentityArn.substring(workloadIdentityArn.lastIndexOf('/') + 1);
|
||||
given().contentType("application/json").body("{\"name\":\"" + name + "\"}")
|
||||
.when().post("/identities/GetWorkloadIdentity")
|
||||
.then().statusCode(200)
|
||||
.body("name", equalTo(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void gatewayTagRoundTrip() {
|
||||
// Regression for issue #9: gateways are AWS-taggable.
|
||||
String gwArn = given().contentType("application/json")
|
||||
.body("{\"name\":\"tagGw\",\"authorizerType\":\"AWS_IAM\","
|
||||
+ "\"roleArn\":\"arn:aws:iam::000000000000:role/gw\",\"tags\":{\"team\":\"core\"}}")
|
||||
.when().post("/gateways/")
|
||||
.then().statusCode(202)
|
||||
.extract().path("gatewayArn");
|
||||
|
||||
// tags provided at create time are retained
|
||||
given().when().get("/tags/" + gwArn)
|
||||
.then().statusCode(200).body("tags.team", equalTo("core"));
|
||||
|
||||
given().contentType("application/json").body("{\"tags\":{\"env\":\"prod\"}}")
|
||||
.when().post("/tags/" + gwArn).then().statusCode(204);
|
||||
given().when().get("/tags/" + gwArn)
|
||||
.then().statusCode(200)
|
||||
.body("tags.env", equalTo("prod"))
|
||||
.body("tags.team", equalTo("core"));
|
||||
|
||||
given().when().delete("/tags/" + gwArn + "?tagKeys=env").then().statusCode(204);
|
||||
given().when().get("/tags/" + gwArn)
|
||||
.then().statusCode(200)
|
||||
.body("tags.env", nullValue())
|
||||
.body("tags.team", equalTo("core"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void taggingUnsupportedResourceReturns400() {
|
||||
// Memory/endpoint ARNs are not taggable (AWS: runtime + gateway only).
|
||||
given().contentType("application/json").body("{\"tags\":{\"x\":\"y\"}}")
|
||||
.when().post("/tags/arn:aws:bedrock-agentcore:us-east-1:000000000000:memory/mymem-abc1234567")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user