monochange 0.5.1

Manage versions and releases for your multiplatform, multilanguage monorepo
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
use std::process::Command;

use monochange_config::load_workspace_configuration;
use monochange_test_helpers::fs::setup_scenario_workspace_from;
use tempfile::TempDir;

use super::*;

fn setup_prepared_release_repo() -> TempDir {
	let tempdir = setup_scenario_workspace_from(
		env!("CARGO_MANIFEST_DIR"),
		"prepared-release/source-github-follow-up",
	);
	let root = tempdir.path();
	git(root, &["init", "-b", "main"]);
	git(root, &["config", "user.name", "monochange tests"]);
	git(root, &["config", "user.email", "monochange@example.com"]);
	git(root, &["add", "."]);
	git(
		root,
		&["-c", "commit.gpgsign=false", "commit", "-m", "initial"],
	);
	tempdir
}

fn git(root: &Path, args: &[&str]) {
	let mut command = Command::new("git");
	command.current_dir(root).args(args);
	for variable in [
		"GIT_DIR",
		"GIT_WORK_TREE",
		"GIT_COMMON_DIR",
		"GIT_INDEX_FILE",
		"GIT_OBJECT_DIRECTORY",
		"GIT_ALTERNATE_OBJECT_DIRECTORIES",
	] {
		command.env_remove(variable);
	}
	let output = command
		.output()
		.unwrap_or_else(|error| panic!("git {args:?}: {error}"));
	assert!(
		output.status.success(),
		"git {args:?} failed: {}{}",
		String::from_utf8_lossy(&output.stdout),
		String::from_utf8_lossy(&output.stderr)
	);
}

fn explicit_artifact_path(root: &Path) -> PathBuf {
	root.join(".monochange/local/unit-prepared-release.json")
}

fn save_artifact(root: &Path, dry_run: bool, explicit_path: &Path) -> WorkspaceConfiguration {
	let configuration = load_workspace_configuration(root)
		.unwrap_or_else(|error| panic!("load workspace configuration: {error}"));
	let prepared = crate::prepare_release_execution_with_file_diffs(root, dry_run, false, false)
		.unwrap_or_else(|error| panic!("prepare release execution: {error}"));
	save_prepared_release_execution(
		root,
		&configuration,
		&prepared.prepared_release,
		&prepared.file_diffs,
		Some(explicit_path),
	)
	.unwrap_or_else(|error| panic!("save prepared release artifact: {error}"));
	configuration
}

#[test]
fn prepared_release_artifact_path_helpers_cover_default_and_explicit_paths() {
	let root = Path::new("/workspace");
	assert_eq!(
		default_prepared_release_cache_path(root),
		root.join(".monochange/local/prepared-release-cache.json")
	);
	assert_eq!(
		resolve_prepared_release_artifact_path(
			root,
			Some(Path::new(".monochange/local/custom.json"))
		),
		root.join(".monochange/local/custom.json")
	);
}

#[test]
fn read_prepared_release_artifact_reports_invalid_json() {
	let tempdir = tempfile::tempdir().unwrap_or_else(|error| panic!("tempdir: {error}"));
	let artifact_path = tempdir.path().join("artifact.json");
	fs::write(&artifact_path, "{invalid json")
		.unwrap_or_else(|error| panic!("write artifact: {error}"));
	let error = read_prepared_release_artifact(&artifact_path)
		.err()
		.unwrap_or_else(|| panic!("expected invalid json error"));
	assert!(
		error
			.to_string()
			.contains("failed to parse prepared release artifact")
	);
}

#[test]
fn git_status_snapshot_sorts_results_and_excludes_artifact_path() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	fs::create_dir_all(root.join(".monochange/local"))
		.unwrap_or_else(|error| panic!("mkdir .monochange: {error}"));
	fs::write(root.join(".monochange/local/cache.json"), "{}")
		.unwrap_or_else(|error| panic!("write cache: {error}"));
	fs::write(root.join("zzz.txt"), "z\n").unwrap_or_else(|error| panic!("write zzz: {error}"));
	fs::write(root.join("aaa.txt"), "a\n").unwrap_or_else(|error| panic!("write aaa: {error}"));

	let lines = git_status_snapshot(root, Some(&root.join(".monochange/local/cache.json")))
		.unwrap_or_else(|error| panic!("git status snapshot: {error}"));
	assert_eq!(
		lines,
		vec!["?? aaa.txt".to_string(), "?? zzz.txt".to_string()]
	);
}

#[test]
fn tracked_path_snapshots_deduplicate_paths_and_mark_deleted_entries() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let configuration = load_workspace_configuration(root)
		.unwrap_or_else(|error| panic!("load workspace configuration: {error}"));
	let prepared = crate::prepare_release_execution_with_file_diffs(root, true, false, false)
		.unwrap_or_else(|error| panic!("prepare release execution: {error}"));
	let changed_file = prepared
		.prepared_release
		.changed_files
		.first()
		.cloned()
		.unwrap_or_else(|| panic!("expected changed file"));
	let deleted_changeset = PathBuf::from(".changeset/deleted.md");
	let duplicate_path = changed_file.clone();

	save_prepared_release_execution(
		root,
		&configuration,
		&prepared.prepared_release,
		&prepared.file_diffs,
		Some(&explicit_artifact_path(root)),
	)
	.unwrap_or_else(|error| panic!("save prepared release artifact: {error}"));

	let snapshots = tracked_path_snapshots(
		root,
		&PreparedRelease {
			changed_files: vec![changed_file.clone(), duplicate_path],
			deleted_changesets: vec![deleted_changeset.clone()],
			..prepared.prepared_release.clone()
		},
	)
	.unwrap_or_else(|error| panic!("tracked path snapshots: {error}"));

	assert_eq!(
		snapshots
			.iter()
			.filter(|snapshot| snapshot.path == changed_file)
			.count(),
		1
	);
	assert!(snapshots.iter().any(|snapshot| {
		snapshot.path == deleted_changeset
			&& snapshot.state == PreparedReleaseTrackedPathState::Deleted
			&& snapshot.hash.is_none()
	}));
}

#[test]
fn render_unified_file_diff_includes_expected_headers() {
	let diff = render_unified_file_diff(
		Path::new("crates/core/Cargo.toml"),
		b"version = \"1.0.0\"\n",
		b"version = \"1.0.1\"\n",
	);
	assert!(diff.contains("--- a/crates/core/Cargo.toml"));
	assert!(diff.contains("+++ b/crates/core/Cargo.toml"));
	assert!(diff.contains("-version = \"1.0.0\""));
	assert!(diff.contains("+version = \"1.0.1\""));
}

#[test]
fn load_prepared_release_execution_rejects_non_dry_run_follow_up_from_dry_run_artifact() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, true, &artifact_path);

	let error =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), false, false)
			.unwrap_err();
	assert!(error.to_string().contains("dry-run artifacts"));
}

#[test]
fn load_prepared_release_execution_returns_cached_release_with_message_and_timings() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = load_workspace_configuration(root)
		.unwrap_or_else(|error| panic!("load workspace configuration: {error}"));
	let prepared = crate::prepare_release_execution_with_file_diffs(root, false, true, false)
		.unwrap_or_else(|error| panic!("prepare release execution: {error}"));
	save_prepared_release_execution(
		root,
		&configuration,
		&prepared.prepared_release,
		&prepared.file_diffs,
		Some(&artifact_path),
	)
	.unwrap_or_else(|error| panic!("save prepared release artifact: {error}"));

	let loaded =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), false, true)
			.unwrap_or_else(|error| panic!("load prepared release execution: {error}"))
			.unwrap_or_else(|| panic!("expected cached prepared release"));

	assert!(loaded.message.contains("reused prepared release artifact"));
	assert_eq!(loaded.execution.prepared_release, prepared.prepared_release);
	assert_eq!(loaded.execution.file_diffs, prepared.file_diffs);
	assert_eq!(loaded.execution.phase_timings.len(), 1);
	assert_eq!(
		loaded.execution.phase_timings[0].label,
		"load prepared release artifact"
	);
}

#[test]
fn load_prepared_release_execution_rejects_configuration_drift() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let _original_configuration = save_artifact(root, true, &artifact_path);
	fs::write(
		root.join("monochange.toml"),
		fs::read_to_string(root.join("monochange.toml"))
			.unwrap_or_else(|error| panic!("read monochange.toml: {error}"))
			.replacen("repo = \"monochange\"", "repo = \"monochange-next\"", 1),
	)
	.unwrap_or_else(|error| panic!("write monochange.toml: {error}"));
	let changed_configuration = load_workspace_configuration(root)
		.unwrap_or_else(|error| panic!("reload workspace configuration: {error}"));

	let error = load_prepared_release_execution(
		root,
		&changed_configuration,
		Some(&artifact_path),
		true,
		false,
	)
	.unwrap_err();
	assert!(
		error
			.to_string()
			.contains("workspace configuration changed")
	);
}

#[test]
fn load_prepared_release_execution_rejects_head_and_status_drift() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, false, &artifact_path);

	fs::write(root.join("README.md"), "head drift\n")
		.unwrap_or_else(|error| panic!("write README: {error}"));
	git(root, &["add", "README.md"]);
	git(
		root,
		&["-c", "commit.gpgsign=false", "commit", "-m", "head drift"],
	);

	let head_error =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), false, false)
			.unwrap_err();
	assert!(head_error.to_string().contains("HEAD changed"));

	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, false, &artifact_path);
	fs::write(root.join("README.md"), "status drift\n")
		.unwrap_or_else(|error| panic!("write README: {error}"));

	let status_error =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), false, false)
			.unwrap_err();
	assert!(
		status_error
			.to_string()
			.contains("workspace status no longer matches")
	);
}

#[test]
fn load_prepared_release_execution_rejects_tracked_path_drift() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, false, &artifact_path);
	let mut artifact = read_prepared_release_artifact(&artifact_path)
		.unwrap_or_else(|error| panic!("read prepared release artifact: {error}"));
	let tracked = artifact
		.tracked_paths
		.iter_mut()
		.find(|tracked| tracked.state == PreparedReleaseTrackedPathState::File)
		.unwrap_or_else(|| panic!("expected tracked file entry"));
	tracked.hash = Some("not-the-real-hash".to_string());
	fs::write(
		&artifact_path,
		serde_json::to_string_pretty(&artifact)
			.unwrap_or_else(|error| panic!("serialize artifact: {error}")),
	)
	.unwrap_or_else(|error| panic!("rewrite artifact: {error}"));
	let error =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), false, false)
			.unwrap_err();
	assert!(error.to_string().contains("workspace content drifted"));
}

#[test]
fn load_prepared_release_execution_rejects_schema_mismatch() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, true, &artifact_path);
	let mut artifact = read_prepared_release_artifact(&artifact_path)
		.unwrap_or_else(|error| panic!("read prepared release artifact: {error}"));
	artifact.schema_version += 1;
	fs::write(
		&artifact_path,
		serde_json::to_string_pretty(&artifact)
			.unwrap_or_else(|error| panic!("serialize artifact: {error}")),
	)
	.unwrap_or_else(|error| panic!("rewrite artifact: {error}"));

	let error =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), true, false)
			.unwrap_err();
	assert!(error.to_string().contains("schema version"));
}

#[test]
fn maybe_load_prepared_release_execution_ignores_stale_default_cache() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let default_path = default_prepared_release_cache_path(root);
	let configuration = load_workspace_configuration(root)
		.unwrap_or_else(|error| panic!("load workspace configuration: {error}"));
	let prepared = crate::prepare_release_execution_with_file_diffs(root, false, false, false)
		.unwrap_or_else(|error| panic!("prepare release execution: {error}"));
	save_prepared_release_execution(
		root,
		&configuration,
		&prepared.prepared_release,
		&prepared.file_diffs,
		None,
	)
	.unwrap_or_else(|error| panic!("save default prepared release artifact: {error}"));
	assert!(default_path.is_file());
	fs::write(
		root.join("crates/core/CHANGELOG.md"),
		"# Changelog\n\nautomatic drift\n",
	)
	.unwrap_or_else(|error| panic!("write drifted changelog: {error}"));

	let loaded = maybe_load_prepared_release_execution(root, &configuration, None, false, false)
		.unwrap_or_else(|error| panic!("maybe load prepared release execution: {error}"));
	assert!(loaded.is_none());
}

#[test]
fn maybe_load_prepared_release_execution_returns_explicit_stale_errors() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, false, &artifact_path);
	fs::write(root.join("README.md"), "explicit stale\n")
		.unwrap_or_else(|error| panic!("write README: {error}"));

	let error = maybe_load_prepared_release_execution(
		root,
		&configuration,
		Some(&artifact_path),
		false,
		false,
	)
	.unwrap_err();
	assert!(
		error
			.to_string()
			.contains("workspace status no longer matches")
	);
}

#[test]
fn load_prepared_release_execution_rejects_missing_diff_previews_when_requested() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = explicit_artifact_path(root);
	let configuration = save_artifact(root, false, &artifact_path);

	let error =
		load_prepared_release_execution(root, &configuration, Some(&artifact_path), false, true)
			.unwrap_err();
	assert!(error.to_string().contains("diff previews"));
}

#[test]
fn status_line_path_handles_short_and_standard_status_lines() {
	assert_eq!(status_line_path("??"), None);
	assert_eq!(
		status_line_path(" M Cargo.toml"),
		Some(PathBuf::from("Cargo.toml"))
	);
}

#[test]
fn ensure_monochange_artifact_ignored_updates_git_exclude_once() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = root.join(".monochange/local/cache.json");

	ensure_monochange_artifact_ignored(root, &artifact_path)
		.unwrap_or_else(|error| panic!("ensure artifact ignored: {error}"));
	ensure_monochange_artifact_ignored(root, &artifact_path)
		.unwrap_or_else(|error| panic!("ensure artifact ignored twice: {error}"));

	let exclude_path = root.join(".git").join("info").join("exclude");
	let exclude = fs::read_to_string(&exclude_path)
		.unwrap_or_else(|error| panic!("read git exclude: {error}"));
	assert_eq!(
		exclude
			.lines()
			.filter(|line| *line == ".monochange/local/")
			.count(),
		1
	);
}

#[test]
fn save_prepared_release_execution_reports_parent_and_write_failures() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let configuration = load_workspace_configuration(root)
		.unwrap_or_else(|error| panic!("load workspace configuration: {error}"));
	let prepared = crate::prepare_release_execution_with_file_diffs(root, false, false, false)
		.unwrap_or_else(|error| panic!("prepare release execution: {error}"));

	let parent_file = root.join("artifact-parent");
	fs::write(&parent_file, "file\n").unwrap_or_else(|error| panic!("write parent file: {error}"));
	let parent_error = save_prepared_release_execution(
		root,
		&configuration,
		&prepared.prepared_release,
		&prepared.file_diffs,
		Some(&parent_file.join("artifact.json")),
	)
	.unwrap_err();
	assert!(
		parent_error
			.to_string()
			.contains("failed to create prepared release artifact directory")
	);

	let artifact_dir = root.join(".monochange/local/write-error");
	fs::create_dir_all(&artifact_dir)
		.unwrap_or_else(|error| panic!("create artifact dir: {error}"));
	let write_error = save_prepared_release_execution(
		root,
		&configuration,
		&prepared.prepared_release,
		&prepared.file_diffs,
		Some(&artifact_dir),
	)
	.unwrap_err();
	assert!(
		write_error
			.to_string()
			.contains("failed to write prepared release artifact")
	);
}

#[test]
fn read_status_hash_and_ignore_helpers_report_non_git_cases() {
	let tempdir = tempfile::tempdir().unwrap_or_else(|error| panic!("tempdir: {error}"));
	let root = tempdir.path();

	let read_error = read_prepared_release_artifact(&root.join("missing.json"))
		.err()
		.unwrap_or_else(|| panic!("expected missing artifact error"));
	assert!(
		read_error
			.to_string()
			.contains("failed to read prepared release artifact")
	);

	let status_error = git_status_snapshot(root, None)
		.err()
		.unwrap_or_else(|| panic!("expected non-git status error"));
	assert!(
		status_error
			.to_string()
			.contains("failed to read git status")
	);

	let hash_error = hash_file_at_path(root, &root.join("missing.txt"))
		.err()
		.unwrap_or_else(|| panic!("expected hash-object failure"));
	assert!(hash_error.to_string().contains("failed to hash"));

	ensure_monochange_artifact_ignored(root, &root.join(".monochange/local/cache.json"))
		.unwrap_or_else(|error| panic!("non-git artifact ignore should succeed: {error}"));
}

#[test]
fn git_status_snapshot_without_excluded_path_keeps_all_lines() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	fs::write(root.join("scratch.txt"), "scratch\n")
		.unwrap_or_else(|error| panic!("write scratch file: {error}"));

	let lines = git_status_snapshot(root, None)
		.unwrap_or_else(|error| panic!("git status snapshot without exclusions: {error}"));
	assert!(lines.iter().any(|line| line.ends_with("scratch.txt")));
}

#[test]
fn ensure_monochange_artifact_ignored_skips_paths_outside_monochange_dir() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let artifact_path = root.join("prepared-release.json");
	let exclude_path = root.join(".git").join("info").join("exclude");

	ensure_monochange_artifact_ignored(root, &artifact_path)
		.unwrap_or_else(|error| panic!("ensure external artifact ignored: {error}"));
	let exclude = fs::read_to_string(&exclude_path).unwrap_or_default();
	assert!(!exclude.contains(".monochange/local/"));
}

#[test]
fn ensure_monochange_artifact_ignored_appends_after_existing_content_without_newline() {
	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let exclude_path = root.join(".git").join("info").join("exclude");
	fs::write(&exclude_path, "*.log")
		.unwrap_or_else(|error| panic!("seed git exclude file: {error}"));

	ensure_monochange_artifact_ignored(root, &root.join(".monochange/local/cache.json"))
		.unwrap_or_else(|error| panic!("append monochange ignore rule: {error}"));

	let exclude = fs::read_to_string(&exclude_path)
		.unwrap_or_else(|error| panic!("read git exclude file: {error}"));
	assert_eq!(exclude, "*.log\n.monochange/local/\n");
}

#[test]
fn ensure_monochange_artifact_ignored_reports_git_resolution_and_write_failures() {
	let removed_root = {
		let tempdir = tempfile::tempdir().unwrap_or_else(|error| panic!("tempdir: {error}"));
		tempdir.path().to_path_buf()
	};
	let resolve_error = ensure_monochange_artifact_ignored(
		&removed_root,
		&removed_root.join(".monochange/local/cache.json"),
	)
	.err()
	.unwrap_or_else(|| panic!("expected git exclude resolution error"));
	assert!(
		resolve_error
			.to_string()
			.contains("failed to resolve git exclude path")
	);

	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let exclude_path = root.join(".git").join("info").join("exclude");
	fs::remove_file(&exclude_path)
		.unwrap_or_else(|error| panic!("remove git exclude file: {error}"));
	fs::create_dir_all(&exclude_path)
		.unwrap_or_else(|error| panic!("create blocking exclude dir: {error}"));

	let write_error =
		ensure_monochange_artifact_ignored(root, &root.join(".monochange/local/cache.json"))
			.err()
			.unwrap_or_else(|| panic!("expected git exclude write error"));
	assert!(
		write_error
			.to_string()
			.contains("failed to update git exclude file")
	);
}

#[test]
fn helper_error_paths_cover_hashing_and_git_exclude_directory_creation() {
	let removed_root = {
		let tempdir = tempfile::tempdir().unwrap_or_else(|error| panic!("tempdir: {error}"));
		let root = tempdir.path().to_path_buf();
		fs::write(root.join("tracked.txt"), "tracked\n")
			.unwrap_or_else(|error| panic!("write tracked file: {error}"));
		root
	};
	let hash_error = hash_file_at_path(&removed_root, &removed_root.join("tracked.txt"))
		.err()
		.unwrap_or_else(|| panic!("expected hash spawn error"));
	assert!(hash_error.to_string().contains("failed to hash"));

	let tempdir = setup_prepared_release_repo();
	let root = tempdir.path();
	let info_dir = root.join(".git/info");
	let backup_dir = root.join(".git/info-backup");
	fs::rename(&info_dir, &backup_dir)
		.unwrap_or_else(|error| panic!("move git info dir aside: {error}"));
	fs::write(&info_dir, "blocking file\n")
		.unwrap_or_else(|error| panic!("write blocking git info file: {error}"));

	let create_dir_error =
		ensure_monochange_artifact_ignored(root, &root.join(".monochange/local/cache.json"))
			.err()
			.unwrap_or_else(|| panic!("expected git exclude directory creation error"));
	assert!(
		create_dir_error
			.to_string()
			.contains("failed to create git exclude directory")
	);
}