@@ -10,6 +10,7 @@ import { TEST_MAPPING, TEST_VERSION } from '../test-constants.js';
1010 * - Download Yarn mappings from Fabric Maven
1111 * - Auto-resolve version to latest build
1212 * - Extract .tiny files from JAR
13+ * - Lookup mappings between different mapping types (official, intermediary, yarn, mojmap)
1314 */
1415
1516describe ( 'Mapping Download' , ( ) => {
@@ -28,4 +29,305 @@ describe('Mapping Download', () => {
2829 // Verify it's an extracted .tiny file (not JAR)
2930 expect ( mappingPath ) . toMatch ( / \. t i n y $ / ) ;
3031 } , 120000 ) ; // 2 minutes timeout
32+
33+ it ( `should download and extract Intermediary mappings for ${ TEST_VERSION } ` , async ( ) => {
34+ const mappingService = getMappingService ( ) ;
35+
36+ const mappingPath = await mappingService . getMappings ( TEST_VERSION , 'intermediary' ) ;
37+
38+ expect ( mappingPath ) . toBeDefined ( ) ;
39+ expect ( existsSync ( mappingPath ) ) . toBe ( true ) ;
40+ expect ( mappingPath ) . toContain ( 'intermediary' ) ;
41+ expect ( mappingPath ) . toMatch ( / \. t i n y $ / ) ;
42+ } , 120000 ) ;
43+
44+ it ( `should download and convert Mojmap for ${ TEST_VERSION } ` , async ( ) => {
45+ const mappingService = getMappingService ( ) ;
46+
47+ const mappingPath = await mappingService . getMappings ( TEST_VERSION , 'mojmap' ) ;
48+
49+ expect ( mappingPath ) . toBeDefined ( ) ;
50+ expect ( existsSync ( mappingPath ) ) . toBe ( true ) ;
51+ expect ( mappingPath ) . toContain ( 'mojmap' ) ;
52+ expect ( mappingPath ) . toMatch ( / \. t i n y $ / ) ;
53+ } , 180000 ) ; // 3 minutes for conversion
54+ } ) ;
55+
56+ describe ( 'Mapping Lookup - Single File' , ( ) => {
57+ /**
58+ * Tests for lookups that can be done in a single file:
59+ * - official ↔ intermediary (intermediary file)
60+ * - intermediary ↔ yarn (yarn file)
61+ * - intermediary ↔ mojmap (mojmap file)
62+ */
63+
64+ it ( 'should lookup intermediary → yarn class mapping' , async ( ) => {
65+ const mappingService = getMappingService ( ) ;
66+
67+ // class_1297 is the intermediary name for Entity
68+ const result = await mappingService . lookupMapping (
69+ TEST_VERSION ,
70+ 'net/minecraft/class_1297' ,
71+ 'intermediary' ,
72+ 'yarn' ,
73+ ) ;
74+
75+ expect ( result . found ) . toBe ( true ) ;
76+ expect ( result . type ) . toBe ( 'class' ) ;
77+ expect ( result . target ) . toContain ( 'Entity' ) ;
78+ } , 60000 ) ;
79+
80+ it ( 'should lookup yarn → intermediary class mapping' , async ( ) => {
81+ const mappingService = getMappingService ( ) ;
82+
83+ const result = await mappingService . lookupMapping (
84+ TEST_VERSION ,
85+ 'net/minecraft/entity/Entity' ,
86+ 'yarn' ,
87+ 'intermediary' ,
88+ ) ;
89+
90+ expect ( result . found ) . toBe ( true ) ;
91+ expect ( result . type ) . toBe ( 'class' ) ;
92+ expect ( result . target ) . toContain ( 'class_' ) ;
93+ } , 60000 ) ;
94+
95+ it ( 'should lookup intermediary → mojmap class mapping' , async ( ) => {
96+ const mappingService = getMappingService ( ) ;
97+
98+ // class_1297 is the intermediary name for Entity
99+ const result = await mappingService . lookupMapping (
100+ TEST_VERSION ,
101+ 'net/minecraft/class_1297' ,
102+ 'intermediary' ,
103+ 'mojmap' ,
104+ ) ;
105+
106+ expect ( result . found ) . toBe ( true ) ;
107+ expect ( result . type ) . toBe ( 'class' ) ;
108+ expect ( result . target ) . toContain ( 'Entity' ) ;
109+ } , 60000 ) ;
110+
111+ it ( 'should lookup mojmap → intermediary class mapping' , async ( ) => {
112+ const mappingService = getMappingService ( ) ;
113+
114+ const result = await mappingService . lookupMapping (
115+ TEST_VERSION ,
116+ 'net/minecraft/world/entity/Entity' ,
117+ 'mojmap' ,
118+ 'intermediary' ,
119+ ) ;
120+
121+ expect ( result . found ) . toBe ( true ) ;
122+ expect ( result . type ) . toBe ( 'class' ) ;
123+ expect ( result . target ) . toContain ( 'class_' ) ;
124+ } , 60000 ) ;
125+
126+ it ( 'should lookup official → intermediary class mapping' , async ( ) => {
127+ const mappingService = getMappingService ( ) ;
128+
129+ // 'a' is the obfuscated name for com/mojang/math/Axis in 1.21.11
130+ // We need to find a valid obfuscated name first
131+ // Let's use a known pattern - lookup by intermediary first to verify
132+ const result = await mappingService . lookupMapping (
133+ TEST_VERSION ,
134+ 'net/minecraft/class_7833' ,
135+ 'intermediary' ,
136+ 'official' ,
137+ ) ;
138+
139+ expect ( result . found ) . toBe ( true ) ;
140+ expect ( result . type ) . toBe ( 'class' ) ;
141+ // Obfuscated names are typically single letters or short strings
142+ expect ( result . target ) . toBeDefined ( ) ;
143+ expect ( result . target ?. length ) . toBeLessThan ( 20 ) ;
144+ } , 60000 ) ;
145+
146+ it ( 'should lookup intermediary → official class mapping' , async ( ) => {
147+ const mappingService = getMappingService ( ) ;
148+
149+ const result = await mappingService . lookupMapping (
150+ TEST_VERSION ,
151+ 'net/minecraft/class_7833' ,
152+ 'intermediary' ,
153+ 'official' ,
154+ ) ;
155+
156+ expect ( result . found ) . toBe ( true ) ;
157+ expect ( result . type ) . toBe ( 'class' ) ;
158+ expect ( result . target ) . toBeDefined ( ) ;
159+ } , 60000 ) ;
160+ } ) ;
161+
162+ describe ( 'Mapping Lookup - Two-Step Bridge' , ( ) => {
163+ /**
164+ * Tests for lookups that require two-step routing via intermediary:
165+ * - official ↔ yarn
166+ * - official ↔ mojmap
167+ * - yarn ↔ mojmap
168+ */
169+
170+ it ( 'should lookup official → yarn (two-step)' , async ( ) => {
171+ const mappingService = getMappingService ( ) ;
172+
173+ // First get an obfuscated name
174+ const intResult = await mappingService . lookupMapping (
175+ TEST_VERSION ,
176+ 'net/minecraft/class_1297' ,
177+ 'intermediary' ,
178+ 'official' ,
179+ ) ;
180+
181+ expect ( intResult . found ) . toBe ( true ) ;
182+ expect ( intResult . target ) . toBeDefined ( ) ;
183+ const obfuscatedName = intResult . target as string ;
184+
185+ // Now lookup from official to yarn
186+ const result = await mappingService . lookupMapping (
187+ TEST_VERSION ,
188+ obfuscatedName ,
189+ 'official' ,
190+ 'yarn' ,
191+ ) ;
192+
193+ expect ( result . found ) . toBe ( true ) ;
194+ expect ( result . type ) . toBe ( 'class' ) ;
195+ expect ( result . target ) . toContain ( 'Entity' ) ;
196+ } , 120000 ) ;
197+
198+ it ( 'should lookup yarn → official (two-step)' , async ( ) => {
199+ const mappingService = getMappingService ( ) ;
200+
201+ const result = await mappingService . lookupMapping (
202+ TEST_VERSION ,
203+ 'net/minecraft/entity/Entity' ,
204+ 'yarn' ,
205+ 'official' ,
206+ ) ;
207+
208+ expect ( result . found ) . toBe ( true ) ;
209+ expect ( result . type ) . toBe ( 'class' ) ;
210+ expect ( result . target ) . toBeDefined ( ) ;
211+ // Obfuscated names are typically short
212+ expect ( result . target ?. length ) . toBeLessThan ( 50 ) ;
213+ } , 120000 ) ;
214+
215+ it ( 'should lookup official → mojmap (two-step)' , async ( ) => {
216+ const mappingService = getMappingService ( ) ;
217+
218+ // First get an obfuscated name
219+ const intResult = await mappingService . lookupMapping (
220+ TEST_VERSION ,
221+ 'net/minecraft/class_1297' ,
222+ 'intermediary' ,
223+ 'official' ,
224+ ) ;
225+
226+ expect ( intResult . found ) . toBe ( true ) ;
227+ expect ( intResult . target ) . toBeDefined ( ) ;
228+ const obfuscatedName = intResult . target as string ;
229+
230+ // Now lookup from official to mojmap
231+ const result = await mappingService . lookupMapping (
232+ TEST_VERSION ,
233+ obfuscatedName ,
234+ 'official' ,
235+ 'mojmap' ,
236+ ) ;
237+
238+ expect ( result . found ) . toBe ( true ) ;
239+ expect ( result . type ) . toBe ( 'class' ) ;
240+ expect ( result . target ) . toContain ( 'Entity' ) ;
241+ } , 120000 ) ;
242+
243+ it ( 'should lookup yarn → mojmap (two-step)' , async ( ) => {
244+ const mappingService = getMappingService ( ) ;
245+
246+ const result = await mappingService . lookupMapping (
247+ TEST_VERSION ,
248+ 'net/minecraft/entity/Entity' ,
249+ 'yarn' ,
250+ 'mojmap' ,
251+ ) ;
252+
253+ expect ( result . found ) . toBe ( true ) ;
254+ expect ( result . type ) . toBe ( 'class' ) ;
255+ // Mojmap uses net/minecraft/world/entity/Entity
256+ expect ( result . target ) . toContain ( 'Entity' ) ;
257+ } , 120000 ) ;
258+
259+ it ( 'should lookup mojmap → yarn (two-step)' , async ( ) => {
260+ const mappingService = getMappingService ( ) ;
261+
262+ const result = await mappingService . lookupMapping (
263+ TEST_VERSION ,
264+ 'net/minecraft/world/entity/Entity' ,
265+ 'mojmap' ,
266+ 'yarn' ,
267+ ) ;
268+
269+ expect ( result . found ) . toBe ( true ) ;
270+ expect ( result . type ) . toBe ( 'class' ) ;
271+ expect ( result . target ) . toContain ( 'Entity' ) ;
272+ } , 120000 ) ;
273+ } ) ;
274+
275+ describe ( 'Mapping Lookup - Methods and Fields' , ( ) => {
276+ it ( 'should lookup method mapping yarn → intermediary' , async ( ) => {
277+ const mappingService = getMappingService ( ) ;
278+
279+ // 'tick' is a common method name in Entity
280+ const result = await mappingService . lookupMapping ( TEST_VERSION , 'tick' , 'yarn' , 'intermediary' ) ;
281+
282+ expect ( result . found ) . toBe ( true ) ;
283+ expect ( result . type ) . toBe ( 'method' ) ;
284+ expect ( result . target ) . toContain ( 'method_' ) ;
285+ expect ( result . className ) . toBeDefined ( ) ;
286+ } , 60000 ) ;
287+
288+ it ( 'should lookup field mapping yarn → intermediary' , async ( ) => {
289+ const mappingService = getMappingService ( ) ;
290+
291+ // Look for a field that exists - 'age' is common in entities
292+ const result = await mappingService . lookupMapping ( TEST_VERSION , 'age' , 'yarn' , 'intermediary' ) ;
293+
294+ // May or may not find it, but should not throw
295+ expect ( result ) . toBeDefined ( ) ;
296+ if ( result . found ) {
297+ expect ( result . type ) . toBe ( 'field' ) ;
298+ expect ( result . target ) . toContain ( 'field_' ) ;
299+ }
300+ } , 60000 ) ;
301+ } ) ;
302+
303+ describe ( 'Mapping Lookup - Same Type' , ( ) => {
304+ it ( 'should return same value when source equals target' , async ( ) => {
305+ const mappingService = getMappingService ( ) ;
306+
307+ const result = await mappingService . lookupMapping (
308+ TEST_VERSION ,
309+ 'net/minecraft/entity/Entity' ,
310+ 'yarn' ,
311+ 'yarn' ,
312+ ) ;
313+
314+ expect ( result . found ) . toBe ( true ) ;
315+ expect ( result . source ) . toBe ( 'net/minecraft/entity/Entity' ) ;
316+ expect ( result . target ) . toBe ( 'net/minecraft/entity/Entity' ) ;
317+ } , 10000 ) ;
318+ } ) ;
319+
320+ describe ( 'Mapping Lookup - Not Found' , ( ) => {
321+ it ( 'should return not found for non-existent symbol' , async ( ) => {
322+ const mappingService = getMappingService ( ) ;
323+
324+ const result = await mappingService . lookupMapping (
325+ TEST_VERSION ,
326+ 'NonExistentClassThatDoesNotExist' ,
327+ 'yarn' ,
328+ 'intermediary' ,
329+ ) ;
330+
331+ expect ( result . found ) . toBe ( false ) ;
332+ } , 60000 ) ;
31333} ) ;
0 commit comments