M5 AP-003 Unnötige Scope-Änderungen entfernt und Adapter-Tests auf

echten Outbound-Request geschärft
This commit is contained in:
2026-04-07 01:07:49 +02:00
parent 167b56bec5
commit 0246699e77
3 changed files with 67 additions and 165 deletions
@@ -102,6 +102,9 @@ public class OpenAiHttpAdapter implements AiInvocationPort {
private final String apiKey;
private final int apiTimeoutSeconds;
// Test-only field to capture the last built JSON body for assertion
private volatile String lastBuiltJsonBody;
/**
* Creates an adapter with configuration from startup configuration.
* <p>
@@ -236,6 +239,8 @@ public class OpenAiHttpAdapter implements AiInvocationPort {
URI endpoint = buildEndpointUri();
String requestBody = buildJsonRequestBody(request);
// Capture for test inspection (test-only field)
this.lastBuiltJsonBody = requestBody;
return HttpRequest.newBuilder(endpoint)
.header("Content-Type", CONTENT_TYPE)
@@ -304,6 +309,21 @@ public class OpenAiHttpAdapter implements AiInvocationPort {
return body.toString();
}
/**
* Package-private accessor for the last constructed JSON body.
* <p>
* <strong>For testing only:</strong> Allows tests to verify the actual
* JSON body sent in HTTP requests without exposing the BodyPublisher internals.
* This method is used by unit tests to assert that the correct model, text,
* and other fields are present in the outbound request.
*
* @return the last JSON body string constructed by {@link #buildRequest(AiRequestRepresentation)},
* or null if no request has been built yet
*/
String getLastBuiltJsonBodyForTesting() {
return lastBuiltJsonBody;
}
/**
* Executes the HTTP request and returns the response.
* <p>