Skip to content

Commit 8479dbf

Browse files
committed
Run the resource checks without an interactive terminal
1 parent ed04c5d commit 8479dbf

3 files changed

Lines changed: 64 additions & 10 deletions

File tree

‎docs/1.21.11/QUALIFICATION.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ Release preparation also adds a CI upload-path regression. It first rejects
9393
the stale 2.4.14 filenames, then passes with an upload glob following the
9494
audited current version. A second regression catches the wrapper workflow's
9595
old branch filter and rejects missing/wrong event targets, including misleading
96-
comments. The full source suite now has 278 tests; the player jar remains C98D.
97-
This does not relabel the earlier 276-test receipt.
96+
comments. Hosted CI also exposed interactive terminal initialisation in the
97+
redirected resource-proof process. The child now disables JLine explicitly;
98+
warnings and errors still fail the proof. Three additional tests check its
99+
launch settings, diagnostic rejection and actual native resource discovery.
100+
The full source suite now has 281 tests; the player jar remains C98D. This
101+
does not relabel the earlier 276-test receipt or the failed hosted runs.
98102

99103
No further production change was needed during this rerun. An isolated build
100104
caught a Steam test that ignored the configured Power jar and used a fixed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package zone.moddev.mc.basepower.testing;
2+
3+
import java.nio.file.Path;
4+
import org.junit.Test;
5+
import static org.junit.Assert.*;
6+
7+
public class NativePackProcessContractTest {
8+
@Test public void redirectedChildUsesNonInteractiveTerminalWithoutDisablingLogging() {
9+
Path root = Path.of("build", "native-pack-resources").toAbsolutePath();
10+
var process = NativePackResourceProof.proofProcess(Path.of("java"), "classpath", root, root, root.resolve("test.log"));
11+
assertTrue(process.command().contains("-Dterminal.jline=false"));
12+
assertEquals("dumb", process.environment().get("TERM"));
13+
assertEquals(ProcessBuilder.Redirect.Type.WRITE, process.redirectOutput().type());
14+
assertTrue(process.redirectErrorStream());
15+
assertFalse(process.command().stream().anyMatch(argument -> argument.contains("log4j")));
16+
}
17+
18+
@Test public void allWarningAndErrorFormsRemainFailures() {
19+
for (String diagnostic : new String[] {
20+
"2026-11-11T23:24:32Z main WARN Advanced terminal features are not available in this environment",
21+
"[main/WARN] Resource pack metadata is invalid",
22+
"[main/ERROR] Dependency discovery failed", "[main/FATAL] Cannot read resource pack"}) {
23+
assertThrows(AssertionError.class, () -> NativePackResourceProof.requireCleanOutput(diagnostic, Path.of("proof.log")));
24+
}
25+
NativePackResourceProof.requireCleanOutput("[main/INFO] Resources loaded", Path.of("proof.log"));
26+
}
27+
28+
@Test public void nativeProofActuallyRunsWithTerminalDisabled() throws Exception {
29+
var proof = NativePackResourceProof.read();
30+
assertTrue(proof.get("interactiveTerminalDisabled").getAsBoolean());
31+
assertEquals(0, proof.getAsJsonArray("warningsAndErrors").size());
32+
assertTrue(proof.getAsJsonObject("CLIENT_RESOURCES").get("resourcesVerified").getAsInt() > 0);
33+
assertTrue(proof.getAsJsonObject("SERVER_DATA").get("resourcesVerified").getAsInt() > 0);
34+
}
35+
}

‎src/test/java/zone/moddev/mc/basepower/testing/NativePackResourceProof.java‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,40 @@ public static synchronized JsonObject read() throws Exception {
5555
Path javaExecutable = Path.of(System.getProperty("java.home"), "bin", "java");
5656
if (!Files.isExecutable(javaExecutable)) javaExecutable = javaExecutable.resolveSibling("java.exe");
5757
Path log = evidence.resolve("forge-resources.log");
58-
Process process = new ProcessBuilder(javaExecutable.toString(), "-XX:ActiveProcessorCount=4", "-Xmx512m",
59-
"--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", "-cp", classpath,
60-
NativePackResourceProof.class.getName(), Path.of("build/resources/main").toAbsolutePath().toString(),
61-
evidence.toString()).directory(evidence.toFile())
62-
.redirectErrorStream(true).redirectOutput(log.toFile()).start();
58+
Process process = proofProcess(javaExecutable, classpath,
59+
Path.of("build/resources/main").toAbsolutePath(), evidence, log).start();
6360
if (!process.waitFor(90, TimeUnit.SECONDS)) {
6461
process.destroyForcibly().waitFor();
6562
throw new AssertionError("Native Forge resource proof timed out: " + log);
6663
}
6764
String output = Files.readString(log);
6865
if (process.exitValue() != 0) throw new AssertionError("Native Forge resource proof failed: " + log + "\n" + output);
66+
requireCleanOutput(output, log);
67+
receipt = JsonParser.parseString(Files.readString(evidence.resolve("receipt.json"))).getAsJsonObject();
68+
return receipt.deepCopy();
69+
}
70+
71+
static ProcessBuilder proofProcess(Path javaExecutable, String classpath, Path resources, Path evidence, Path log) {
72+
// The child has redirected output, not an interactive terminal. Disable only JLine, never diagnostics.
73+
ProcessBuilder builder = new ProcessBuilder(javaExecutable.toString(), "-XX:ActiveProcessorCount=4", "-Xmx512m",
74+
"-Dterminal.jline=false", "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", "-cp", classpath,
75+
NativePackResourceProof.class.getName(), resources.toString(), evidence.toString())
76+
.directory(evidence.toFile()).redirectErrorStream(true).redirectOutput(log.toFile());
77+
builder.environment().put("TERM", "dumb");
78+
return builder;
79+
}
80+
81+
static void requireCleanOutput(String output, Path log) {
6982
if (java.util.regex.Pattern.compile("(?m)(?:\\[[^\\r\\n]*\\b(?:WARN|ERROR|FATAL)\\b[^\\r\\n]*\\]|\\bmain (?:WARN|ERROR|FATAL)\\b)")
7083
.matcher(output).find()) {
7184
throw new AssertionError("Native Forge resource diagnostic in " + log + "\n" + output);
7285
}
73-
receipt = JsonParser.parseString(Files.readString(evidence.resolve("receipt.json"))).getAsJsonObject();
74-
return receipt.deepCopy();
7586
}
7687

7788
public static void main(String[] args) throws Exception {
89+
if (!"false".equals(System.getProperty("terminal.jline"))) {
90+
throw new AssertionError("The redirected proof child must not initialise an interactive terminal");
91+
}
7892
SharedConstants.tryDetectVersion();
7993
Bootstrap.bootStrap();
8094
Path resources = Path.of(args[0]);
@@ -105,6 +119,7 @@ public static void main(String[] args) throws Exception {
105119
var logger = (org.apache.logging.log4j.core.Logger)LogManager.getRootLogger();
106120
logger.addAppender(appender);
107121
JsonObject result = new JsonObject();
122+
result.addProperty("interactiveTerminalDisabled", true);
108123
JsonArray dependencies = new JsonArray();
109124
for (var dependency : mod.getModInfos().getFirst().getDependencies()) {
110125
JsonObject entry = new JsonObject();
@@ -191,6 +206,6 @@ public static void main(String[] args) throws Exception {
191206
result.add("warningsAndErrors", messages);
192207
Files.writeString(evidence.resolve("receipt.json"), result.toString(), StandardCharsets.UTF_8);
193208
if (!diagnostics.isEmpty()) throw new AssertionError("Native Forge resource diagnostics: " + diagnostics);
194-
System.out.println("BASESTEAM_NATIVE_PACK_RESOURCES_PASS " + result);
209+
System.out.println("BASEPOWER_NATIVE_PACK_RESOURCES_PASS " + result);
195210
}
196211
}

0 commit comments

Comments
 (0)