@@ -198,6 +198,193 @@ tasks.named('javadoc', Javadoc).configure {
198198
199199tasks. 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
203390def 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
257453def surfaceIntegrationTest = tasks. register(' surfaceIntegrationTest' ) {
0 commit comments