mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
chore(config): declare every toggleable service in both application.yml files (#2422)
Six services (tagging, pipes, configservice, docdb, bedrock-agent-core and bedrock-agent-core-control) had no key in application.yml, and lightsail and cloudhsmv2 had a bare key with no child, so those two bound to nothing. All eight resolved only through the interface @WithDefault, which AGENTS.md does not treat as the source of truth: the YAML defines effective runtime behaviour and is what a user reads and edits. Add the missing keys to src/main/resources/application.yml and to the test config, and add ServiceConfigYamlCoverageTest so the next service cannot drift out. It derives each key with SmallRye's StringUtil.skewer, checking the real binding name rather than a reimplemented guess, and exempts configs with no enabled() toggle such as DuckConfig. The test config keys are for explicitness, not necessity: SmallRye merges both files as config sources per property, with the test file winning per key, so a service absent from the test config would inherit the main value rather than break. Declaring both keeps the two files readable side by side and stops a test-only override from being indistinguishable from an omission. An earlier draft of this message claimed the test file was required because Quarkus replaces rather than merges; that was wrong, and is corrected here. Every value written equals the prior @WithDefault, so runtime behaviour is unchanged. Typed chore rather than fix for that reason.
This commit is contained in:
1 parent
8b13725283
commit
a732e26bc5
3 files changed
+102
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import io.smallrye.config.common.utils.StringUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Guards the rule that {@code application.yml} — not an interface {@code @WithDefault} —
|
||||
* is the source of truth for which services run. A service reachable only through its
|
||||
* fallback default is invisible to anyone reading the config and cannot be toggled from
|
||||
* the file, which is how six services drifted out of both YAMLs before this test existed.
|
||||
*/
|
||||
class ServiceConfigYamlCoverageTest {
|
||||
|
||||
private static final List<Path> CONFIGS = List.of(
|
||||
Path.of("src/main/resources/application.yml"),
|
||||
Path.of("src/test/resources/application.yml"));
|
||||
|
||||
@Test
|
||||
void everyToggleableServiceDeclaresEnabledInBothConfigs() throws IOException {
|
||||
List<String> missing = new ArrayList<>();
|
||||
|
||||
for (Path config : CONFIGS) {
|
||||
JsonNode services = new YAMLMapper().readTree(config.toFile())
|
||||
.path("floci").path("services");
|
||||
|
||||
for (Method accessor : EmulatorConfig.ServicesConfig.class.getDeclaredMethods()) {
|
||||
if (!declaresEnabledToggle(accessor.getReturnType())) {
|
||||
continue;
|
||||
}
|
||||
String key = StringUtil.skewer(accessor.getName());
|
||||
if (!services.path(key).path("enabled").isBoolean()) {
|
||||
missing.add(config + " -> floci.services." + key + ".enabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(missing.isEmpty(),
|
||||
"Every service config with an enabled() toggle must declare it explicitly in both "
|
||||
+ "application.yml files. Note a bare 'service-name:' key with no child does "
|
||||
+ "not count, since it binds to nothing. Missing: " + missing);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* off, so they are exempt.
|
||||
*/
|
||||
private static boolean declaresEnabledToggle(Class<?> configInterface) {
|
||||
for (Method method : configInterface.getDeclaredMethods()) {
|
||||
if (method.getName().equals("enabled")
|
||||
&& method.getParameterCount() == 0
|
||||
&& (method.getReturnType() == boolean.class || method.getReturnType() == Boolean.class)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user