From 4f9866418fa5829962226276daeacd327d72002d Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Sun, 25 Oct 2026 06:09:52 -0500 Subject: [PATCH] test(config): accept declared YAML configuration expressions (#6477) * test(config): accept declared YAML configuration expressions Recognize nonempty YAML enabled declarations before expression resolution, while preserving rejection of missing, null and blank declarations. Signed-off-by: Andre Kurait * test(config): reject container nodes as toggle declarations Reject YAML objects and arrays in the enabled declaration coverage guard while preserving scalar expression handling. Cover empty mappings and sequences alongside missing, null and blank declarations. Signed-off-by: Andre Kurait --------- Signed-off-by: Andre Kurait --- .../config/ServiceConfigYamlCoverageTest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/hectorvent/floci/config/ServiceConfigYamlCoverageTest.java b/src/test/java/io/github/hectorvent/floci/config/ServiceConfigYamlCoverageTest.java index dac89ff9d8..36f5c586a6 100644 --- a/src/test/java/io/github/hectorvent/floci/config/ServiceConfigYamlCoverageTest.java +++ b/src/test/java/io/github/hectorvent/floci/config/ServiceConfigYamlCoverageTest.java @@ -11,6 +11,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -38,7 +39,7 @@ class ServiceConfigYamlCoverageTest { continue; } String key = StringUtil.skewer(accessor.getName()); - if (!services.path(key).path("enabled").isBoolean()) { + if (!declaresEnabled(services.path(key))) { missing.add(config + " -> floci.services." + key + ".enabled"); } } @@ -50,6 +51,32 @@ class ServiceConfigYamlCoverageTest { + "not count, since it binds to nothing. Missing: " + missing); } + @Test + void explicitBooleanAndEnvironmentExpressionDeclareTheToggle() throws IOException { + for (String value : List.of("true", "false", "${FLOCI_SERVICES_RESOURCE_GROUPS_ENABLED:true}")) { + JsonNode service = new YAMLMapper().readTree("enabled: " + value); + assertTrue(declaresEnabled(service), value); + } + } + + @Test + void missingBareNullAndEmptyDeclarationsRemainMissing() throws IOException { + for (String yaml : List.of("{}", "service:", "service: {}", "service: {enabled: null}", + "service: {enabled: ''}", "service: {enabled: ' '}", + "service: {enabled: {}}", "service: {enabled: []}")) { + JsonNode service = new YAMLMapper().readTree(yaml).path("service"); + assertFalse(declaresEnabled(service), yaml); + } + } + + private static boolean declaresEnabled(JsonNode service) { + JsonNode enabled = service.path("enabled"); + // Config binding validates Boolean values after resolving expressions. This guard only + // checks that the YAML declares a value instead of relying on the interface fallback. + return enabled.isValueNode() && !enabled.isNull() + && (!enabled.isTextual() || !enabled.textValue().isBlank()); + } + /** * Config records without an {@code enabled()} toggle (for example {@code DuckConfig}, * which only carries an image and an optional URL) are not services that can be turned