rmcl 0.3.1

A fully featured Minecraft TUI launcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
// integration tests for build_launch_invocation - the seam that takes an
// instance config plus resolved auth credentials and returns the full java
// invocation that would be spawned. these tests build the expected on-disk
// fixture layout in a tempdir, call the seam, and assert on the rendered
// LaunchInvocation. nothing here actually spawns a process.

use std::path::PathBuf;

use chrono::Utc;
use serde_json::json;
use tempfile::TempDir;

use rmcl::instance::launch::{LaunchAuth, LaunchError, build_launch_invocation};
use rmcl::instance::models::{InstanceConfig, ModLoader};

// ---------- helpers ----------

const PLAYER: &str = "TestPlayer";
const PLAYER_UUID: &str = "00000000-0000-0000-0000-000000000001";
const PLAYER_TOKEN: &str = "secret-access-token";

fn test_auth() -> LaunchAuth<'static> {
    LaunchAuth {
        username: PLAYER,
        uuid: PLAYER_UUID,
        token: PLAYER_TOKEN,
        user_type: "msa",
    }
}

fn make_config(name: &str, game_version: &str, loader: ModLoader) -> InstanceConfig {
    make_config_with(name, game_version, loader, None)
}

fn make_config_with(
    name: &str,
    game_version: &str,
    loader: ModLoader,
    loader_version: Option<&str>,
) -> InstanceConfig {
    InstanceConfig {
        name: name.into(),
        game_version: game_version.into(),
        loader,
        loader_version: loader_version.map(str::to_owned),
        created: Utc::now(),
        last_played: None,
        // pinned to a deterministic value so detect_java_path is never
        // invoked and tests don't depend on the host's java install.
        java_path: Some("/usr/bin/java-test".into()),
        memory_max: None,
        memory_min: None,
        jvm_args: Vec::new(),
        resolution: None,
    }
}

// builds the on-disk layout that build_launch_invocation expects:
//   <tmp>/instances/<name>/.minecraft/        (instance dir, created empty)
//   <tmp>/meta/versions/<game_version>/meta.json
//   <tmp>/meta/loader-profiles/               (created empty)
//   <tmp>/meta/libraries/                     (created empty)
struct Fixture {
    _tmp: TempDir,
    instances_dir: PathBuf,
    meta_dir: PathBuf,
}

impl Fixture {
    fn new(instance_name: &str, game_version: &str, vanilla_meta: serde_json::Value) -> Self {
        let tmp = tempfile::tempdir().unwrap();
        let instances_dir = tmp.path().join("instances");
        let meta_dir = tmp.path().join("meta");

        let instance_minecraft = instances_dir.join(instance_name).join(".minecraft");
        std::fs::create_dir_all(&instance_minecraft).unwrap();

        std::fs::create_dir_all(meta_dir.join("libraries")).unwrap();
        std::fs::create_dir_all(meta_dir.join("loader-profiles")).unwrap();
        let version_dir = meta_dir.join("versions").join(game_version);
        std::fs::create_dir_all(&version_dir).unwrap();
        std::fs::write(
            version_dir.join("meta.json"),
            serde_json::to_vec_pretty(&vanilla_meta).unwrap(),
        )
        .unwrap();

        Self {
            _tmp: tmp,
            instances_dir,
            meta_dir,
        }
    }

    fn write_loader_profile(&self, filename: &str, content: serde_json::Value) {
        std::fs::write(
            self.meta_dir.join("loader-profiles").join(filename),
            serde_json::to_vec_pretty(&content).unwrap(),
        )
        .unwrap();
    }

    fn instance_libraries_dir(&self, instance_name: &str) -> PathBuf {
        self.instances_dir
            .join(instance_name)
            .join(".minecraft")
            .join("libraries")
    }
}

fn modern_vanilla_meta(id: &str) -> serde_json::Value {
    json!({
        "id": id,
        "type": "release",
        "mainClass": "net.minecraft.client.main.Main",
        "assetIndex": {
            "id": "5",
            "url": "https://example.com/assets/index.json",
            "sha1": "0000000000000000000000000000000000000000"
        },
        "libraries": [
            {
                "name": "org.slf4j:slf4j-api:2.0.7",
                "downloads": {
                    "artifact": {
                        "url": "https://example.com/slf4j.jar",
                        "path": "org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar",
                        "sha1": "0000000000000000000000000000000000000000",
                        "size": 0
                    }
                }
            }
        ],
        "arguments": {
            "game": [
                "--username", "${auth_player_name}",
                "--version", "${version_name}",
                "--uuid", "${auth_uuid}",
                "--accessToken", "${auth_access_token}",
                "--userType", "${user_type}",
                "--versionType", "${version_type}"
            ],
            "jvm": [
                "-Djava.library.path=${natives_directory}",
                "-Dminecraft.launcher.brand=${launcher_name}"
            ]
        }
    })
}

fn legacy_vanilla_meta(id: &str) -> serde_json::Value {
    json!({
        "id": id,
        "type": "release",
        "mainClass": "net.minecraft.launchwrapper.Launch",
        "assetIndex": {
            "id": "1.7.10",
            "url": "https://example.com/assets/index.json",
            "sha1": "0000000000000000000000000000000000000000"
        },
        "libraries": [],
        "minecraftArguments": "--username ${auth_player_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type}"
    })
}

fn platform_classpath_sep() -> &'static str {
    if cfg!(windows) { ";" } else { ":" }
}

// ---------- vanilla ----------

#[tokio::test]
async fn vanilla_modern_builds_complete_invocation() {
    let fx = Fixture::new("v1", "1.20.1", modern_vanilla_meta("1.20.1"));
    let config = make_config("v1", "1.20.1", ModLoader::Vanilla);

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert_eq!(inv.java, "/usr/bin/java-test");
    assert_eq!(inv.main_class, "net.minecraft.client.main.Main");
    assert!(inv.extra_args.is_empty());

    let expected_natives = fx
        .meta_dir
        .join("versions")
        .join("1.20.1")
        .join("natives");
    assert!(
        inv.jvm_args.iter().any(|a| a
            == &format!("-Djava.library.path={}", expected_natives.display())),
        "jvm_args missing natives substitution: {:?}",
        inv.jvm_args
    );
    assert!(
        inv.jvm_args
            .iter()
            .any(|a| a == "-Dminecraft.launcher.brand=rmcl"),
        "jvm_args missing launcher brand: {:?}",
        inv.jvm_args
    );

    // working_dir is <instances_dir>/<name>/.minecraft
    assert_eq!(
        inv.working_dir,
        fx.instances_dir.join("v1").join(".minecraft")
    );
    // classpath = the one vanilla lib + the vanilla client jar
    let slf4j = fx
        .meta_dir
        .join("libraries/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar");
    let client_jar = fx.meta_dir.join("versions/1.20.1/1.20.1.jar");
    assert!(inv.classpath.contains(&slf4j));
    assert!(inv.classpath.contains(&client_jar));
}

#[tokio::test]
async fn vanilla_legacy_args_format_substitutes_tokens() {
    let fx = Fixture::new("vlegacy", "1.7.10", legacy_vanilla_meta("1.7.10"));
    let config = make_config("vlegacy", "1.7.10", ModLoader::Vanilla);

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert_eq!(inv.main_class, "net.minecraft.launchwrapper.Launch");

    // legacy format has no upstream jvm args; jvm_args should be just Xms/Xmx
    assert_eq!(inv.jvm_args.len(), 2);
    assert!(inv.jvm_args[0].starts_with("-Xms"));
    assert!(inv.jvm_args[1].starts_with("-Xmx"));

    // game_args should be space-split with substitutions applied
    let joined = inv.game_args.join(" ");
    assert!(joined.contains(&format!("--username {}", PLAYER)));
    assert!(joined.contains(&format!("--uuid {}", PLAYER_UUID)));
    assert!(joined.contains(&format!("--accessToken {}", PLAYER_TOKEN)));
    assert!(joined.contains("--userType msa"));
}

// ---------- forge ----------

#[tokio::test]
async fn forge_modern_includes_add_opens() {
    let fx = Fixture::new("f1", "1.20.1", modern_vanilla_meta("1.20.1"));
    fx.write_loader_profile(
        "forge-1.20.1-47.2.0.json",
        json!({
            "id": "1.20.1-forge-47.2.0",
            "inheritsFrom": "1.20.1",
            "type": "release",
            "mainClass": "cpw.mods.bootstraplauncher.BootstrapLauncher",
            "libraries": [
                { "name": "net.minecraftforge:fmlloader:1.20.1-47.2.0" }
            ],
            "arguments": {
                "game": ["--launchTarget", "forge_client"],
                "jvm": [
                    "--add-opens",
                    "java.base/sun.security.util=ALL-UNNAMED",
                    "-DignoreList=bootstraplauncher,securejarhandler"
                ]
            }
        }),
    );
    let config = make_config_with("f1", "1.20.1", ModLoader::Forge, Some("47.2.0"));

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert_eq!(inv.main_class, "cpw.mods.bootstraplauncher.BootstrapLauncher");
    assert!(
        inv.jvm_args.iter().any(|a| a == "--add-opens"),
        "Forge --add-opens missing: {:?}",
        inv.jvm_args
    );
    assert!(
        inv.jvm_args
            .iter()
            .any(|a| a == "java.base/sun.security.util=ALL-UNNAMED"),
        "Forge --add-opens target missing: {:?}",
        inv.jvm_args
    );
    assert!(
        inv.game_args
            .windows(2)
            .any(|w| w == ["--launchTarget", "forge_client"]),
        "Forge launchTarget missing from game_args: {:?}",
        inv.game_args
    );
}

#[tokio::test]
async fn forge_local_lib_dir_preferred_over_meta_dir() {
    let fx = Fixture::new("f2", "1.20.1", modern_vanilla_meta("1.20.1"));
    fx.write_loader_profile(
        "forge-1.20.1-47.2.0.json",
        json!({
            "id": "1.20.1-forge-47.2.0",
            "inheritsFrom": "1.20.1",
            "type": "release",
            "mainClass": "cpw.mods.bootstraplauncher.BootstrapLauncher",
            "libraries": [
                { "name": "net.minecraftforge:fmlloader:1.20.1-47.2.0" }
            ],
            "arguments": { "game": [], "jvm": [] }
        }),
    );

    // drop fmlloader into the instance-local libraries dir so the launcher
    // finds it there rather than under the shared meta cache.
    let local_lib =
        fx.instance_libraries_dir("f2")
            .join("net/minecraftforge/fmlloader/1.20.1-47.2.0");
    std::fs::create_dir_all(&local_lib).unwrap();
    let local_jar = local_lib.join("fmlloader-1.20.1-47.2.0.jar");
    std::fs::write(&local_jar, b"jar").unwrap();

    let config = make_config_with("f2", "1.20.1", ModLoader::Forge, Some("47.2.0"));
    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert!(
        inv.classpath.contains(&local_jar),
        "expected local fmlloader on classpath: {:?}",
        inv.classpath
    );
    // and the meta-dir candidate should not appear
    let meta_candidate = fx
        .meta_dir
        .join("libraries/net/minecraftforge/fmlloader/1.20.1-47.2.0/fmlloader-1.20.1-47.2.0.jar");
    assert!(
        !inv.classpath.contains(&meta_candidate),
        "meta-dir candidate should not be on classpath when local exists"
    );
}

// ---------- fabric ----------

#[tokio::test]
async fn fabric_implicit_inheritsfrom_resolves() {
    let fx = Fixture::new("fab", "1.20.1", modern_vanilla_meta("1.20.1"));
    // Fabric upstream profiles omit inheritsFrom; the launch flow patches it
    // in before resolving. assert that the merge picks up Fabric's main class.
    fx.write_loader_profile(
        "fabric-1.20.1-0.15.0.json",
        json!({
            "id": "fabric-loader-0.15.0-1.20.1",
            "type": "release",
            "mainClass": "net.fabricmc.loader.impl.launch.knot.KnotClient",
            "libraries": [
                { "name": "net.fabricmc:fabric-loader:0.15.0" }
            ]
        }),
    );
    let config = make_config_with("fab", "1.20.1", ModLoader::Fabric, Some("0.15.0"));

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert_eq!(
        inv.main_class,
        "net.fabricmc.loader.impl.launch.knot.KnotClient"
    );
    // both fabric-loader and vanilla slf4j must appear on the merged classpath
    let fabric_loader = fx
        .meta_dir
        .join("libraries/net/fabricmc/fabric-loader/0.15.0/fabric-loader-0.15.0.jar");
    let slf4j = fx
        .meta_dir
        .join("libraries/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar");
    assert!(
        inv.classpath.contains(&fabric_loader),
        "fabric-loader missing from classpath: {:?}",
        inv.classpath
    );
    assert!(
        inv.classpath.contains(&slf4j),
        "vanilla slf4j missing from classpath: {:?}",
        inv.classpath
    );
}

// ---------- neoforge ----------

#[tokio::test]
async fn neoforge_inheritsfrom_resolves() {
    let fx = Fixture::new("ne", "1.20.6", modern_vanilla_meta("1.20.6"));
    fx.write_loader_profile(
        "neoforge-20.4.190.json",
        json!({
            "id": "neoforge-20.4.190",
            "inheritsFrom": "1.20.6",
            "type": "release",
            "mainClass": "cpw.mods.bootstraplauncher.BootstrapLauncher",
            "libraries": [
                { "name": "net.neoforged:neoforge:20.4.190" }
            ],
            "arguments": {
                "game": [],
                "jvm": ["--add-modules", "ALL-MODULE-PATH"]
            }
        }),
    );
    let config = make_config_with("ne", "1.20.6", ModLoader::NeoForge, Some("20.4.190"));

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert_eq!(inv.main_class, "cpw.mods.bootstraplauncher.BootstrapLauncher");
    assert!(
        inv.jvm_args
            .windows(2)
            .any(|w| w == ["--add-modules", "ALL-MODULE-PATH"]),
        "NeoForge --add-modules missing: {:?}",
        inv.jvm_args
    );
}

// ---------- template substitution ----------

#[tokio::test]
async fn auth_credentials_substituted_in_game_args() {
    let fx = Fixture::new("auth", "1.20.1", modern_vanilla_meta("1.20.1"));
    let config = make_config("auth", "1.20.1", ModLoader::Vanilla);

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert!(
        inv.game_args.iter().any(|a| a == PLAYER),
        "auth_player_name not substituted: {:?}",
        inv.game_args
    );
    assert!(
        inv.game_args.iter().any(|a| a == PLAYER_UUID),
        "auth_uuid not substituted: {:?}",
        inv.game_args
    );
    assert!(
        inv.game_args.iter().any(|a| a == PLAYER_TOKEN),
        "auth_access_token not substituted: {:?}",
        inv.game_args
    );
    assert!(
        inv.game_args.iter().any(|a| a == "msa"),
        "user_type not substituted: {:?}",
        inv.game_args
    );
}

#[tokio::test]
async fn version_type_substituted() {
    // type = "snapshot" in the fixture; ${version_type} should render that
    let mut meta = modern_vanilla_meta("1.20.1");
    meta["type"] = json!("snapshot");
    let fx = Fixture::new("vt", "1.20.1", meta);
    let config = make_config("vt", "1.20.1", ModLoader::Vanilla);

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert!(
        inv.game_args.iter().any(|a| a == "snapshot"),
        "version_type not substituted to 'snapshot': {:?}",
        inv.game_args
    );
}

// ---------- classpath ----------

#[tokio::test]
async fn classpath_uses_platform_separator() {
    let fx = Fixture::new("cp", "1.20.1", modern_vanilla_meta("1.20.1"));
    let config = make_config("cp", "1.20.1", ModLoader::Vanilla);

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    // with two classpath entries we should see exactly one separator
    assert_eq!(inv.classpath.len(), 2);
    let sep = platform_classpath_sep();
    assert_eq!(inv.classpath_string.matches(sep).count(), 1);
}

#[tokio::test]
async fn rule_disallow_excludes_library() {
    // a library whose rule always denies must not appear on the classpath
    let mut meta = modern_vanilla_meta("1.20.1");
    meta["libraries"] = json!([
        {
            "name": "org.slf4j:slf4j-api:2.0.7",
            "downloads": {
                "artifact": {
                    "url": "",
                    "path": "org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar",
                    "sha1": "0000000000000000000000000000000000000000",
                    "size": 0
                }
            }
        },
        {
            "name": "com.denied:lib:1.0",
            "rules": [{ "action": "disallow" }],
            "downloads": {
                "artifact": {
                    "url": "",
                    "path": "com/denied/lib/1.0/lib-1.0.jar",
                    "sha1": "0000000000000000000000000000000000000000",
                    "size": 0
                }
            }
        }
    ]);
    let fx = Fixture::new("rule", "1.20.1", meta);
    let config = make_config("rule", "1.20.1", ModLoader::Vanilla);

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    let denied = fx
        .meta_dir
        .join("libraries/com/denied/lib/1.0/lib-1.0.jar");
    assert!(
        !inv.classpath.contains(&denied),
        "denied library was included: {:?}",
        inv.classpath
    );
}

// ---------- memory ----------

#[tokio::test]
async fn xms_xmx_use_config_memory() {
    let fx = Fixture::new("mem", "1.20.1", modern_vanilla_meta("1.20.1"));
    let mut config = make_config("mem", "1.20.1", ModLoader::Vanilla);
    config.memory_min = Some("1G".into());
    config.memory_max = Some("4G".into());

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert!(inv.jvm_args.iter().any(|a| a == "-Xms1G"));
    assert!(inv.jvm_args.iter().any(|a| a == "-Xmx4G"));
}

#[tokio::test]
async fn default_memory_used_when_unset() {
    let fx = Fixture::new("memdef", "1.20.1", modern_vanilla_meta("1.20.1"));
    let config = make_config("memdef", "1.20.1", ModLoader::Vanilla);
    // memory_min and memory_max default to None in make_config

    let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap();

    assert!(inv.jvm_args.iter().any(|a| a == "-Xms512M"));
    assert!(inv.jvm_args.iter().any(|a| a == "-Xmx2G"));
}

// ---------- error paths ----------

#[tokio::test]
async fn meta_not_found_returns_error() {
    let tmp = tempfile::tempdir().unwrap();
    let instances_dir = tmp.path().join("instances");
    let meta_dir = tmp.path().join("meta");
    std::fs::create_dir_all(instances_dir.join("ghost").join(".minecraft")).unwrap();
    std::fs::create_dir_all(meta_dir.join("versions")).unwrap();

    let config = make_config("ghost", "1.20.1", ModLoader::Vanilla);
    let err = build_launch_invocation(&config, &instances_dir, &meta_dir, &test_auth())
        .await
        .unwrap_err();
    assert!(
        matches!(err, LaunchError::MetaNotFound(_)),
        "expected MetaNotFound, got: {err:?}"
    );
}

#[tokio::test]
async fn loader_profile_missing_returns_error() {
    let fx = Fixture::new("lpmiss", "1.20.1", modern_vanilla_meta("1.20.1"));
    let config = make_config_with("lpmiss", "1.20.1", ModLoader::Fabric, Some("0.15.0"));

    let err = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap_err();
    assert!(
        matches!(err, LaunchError::MetaNotFound(_)),
        "expected MetaNotFound for missing loader profile, got: {err:?}"
    );
}

#[tokio::test]
async fn merged_profile_missing_main_class_fails() {
    // a meta.json that deserialises cleanly but lacks the required mainClass
    // must surface as a Parse error; otherwise the launcher would try to
    // unwrap None and crash later.
    let mut meta = modern_vanilla_meta("1.20.1");
    meta.as_object_mut().unwrap().remove("mainClass");
    let fx = Fixture::new("nomc", "1.20.1", meta);
    let config = make_config("nomc", "1.20.1", ModLoader::Vanilla);

    let err = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap_err();
    let msg = format!("{err:?}");
    assert!(
        matches!(err, LaunchError::Parse(_)) && msg.contains("mainClass"),
        "expected Parse error mentioning mainClass, got: {err:?}"
    );
}

#[tokio::test]
async fn legacy_loader_profile_missing_loader_version_errors() {
    // an instance with no loader_version recorded must error out cleanly
    // when its loader profile is in the legacy stripped shape (no
    // inheritsFrom, no arguments, no minecraftArguments, but has the rmcl
    // 0.3.0-era gameArguments field).
    let fx = Fixture::new("nolv", "1.20.1", modern_vanilla_meta("1.20.1"));
    fx.write_loader_profile(
        "forge-1.20.1-unknown.json",
        json!({
            "id": "1.20.1-forge",
            "mainClass": "cpw.mods.bootstraplauncher.BootstrapLauncher",
            "libraries": [],
            "gameArguments": ["--launchTarget", "forge_client"]
        }),
    );

    let mut config = make_config("nolv", "1.20.1", ModLoader::Forge);
    config.loader_version = None;

    let err = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap_err();
    let msg = format!("{err:?}");
    assert!(
        matches!(err, LaunchError::Parse(_)) && msg.contains("Reinstall"),
        "expected Parse error asking for reinstall, got: {err:?}"
    );
}

#[tokio::test]
async fn legacy_loader_profile_missing_installer_json_errors() {
    // legacy stripped profile + loader_version, but the installer JSON the
    // migration would copy from isn't present on disk. Parse error.
    let fx = Fixture::new("noinst", "1.20.1", modern_vanilla_meta("1.20.1"));
    fx.write_loader_profile(
        "forge-1.20.1-47.2.0.json",
        json!({
            "id": "1.20.1-forge-47.2.0",
            "mainClass": "cpw.mods.bootstraplauncher.BootstrapLauncher",
            "libraries": [],
            "gameArguments": ["--launchTarget", "forge_client"]
        }),
    );

    let config = make_config_with("noinst", "1.20.1", ModLoader::Forge, Some("47.2.0"));

    let err = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth())
        .await
        .unwrap_err();
    let msg = format!("{err:?}");
    assert!(
        matches!(err, LaunchError::Parse(_))
            && msg.contains("installer JSON")
            && msg.contains("missing"),
        "expected Parse error about missing installer JSON, got: {err:?}"
    );
}