rust-doctor 0.6.0

Local-first health audit for Cargo workspaces: curated Clippy lints and native detectors, scored out of 100
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
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
684
685
686
687
688
689
690
691
692
use std::collections::BTreeSet;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::io;
#[cfg(unix)]
use std::os::unix::fs::{DirBuilderExt, PermissionsExt};
use std::path::{Component, Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};

use crate::internal_error::InternalError;
use crate::git::{self, GitCall, GitFailure};

pub(crate) const ENTRY_LIMIT: usize = 100_000;
pub(crate) const BLOB_LIMIT: u64 = 64 * 1024 * 1024;
pub(crate) const TOTAL_BLOB_LIMIT: u64 = 1024 * 1024 * 1024;
pub(crate) const INVENTORY_OUTPUT_LIMIT: usize = 16 * 1024 * 1024;
const PATH_LIMIT: usize = 4_096;
const COMMAND_OUTPUT_LIMIT: usize = 4_096;
const TEMP_ATTEMPTS: usize = 128;

/// Every git call of this module reports at this stage, including the two
/// outcomes it does not name: a git that could not start, and a stream that
/// overflowed the bound this module publishes in its own oracle.
const STAGE: &str = "baseline";

const INVENTORY_FAILURE: GitFailure =
    GitFailure::new("baseline-inventory-failed", "Git baseline inventory failed.");
const LIMIT_EXCEEDED: GitFailure = GitFailure::new(
    "baseline-limit-exceeded",
    "Git baseline snapshot exceeds a supported limit.",
);
const MATERIALIZATION_FAILURE: GitFailure = GitFailure::new(
    "baseline-materialization-failed",
    "Git baseline materialization failed.",
);

static NEXT_TEMP: AtomicU64 = AtomicU64::new(0);

#[derive(Debug)]
struct Inventory {
    symlinks: Vec<PathBuf>,
}

#[derive(Debug)]
struct TempRoot {
    path: PathBuf,
    cleanup_pending: bool,
}

impl TempRoot {
    fn path(&self) -> &Path {
        &self.path
    }

    fn into_path(mut self) -> PathBuf {
        self.cleanup_pending = false;
        self.path.clone()
    }

    fn cleanup_with(
        &mut self,
        remove: impl FnOnce(&Path) -> io::Result<()>,
    ) -> Result<(), InternalError> {
        match remove(&self.path) {
            Ok(()) => {
                self.cleanup_pending = false;
                Ok(())
            }
            Err(error) if error.kind() == io::ErrorKind::NotFound => {
                self.cleanup_pending = false;
                Ok(())
            }
            Err(_) => Err(cleanup_failed()),
        }
    }
}

impl Drop for TempRoot {
    fn drop(&mut self) {
        if self.cleanup_pending {
            let _ = remove_snapshot(&self.path);
        }
    }
}

#[derive(Debug)]
pub(crate) struct Snapshot {
    root: PathBuf,
    tree: PathBuf,
    target: PathBuf,
    workspace: PathBuf,
    cleanup_pending: bool,
}

impl Snapshot {
    pub(crate) fn workspace(&self) -> &Path {
        &self.workspace
    }

    pub(crate) fn target(&self) -> &Path {
        &self.target
    }

    pub(crate) fn cleanup(mut self) -> Result<(), InternalError> {
        self.cleanup_with(remove_snapshot)
    }

    fn cleanup_with(
        &mut self,
        remove: impl FnOnce(&Path) -> io::Result<()>,
    ) -> Result<(), InternalError> {
        match remove(&self.root) {
            Ok(()) => {
                self.cleanup_pending = false;
                Ok(())
            }
            Err(error) if error.kind() == io::ErrorKind::NotFound => {
                self.cleanup_pending = false;
                Ok(())
            }
            Err(_) => Err(cleanup_failed()),
        }
    }
}

impl Drop for Snapshot {
    fn drop(&mut self) {
        if self.cleanup_pending {
            let _ = remove_snapshot(&self.root);
        }
    }
}

pub(crate) fn materialize(
    workspace_root: &Path,
    comparison_base: &str,
) -> Result<Snapshot, InternalError> {
    let inventory_entries = git::run_git(
        Path::new("git"),
        workspace_root,
        &GitCall {
            arguments: git::git_arguments(
                workspace_root,
                ["ls-tree", "-r", "-z", "-l", "--full-tree", comparison_base],
            ),
            stdout_limit: INVENTORY_OUTPUT_LIMIT,
            stage: STAGE,
            failure: INVENTORY_FAILURE,
            overflow: LIMIT_EXCEEDED,
        },
    )?;
    let inventory = parse_inventory(&inventory_entries)?;
    let repository_root = repository_root(workspace_root)?;
    let workspace_relative = workspace_root
        .strip_prefix(&repository_root)
        .map_err(|_| materialization_failed())?;
    let root = create_temp_root(&repository_root)?.into_path();
    let tree = root.join("tree");
    let target = root.join("target");
    let workspace = tree.join(workspace_relative);
    let snapshot = Snapshot {
        root,
        tree,
        target,
        workspace,
        cleanup_pending: true,
    };

    let result = materialize_inventory(workspace_root, comparison_base, &inventory, &snapshot);
    match result {
        Ok(()) => Ok(snapshot),
        Err(error) => match snapshot.cleanup() {
            Ok(()) => Err(error),
            Err(cleanup) => Err(cleanup),
        },
    }
}

fn materialize_inventory(
    workspace_root: &Path,
    comparison_base: &str,
    inventory: &Inventory,
    snapshot: &Snapshot,
) -> Result<(), InternalError> {
    fs::create_dir(&snapshot.tree).map_err(|_| temp_unavailable())?;
    fs::create_dir(&snapshot.target).map_err(|_| temp_unavailable())?;
    let index = snapshot.root.join("index");

    git::run_git_with_index(
        Path::new("git"),
        workspace_root,
        &GitCall {
            arguments: git::git_arguments(workspace_root, ["read-tree", comparison_base]),
            stdout_limit: COMMAND_OUTPUT_LIMIT,
            stage: STAGE,
            failure: MATERIALIZATION_FAILURE,
            overflow: MATERIALIZATION_FAILURE,
        },
        &index,
    )?;

    let mut prefix = OsString::from("--prefix=");
    prefix.push(snapshot.tree.as_os_str());
    prefix.push(std::path::MAIN_SEPARATOR_STR);
    git::run_git_with_index(
        Path::new("git"),
        workspace_root,
        &GitCall {
            arguments: git::git_arguments(
                workspace_root,
                [
                    OsString::from("checkout-index"),
                    OsString::from("--all"),
                    OsString::from("--force"),
                    prefix,
                ],
            ),
            stdout_limit: COMMAND_OUTPUT_LIMIT,
            stage: STAGE,
            failure: MATERIALIZATION_FAILURE,
            overflow: MATERIALIZATION_FAILURE,
        },
        &index,
    )?;

    validate_materialized_symlinks(&snapshot.tree, &inventory.symlinks)
}

fn parse_inventory(output: &[u8]) -> Result<Inventory, InternalError> {
    if output.is_empty() {
        return Ok(Inventory {
            symlinks: Vec::new(),
        });
    }
    if !output.ends_with(&[0]) {
        return Err(inventory_failed());
    }

    let mut total_bytes = 0_u64;
    let mut paths = BTreeSet::new();
    let mut symlinks = Vec::new();
    for (entries, record) in output[..output.len() - 1]
        .split(|byte| *byte == 0)
        .enumerate()
    {
        if entries == ENTRY_LIMIT {
            return Err(limit_exceeded());
        }
        let Some(separator) = record.iter().position(|byte| *byte == b'\t') else {
            return Err(inventory_failed());
        };
        let (header, raw_path) = record.split_at(separator);
        let raw_path = &raw_path[1..];
        let fields: Vec<_> = header
            .split(|byte| byte.is_ascii_whitespace())
            .filter(|field| !field.is_empty())
            .collect();
        if fields.len() != 4 {
            return Err(inventory_failed());
        }
        let mode = fields[0];
        let kind = fields[1];
        let oid = fields[2];
        if kind != b"blob"
            || !matches!(mode, b"100644" | b"100755" | b"120000")
            || !matches!(oid.len(), 40 | 64)
            || !oid.iter().all(u8::is_ascii_hexdigit)
        {
            return Err(entry_invalid());
        }
        let size = parse_decimal(fields[3]).ok_or_else(inventory_failed)?;
        if size > BLOB_LIMIT {
            return Err(limit_exceeded());
        }
        total_bytes = total_bytes
            .checked_add(size)
            .filter(|total| *total <= TOTAL_BLOB_LIMIT)
            .ok_or_else(limit_exceeded)?;

        let path = validate_inventory_path(raw_path)?;
        if !paths.insert(path.clone()) {
            return Err(entry_invalid());
        }
        if mode == b"120000" {
            symlinks.push(PathBuf::from(path));
        }
    }
    Ok(Inventory { symlinks })
}

fn validate_inventory_path(raw_path: &[u8]) -> Result<String, InternalError> {
    if raw_path.is_empty() || raw_path.len() > PATH_LIMIT {
        return Err(entry_invalid());
    }
    let path = std::str::from_utf8(raw_path).map_err(|_| entry_invalid())?;
    if path
        .split('/')
        .any(|component| component.is_empty() || matches!(component, "." | ".."))
        || Path::new(path).is_absolute()
        || !Path::new(path)
            .components()
            .all(|component| matches!(component, Component::Normal(_)))
    {
        return Err(entry_invalid());
    }
    Ok(path.to_owned())
}

fn parse_decimal(bytes: &[u8]) -> Option<u64> {
    if bytes.is_empty() || !bytes.iter().all(u8::is_ascii_digit) {
        return None;
    }
    std::str::from_utf8(bytes).ok()?.parse().ok()
}

fn validate_materialized_symlinks(tree: &Path, symlinks: &[PathBuf]) -> Result<(), InternalError> {
    for relative in symlinks {
        let link = tree.join(relative);
        let metadata = link.symlink_metadata().map_err(|_| entry_invalid())?;
        if !metadata.file_type().is_symlink() {
            return Err(entry_invalid());
        }
        let target = fs::read_link(&link).map_err(|_| entry_invalid())?;
        if target.as_os_str().is_empty()
            || target.is_absolute()
            || !target
                .components()
                .all(|component| matches!(component, Component::Normal(_)))
        {
            return Err(entry_invalid());
        }
        let Some(parent) = link.parent() else {
            return Err(entry_invalid());
        };
        if !parent.join(target).starts_with(tree) {
            return Err(entry_invalid());
        }
    }
    Ok(())
}

fn repository_root(workspace_root: &Path) -> Result<PathBuf, InternalError> {
    workspace_root
        .ancestors()
        .find(|ancestor| ancestor.join(".git").symlink_metadata().is_ok())
        .map(Path::to_path_buf)
        .ok_or_else(materialization_failed)
}

fn create_temp_root(repository_root: &Path) -> Result<TempRoot, InternalError> {
    create_temp_root_in(repository_root, &env::temp_dir())
}

fn create_temp_root_in(
    repository_root: &Path,
    temporary_root: &Path,
) -> Result<TempRoot, InternalError> {
    let temporary = temporary_root
        .canonicalize()
        .map_err(|_| temp_unavailable())?;
    let repository = repository_root
        .canonicalize()
        .map_err(|_| temp_unavailable())?;
    if temporary.starts_with(&repository) {
        return Err(temp_unavailable());
    }
    for _ in 0..TEMP_ATTEMPTS {
        let sequence = NEXT_TEMP.fetch_add(1, Ordering::Relaxed);
        let root = temporary.join(format!(
            "rust-doctor-baseline-{}-{sequence}",
            std::process::id()
        ));
        match create_private_directory(&root) {
            Ok(()) => {
                return finalize_temp_root(
                    TempRoot {
                        path: root,
                        cleanup_pending: true,
                    },
                    finalize_private_permissions,
                    |path| fs::remove_dir(path),
                );
            }
            Err(error) if error.kind() == io::ErrorKind::AlreadyExists => {}
            Err(_) => return Err(temp_unavailable()),
        }
    }
    Err(temp_unavailable())
}

fn finalize_temp_root(
    mut root: TempRoot,
    finalize: impl FnOnce(&Path) -> io::Result<()>,
    remove: impl FnOnce(&Path) -> io::Result<()>,
) -> Result<TempRoot, InternalError> {
    if finalize(root.path()).is_ok() {
        return Ok(root);
    }
    match root.cleanup_with(remove) {
        Ok(()) => Err(temp_unavailable()),
        Err(error) => Err(error),
    }
}

#[cfg(unix)]
fn create_private_directory(path: &Path) -> io::Result<()> {
    fs::DirBuilder::new().mode(0o700).create(path)
}

#[cfg(not(unix))]
fn create_private_directory(path: &Path) -> io::Result<()> {
    fs::create_dir(path)
}

#[cfg(unix)]
fn finalize_private_permissions(path: &Path) -> io::Result<()> {
    fs::set_permissions(path, fs::Permissions::from_mode(0o700))
}

#[cfg(not(unix))]
fn finalize_private_permissions(_path: &Path) -> io::Result<()> {
    Ok(())
}

fn remove_snapshot(root: &Path) -> io::Result<()> {
    fs::remove_dir_all(root)
}

fn inventory_failed() -> InternalError {
    INVENTORY_FAILURE.error(STAGE)
}

pub(crate) fn limit_exceeded() -> InternalError {
    LIMIT_EXCEEDED.error(STAGE)
}

fn entry_invalid() -> InternalError {
    InternalError::new(
        STAGE,
        "baseline-entry-invalid",
        "Git baseline contains an unsupported entry.",
    )
}

fn temp_unavailable() -> InternalError {
    InternalError::new(
        STAGE,
        "baseline-temp-unavailable",
        "Git baseline temporary storage is unavailable.",
    )
}

fn materialization_failed() -> InternalError {
    MATERIALIZATION_FAILURE.error(STAGE)
}

pub(crate) fn scan_incomplete() -> InternalError {
    InternalError::new(
        STAGE,
        "baseline-scan-incomplete",
        "Git baseline scan is incomplete.",
    )
}

pub(crate) fn cleanup_failed() -> InternalError {
    InternalError::new(
        STAGE,
        "baseline-cleanup-failed",
        "Git baseline cleanup failed.",
    )
}

#[cfg(test)]
mod tests {
    use super::*;

    fn record(mode: &str, kind: &str, size: u64, path: &str) -> Vec<u8> {
        format!("{mode} {kind} {} {size}\t{path}\0", "1".repeat(40)).into_bytes()
    }

    #[test]
    fn inventory_accepts_regular_files_and_symlinks_at_bounds() {
        let mut bytes = record("100644", "blob", BLOB_LIMIT, "src/lib.rs");
        bytes.extend(record("120000", "blob", 8, "linked.rs"));
        let inventory = parse_inventory(&bytes).unwrap();
        assert_eq!(inventory.symlinks, [PathBuf::from("linked.rs")]);
    }

    #[test]
    fn inventory_rejects_closed_entries_without_disclosing_paths() {
        let cases = [
            format!("160000 commit {} -\tprivate-gitlink\0", "1".repeat(40)).into_bytes(),
            record("100644", "blob", 1, "/private/absolute"),
            record("100644", "blob", 1, "private/../escape"),
            record("100644", "blob", 1, "private//empty"),
            record("100644", "blob", BLOB_LIMIT + 1, "private-large"),
        ];
        for bytes in cases {
            let error = parse_inventory(&bytes).unwrap_err();
            assert!(matches!(
                error.code,
                "baseline-entry-invalid" | "baseline-limit-exceeded"
            ));
            assert!(!error.message.contains("private"));
        }

        let mut non_utf8 = record("100644", "blob", 1, "valid");
        let path_start = non_utf8.len() - 6;
        non_utf8[path_start] = 0xff;
        assert_eq!(
            parse_inventory(&non_utf8).unwrap_err().code,
            "baseline-entry-invalid"
        );
    }

    #[test]
    fn inventory_cardinality_and_total_size_are_closed_at_first_excess() {
        let mut entries = Vec::new();
        for index in 0..ENTRY_LIMIT {
            entries.extend(record("100644", "blob", 1, &format!("{index:06}")));
        }
        assert!(parse_inventory(&entries).is_ok());
        entries.extend(record("100644", "blob", 1, "overflow"));
        assert_eq!(
            parse_inventory(&entries).unwrap_err().code,
            "baseline-limit-exceeded"
        );

        let mut total = Vec::new();
        for index in 0..16 {
            total.extend(record(
                "100644",
                "blob",
                BLOB_LIMIT,
                &format!("blob-{index}"),
            ));
        }
        assert!(parse_inventory(&total).is_ok());
        total.extend(record("100644", "blob", BLOB_LIMIT, "blob-overflow"));
        assert_eq!(
            parse_inventory(&total).unwrap_err().code,
            "baseline-limit-exceeded"
        );
    }

    #[test]
    fn inventory_path_length_accepts_the_limit_and_rejects_the_next_byte() {
        assert!(parse_inventory(&record("100644", "blob", 1, &"x".repeat(PATH_LIMIT))).is_ok());
        assert_eq!(
            parse_inventory(&record("100644", "blob", 1, &"x".repeat(PATH_LIMIT + 1)))
                .unwrap_err()
                .code,
            "baseline-entry-invalid"
        );
    }

    #[cfg(unix)]
    #[test]
    fn symlink_targets_are_relative_normal_and_contained() {
        use std::os::unix::fs::symlink;

        let root = Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("target/baseline-symlink-validation")
            .join(std::process::id().to_string());
        let _ = fs::remove_dir_all(&root);
        fs::create_dir_all(root.join("src")).unwrap();
        fs::write(root.join("src/lib.rs"), "").unwrap();
        symlink("lib.rs", root.join("src/internal.rs")).unwrap();
        assert!(validate_materialized_symlinks(&root, &[PathBuf::from("src/internal.rs")]).is_ok());

        fs::remove_file(root.join("src/internal.rs")).unwrap();
        symlink("../outside.rs", root.join("src/internal.rs")).unwrap();
        assert_eq!(
            validate_materialized_symlinks(&root, &[PathBuf::from("src/internal.rs")])
                .unwrap_err()
                .code,
            "baseline-entry-invalid"
        );
        fs::remove_dir_all(&root).unwrap();
    }

    #[test]
    fn cleanup_failure_is_closed_and_drop_retries_the_snapshot_root() {
        let root = Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("target/baseline-cleanup-failure")
            .join(std::process::id().to_string());
        let _ = fs::remove_dir_all(&root);
        fs::create_dir_all(&root).unwrap();
        let mut snapshot = Snapshot {
            tree: root.join("tree"),
            target: root.join("target"),
            workspace: root.join("tree"),
            root: root.clone(),
            cleanup_pending: true,
        };
        let error = snapshot
            .cleanup_with(|_| Err(io::Error::new(io::ErrorKind::PermissionDenied, "closed")))
            .unwrap_err();
        assert_eq!(
            (error.stage, error.code),
            ("baseline", "baseline-cleanup-failed")
        );
        drop(snapshot);
        assert!(!root.exists());
    }

    #[cfg(unix)]
    #[test]
    fn temporary_root_is_created_atomically_private_and_outside_the_repository() {
        use std::os::unix::fs::PermissionsExt;

        let repository = Path::new(env!("CARGO_MANIFEST_DIR"))
            .canonicalize()
            .unwrap();
        let root = create_temp_root(&repository).unwrap();
        assert!(!root.path().starts_with(&repository));
        assert_eq!(
            fs::symlink_metadata(root.path())
                .unwrap()
                .permissions()
                .mode()
                & 0o777,
            0o700
        );
        let path = root.into_path();
        fs::remove_dir(path).unwrap();
    }

    #[test]
    fn permission_finalization_failure_is_owned_and_reports_failed_cleanup() {
        let root = Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("target/baseline-permission-cleanup-failure")
            .join(std::process::id().to_string());
        let _ = fs::remove_dir_all(&root);
        fs::create_dir_all(&root).unwrap();
        let owner = TempRoot {
            path: root.clone(),
            cleanup_pending: true,
        };

        let error = finalize_temp_root(
            owner,
            |_| Err(io::Error::new(io::ErrorKind::PermissionDenied, "finalize")),
            |_| Err(io::Error::new(io::ErrorKind::PermissionDenied, "cleanup")),
        )
        .unwrap_err();

        assert_eq!(error.code, "baseline-cleanup-failed");
        assert!(!root.exists(), "the RAII owner must retry cleanup on drop");
    }

    /// The rejected case is containment, and it is built from a scratch tree
    /// rather than from this repository. Deriving it from `CARGO_MANIFEST_DIR`
    /// made the test assert a property of the machine: where `target/` is a
    /// symlink to a build directory elsewhere, the path canonicalizes outside
    /// the repository, the guard rightly accepts it, and the test fails while
    /// the code under test is correct.
    #[test]
    fn temporary_root_inside_the_repository_is_rejected() {
        let scratch = env::temp_dir()
            .canonicalize()
            .unwrap()
            .join(format!("rust-doctor-temp-boundary-{}", std::process::id()));
        let repository = scratch.join("repository");
        let temporary = repository.join("target/baseline-temp-boundary");
        let _ = fs::remove_dir_all(&scratch);
        fs::create_dir_all(&temporary).unwrap();

        let error = create_temp_root_in(&repository, &temporary).unwrap_err();

        assert_eq!(error.code, "baseline-temp-unavailable");
        fs::remove_dir_all(&scratch).unwrap();
    }

    #[test]
    fn production_limits_match_the_versioned_oracle() {
        let oracle: serde_json::Value =
            serde_json::from_str(include_str!("../tests/fixtures/baseline/oracle.json")).unwrap();
        let limits = &oracle["limits"];

        assert_eq!(limits["entries"], ENTRY_LIMIT);
        assert_eq!(limits["blob_bytes"], BLOB_LIMIT);
        assert_eq!(limits["total_blob_bytes"], TOTAL_BLOB_LIMIT);
        assert_eq!(limits["inventory_stdout_bytes"], INVENTORY_OUTPUT_LIMIT);
        assert_eq!(limits["path_bytes"], PATH_LIMIT);
        assert_eq!(
            limits["stderr_bytes"],
            crate::git::STDERR_OUTPUT_LIMIT
        );
    }
}