mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 04:32:24 +00:00
test: freeze generated trait and pass-through behavior
This commit is contained in:
1 parent
57b314dd4e
commit
2aa9928ad0
7 files changed
+174
-12
No files matched your search
+16
-8
@@ -24,14 +24,15 @@ No trustworthy tool will produce a maintainable Java port automatically. A decom
|
||||
## Current status
|
||||
|
||||
The binary and source-level consumer audits are complete. Phase 0 still lacks a pre-optimization profile. The
|
||||
low-coupling Phase 3 queue is complete; before entering measured hot-path work, the immediate milestone is the
|
||||
remaining generated-tile portion of the audit-derived compatibility gate below.
|
||||
low-coupling Phase 3 queue and the audit-derived immediate compatibility gate are complete. The next milestone is a
|
||||
focused CPU/allocation baseline before entering measured hot-path work.
|
||||
|
||||
That audit found and this branch has now repaired one existing regression: Schematica 1.12.6 reflects the original private
|
||||
`MultiPartRegistry$` field `codechicken$multipart$MultiPartRegistry$$typeMap` and casts it to a Scala mutable map. The
|
||||
companion again exposes that exact private field as a live view of the canonical Java `HashMap`, and a test performs
|
||||
Schematica's reflective lookup. The remaining source-only member guards, `TileMultipart` ordering/move lifecycle, and
|
||||
compact mixed-part NBT/description packet are also frozen; generated-trait and pass-through fixtures are next.
|
||||
Schematica's reflective lookup. The remaining source-only member guards, `TileMultipart` ordering/move lifecycle,
|
||||
compact mixed-part NBT/description packet, generated Scala and Java traits, and a server-only pass-through interface
|
||||
are also frozen.
|
||||
|
||||
Phase 1 has not properly started: GTNHLib is present but was added at `api` scope to satisfy a test compile rather
|
||||
than because a migration change needed it, and no Forge mod dependency was declared. Revisit that entry only when a
|
||||
@@ -294,7 +295,7 @@ retained, as are both registries, the central part/tile types, scheduler/helper
|
||||
|
||||
Exit condition: leaf code is Java and no longer generates avoidable Scala closures or collection adapters.
|
||||
|
||||
### Immediate compatibility gate — current next milestone
|
||||
### Immediate compatibility gate — complete
|
||||
|
||||
Do this before another source conversion:
|
||||
|
||||
@@ -307,7 +308,7 @@ Do this before another source conversion:
|
||||
rebinding, add/remove/replace callback order, moving the live tile, and `onMoved`.
|
||||
- [x] Add compact mixed-part NBT and description-packet fixtures. The existing torch/button parts provide the needed
|
||||
distinct IDs, order, slots and payload without adding downstream mods or a test-only part registry.
|
||||
- [ ] Freeze one generated Scala trait, one Java trait, and representative pass-through interfaces before changing
|
||||
- [x] Freeze one generated Scala trait, one Java trait, and representative pass-through interfaces before changing
|
||||
built-in tile traits or either generator.
|
||||
|
||||
Exit condition: every source-only constraint that can silently fail has an automated structural/behavioral guard,
|
||||
@@ -394,7 +395,7 @@ The work should move from low to high risk while keeping a buildable mixed-langu
|
||||
Extensive tests are both possible and recommended here. Their purpose is not to prove that the current Scala behavior is ideal; it is to make its observable behavior explicit before translation, so every later difference is intentional.
|
||||
|
||||
The repository now has a Java-8-compatible JUnit Jupiter suite and a small Forge integration runner. The current
|
||||
baseline is 130 plain-JVM tests and 25 Forge server tests. Minecraft 1.7.10 does not provide the modern GameTest
|
||||
baseline is 130 plain-JVM tests and 28 Forge server tests. Minecraft 1.7.10 does not provide the modern GameTest
|
||||
framework, so game-dependent coverage continues through the existing narrow Forge harness rather than a second test
|
||||
framework.
|
||||
|
||||
@@ -623,4 +624,11 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
- Froze the complete logical chunk-description payload around the same torch/button pair: packet type, chunk
|
||||
coordinates, tile count, nibble-relative X/Z, full Y, part count, sorted runtime part IDs, part order and both meta
|
||||
bytes. CodeChickenLib's deferred Deflater transport step is deliberately outside this FMP fixture.
|
||||
- The expanded baseline is 130 plain-JVM tests and 25 Forge server tests, all passing.
|
||||
- Froze representative generated-trait behavior. The existing `TSlottedTile` fixture pins built-in Scala trait class
|
||||
caching and field initialization; a ProjectRed-shaped external Scala microblock trait pins registration by name,
|
||||
trait initialization and method dispatch; and `TPartialOcclusionTile` pins Java-trait rewriting and override
|
||||
dispatch through the generated tile.
|
||||
- Froze a server-only pass-through interface with primitive/reference overloads. The generated tile forwards to one
|
||||
implementing part, rejects a second implementor, preserves and rebinds its delegate through `copyFrom`, and clears
|
||||
the generated implementation field on removal.
|
||||
- The expanded baseline is 130 plain-JVM tests and 28 Forge server tests, all passing.
|
||||
@@ -495,10 +495,17 @@ behavior:
|
||||
fields, before converting their owners.
|
||||
3. Keep the completed `TileMultipart` list/map/slot and live-move characterization green before optimizing storage or
|
||||
iteration.
|
||||
4. Characterize pass-through interfaces and ProjectRed's external Scala trait before changing either generator.
|
||||
4. Keep the completed pass-through and ProjectRed-shaped external Scala-trait characterization green before changing
|
||||
either generator.
|
||||
5. Keep the completed compact mixed NBT/chunk-description fixture green; add subsystem-specific payload cases when
|
||||
converting microblocks or Minecraft part implementations.
|
||||
6. Treat Scala runtime removal as downstream coordination work after the Java port, not as a requirement of it.
|
||||
|
||||
Current-branch generator verification: `ForgeEnvironmentSmokeTest` pins cached built-in `TSlottedTile` generation,
|
||||
an external Scala microblock trait registered by name like ProjectRed's `LightMicroblock`, Java
|
||||
`TPartialOcclusionTile` rewriting and override dispatch, and server-only pass-through forwarding, overloading,
|
||||
single-implementor selection, copying/rebinding, and removal cleanup. Full downstream mixed tiles and client-side
|
||||
selection remain Phase 7 integration cases.
|
||||
|
||||
With these gates, the source audit is actionable: the port can simplify internals freely where no listed observation
|
||||
changes, while each externally observed behavior has a named consumer and a focused way to prove compatibility.
|
||||
@@ -57,7 +57,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
|
||||
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
|
||||
```
|
||||
|
||||
Current baseline: **130 plain-JVM tests, 25 Forge server tests, all passing at their last completed runs.**
|
||||
Current baseline: **130 plain-JVM tests, 28 Forge server tests, all passing at their last completed runs.**
|
||||
|
||||
### ABI diff against the reference
|
||||
|
||||
@@ -207,8 +207,13 @@ sequence (`onWorldSeparate`, then `onMoved`/`onWorldJoin`) while preserving the
|
||||
The same ordered torch/button pair now supplies a compact NBT fixture and an exact logical chunk-description fixture.
|
||||
The latter pins FMP's framing and payload before CodeChickenLib applies deferred transport compression.
|
||||
|
||||
Next freeze representative generated Scala/Java traits and pass-through interfaces. The checklist is in the
|
||||
"Immediate compatibility gate" section of `JAVA_MIGRATION.md`.
|
||||
The immediate compatibility gate is complete. `ForgeEnvironmentSmokeTest` now freezes built-in and external Scala
|
||||
trait generation, Java-trait rewriting/dispatch, generated-class reuse, and a server-only pass-through interface's
|
||||
overloads, single-implementor rule, copy/rebind behavior, and removal cleanup.
|
||||
|
||||
Next capture a focused CPU/allocation baseline for `TileMultipart.updateEntity`, `TileMultipart.operate`, and redstone
|
||||
queries. Use the measurements to select the first Phase 4 change rather than assuming the statically visible
|
||||
allocations dominate.
|
||||
|
||||
`IRedstonePart.scala` is misleadingly named and is **not** a marker-trait file. It holds six traits plus
|
||||
`RedstoneInteractions`, whose `MODULE$` is load-bearing. After the compatibility gate and an initial profile, port the
|
||||
@@ -231,6 +236,8 @@ all of `multipart/asm/`. The ASM subsystem should be last; freeze generated-clas
|
||||
Every port since `TCuboidPart` has deferred something to it, and `BlockMultipart` leans on it hardest: breaking, selection boxes, collision, pick block, activation, particles and
|
||||
light are covered by nothing automated. Run it in a real client before this branch goes near a release.
|
||||
- No CPU or allocation profiles exist. Phase 4 has not started, so there is no baseline to compare against.
|
||||
- The server side of flag-sensitive pass-through registration is automated; client-side exclusion still belongs to
|
||||
the packaged-client/manual compatibility run.
|
||||
- Microblock-specific NBT and packet payloads still need characterization immediately before that subsystem changes;
|
||||
the compact core tile/part fixture is complete.
|
||||
- `TileMultipart`'s `partList` still republishes an immutable Scala `Seq` on every mutation, and `operate` still
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -22,11 +23,14 @@ import org.junit.jupiter.api.Test;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.data.MCDataOutputWrapper;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.microblock.FaceMicroClass$;
|
||||
import codechicken.microblock.HollowMicroClass$;
|
||||
import codechicken.microblock.Microblock;
|
||||
import codechicken.microblock.MicroblockGenerator;
|
||||
import codechicken.multipart.JPartialOcclusion;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.MultipartHelper;
|
||||
import codechicken.multipart.TFacePart;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
@@ -34,6 +38,8 @@ import codechicken.multipart.asm.MultipartMixinFactory;
|
||||
import codechicken.multipart.scalatraits.TSlottedTile;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import scala.collection.JavaConversions;
|
||||
import scala.collection.Seq;
|
||||
import scala.collection.immutable.Nil$;
|
||||
|
||||
class ForgeEnvironmentSmokeTest {
|
||||
@@ -76,6 +82,23 @@ class ForgeEnvironmentSmokeTest {
|
||||
assertFalse(((TFacePart) hollow).solid(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedMicroblockInitializesAndDispatchesAnExternalScalaTrait() throws Exception {
|
||||
BitSet traits = new BitSet();
|
||||
traits.set(FaceMicroClass$.MODULE$.baseTraitId());
|
||||
traits.set(ForgeMultipartFunctionalTestMod.externalScalaMicroblockTraitId);
|
||||
Seq<Object> arguments = JavaConversions.asScalaBuffer(Collections.<Object>singletonList(0)).toList();
|
||||
|
||||
Microblock microblock = (Microblock) MicroblockGenerator.construct(traits, arguments);
|
||||
Class<?> trait = Class.forName("codechicken.multipart.test.ExternalScalaMicroblockFixture");
|
||||
|
||||
assertTrue(trait.isInterface());
|
||||
assertTrue(trait.isInstance(microblock));
|
||||
assertTrue(microblock.shouldRenderDynamic());
|
||||
assertEquals(41, microblock.getLightValue());
|
||||
assertEquals(41, ((Number) microblock.getClass().getMethod("fixtureState").invoke(microblock)).intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Part registration needs FML's active mod container, so none of this is reachable from a plain JVM test. Startup
|
||||
* exercises both overloads downstream depends on: Content registers through the deprecated IPartFactory array form,
|
||||
@@ -149,4 +172,86 @@ class ForgeEnvironmentSmokeTest {
|
||||
assertSame(first.getClass(), second.getClass());
|
||||
assertEquals(27, ((TSlottedTile) first).v_partMap().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedJavaTraitOverridesPartialOcclusion() throws Exception {
|
||||
PartialPart existing = new PartialPart(voxel(0));
|
||||
TileMultipart tile = MultipartHelper.createTileFromParts(Collections.singletonList(existing));
|
||||
Class<?> trait = Class.forName("codechicken.multipart.scalatraits.TPartialOcclusionTile");
|
||||
|
||||
assertTrue(trait.isInterface(), "The registered Java mixin class is rewritten to a trait interface");
|
||||
assertTrue(trait.isInstance(tile));
|
||||
assertEquals(
|
||||
boolean.class,
|
||||
tile.getClass().getMethod("partialOcclusionTest", scala.collection.Seq.class).getReturnType());
|
||||
assertTrue(tile.canAddPart(new PartialPart(voxel(1))));
|
||||
assertFalse(tile.canAddPart(new PartialPart(voxel(0))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedServerPassThroughDelegatesCopiesAndAllowsOnlyOneImplementor() throws Exception {
|
||||
PassThroughPart part = new PassThroughPart();
|
||||
TileMultipart tile = MultipartHelper.createTileFromParts(Collections.singletonList(part));
|
||||
|
||||
assertTrue(tile instanceof GeneratorPassThroughFixture);
|
||||
GeneratorPassThroughFixture api = (GeneratorPassThroughFixture) tile;
|
||||
assertEquals(12, api.transform(5));
|
||||
assertEquals("part:value", api.transform("value"));
|
||||
assertSame(part, api.implementation());
|
||||
assertFalse(tile.canAddPart(new PassThroughPart()));
|
||||
|
||||
TileMultipart copy = (TileMultipart) tile.getClass().getDeclaredConstructor().newInstance();
|
||||
copy.from(tile);
|
||||
assertSame(part, ((GeneratorPassThroughFixture) copy).implementation());
|
||||
assertSame(copy, part.tile());
|
||||
|
||||
copy.partRemoved(part, 0);
|
||||
assertTrue(copy.canAddPart(new PassThroughPart()), "Removing the delegate must clear the generated impl field");
|
||||
}
|
||||
|
||||
private static Cuboid6 voxel(int x) {
|
||||
return new Cuboid6(x / 8d, 0, 0, (x + 1) / 8d, 1 / 8d, 1 / 8d);
|
||||
}
|
||||
|
||||
private static final class PartialPart extends TMultiPart implements JPartialOcclusion {
|
||||
|
||||
private final Cuboid6 box;
|
||||
|
||||
private PartialPart(Cuboid6 box) {
|
||||
this.box = box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "partial_fixture";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getPartialOcclusionBoxes() {
|
||||
return Collections.singletonList(box);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PassThroughPart extends TMultiPart implements GeneratorPassThroughFixture {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "pass_through_fixture";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int transform(int value) {
|
||||
return value + 7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transform(String value) {
|
||||
return "part:" + value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TMultiPart implementation() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -19,6 +19,8 @@ import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
|
||||
import org.junit.platform.launcher.listeners.TestExecutionSummary;
|
||||
import org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener;
|
||||
|
||||
import codechicken.microblock.MicroblockGenerator;
|
||||
import codechicken.multipart.MultipartGenerator;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
@@ -39,6 +41,7 @@ public final class ForgeMultipartFunctionalTestMod {
|
||||
static boolean postInitialized;
|
||||
static boolean serverAboutToStart;
|
||||
static boolean serverStarted;
|
||||
static int externalScalaMicroblockTraitId;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
@@ -47,6 +50,9 @@ public final class ForgeMultipartFunctionalTestMod {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
MultipartGenerator.registerPassThroughInterface(GeneratorPassThroughFixture.class.getName(), false, true);
|
||||
externalScalaMicroblockTraitId = MicroblockGenerator
|
||||
.registerTrait("codechicken.multipart.test.ExternalScalaMicroblockFixture");
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package codechicken.multipart.test;
|
||||
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
||||
/** Representative external tile API for generated pass-through characterization. */
|
||||
public interface GeneratorPassThroughFixture {
|
||||
|
||||
int transform(int value);
|
||||
|
||||
String transform(String value);
|
||||
|
||||
TMultiPart implementation();
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package codechicken.multipart.test
|
||||
|
||||
import codechicken.microblock.Microblock
|
||||
|
||||
/** Minimal external Scala trait matching ProjectRed's MicroblockGenerator
|
||||
* registration path.
|
||||
*/
|
||||
trait ExternalScalaMicroblockFixture extends Microblock {
|
||||
private var state = 41
|
||||
|
||||
def fixtureState = state
|
||||
|
||||
override def shouldRenderDynamic = true
|
||||
|
||||
override def getLightValue = state
|
||||
}
|
||||
Reference in new issue
Block a user