alef 0.71.0

Opinionated polyglot binding generator for Rust libraries
Documentation
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
use super::*;
use tempfile::TempDir;

fn config(root: &Path) -> ResolvedCrateConfig {
    let manifest = root.join("Cargo.toml").to_string_lossy().replace('\\', "/");
    let source = format!(
        "[workspace]\nlanguages = [\"csharp\", \"dart\", \"zig\"]\n\
         [[crates]]\nname = \"sample\"\nsources = [\"src/lib.rs\"]\nversion_from = \"{manifest}\"\n"
    );
    let parsed: crate::core::config::NewAlefConfig = toml::from_str(&source).expect("config parses");
    parsed.resolve().expect("config resolves").remove(0)
}

fn workspace(version: &str) -> TempDir {
    let temp = TempDir::new().expect("tempdir");
    std::fs::write(
        temp.path().join("Cargo.toml"),
        format!(
            "[workspace]\nmembers = [\"crates/sample\", \"crates/helper\"]\n\
             [workspace.package]\nversion = \"{version}\"\n"
        ),
    )
    .expect("workspace manifest");
    for name in ["sample", "helper"] {
        let directory = temp.path().join("crates").join(name);
        std::fs::create_dir_all(&directory).expect("crate directory");
        std::fs::write(
            directory.join("Cargo.toml"),
            format!("[package]\nname = \"{name}\"\nversion.workspace = true\n"),
        )
        .expect("crate manifest");
    }
    temp
}

#[test]
fn discovers_nested_csproj_and_checks_all_version_fields() {
    let temp = workspace("1.2.3");
    let project = temp.path().join("packages/csharp/src/Sample/Sample.csproj");
    std::fs::create_dir_all(project.parent().expect("project parent")).expect("project directory");
    std::fs::write(
        &project,
        concat!(
            "<Project><PropertyGroup>",
            "<Version>1.2.3</Version>",
            "<AssemblyVersion>1.2.2</AssemblyVersion>",
            "<FileVersion>1.2.1</FileVersion>",
            "<InformationalVersion>1.2.0</InformationalVersion>",
            "</PropertyGroup></Project>",
        ),
    )
    .expect("csproj");

    let checks = collect(&config(temp.path()), temp.path(), "1.2.3");
    let project_checks: Vec<_> = checks
        .iter()
        .filter(|check| check.label.contains("Sample.csproj#"))
        .collect();
    assert_eq!(project_checks.len(), 4);
    assert!(
        project_checks
            .iter()
            .any(|check| check.label.ends_with("#Version") && check.matches)
    );
    for field in ["AssemblyVersion", "FileVersion", "InformationalVersion"] {
        assert!(
            project_checks
                .iter()
                .any(|check| check.label.ends_with(&format!("#{field}")) && !check.matches)
        );
    }
}

/// Write a csproj whose four version fields carry exactly what the generator
/// emits for `canonical`, then return its checks.
fn generator_shaped_csproj_checks(canonical: &str) -> Vec<VersionCheck> {
    let temp = workspace(canonical);
    let project = temp.path().join("packages/csharp/src/Sample/Sample.csproj");
    std::fs::create_dir_all(project.parent().expect("project parent")).expect("project directory");
    let assembly = crate::core::version::to_dotnet_assembly_version(canonical);
    std::fs::write(
        &project,
        format!(
            "<Project><PropertyGroup>\
             <Version>{canonical}</Version>\
             <AssemblyVersion>{assembly}</AssemblyVersion>\
             <FileVersion>{assembly}</FileVersion>\
             <InformationalVersion>{canonical}</InformationalVersion>\
             </PropertyGroup></Project>",
        ),
    )
    .expect("csproj");

    collect(&config(temp.path()), temp.path(), canonical)
        .into_iter()
        .filter(|check| check.label.contains("Sample.csproj#"))
        .collect()
}

#[test]
fn generated_four_component_assembly_version_is_not_reported_as_a_mismatch() {
    let checks = generator_shaped_csproj_checks("1.17.0");
    assert_eq!(checks.len(), 4);
    for check in &checks {
        assert!(
            check.matches,
            "generator output must validate clean, but {} reported {:?}",
            check.label, check.found
        );
    }
}

#[test]
fn prerelease_assembly_version_matches_while_semver_fields_keep_the_prerelease() {
    let checks = generator_shaped_csproj_checks("1.9.0-rc.48");
    let find = |suffix: &str| {
        checks
            .iter()
            .find(|check| check.label.ends_with(suffix))
            .unwrap_or_else(|| panic!("missing {suffix}"))
    };
    for suffix in ["#AssemblyVersion", "#FileVersion"] {
        let check = find(suffix);
        assert!(check.matches, "{suffix} should match: {:?}", check.found);
        assert_eq!(check.found.as_deref(), Some("1.9.0.0"));
    }
    for suffix in ["#Version", "#InformationalVersion"] {
        let check = find(suffix);
        assert!(check.matches, "{suffix} should match: {:?}", check.found);
        assert_eq!(check.found.as_deref(), Some("1.9.0-rc.48"));
    }
}

#[test]
fn semver_fields_still_reject_the_four_component_assembly_form() {
    let temp = workspace("1.17.0");
    let project = temp.path().join("packages/csharp/src/Sample/Sample.csproj");
    std::fs::create_dir_all(project.parent().expect("project parent")).expect("project directory");
    std::fs::write(
        &project,
        concat!(
            "<Project><PropertyGroup>",
            "<Version>1.17.0.0</Version>",
            "<InformationalVersion>1.17.0.0</InformationalVersion>",
            "</PropertyGroup></Project>",
        ),
    )
    .expect("csproj");

    let checks = collect(&config(temp.path()), temp.path(), "1.17.0");
    for suffix in ["#Version", "#InformationalVersion"] {
        let check = checks
            .iter()
            .find(|check| check.label.ends_with(suffix))
            .unwrap_or_else(|| panic!("missing {suffix}"));
        assert!(
            !check.matches,
            "{suffix} carries full SemVer and must not accept the assembly form"
        );
    }
}

#[test]
fn checks_dart_and_zig_manifests() {
    let temp = workspace("2.0.0");
    std::fs::create_dir_all(temp.path().join("packages/dart")).expect("dart directory");
    std::fs::write(
        temp.path().join("packages/dart/pubspec.yaml"),
        "name: sample\nversion: 2.0.0 # release\n",
    )
    .expect("pubspec");
    std::fs::create_dir_all(temp.path().join("packages/zig")).expect("zig directory");
    std::fs::write(
        temp.path().join("packages/zig/build.zig.zon"),
        ".{\n    .name = \"sample\",\n    .version = \"1.9.0\",\n}\n",
    )
    .expect("zig manifest");

    let checks = collect(&config(temp.path()), temp.path(), "2.0.0");
    let dart = checks
        .iter()
        .find(|check| check.label.ends_with("pubspec.yaml"))
        .expect("dart check");
    let zig = checks
        .iter()
        .find(|check| check.label.ends_with("build.zig.zon"))
        .expect("zig check");
    assert!(dart.matches);
    assert!(!zig.matches);
}

#[test]
fn checks_each_local_package_in_every_cargo_lock() {
    let temp = workspace("3.4.5");
    std::fs::write(
        temp.path().join("crates/helper/Cargo.toml"),
        "[package]\nname = \"helper\"\nversion = \"4.0.0\"\n",
    )
    .expect("versioned helper manifest");
    let nested = temp.path().join("packages/elixir/native/sample");
    std::fs::create_dir_all(&nested).expect("lock directory");
    let lock = concat!(
        "version = 4\n\n",
        "[[package]]\nname = \"sample\"\nversion = \"3.4.4\"\n\n",
        "[[package]]\nname = \"helper\"\nversion = \"4.0.0\"\n\n",
        "[[package]]\nname = \"serde\"\nversion = \"1.0.0\"\nsource = \"registry+https://example.invalid/index\"\n",
    );
    std::fs::write(nested.join("Cargo.lock"), lock).expect("nested lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");
    let lock_checks: Vec<_> = checks
        .iter()
        .filter(|check| check.label.contains("Cargo.lock#"))
        .collect();
    assert_eq!(lock_checks.len(), 2);
    assert!(
        lock_checks
            .iter()
            .any(|check| check.label.ends_with("#sample") && !check.matches)
    );
    assert!(
        lock_checks
            .iter()
            .any(|check| check.label.ends_with("#helper") && check.matches)
    );
    assert!(lock_checks.iter().all(|check| !check.label.contains("//")));
}

/// Reproduces the false-positive MISMATCH observed in a consumer repo: a vendored/frozen
/// copy of a crate's `Cargo.toml` (e.g. under a Rustler `vendor/` tree carried for
/// offline builds) declares the same `name` as the live crate but at a stale,
/// explicit version. `cargo_manifest_versions` keys its map by name alone, so
/// without the `vendor` exclusion the vendored entry silently overwrites the live
/// one and every *other* Cargo.lock's genuinely-matching `sample` entry gets
/// compared against the wrong expected version.
#[test]
fn vendored_duplicate_package_name_does_not_poison_manifest_versions() {
    let temp = workspace("3.4.5");
    std::fs::create_dir_all(temp.path().join("vendor/sample")).expect("vendor directory");
    std::fs::write(
        temp.path().join("vendor/sample/Cargo.toml"),
        "[package]\nname = \"sample\"\nversion = \"9.9.9\"\n",
    )
    .expect("vendored manifest");

    let nested = temp.path().join("packages/elixir/native/consumer");
    std::fs::create_dir_all(&nested).expect("lock directory");
    std::fs::write(
        nested.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample\"\nversion = \"3.4.5\"\n",
    )
    .expect("nested lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");
    let sample = checks
        .iter()
        .find(|check| check.label.ends_with("consumer/Cargo.lock#sample"))
        .expect("sample check present");
    assert!(
        sample.matches,
        "live entry matching canonical must not be poisoned by the vendored copy: {sample:?}"
    );
    assert!(
        checks.iter().all(|check| !check.label.contains("vendor/")),
        "vendored Cargo.lock/Cargo.toml must not be walked at all: {checks:?}"
    );
}

/// Same mechanism as the vendor case, but for Mix's fetched-dependency cache
/// (`deps/`), which is how the consumer repo's `<crate>_nif` false positive actually
/// occurred — a Hex-fetched copy of the elixir package under `deps/` bundles its own
/// frozen `Cargo.toml` at the last-published version.
#[test]
fn deps_fetched_duplicate_package_name_does_not_poison_manifest_versions() {
    let temp = workspace("3.4.5");
    std::fs::create_dir_all(temp.path().join("test_apps/elixir/deps/sample_pkg/native/sample"))
        .expect("deps directory");
    std::fs::write(
        temp.path()
            .join("test_apps/elixir/deps/sample_pkg/native/sample/Cargo.toml"),
        "[package]\nname = \"sample\"\nversion = \"1.8.1\"\n",
    )
    .expect("deps-fetched manifest");

    let nested = temp.path().join("packages/elixir/native/consumer");
    std::fs::create_dir_all(&nested).expect("lock directory");
    std::fs::write(
        nested.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample\"\nversion = \"3.4.5\"\n",
    )
    .expect("nested lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");
    let sample = checks
        .iter()
        .find(|check| check.label.ends_with("consumer/Cargo.lock#sample"))
        .expect("sample check present");
    assert!(
        sample.matches,
        "live entry matching canonical must not be poisoned by the deps-fetched copy: {sample:?}"
    );
}

/// Guard against the lazy fix: a genuinely stale local Cargo.lock (no vendor/deps
/// involvement, a real path dependency that hasn't been `cargo update`d) must keep
/// failing even in the presence of an unrelated vendored duplicate name elsewhere.
#[test]
fn genuine_drift_outside_vendor_still_fails() {
    let temp = workspace("3.4.5");
    std::fs::create_dir_all(temp.path().join("vendor/sample")).expect("vendor directory");
    std::fs::write(
        temp.path().join("vendor/sample/Cargo.toml"),
        "[package]\nname = \"sample\"\nversion = \"9.9.9\"\n",
    )
    .expect("vendored manifest");

    let nested = temp.path().join("e2e/rust");
    std::fs::create_dir_all(&nested).expect("lock directory");
    std::fs::write(
        nested.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample\"\nversion = \"3.4.0\"\n",
    )
    .expect("stale nested lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");
    let sample = checks
        .iter()
        .find(|check| check.label.ends_with("e2e/rust/Cargo.lock#sample"))
        .expect("sample check present");
    assert!(
        !sample.matches,
        "genuinely stale lockfile entry must still be reported as a mismatch: {sample:?}"
    );
    assert_eq!(sample.found.as_deref(), Some("3.4.0"));
    assert_eq!(
        sample.blocked_on_publish, None,
        "drift with no pending-release dependency is a chore, not a publish blocker: {sample:?}"
    );
}

/// Write a `.git` marker of the shape a linked worktree or submodule checkout
/// carries: a FILE pointing at the owning repository's gitdir.
fn write_git_marker(checkout_root: &Path, gitdir: &str) {
    std::fs::create_dir_all(checkout_root).expect("checkout root");
    std::fs::write(checkout_root.join(".git"), format!("gitdir: {gitdir}\n")).expect("git marker file");
}

/// A linked `git worktree` checked out inside the repo (e.g. under `.worktrees/`)
/// is a different checkout at a different commit, and nothing in `.gitmodules`
/// claims it as part of this repo. Its manifests must not be walked at all —
/// neither to raise mismatches of their own nor to overwrite the live entry for a
/// package name they happen to share.
#[test]
fn unregistered_nested_worktree_is_excluded_from_the_version_map() {
    let temp = workspace("3.4.5");
    std::fs::write(
        temp.path().join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample\"\nversion = \"3.4.5\"\n",
    )
    .expect("root lock");
    let worktree_root = temp.path().join(".worktrees/scratch-lane");
    write_git_marker(&worktree_root, "../../.git/worktrees/scratch-lane");
    std::fs::write(
        worktree_root.join("Cargo.toml"),
        "[package]\nname = \"sample\"\nversion = \"9.0.0\"\n",
    )
    .expect("worktree manifest");
    std::fs::write(
        worktree_root.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample\"\nversion = \"3.4.0\"\n",
    )
    .expect("worktree lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");
    assert!(
        checks.iter().all(|check| !check.label.contains(".worktrees")),
        "no check should be produced for anything under the unregistered worktree: {checks:?}"
    );
    let sample = checks
        .iter()
        .find(|check| check.label == "Cargo.lock#sample")
        .expect("root sample check present");
    assert!(
        sample.matches,
        "the live root lockfile must not be poisoned by the worktree's stale manifest: {sample:?}"
    );
}

/// The other half of the same discriminator: a submodule checkout carries the very
/// same `.git` marker file as a stray worktree, but `.gitmodules` registers its
/// path, making it a declared part of this repo's version surface. Both scans must
/// still descend into it — the `#subcrate` check can only exist if the submodule's
/// `Cargo.toml` reached the manifest map *and* its `Cargo.lock` was walked.
#[test]
fn gitmodules_registered_submodule_is_still_validated() {
    let temp = workspace("3.4.5");
    std::fs::write(
        temp.path().join(".gitmodules"),
        "[submodule \"subcrate\"]\n\tpath = libs/subcrate\n\turl = https://example.invalid/subcrate.git\n",
    )
    .expect("gitmodules");
    let submodule_root = temp.path().join("libs/subcrate");
    write_git_marker(&submodule_root, "../../.git/modules/subcrate");
    std::fs::write(
        submodule_root.join("Cargo.toml"),
        "[package]\nname = \"subcrate\"\nversion = \"3.4.5\"\n",
    )
    .expect("submodule manifest");
    std::fs::write(
        submodule_root.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"subcrate\"\nversion = \"3.4.0\"\n",
    )
    .expect("submodule lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");
    let subcrate = checks
        .iter()
        .find(|check| check.label == "libs/subcrate/Cargo.lock#subcrate")
        .expect("registered submodule must still be validated");
    assert!(
        !subcrate.matches,
        "genuine drift inside a registered submodule must still be reported: {subcrate:?}"
    );
    assert_eq!(subcrate.found.as_deref(), Some("3.4.0"));
}

fn init_git_repo(root: &Path) {
    let status = crate::test_support::git_command(root)
        .args(["init", "-q"])
        .status()
        .expect("git init");
    assert!(status.success(), "git init must succeed for tracked-discovery tests");
}

fn git_add(root: &Path, relative: &str) {
    let status = crate::test_support::git_command(root)
        .args(["add", "--", relative])
        .status()
        .expect("git add");
    assert!(
        status.success(),
        "git add must succeed for tracked-discovery tests: {relative}"
    );
}

/// A workspace at `1.15.1` whose ruby native crate is committed at the canonical version and
/// whose gem-build staging tree holds a gitignored copy of the very same two manifests, frozen
/// at the previous release. This is the exact shape a consumer reported: `packages/ruby/tmp/`
/// is `tracked=no, ignored=yes`, and glob order puts it *after* the tracked original, so the
/// stale copy is the last writer into the name-keyed manifest map.
fn workspace_with_gem_staging_copies() -> TempDir {
    let temp = workspace("1.15.1");
    init_git_repo(temp.path());
    std::fs::write(temp.path().join(".gitignore"), "packages/ruby/tmp/\n").expect("gitignore");

    let native = temp.path().join("packages/ruby/ext/sample_rb/native");
    std::fs::create_dir_all(&native).expect("native directory");
    std::fs::write(
        native.join("Cargo.toml"),
        "[package]\nname = \"sample-rb\"\nversion = \"1.15.1\"\n",
    )
    .expect("native manifest");
    std::fs::write(
        native.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample-rb\"\nversion = \"1.15.1\"\n",
    )
    .expect("native lock");

    let staged = temp.path().join("packages/ruby/tmp/ruby/stage/ext/sample_rb/native");
    std::fs::create_dir_all(&staged).expect("stage directory");
    std::fs::write(
        staged.join("Cargo.toml"),
        "[package]\nname = \"sample-rb\"\nversion = \"1.15.0\"\n",
    )
    .expect("staged manifest");
    std::fs::write(
        staged.join("Cargo.lock"),
        "version = 4\n\n[[package]]\nname = \"sample-rb\"\nversion = \"1.15.0\"\n",
    )
    .expect("staged lock");

    for relative in [
        ".gitignore",
        "Cargo.toml",
        "crates/sample/Cargo.toml",
        "crates/helper/Cargo.toml",
        "packages/ruby/ext/sample_rb/native/Cargo.toml",
        "packages/ruby/ext/sample_rb/native/Cargo.lock",
    ] {
        git_add(temp.path(), relative);
    }
    temp
}

/// Defect 1: build staging is not part of the repository's version surface. Every row it
/// produced described a stale copy of a file whose tracked original is correct.
#[test]
fn gitignored_gem_staging_tree_is_not_scanned() {
    let temp = workspace_with_gem_staging_copies();

    let checks = collect(&config(temp.path()), temp.path(), "1.15.1");

    assert!(
        checks.iter().all(|check| !check.label.contains("/tmp/")),
        "untracked build staging must not be discovered at all: {checks:?}"
    );
    assert!(
        checks
            .iter()
            .any(|check| check.label == "packages/ruby/ext/sample_rb/native/Cargo.lock#sample-rb"),
        "the tracked original must still be checked: {checks:?}"
    );
}

/// Defect 2: the staged `Cargo.toml` declares the same package name as the tracked one, and
/// `cargo_manifest_versions` keys its map by name alone, so the ignored copy decided the
/// *expected* value for the tracked lockfile — which then failed while literally reading the
/// canonical version, in a run where every other canonical row printed `ok`.
#[test]
fn manifest_reading_the_canonical_version_is_never_reported_as_a_mismatch() {
    let temp = workspace_with_gem_staging_copies();

    let checks = collect(&config(temp.path()), temp.path(), "1.15.1");

    let tracked = checks
        .iter()
        .find(|check| check.label == "packages/ruby/ext/sample_rb/native/Cargo.lock#sample-rb")
        .expect("tracked native lock check present");
    assert!(
        tracked.matches,
        "a manifest whose version equals the workspace version must pass: {tracked:?}"
    );
    assert!(
        checks
            .iter()
            .all(|check| check.found.as_deref() != Some("1.15.1") || check.matches),
        "no row that reads the canonical version may be a mismatch: {checks:?}"
    );
}

/// The enhancement: an e2e app that depends on the *published* crate at the version being
/// released cannot have its lockfile refreshed until that release exists on the registry —
/// `cargo` cannot resolve `sample = "3.4.5"` while the index tops out at `3.4.4`. The row is
/// still a mismatch, but it is a publish blocker rather than a chore somebody forgot, and the
/// output has to be able to say which.
#[test]
fn drift_blocked_on_an_unpublished_release_is_labelled_as_such() {
    let temp = workspace("3.4.5");
    let app = temp.path().join("test_apps/rust");
    std::fs::create_dir_all(&app).expect("app directory");
    std::fs::write(
        app.join("Cargo.toml"),
        "[package]\nname = \"sample-e2e-rust\"\nversion = \"3.4.5\"\n\n\
         [dependencies]\nsample_alias = { package = \"sample\", version = \"3.4.5\" }\n",
    )
    .expect("app manifest");
    std::fs::write(
        app.join("Cargo.lock"),
        "version = 4\n\n\
         [[package]]\nname = \"sample\"\nversion = \"3.4.4\"\n\
         source = \"registry+https://example.invalid/index\"\n\n\
         [[package]]\nname = \"sample-e2e-rust\"\nversion = \"3.4.0\"\n",
    )
    .expect("app lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");

    let app_check = checks
        .iter()
        .find(|check| check.label == "test_apps/rust/Cargo.lock#sample-e2e-rust")
        .expect("app lock check present");
    assert!(!app_check.matches, "the row is still a mismatch: {app_check:?}");
    assert_eq!(
        app_check.blocked_on_publish.as_deref(),
        Some("sample@3.4.5"),
        "the row must name the release it waits on: {app_check:?}"
    );
}

/// The inverse guard, so the label cannot degrade into "every mismatch is somebody else's
/// problem": the same drift, with the dependency resolved from a local path instead of the
/// registry, is refreshable today and must stay plain drift.
#[test]
fn drift_resolvable_from_a_path_dependency_is_not_labelled_unresolvable() {
    let temp = workspace("3.4.5");
    let app = temp.path().join("test_apps/rust");
    std::fs::create_dir_all(&app).expect("app directory");
    std::fs::write(
        app.join("Cargo.toml"),
        "[package]\nname = \"sample-e2e-rust\"\nversion = \"3.4.5\"\n\n\
         [dependencies]\nsample = { version = \"3.4.5\", path = \"../../crates/sample\" }\n",
    )
    .expect("app manifest");
    std::fs::write(
        app.join("Cargo.lock"),
        "version = 4\n\n\
         [[package]]\nname = \"sample\"\nversion = \"3.4.5\"\n\n\
         [[package]]\nname = \"sample-e2e-rust\"\nversion = \"3.4.0\"\n",
    )
    .expect("app lock");

    let checks = collect(&config(temp.path()), temp.path(), "3.4.5");

    let app_check = checks
        .iter()
        .find(|check| check.label == "test_apps/rust/Cargo.lock#sample-e2e-rust")
        .expect("app lock check present");
    assert!(!app_check.matches, "the row is still a mismatch: {app_check:?}");
    assert_eq!(
        app_check.blocked_on_publish, None,
        "a lockfile cargo can refresh right now is plain drift: {app_check:?}"
    );
}