mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test: share one profile across four Bedrock proxy test classes (#5850)
Slice 10 of #4542. BedrockProxyIntegrationTest, BedrockProxyPassthroughIntegrationTest, and the cancellation and logging pair ran on three profiles between them. They now share BedrockProxyBackendProfile: the proxy backend on one stand-in port, the API key, the model mapping, and passthrough on. Each override only reaches the classes that test it. Only the stand-in in BedrockProxyIntegrationTest reads the Authorization header. The other classes call model ids the mapping does not name, and every call in BedrockProxyIntegrationTest names the mapped id, which the mapping resolves before passthrough is consulted. The one test that needs passthrough off, converse_noMappingNoDefaultNoPassthrough_returns400, moves to BedrockProxyTimeoutIntegrationTest, whose profile leaves passthrough off and sets no default model. The issue had the timeout class joining the shared profile too. It stays apart: its one-second request timeout would also close the upstreams the cancellation tests stall before their headers, so those tests would pass without a disconnect closing them. The new profile's javadoc lists each override, the classes that rely on it, why it is inert for the others, and why the timeout class stays apart. The moved classes gain or update a class javadoc saying what they get from it.
This commit is contained in:
1 parent
b0777a4020
commit
dea7e53f8f
6 files changed
+115
-66
No files matched your search
+13
-13
@@ -1,8 +1,8 @@
|
||||
package io.github.hectorvent.floci.services.bedrockruntime;
|
||||
|
||||
import io.github.hectorvent.floci.testing.BedrockProxyBackendProfile;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -17,17 +17,26 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.PORT;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Verifies that a caller who disconnects closes the upstream request, whether the upstream has
|
||||
* sent nothing yet, part of a response, or one streamed token.
|
||||
*
|
||||
* <p>The backend URL and passthrough come from {@link BedrockProxyBackendProfile}, which this class
|
||||
* shares with the other proxy classes that talk to a stand-in. The {@code fixture} model id is not
|
||||
* in that profile's mapping, so it reaches the stand-in through passthrough. The profile keeps the
|
||||
* default 60-second request timeout, far longer than these tests wait, so only the disconnect can
|
||||
* close an upstream that stalls before its headers.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(BedrockProxyCancellationIntegrationTest.Profile.class)
|
||||
@TestProfile(BedrockProxyBackendProfile.class)
|
||||
class BedrockProxyCancellationIntegrationTest {
|
||||
private static final int PORT = 18939;
|
||||
@TestHTTPResource
|
||||
URI base;
|
||||
|
||||
@@ -169,13 +178,4 @@ class BedrockProxyCancellationIntegrationTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Profile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("floci.services.bedrock-runtime.backend", "proxy",
|
||||
"floci.services.bedrock-runtime.proxy.url", "http://127.0.0.1:" + PORT + "/v1",
|
||||
"floci.services.bedrock-runtime.proxy.passthrough", "true");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-33
@@ -6,8 +6,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.sun.net.httpserver.Headers;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.testing.BedrockProxyBackendProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -20,9 +20,10 @@ import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.MAPPED_MODEL_ID;
|
||||
import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.PORT;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@@ -37,15 +38,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
* Verifies the Bedrock Runtime {@code proxy} backend translates Converse requests to
|
||||
* OpenAI Chat Completions and translates the response back to the Bedrock shape,
|
||||
* against a real (mock) OpenAI-compatible backend.
|
||||
*
|
||||
* <p>The backend, its URL, the API key and the model mapping come from
|
||||
* {@link BedrockProxyBackendProfile}, which this class shares with the other proxy classes that
|
||||
* talk to a stand-in. That profile also turns passthrough on, which no test here reaches, since
|
||||
* every call names the mapped model id. The case with no mapping, no default model and no
|
||||
* passthrough is in {@code BedrockProxyTimeoutIntegrationTest}, where passthrough stays off.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(BedrockProxyIntegrationTest.ProxyBackendProfile.class)
|
||||
@TestProfile(BedrockProxyBackendProfile.class)
|
||||
class BedrockProxyIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/bedrock/aws4_request";
|
||||
private static final int PORT = 18930;
|
||||
private static final String MAPPED_MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0";
|
||||
|
||||
@Inject
|
||||
ObjectMapper objectMapper;
|
||||
@@ -1322,32 +1327,4 @@ class BedrockProxyIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void converse_noMappingNoDefaultNoPassthrough_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"messages": [{"role": "user", "content": [{"text": "hi"}]}]}
|
||||
""")
|
||||
.when()
|
||||
.post("/model/unmapped.model-v1:0/converse")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
public static final class ProxyBackendProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.services.bedrock-runtime.backend", "proxy",
|
||||
"floci.services.bedrock-runtime.proxy.url", "http://127.0.0.1:" + PORT + "/v1",
|
||||
"floci.services.bedrock-runtime.proxy.api-key", "test-key",
|
||||
"floci.services.bedrock-runtime.proxy.model-mapping",
|
||||
MAPPED_MODEL_ID + "=claude-3-haiku"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-3
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.bedrockruntime;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.services.bedrockruntime.backend.ProxyBackend;
|
||||
import io.github.hectorvent.floci.testing.BedrockProxyBackendProfile;
|
||||
import io.github.hectorvent.floci.testutil.LogCapture;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
@@ -25,6 +26,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.PORT;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -32,8 +34,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Verifies that an upstream error reaches the caller as ModelErrorException with a bounded
|
||||
* description, while the operational log keeps the status and leaves out the upstream body.
|
||||
*
|
||||
* <p>The backend URL and passthrough come from {@link BedrockProxyBackendProfile}, which this class
|
||||
* shares with the other proxy classes that talk to a stand-in. The {@code fixture} model id is not
|
||||
* in that profile's mapping, so it reaches the stand-in through passthrough.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(BedrockProxyCancellationIntegrationTest.Profile.class)
|
||||
@TestProfile(BedrockProxyBackendProfile.class)
|
||||
class BedrockProxyLoggingIntegrationTest {
|
||||
|
||||
@TestHTTPResource
|
||||
@@ -43,7 +53,7 @@ class BedrockProxyLoggingIntegrationTest {
|
||||
@ValueSource(strings = {"converse", "converse-stream"})
|
||||
void upstreamErrorIsLoggedWithoutResponseBody(String operation) throws IOException {
|
||||
String marker = "synthetic-private-upstream-content";
|
||||
HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 18939), 0);
|
||||
HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", PORT), 0);
|
||||
backend.createContext("/v1/chat/completions", exchange -> {
|
||||
exchange.getRequestBody().readAllBytes();
|
||||
byte[] body = ("{\"error\":\"" + marker + "\"}").getBytes(StandardCharsets.UTF_8);
|
||||
@@ -80,7 +90,7 @@ class BedrockProxyLoggingIntegrationTest {
|
||||
@Test
|
||||
void streamingErrorBodyReadIsBoundedWithoutWaitingForEof() throws Exception {
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 18939), 0);
|
||||
HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", PORT), 0);
|
||||
backend.createContext("/v1/chat/completions", exchange -> {
|
||||
exchange.getRequestBody().readAllBytes();
|
||||
exchange.sendResponseHeaders(503, 32768);
|
||||
|
||||
+7
-17
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.bedrockruntime;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.testing.BedrockProxyBackendProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -14,9 +14,9 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.PORT;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -24,16 +24,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
/**
|
||||
* Verifies that with {@code proxy.passthrough=true} the raw Bedrock model id is forwarded
|
||||
* as-is to the OpenAI-compatible backend, bypassing the mapping/default-model requirement.
|
||||
* Kept in a separate class/profile since {@code @TestProfile} config overrides require a
|
||||
* fresh Quarkus application context, one per distinct override set.
|
||||
*
|
||||
* <p>Passthrough and the backend URL come from {@link BedrockProxyBackendProfile}, which this class
|
||||
* shares with the other proxy classes that talk to a stand-in. The raw model id is not in that
|
||||
* profile's mapping, so it reaches the backend through passthrough alone.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(BedrockProxyPassthroughIntegrationTest.PassthroughProfile.class)
|
||||
@TestProfile(BedrockProxyBackendProfile.class)
|
||||
class BedrockProxyPassthroughIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/bedrock/aws4_request";
|
||||
private static final int PORT = 18931;
|
||||
private static final String RAW_MODEL_ID = "meta.llama3-8b-instruct-v1:0";
|
||||
|
||||
@Inject
|
||||
@@ -87,15 +88,4 @@ class BedrockProxyPassthroughIntegrationTest {
|
||||
JsonNode sentRequest = objectMapper.readTree(receivedBody.get());
|
||||
assertEquals(RAW_MODEL_ID, sentRequest.path("model").asText());
|
||||
}
|
||||
|
||||
public static final class PassthroughProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.services.bedrock-runtime.backend", "proxy",
|
||||
"floci.services.bedrock-runtime.proxy.url", "http://127.0.0.1:" + PORT + "/v1",
|
||||
"floci.services.bedrock-runtime.proxy.passthrough", "true"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -6,6 +6,7 @@ import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@@ -21,6 +22,13 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
* Verifies that a slow backend response is surfaced as ModelTimeoutException (408),
|
||||
* not the generic ModelErrorException (424) - the AWS SDKs' default retry strategy
|
||||
* treats 408 as retryable and 424 as terminal.
|
||||
*
|
||||
* <p>Its profile leaves passthrough off and the default model unset, so this class also checks that
|
||||
* a model id with no mapping is refused before any backend call. It stays apart from
|
||||
* {@code BedrockProxyBackendProfile}, which the other proxy classes share: that profile turns
|
||||
* passthrough on, and a one-second timeout there would also close the upstreams that
|
||||
* {@code BedrockProxyCancellationIntegrationTest} stalls before their headers, so those tests
|
||||
* would pass without a disconnect closing them.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(BedrockProxyTimeoutIntegrationTest.SlowProxyBackendProfile.class)
|
||||
@@ -74,6 +82,21 @@ class BedrockProxyTimeoutIntegrationTest {
|
||||
.body("__type", equalTo("ModelTimeoutException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void converse_noMappingNoDefaultNoPassthrough_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"messages": [{"role": "user", "content": [{"text": "hi"}]}]}
|
||||
""")
|
||||
.when()
|
||||
.post("/model/unmapped.model-v1:0/converse")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
public static final class SlowProxyBackendProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.testing;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Runs the Bedrock Runtime {@code proxy} backend against a stand-in OpenAI-compatible server on
|
||||
* port {@value #PORT}, for the classes that test the proxy. Quarkus builds the application once
|
||||
* per distinct profile class, so they share this one rather than each declaring their own. Each
|
||||
* class starts its own stand-in on that port and stops it when its test ends.
|
||||
*
|
||||
* <p>The overrides, all under {@code floci.services.bedrock-runtime}, and who relies on them:
|
||||
* <ul>
|
||||
* <li>{@code backend=proxy}, with {@code proxy.url} on port {@value #PORT}, sends Converse to the
|
||||
* stand-in. Every class here relies on it.</li>
|
||||
* <li>{@code proxy.api-key=test-key} is sent as a bearer token.
|
||||
* {@code BedrockProxyIntegrationTest} relies on it.</li>
|
||||
* <li>{@code proxy.model-mapping} maps {@value #MAPPED_MODEL_ID} to {@code claude-3-haiku}.
|
||||
* {@code BedrockProxyIntegrationTest} relies on it.</li>
|
||||
* <li>{@code proxy.passthrough=true} forwards a model id with no mapping as it is.
|
||||
* {@code BedrockProxyPassthroughIntegrationTest}, {@code BedrockProxyCancellationIntegrationTest}
|
||||
* and {@code BedrockProxyLoggingIntegrationTest} rely on it.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Each override is inert for the classes that do not rely on it. Only the stand-in in
|
||||
* {@code BedrockProxyIntegrationTest} reads the {@code Authorization} header. The other classes
|
||||
* call model ids the mapping does not name, and every call in {@code BedrockProxyIntegrationTest}
|
||||
* names the mapped id, which the mapping resolves before passthrough is consulted.
|
||||
*
|
||||
* <p>{@code BedrockProxyTimeoutIntegrationTest} stays apart. Its one-second request timeout would
|
||||
* also close an upstream that stalls before its headers, so the cancellation tests would pass
|
||||
* without the disconnect handling they check. It also holds the test that needs passthrough off.
|
||||
*/
|
||||
public class BedrockProxyBackendProfile implements QuarkusTestProfile {
|
||||
|
||||
public static final int PORT = 18930;
|
||||
public static final String MAPPED_MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0";
|
||||
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.services.bedrock-runtime.backend", "proxy",
|
||||
"floci.services.bedrock-runtime.proxy.url", "http://127.0.0.1:" + PORT + "/v1",
|
||||
"floci.services.bedrock-runtime.proxy.api-key", "test-key",
|
||||
"floci.services.bedrock-runtime.proxy.model-mapping", MAPPED_MODEL_ID + "=claude-3-haiku",
|
||||
"floci.services.bedrock-runtime.proxy.passthrough", "true");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user