fix(core): answer /_floci/ui/status with a map the native image can serialize (#8800)

GET /_floci/ui/status answered 500 in the native image: Jackson found
no properties on UiController.StatusResponse, a record whose components
the image carried no reflection metadata for, although the record had
@RegisterForReflection. The UI launcher polls this endpoint, so its
wait view stayed on "Starting Floci UI" after the sidecar was up.

The body is now a map, as the other /_floci endpoints build theirs,
which needs no reflection. Its {ready, url, error} shape is unchanged.

The AWS CLI compatibility suite, which runs against the native image,
calls the endpoint so a body that cannot be serialized there shows up.

Closes #5251
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 21:20:07 -04:00
1 parent 6bde4e6bb3
commit c2b9957032
4 files changed
+59 -16

No files matched your search

@@ -0,0 +1,16 @@
#!/usr/bin/env bats
# Floci UI launcher endpoints. These suites run against the native image, where a JSON body
# Jackson needs reflection metadata for answers 500 if that metadata is missing (#5251).
setup() {
load 'test_helper/common-setup'
}
@test "Floci UI: the status endpoint answers with its JSON body before the UI starts" {
run curl -sS -w '\n%{http_code}' "$FLOCI_ENDPOINT/_floci/ui/status"
assert_success
[ "$(printf '%s\n' "$output" | tail -n 1)" = "200" ]
body="$(printf '%s\n' "$output" | head -n -1)"
[ "$(printf '%s' "$body" | jq -r '.ready | type')" = "boolean" ]
[ "$(printf '%s' "$body" | jq -r 'has("url") and has("error")')" = "true" ]
}
@@ -3,7 +3,6 @@ package io.floci.aws.lifecycle;
import io.floci.aws.services.floci.ui.FlociUiManager;
import io.floci.aws.services.floci.ui.FlociUiManager.UiStatus;
import io.floci.aws.services.floci.ui.UiPages;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
@@ -12,6 +11,9 @@ import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Browser-facing endpoints that launch and redirect to the floci-ui sidecar.
*
@@ -42,21 +44,31 @@ public class UiController {
return Response.ok(uiPages.landingHtml()).build();
}
@RegisterForReflection
public record StatusResponse(boolean ready, String url, String error) {}
/**
* The sidecar's state. The body is a map, as the other {@code /_floci} endpoints build theirs: a record needs
* reflection metadata for its components that the native image did not have, and Jackson found no properties on
* it there, so the endpoint answered 500 and the wait view never redirected.
*/
@GET
@Path("/status")
@Produces(MediaType.APPLICATION_JSON)
public Response status(@HeaderParam("Host") String host) {
UiStatus s = uiManager.status();
if (s.error() != null) {
return Response.ok(new StatusResponse(false, null, s.error())).build();
return Response.ok(statusBody(false, null, s.error())).build();
}
if (s.ready() && s.hostPort() > 0) {
return Response.ok(new StatusResponse(true, redirectUrl(host, s.hostPort()), null)).build();
return Response.ok(statusBody(true, redirectUrl(host, s.hostPort()), null)).build();
}
return Response.ok(new StatusResponse(false, null, null)).build();
return Response.ok(statusBody(false, null, null)).build();
}
private static Map<String, Object> statusBody(boolean ready, String url, String error) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("ready", ready);
body.put("url", url);
body.put("error", error);
return body;
}
/** Builds the browser-reachable UI URL from the request Host and the published port. */
@@ -1,6 +1,5 @@
package io.floci.aws.lifecycle;
import io.floci.aws.lifecycle.UiController.StatusResponse;
import io.floci.aws.services.floci.ui.FlociUiManager;
import io.floci.aws.services.floci.ui.FlociUiManager.UiStatus;
import io.floci.aws.services.floci.ui.UiPages;
@@ -11,6 +10,9 @@ import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -40,7 +42,7 @@ class UiControllerTest {
void readyStatusReplacesOnlyTheHostPort(String host, String url) {
when(uiManager.status()).thenReturn(new UiStatus(true, true, 4500, null));
assertEquals(new StatusResponse(true, url, null), status(host));
assertEquals(body(true, url, null), status(host));
}
@ParameterizedTest
@@ -52,7 +54,7 @@ class UiControllerTest {
void malformedHostsKeepTheExistingBehavior(String host, String url) {
when(uiManager.status()).thenReturn(new UiStatus(true, true, 4500, null));
assertEquals(new StatusResponse(true, url, null), status(host));
assertEquals(body(true, url, null), status(host));
}
@ParameterizedTest
@@ -61,7 +63,7 @@ class UiControllerTest {
void missingHostDefaultsToLocalhost(String host) {
when(uiManager.status()).thenReturn(new UiStatus(true, true, 4500, null));
assertEquals(new StatusResponse(true, "http://localhost:4500/", null), status(host));
assertEquals(body(true, "http://localhost:4500/", null), status(host));
}
@ParameterizedTest
@@ -69,17 +71,26 @@ class UiControllerTest {
void statusWithoutAReadyPublishedPortHasNoUrl(boolean ready, int port) {
when(uiManager.status()).thenReturn(new UiStatus(true, ready, port, null));
assertEquals(new StatusResponse(false, null, null), status("[::1]:4566"));
assertEquals(body(false, null, null), status("[::1]:4566"));
}
@Test
void statusErrorTakesPrecedenceOverReadiness() {
when(uiManager.status()).thenReturn(new UiStatus(true, true, 4500, "sidecar failed"));
assertEquals(new StatusResponse(false, null, "sidecar failed"), status("[::1]:4566"));
assertEquals(body(false, null, "sidecar failed"), status("[::1]:4566"));
}
private StatusResponse status(String host) {
return (StatusResponse) controller.status(host).getEntity();
private Map<?, ?> status(String host) {
return (Map<?, ?>) controller.status(host).getEntity();
}
/** The {@code {ready, url, error}} body the wait view reads, every key present even when its value is null. */
private static Map<String, Object> body(boolean ready, String url, String error) {
Map<String, Object> body = new HashMap<>();
body.put("ready", ready);
body.put("url", url);
body.put("error", error);
return body;
}
}
@@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
/**
@@ -59,6 +60,9 @@ class UiLandingIntegrationTest {
.get("/_floci/ui/status")
.then()
.statusCode(200)
.body("ready", is(false));
.contentType(containsString("application/json"))
.body("ready", is(false))
.body("$", hasKey("url"))
.body("$", hasKey("error"));
}
}