Gate hydrology probes

- Count roof breaches as sea inlet check failures
- Count raised berms over the fill cap as hydrology probe failures
- Exit the sea inlet gate with 1 on failed checks, order mismatches, inlets off sea level or leaks the inlets add
- Exit sea inlet inventory with 1 when a window fails to plan
- Exit the cave pool probe with 1 on containment failures or order mismatches
- Print a gate status line for both probes
- Cover the failure counting in the probe unit tests
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 16:02:46 -05:00
1 parent 30c7492679
commit bb6f3ca40b
6 files changed
+127 -22

No files matched your search

@@ -80,19 +80,30 @@ public final class CavePoolProbe {
}
}
record Gate(Counts counts, int orderMismatches) {
long failures() {
return counts.failures() + orderMismatches;
}
String line() {
return String.format(Locale.ROOT, "CAVE_POOL_GATE status=%s failures=%d containment_failures=%d order_mismatches=%d",
failures() == 0L ? "PASS" : "FAIL", failures(), counts.failures(), orderMismatches);
}
}
static Counts check(Engine engine, Area area, ExecutorService workers) throws Exception {
return count(survey(engine, area, workers), area);
}
public static void main(String[] arguments) {
int exitCode = 1;
try {
scan(Configuration.parse(arguments));
System.exit(0);
exitCode = scan(Configuration.parse(arguments)).failures() == 0L ? 0 : 1;
} catch (Throwable failure) {
System.out.println(LOG_PREFIX + " FAIL");
failure.printStackTrace(System.out);
System.exit(1);
}
System.exit(exitCode);
}
private static RealPackProbeSupport.Workspace workspace(Configuration configuration) throws Exception {
@@ -100,7 +111,7 @@ public final class CavePoolProbe {
LOG_PREFIX, null, configuration.work()));
}
private static void scan(Configuration configuration) throws Exception {
private static Gate scan(Configuration configuration) throws Exception {
try (RealPackProbeSupport.Workspace workspace = workspace(configuration)) {
Survey forward;
try (RealPackProbeSupport.EngineSession session = workspace.openEngine(configuration.seed(), false, "forward")) {
@@ -109,7 +120,8 @@ public final class CavePoolProbe {
forward = survey(engine, configuration.area(), null);
requireQuiet(engine, "forward");
}
report(count(forward, configuration.area()));
Counts counts = count(forward, configuration.area());
report(counts);
Map<Long, Long> shuffled;
try (RealPackProbeSupport.EngineSession session = workspace.openEngine(configuration.seed(), false, "shuffled")) {
Engine engine = session.engine();
@@ -117,7 +129,9 @@ public final class CavePoolProbe {
shuffled = hashes(engine, configuration);
requireQuiet(engine, "shuffled");
}
compare(forward.hashes(), shuffled);
Gate gate = new Gate(counts, compare(forward.hashes(), shuffled));
System.out.println(gate.line());
return gate;
}
}
@@ -338,7 +352,7 @@ public final class CavePoolProbe {
}
}
private static void compare(Map<Long, Long> forward, Map<Long, Long> shuffled) {
static int compare(Map<Long, Long> forward, Map<Long, Long> shuffled) {
int mismatches = 0;
List<String> examples = new ArrayList<>();
for (Map.Entry<Long, Long> entry : forward.entrySet()) {
@@ -355,6 +369,7 @@ public final class CavePoolProbe {
}
System.out.printf(Locale.ROOT, "CAVE_POOL_ORDER chunks=%d mismatches=%d signature=%016x examples=%s%n", forward.size(), mismatches,
signature, examples);
return mismatches;
}
static Counts count(Survey survey, Area area) {
@@ -43,7 +43,7 @@ final class HydrologyReport {
boolean passes() {
return maxDependencyDepth() == 0 && sum(WindowMetrics::containmentLeaks) == 0 && sum(WindowMetrics::risingWaterSegments) == 0
&& sum(WindowMetrics::seamMismatches) == 0 && sum(WindowMetrics::tickConversionCells) == 0
&& sum(WindowMetrics::missingSurface) == 0
&& sum(WindowMetrics::missingSurface) == 0 && sum(WindowMetrics::bermOverCap) == 0
&& sum(WindowMetrics::inletFailures) == 0 && sum(WindowMetrics::cavePoolFailures) == 0 && generationErrors == 0
&& failures.isEmpty();
}
@@ -61,21 +61,23 @@ public final class SeaInletProbe {
}
public static void main(String[] arguments) {
int exitCode = 1;
try {
Configuration configuration = Configuration.parse(arguments);
long failures = 0L;
if (configuration.mode().equals("inventory")) {
inventory(configuration);
failures = inventory(configuration);
} else if (configuration.mode().equals("dump")) {
dump(configuration);
} else {
gate(configuration);
failures = gate(configuration).failures();
}
System.exit(0);
exitCode = failures == 0L ? 0 : 1;
} catch (Throwable failure) {
System.out.println(LOG + " FAIL");
failure.printStackTrace(System.out);
System.exit(1);
}
System.exit(exitCode);
}
private static void dump(Configuration configuration) throws Exception {
@@ -101,7 +103,8 @@ public final class SeaInletProbe {
}
}
private static void inventory(Configuration configuration) throws Exception {
private static int inventory(Configuration configuration) throws Exception {
int failedWindows = 0;
try (RealPackProbeSupport.Workspace workspace = workspace(configuration, configuration.packOn());
RealPackProbeSupport.EngineSession session = workspace.openEngine(configuration.seed(), false, "inventory")) {
HydrologyRuntime runtime = session.engine().getComplex().getHydrologyRuntime();
@@ -113,6 +116,7 @@ public final class SeaInletProbe {
owned = coast[1] == 0 ? Map.of() : owned(runtime, wx, wx, wz, wz);
} catch (RuntimeException failure) {
System.out.println("SEA_INLET_WINDOW_FAILED wx=" + wx + " wz=" + wz + " " + rootMessage(failure));
failedWindows++;
continue;
}
double length = 0D;
@@ -124,6 +128,7 @@ public final class SeaInletProbe {
}
}
}
return failedWindows;
}
private static String rootMessage(Throwable failure) {
@@ -164,7 +169,7 @@ public final class SeaInletProbe {
return new int[]{below, cliff};
}
private static void gate(Configuration configuration) throws Exception {
private static Gate gate(Configuration configuration) throws Exception {
List<long[]> tiles = tileChunks(configuration);
Run forward = run(configuration, configuration.packOn(), tiles, null, false, true, 1, "on-forward");
List<long[]> all = new ArrayList<>(forward.order);
@@ -175,7 +180,7 @@ public final class SeaInletProbe {
System.out.println(LOG + " scan chunks " + forward.scanChunks.size() + ", generated chunks " + all.size());
Run reverse = run(configuration, configuration.packOn(), all, null, true, false, configuration.threads(), "on-reverse");
Run baseline = run(configuration, configuration.packOff(), scanned, forward.scanChunks, false, false, configuration.threads(), "off");
report(configuration, forward.inlets, forward, reverse, baseline);
return report(configuration, forward.inlets, forward, reverse, baseline);
}
private static Run run(Configuration configuration, File pack, List<long[]> chunks, Set<Long> scanChunks, boolean reverse, boolean inventory,
@@ -256,7 +261,23 @@ public final class SeaInletProbe {
static final Checks NONE = new Checks(0, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, List.of());
long failures() {
return leaks + missingWater + waterAbove + roofViolations + openRoofViolations + disconnected + shellOpen + shellLoose;
return leaks + missingWater + waterAbove + roofViolations + roofBreaches + openRoofViolations + disconnected + shellOpen + shellLoose;
}
}
record Gate(Checks checks, int orderMismatches, int inletsWithOtherLevel, int waterLeaksOn, int waterLeaksOff) {
long addedLeaks() {
return Math.max(0, waterLeaksOn - waterLeaksOff);
}
long failures() {
return checks.failures() + orderMismatches + inletsWithOtherLevel + addedLeaks();
}
String line() {
return String.format(Locale.ROOT, "SEA_INLET_GATE status=%s failures=%d checkFailures=%d orderMismatches=%d inletsWithOtherLevel=%d"
+ " addedLeaks=%d", failures() == 0L ? "PASS" : "FAIL", failures(), checks.failures(), orderMismatches,
inletsWithOtherLevel, addedLeaks());
}
}
@@ -295,8 +316,12 @@ public final class SeaInletProbe {
}
Scan scan = new Scan(run, run.sea, run.roofClearance, inlets);
scan.run();
return checks(scan);
}
private static Checks checks(Scan scan) {
Scan.InletStats total = scan.total;
return new Checks(inlets.size(), total.leaks, total.missingWater, total.waterAbove, total.roofViolations, total.roofBreaches,
return new Checks(scan.inlets.size(), total.leaks, total.missingWater, total.waterAbove, total.roofViolations, total.roofBreaches,
total.openRoofViolations, total.disconnected, scan.shellOpen, scan.shellLoose, total.looseBeds, List.copyOf(scan.examples));
}
@@ -363,7 +388,7 @@ public final class SeaInletProbe {
return chunks;
}
private static void report(Configuration configuration, Map<Long, SeaInlet> touching, Run on, Run reverse, Run off) {
private static Gate report(Configuration configuration, Map<Long, SeaInlet> touching, Run on, Run reverse, Run off) {
int sea = on.sea;
int clearance = on.roofClearance;
List<SeaInlet> owned = new ArrayList<>();
@@ -413,6 +438,9 @@ public final class SeaInletProbe {
scan.shellOpen, scan.shellLoose, maxOpenLandStations(owned), scan.total.looseBeds);
System.out.printf(Locale.ROOT, "SEA_INLET_DETERMINISM chunks=%d reverseChunks=%d mismatches=%d crossChunkInlets=%d crossWindowInlets=%d%n",
on.hashes.size(), reverse.hashes.size(), mismatches, scan.crossChunk(), scan.crossWindow());
Gate gate = new Gate(checks(scan), mismatches, offLevel, onLeaks, offLeaks);
System.out.println(gate.line());
return gate;
}
private static int openStations(SeaInlet inlet) {