test: guard source-only consumer reflection contracts

This commit is contained in:
Algent committed 2026-08-27 14:11:53 +03:00
1 parent 49ed6fd751
commit 4616b5834c
4 files changed
+96 -7

No files matched your search

+10 -3
View File
@@ -30,7 +30,8 @@ tile work, the immediate milestone is the audit-derived compatibility gate below
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 are next.
Schematica's reflective lookup. The remaining source-only member guards are also frozen; tile ordering and lifecycle
characterization is next.
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
@@ -299,7 +300,7 @@ Do this before another source conversion:
- [x] Restore Schematica's reflective `MultiPartRegistry$` type-map view with its exact field name and Scala mutable-map
shape, backed by the canonical Java registry state; add a regression test that performs Schematica's actual lookup.
- [ ] Add exact member-level guards for GuideNH's `BlockMicroMaterial.block/meta` mixin fields, Et Futurum's mutable
- [x] Add exact member-level guards for GuideNH's `BlockMicroMaterial.block/meta` mixin fields, Et Futurum's mutable
`ButtonPart.metaSideMap/sideMetaMap`, Iguana's `ItemSaw.harvestLevel`, and Galacticraft's name-only
`registerMaterial` lookup.
- [ ] Freeze `TileMultipart` order and lifecycle observations: `parts`/`id` NBT, `partList`/`jPartList`, `partMap`, slot
@@ -393,7 +394,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 126 plain-JVM tests and 22 Forge server tests. Minecraft 1.7.10 does not provide the modern GameTest
baseline is 130 plain-JVM tests and 22 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.
@@ -604,3 +605,9 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
canonical Java registry map. The wrapper adds no copied state or synchronization path.
- Proved through the reflected Scala view that Schematica can resolve a factory and that the Java registry immediately
sees the same entry. The focused registry suite and all 126 plain-JVM tests pass.
- Added four source-consumer structural guards without adding downstream mods as test dependencies. They pin GuideNH's
two `BlockMicroMaterial` mixin targets, Et Futurum's mutable static button-orientation arrays, and Iguana's reflected
`ItemSaw.harvestLevel` field.
- Reproduced Galacticraft's name-only method scan and froze its dangerous assumption: exactly one public
`MicroMaterialRegistry.registerMaterial` method may exist, it must accept `(IMicroMaterial, String)`, and
`BlockMicroMaterial(Block, int)` must remain reflectively constructible. All 130 plain-JVM tests pass.
+4
View File
@@ -411,6 +411,10 @@ requirements:
These need targeted runtime tests or explicit downstream patches. They cannot be proven safe by `javap` ABI diffing.
**Current branch:** `ConsumerReflectionCompatibilityTest` now freezes the GuideNH, Et Futurum, Iguana, and
Galacticraft member shapes above. Schematica's registry lookup has its own live-view regression test. The manual client
checks remain necessary for end-to-end integration behavior.
## Data and ordering contracts
### Core NBT and identity
+7 -4
View File
@@ -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: **126 plain-JVM tests, 22 Forge server tests, all passing at their last completed runs.**
Current baseline: **130 plain-JVM tests, 22 Forge server tests, all passing at their last completed runs.**
### ABI diff against the reference
@@ -197,9 +197,12 @@ Both `package.scala` objects are gone, removed rather than ported. `MultipartRen
canonical Java map, and `MultiPartRegistryCharacterizationTest` reproduces Schematica's reflective lookup and proves
both views reach the same factory.
Next close the remaining audit-derived test gap: exact reflection/mixin fields, tile list/order/move lifecycle, compact
mixed NBT/packet fixtures, and representative generated-trait/pass-through fixtures. The checklist is in the
"Immediate compatibility gate" section of `JAVA_MIGRATION.md`.
The source-only member guards are also complete: GuideNH's mixin fields, Et Futurum's button arrays, Iguana's saw
field, and Galacticraft's name-only registration lookup are pinned by `ConsumerReflectionCompatibilityTest`.
Next characterize tile list/order/move lifecycle, followed by compact mixed NBT/packet fixtures and representative
generated-trait/pass-through fixtures. The checklist is in the "Immediate compatibility gate" section of
`JAVA_MIGRATION.md`.
`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
@@ -0,0 +1,75 @@
package codechicken.multipart;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import net.minecraft.block.Block;
import org.junit.jupiter.api.Test;
import codechicken.microblock.BlockMicroMaterial;
import codechicken.microblock.ItemSaw;
import codechicken.microblock.MicroMaterialRegistry;
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial;
import codechicken.multipart.minecraft.ButtonPart;
import cpw.mods.fml.relauncher.ReflectionHelper;
/** Source-only compatibility contracts used by optional integrations in the target pack. */
class ConsumerReflectionCompatibilityTest {
@Test
void guideNhMixinCanTargetBlockMicroMaterialFields() throws NoSuchFieldException {
Field block = field(BlockMicroMaterial.class, "block", Block.class);
Field meta = field(BlockMicroMaterial.class, "meta", int.class);
assertFalse(Modifier.isStatic(block.getModifiers()));
assertFalse(Modifier.isStatic(meta.getModifiers()));
}
@Test
void etFuturumCanReplaceButtonOrientationArrays() {
Field metaSideMap = ReflectionHelper.findField(ButtonPart.class, "metaSideMap");
Field sideMetaMap = ReflectionHelper.findField(ButtonPart.class, "sideMetaMap");
assertMutableStaticIntArray(metaSideMap);
assertMutableStaticIntArray(sideMetaMap);
}
@Test
void iguanaCanFindTheSawHarvestLevel() throws NoSuchFieldException {
Field harvestLevel = field(ItemSaw.class, "harvestLevel", int.class);
assertFalse(Modifier.isStatic(harvestLevel.getModifiers()));
}
@Test
void galacticraftNameOnlyLookupFindsOneCompatibleRegistrationMethod() throws NoSuchMethodException {
Method[] methods = Arrays.stream(MicroMaterialRegistry.class.getMethods())
.filter(method -> method.getName().equals("registerMaterial")).toArray(Method[]::new);
assertEquals(1, methods.length, "Galacticraft invokes the first public method with this name");
assertTrue(Modifier.isStatic(methods[0].getModifiers()));
assertArrayEquals(new Class<?>[] { IMicroMaterial.class, String.class }, methods[0].getParameterTypes());
assertNotNull(BlockMicroMaterial.class.getConstructor(Block.class, int.class));
}
private static Field field(Class<?> owner, String name, Class<?> type) throws NoSuchFieldException {
Field field = owner.getDeclaredField(name);
assertEquals(type, field.getType());
return field;
}
private static void assertMutableStaticIntArray(Field field) {
assertEquals(int[].class, field.getType());
assertTrue(Modifier.isStatic(field.getModifiers()));
assertFalse(Modifier.isFinal(field.getModifiers()));
}
}