Skip to content

Commit 0d8fcd7

Browse files
committed
Audit NeoForge 1.21.1 runtime logs and fluid writes
1 parent 40c0d0d commit 0d8fcd7

5 files changed

Lines changed: 390 additions & 1 deletion

File tree

‎CHANGELOG.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Version 4.0.6
22

33
* Preserve generated worlds made with Mineralogy 1.10, 1.12, or 5.x by reading their saved mod metadata and exact legacy configuration before creating the OreSpawn world profile.
44
* Write human-readable, idempotent upgrade reports for legacy OreSpawn and Mineralogy imports while retaining source files and existing chunks unchanged.
5+
* Audit automated runtime logs and dynamic-fluid generation so logged worldgen failures cannot pass merely because the process exits normally.
56
* Qualify existing OreSpawn 4.0.5 global and per-world profiles without changing explicit Custom values or provider definitions.
67
* Fix provider top and filler materials being generated one block below exposed ground.
78
* Apply underwater materials from the corrected ground and ceiling materials to roof undersides.

‎build.gradle‎

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,193 @@ tasks.named('javadoc', Javadoc).configure {
198198

199199
tasks.named('test', Test).configure {
200200
useJUnitPlatform()
201+
// Unit tests inspect target files relative to the checkout, but they do
202+
// not need NeoForge's rolling runtime files. A console-only logger keeps
203+
// them from contending with Eclipse/client logs in this working directory.
204+
systemProperty 'log4j.configurationFile', file('src/test/resources/log4j2-test.xml').absolutePath
205+
// Loaded only through an isolated URLClassLoader by the parity test. This
206+
// is deliberately not a Gradle dependency and cannot leak into Eclipse or
207+
// a published OreSpawn jar.
208+
File mineralogy5Oracle = file('../../MinecraftMineralogy 118/MinecraftMineralogy/build/libs/Mineralogy-1.18.2-5.4.0.jar')
209+
if (mineralogy5Oracle.isFile()) {
210+
systemProperty 'orespawn.mineralogy5Oracle', mineralogy5Oracle.absolutePath
211+
}
212+
}
213+
214+
// Several registry-focused tests initialize the real global config singleton.
215+
// Keep that target-native coverage without creating or changing a developer's
216+
// checkout config as a side effect of `test` or `build`.
217+
def unitTestWorldgenConfig = file('config/orespawn-worldgen.json')
218+
def unitTestWorldgenConfigWasPresent = false
219+
byte[] unitTestWorldgenConfigBytes = null
220+
tasks.named('test', Test).configure {
221+
doFirst {
222+
unitTestWorldgenConfigWasPresent = unitTestWorldgenConfig.isFile()
223+
unitTestWorldgenConfigBytes = unitTestWorldgenConfigWasPresent
224+
? unitTestWorldgenConfig.bytes : null
225+
}
226+
}
227+
def preserveDeveloperWorldgenConfig = tasks.register('preserveDeveloperWorldgenConfig') {
228+
doLast {
229+
if (unitTestWorldgenConfigWasPresent) {
230+
byte[] after = unitTestWorldgenConfig.isFile() ? unitTestWorldgenConfig.bytes : null
231+
if (after == null || !java.util.Arrays.equals(unitTestWorldgenConfigBytes, after)) {
232+
unitTestWorldgenConfig.parentFile.mkdirs()
233+
unitTestWorldgenConfig.bytes = unitTestWorldgenConfigBytes
234+
throw new GradleException('Unit tests changed config/orespawn-worldgen.json; the original was restored')
235+
}
236+
} else if (unitTestWorldgenConfig.isFile()) {
237+
delete unitTestWorldgenConfig
238+
}
239+
}
240+
}
241+
tasks.named('test') {
242+
finalizedBy preserveDeveloperWorldgenConfig
243+
}
244+
245+
// A NeoForge process is not green merely because it returns exit code zero.
246+
// The loader can log a worldgen/linkage failure and still shut down normally.
247+
// NeoForge 21.1 probes the macOS kqueue and Linux epoll transports on Windows.
248+
// Their bounded DEBUG/Appender stack blocks are harmless when followed by the
249+
// normal NIO fallback. Do not broaden this to standalone initializer/linkage
250+
// failures or to any other ERROR/FATAL record.
251+
252+
def runtimeCrashSnapshot = { File runDirectory ->
253+
File crashDirectory = new File(runDirectory, 'crash-reports')
254+
if (!crashDirectory.isDirectory()) return [] as Set
255+
return fileTree(crashDirectory) { include '**/*' }.files
256+
.findAll { it.isFile() }.collect { it.absolutePath } as Set
257+
}
258+
259+
def assertRuntimeLogsClean = { File runDirectory, String context, Set priorCrashes ->
260+
File crashDirectory = new File(runDirectory, 'crash-reports')
261+
if (crashDirectory.isDirectory()) {
262+
def crashes = fileTree(crashDirectory) { include '**/*' }.files
263+
.findAll { it.isFile() && !priorCrashes.contains(it.absolutePath) }
264+
if (!crashes.isEmpty()) {
265+
throw new GradleException("${context} produced crash report ${crashes.first()}")
266+
}
267+
}
268+
269+
File logsDirectory = new File(runDirectory, 'logs')
270+
if (!logsDirectory.isDirectory()) return
271+
def failures = []
272+
[new File(logsDirectory, 'latest.log'), new File(logsDirectory, 'debug.log')]
273+
.findAll { it.isFile() }.each { File log ->
274+
int lineNumber = 0
275+
boolean nativeTransportFallback = false
276+
log.eachLine('UTF-8') { String line ->
277+
lineNumber++
278+
boolean nativeTransportStart =
279+
line.contains('[io.ne.ch.kq.KQueue/]: KQueue support is not available') ||
280+
line.contains('[io.ne.ch.ep.Epoll/]: Epoll support is not available')
281+
boolean nativeTransportAppender = nativeTransportFallback &&
282+
line.contains('Server thread ERROR An exception occurred processing Appender DebugFile')
283+
boolean startsLogRecord = line ==~ /^\[[0-9]{2}:[0-9]{2}:[0-9]{2}\].*/ ||
284+
line ==~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T.* (?:TRACE|DEBUG|INFO|WARN|ERROR|FATAL) .*/
285+
if (startsLogRecord && !nativeTransportStart && !nativeTransportAppender) {
286+
nativeTransportFallback = false
287+
}
288+
if (nativeTransportStart) nativeTransportFallback = true
289+
boolean unexpectedSeverity = line ==~ /.*\/(?:ERROR|FATAL)\].*/
290+
boolean knownNoise = nativeTransportFallback
291+
boolean fatalText = line.contains('Encountered an unexpected exception') ||
292+
line.contains('Exception stopping the server') ||
293+
line.contains('Migration audit failed') ||
294+
line.contains('java.lang.Error:') ||
295+
line.contains('NoSuchMethodError') ||
296+
line.contains('NoClassDefFoundError') ||
297+
line.contains('ExceptionInInitializerError') ||
298+
line.contains('Tried to assign a mutable BlockPos') ||
299+
line.contains('causing cascading worldgen lag')
300+
if ((unexpectedSeverity || fatalText) && !knownNoise) {
301+
failures.add("${log.name}:${lineNumber}: ${line}")
302+
}
303+
}
304+
}
305+
if (!failures.isEmpty()) {
306+
throw new GradleException("${context} logged unexpected errors:\n"
307+
+ failures.take(20).join('\n'))
308+
}
309+
}
310+
311+
tasks.register('runtimeLogScannerTest') {
312+
group = 'verification'
313+
description = 'Proves runtime log validation rejects real NeoForge failures.'
314+
doLast {
315+
File probe = file("${buildDir}/runtime-log-scanner-test")
316+
delete probe
317+
File logs = new File(probe, 'logs'); logs.mkdirs()
318+
new File(logs, 'latest.log').setText(
319+
'[Server thread/INFO] [neoforge]: Done\n', 'UTF-8')
320+
assertRuntimeLogsClean(probe, 'scanner-clean-log-probe', [] as Set)
321+
new File(logs, 'latest.log').setText(
322+
'[Server thread/WARN]: Tried to assign a mutable BlockPos to tick data...\n', 'UTF-8')
323+
boolean rejected = false
324+
try { assertRuntimeLogsClean(probe, 'scanner-mutable-position-probe', [] as Set) }
325+
catch (GradleException expected) { rejected = true }
326+
if (!rejected) throw new GradleException('Runtime log scanner accepted a mutable BlockPos leak')
327+
new File(logs, 'latest.log').setText(
328+
'[Server thread/DEBUG] [neoforge]: Minecraft loaded a new chunk while populating another, causing cascading worldgen lag.\n', 'UTF-8')
329+
rejected = false
330+
try { assertRuntimeLogsClean(probe, 'scanner-cascading-probe', [] as Set) }
331+
catch (GradleException expected) { rejected = true }
332+
if (!rejected) throw new GradleException('Runtime log scanner accepted cascading worldgen')
333+
new File(logs, 'latest.log').setText(
334+
'[Server thread/ERROR] [example]: Unexpected fixture failure\n', 'UTF-8')
335+
rejected = false
336+
try { assertRuntimeLogsClean(probe, 'scanner-severity-probe', [] as Set) }
337+
catch (GradleException expected) { rejected = true }
338+
if (!rejected) throw new GradleException('Runtime log scanner accepted an unexpected ERROR line')
339+
new File(logs, 'latest.log').setText(
340+
'[10:00:00] [Server thread/DEBUG] [io.ne.ch.kq.KQueue/]: KQueue support is not available\n' +
341+
'java.lang.ExceptionInInitializerError: null\n' +
342+
'2026-08-17T10:00:00Z Server thread ERROR An exception occurred processing Appender DebugFile\n' +
343+
'Caused by: java.lang.NoClassDefFoundError: Could not initialize class io.netty.channel.kqueue.Native\n' +
344+
'[10:00:01] [Server thread/DEBUG] [io.ne.ch.ni.NioIoHandler/]: NIO fallback active\n', 'UTF-8')
345+
assertRuntimeLogsClean(probe, 'scanner-windows-native-transport-probe', [] as Set)
346+
new File(logs, 'latest.log').setText(
347+
'[Server thread/ERROR] [example]: java.lang.ExceptionInInitializerError: real failure\n', 'UTF-8')
348+
rejected = false
349+
try { assertRuntimeLogsClean(probe, 'scanner-standalone-initializer-probe', [] as Set) }
350+
catch (GradleException expected) { rejected = true }
351+
if (!rejected) throw new GradleException('Runtime log scanner accepted a standalone initializer failure')
352+
delete probe
353+
}
354+
}
355+
356+
tasks.named('check') {
357+
dependsOn 'runtimeLogScannerTest'
358+
}
359+
360+
tasks.register('verifyMineralogyOracleIsolation') {
361+
group = 'verification'
362+
description = 'Prevents published Mineralogy engines from leaking into Gradle configurations or ordinary Eclipse launches.'
363+
doLast {
364+
configurations.each { configuration ->
365+
if (configuration.canBeResolved &&
366+
configuration.files.any { it.name ==~ /Mineralogy-.*\.jar/ }) {
367+
throw new GradleException("Mineralogy oracle leaked into Gradle configuration ${configuration.name}")
368+
}
369+
}
370+
}
371+
}
372+
373+
tasks.named('check') {
374+
dependsOn 'verifyMineralogyOracleIsolation'
375+
}
376+
377+
['runClient', 'runServer', 'runGameTestServer', 'runClientData'].each { String taskName ->
378+
tasks.matching { it.name == taskName }.configureEach { JavaExec runTask ->
379+
doFirst {
380+
new File(runTask.workingDir, 'mods').mkdirs()
381+
runTask.ext.oreSpawnCrashSnapshot = runtimeCrashSnapshot(runTask.workingDir)
382+
}
383+
doLast {
384+
assertRuntimeLogsClean(runTask.workingDir, taskName,
385+
runTask.ext.oreSpawnCrashSnapshot as Set)
386+
}
387+
}
201388
}
202389

203390
def surfaceIntegrationClasses = layout.buildDirectory.dir('surface-integration-fixture/classes')
@@ -252,6 +439,15 @@ tasks.configureEach {
252439
} else if (name == 'runSurfaceIntegrationReload') {
253440
dependsOn 'runSurfaceIntegrationFresh'
254441
}
442+
if (name == 'runSurfaceIntegrationFresh' || name == 'runSurfaceIntegrationReload') {
443+
doFirst {
444+
ext.oreSpawnCrashSnapshot = runtimeCrashSnapshot(workingDir)
445+
}
446+
doLast {
447+
assertRuntimeLogsClean(workingDir, "NeoForge 1.21.1 ${name}",
448+
ext.oreSpawnCrashSnapshot as Set)
449+
}
450+
}
255451
}
256452

257453
def surfaceIntegrationTest = tasks.register('surfaceIntegrationTest') {

‎src/biomeIntegrationTest/java/zone/moddev/mc/orespawn/testmod/SurfaceProbeTestMod.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ private static long auditDynamicFluid(ServerLevel level) {
382382
}
383383
}
384384
if (water == 0L) {
385-
throw new IllegalStateException("NeoForge 21.11 dynamic fluid deposit produced no covered flowing-water blocks");
385+
throw new IllegalStateException("NeoForge 21.1 dynamic fluid deposit produced no covered flowing-water blocks");
386386
}
387387
return water;
388388
}

0 commit comments

Comments
 (0)