diff --git a/plugin.json b/plugin.json index c38ef81..780db64 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "floci", - "version": "1.1.0", + "version": "1.1.1", "description": "Run, wire up and troubleshoot Floci, the free local emulators for AWS, GCP, Azure and OCI: floci-cli lifecycle, safe wiring of aws, gcloud, az, oci and the SDKs, docker run and Docker Compose files, several instances side by side, lookups in the published docs, and the Floci MCP server for agent tools.", "author": { "name": "Floci", diff --git a/skills/floci/references/troubleshooting.md b/skills/floci/references/troubleshooting.md index d3f3d7d..e99d49f 100644 --- a/skills/floci/references/troubleshooting.md +++ b/skills/floci/references/troubleshooting.md @@ -29,6 +29,7 @@ profile with a different `--port` rather than stopping containers you did not st Read `logs`. First pulls of the image and of child images (Lambda runtimes, postgres, k3s) can be slow; raise `--timeout`. `wait --service ` waits for one service on AWS, GCP and OCI; an unknown name, or any name on Azure, just times out. +`wait --service` on a service switched off (see docker.md) times out as well. **Requests reach real cloud** Most common cause is a fresh shell without the `eval`. Re-run the `env` command in the same diff --git a/src/main/java/io/floci/cli/http/FlociHttpClient.java b/src/main/java/io/floci/cli/http/FlociHttpClient.java index fbdc632..5d456a4 100644 --- a/src/main/java/io/floci/cli/http/FlociHttpClient.java +++ b/src/main/java/io/floci/cli/http/FlociHttpClient.java @@ -252,14 +252,16 @@ public class FlociHttpClient { } // Older images report services as an array of names; the contract reports a - // {name: status} object. Accept both. + // {name: status} object, where "available" marks a disabled service. Accept both. private static String[] serviceNames(JsonNode services) { if (services.isArray()) { return MAPPER.convertValue(services, String[].class); } if (services.isObject()) { List names = new ArrayList<>(); - services.fieldNames().forEachRemaining(names::add); + for (var service : services.properties()) { + if (!service.getValue().asText().equals("available")) names.add(service.getKey()); + } return names.toArray(String[]::new); } return new String[0]; diff --git a/src/test/java/io/floci/cli/unit/ControlPlaneFallbackTest.java b/src/test/java/io/floci/cli/unit/ControlPlaneFallbackTest.java index 4aa3f16..e5fe5c5 100644 --- a/src/test/java/io/floci/cli/unit/ControlPlaneFallbackTest.java +++ b/src/test/java/io/floci/cli/unit/ControlPlaneFallbackTest.java @@ -2,6 +2,8 @@ package io.floci.cli.unit; import com.sun.net.httpserver.HttpServer; import io.floci.cli.ProductProfile; +import io.floci.cli.commands.WaitCommand; +import io.floci.cli.docker.DockerClient; import io.floci.cli.doctor.CheckResult; import io.floci.cli.doctor.CheckStatus; import io.floci.cli.doctor.checks.EndpointReachableCheck; @@ -13,13 +15,17 @@ 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; +import picocli.CommandLine; +import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import java.io.PrintStream; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; @@ -307,6 +313,40 @@ class ControlPlaneFallbackTest { assertArrayEquals(new String[]{"s3", "sqs"}, client(ProductProfile.AWS).health().services()); } + /** The contract reports a disabled service as "available": it is left out, and any other status is kept. */ + @Test + void aServiceReportedAsAvailableIsDisabledAndLeftOut() throws Exception { + route("GET /_floci/health", 200, "{\"status\":\"UP\",\"cloud\":\"aws\",\"services\":{\"s3\":\"running\",\"sqs\":\"available\",\"sns\":\"running\"}}"); + assertArrayEquals(new String[]{"s3", "sns"}, client(ProductProfile.AWS).health().services()); + + route("GET /_floci/health", 200, HEALTH_UP); + assertArrayEquals(new String[]{"storage"}, client(ProductProfile.OCI).health().services()); + } + + @Test + void waitForADisabledServiceTimesOut() { + route("GET /_floci/health", 200, "{\"status\":\"UP\",\"cloud\":\"aws\",\"services\":{\"s3\":\"running\",\"sqs\":\"available\"}}"); + DockerClient noContainer = new DockerClient() { + @Override + public Optional inspectContainer(String name) { + return Optional.empty(); + } + }; + PrintStream out = System.out; + PrintStream err = System.err; + ByteArrayOutputStream errBuf = new ByteArrayOutputStream(); + System.setOut(new PrintStream(new ByteArrayOutputStream())); + System.setErr(new PrintStream(errBuf)); + try { + assertEquals(0, new CommandLine(new WaitCommand(ProductProfile.AWS, noContainer)).execute("--service", "s3", "--endpoint", endpoint())); + assertEquals(1, new CommandLine(new WaitCommand(ProductProfile.AWS, noContainer)).execute("--service", "sqs", "--timeout", "300ms", "--endpoint", endpoint())); + assertTrue(errBuf.toString().contains("Timed out waiting"), errBuf.toString()); + } finally { + System.setOut(out); + System.setErr(err); + } + } + // ---- doctor ------------------------------------------------------------------------------ @Test