diff --git a/fleetd/src/test/java/dev/ltms/fleet/FleetdExhaustionDetectionArmedWiringTest.java b/fleetd/src/test/java/dev/ltms/fleet/FleetdExhaustionDetectionArmedWiringTest.java index b11ff05..e1ddb29 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/FleetdExhaustionDetectionArmedWiringTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/FleetdExhaustionDetectionArmedWiringTest.java @@ -10,6 +10,8 @@ import org.junit.jupiter.api.io.TempDir; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Map; +import java.util.regex.Pattern; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -63,8 +65,30 @@ class FleetdExhaustionDetectionArmedWiringTest { assertTrue(config.get().profiles().get("terra").hasExhaustedPattern()); FleetMcp.QuarantineSource source = Fleetd.quarantineSource(config, BackendQuarantine.none(), - java.util.Map.of()); + Map.of()); assertFalse(source.exhaustedPatternArmed().apply("terra"), "exhaustionDetectionArmed must use the startup pattern map, not config.get()"); } + + @Test + @DisplayName("a profile in the startup pattern map is reported as armed") + void aProfileInTheStartupMapIsArmed(@TempDir Path dir) throws Exception { + // fleetd #404, second direction. The test above only ever passes an EMPTY startup map, so + // it cannot tell a correct lookup from one that is permanently off. Measured: replacing the + // armed lambda with `profile -> false` left the whole suite green at 1475 tests. That + // mutation would make #395's visibility feature dead — an operator fixing a detection gap + // would be told the gap is still open after fixing it, forever. Both directions are needed: + // this test is the only thing that fails when the field stops reporting armed at all. + Path file = dir.resolve("fleetd.yaml"); + Files.writeString(file, WITH_PATTERN); + ConfigRef config = new ConfigRef(file, FleetConfig.load(file)); + + FleetMcp.QuarantineSource source = Fleetd.quarantineSource(config, BackendQuarantine.none(), + Map.of("terra", Pattern.compile("usage limit"))); + + assertTrue(source.exhaustedPatternArmed().apply("terra"), + "a profile whose pattern was compiled at startup must report armed"); + assertFalse(source.exhaustedPatternArmed().apply("sonnet"), + "a profile absent from the startup map must not report armed"); + } }