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
//! Unit tests for the `tm doctor` `rtk` check's pure fold (#7311).
//!
//! Why: the check's verdict must be provable without an `rtk` on the test
//! machine's PATH — otherwise the suite passes or fails on which developer ran
//! it. Every case below injects its own resolver and version probe.
//! What: both branches of [`super::build_rtk_check`], the advisory-only
//! guarantee, and the standing constraint that no message ever suggests
//! `rtk init`.
//! Test: this is the test file.
use super::*;
/// A resolver that always finds `rtk` at `path`.
fn found(path: &'static str) -> impl Fn(&str) -> Option<PathBuf> {
move |name| {
assert_eq!(name, "rtk", "the check must resolve `rtk`, not `{name}`");
Some(PathBuf::from(path))
}
}
/// A resolver that never finds anything.
fn absent(_name: &str) -> Option<PathBuf> {
None
}
/// Why: a resolved binary with a working `--version` is the healthy case and
/// must report `Ok` naming both the path and the version.
/// What: injects a resolver returning `/opt/homebrew/bin/rtk` and a version
/// probe returning `rtk 0.9.1`.
/// Test: this is the test.
#[test]
fn build_rtk_check_present_is_ok() {
let check = build_rtk_check(&found("/opt/homebrew/bin/rtk"), &|_| {
Some("rtk 0.9.1".to_owned())
});
assert_eq!(check.name, "rtk");
assert_eq!(check.status, CheckStatus::Ok);
assert!(
check.message.contains("/opt/homebrew/bin/rtk"),
"message must name the resolved path: {}",
check.message
);
assert!(
check.message.contains("rtk 0.9.1"),
"message must carry the version: {}",
check.message
);
}
/// Why: a version probe that times out or fails must not downgrade a binary
/// the resolver actually found — presence is what the check reports.
/// What: injects a resolver that finds the binary and a probe returning `None`.
/// Test: this is the test.
#[test]
fn build_rtk_check_present_without_version_is_ok() {
let check = build_rtk_check(&found("/usr/local/bin/rtk"), &|_| None);
assert_eq!(check.status, CheckStatus::Ok);
assert!(
check.message.contains("/usr/local/bin/rtk"),
"message must still name the path: {}",
check.message
);
}
/// Why: an absent binary is the whole reason the check exists, and the operator
/// needs the install command AND the `rtk init` prohibition in the same line.
/// What: injects the always-absent resolver; asserts `Warn` plus the exact
/// remediation literal.
/// Test: this is the test.
#[test]
fn build_rtk_check_absent_warns_with_remediation() {
let check = build_rtk_check(&absent, &|_| {
panic!("must not probe a binary that is absent")
});
assert_eq!(check.status, CheckStatus::Warn);
assert!(
check.message.contains(RTK_REMEDIATION),
"message must carry the remediation: {}",
check.message
);
assert!(
check.message.contains("brew install rtk"),
"remediation must name the install command: {}",
check.message
);
}
/// Why: a missing rtk leaves `tm compress` working through its native fallback,
/// so this check must never turn `tm doctor` red.
/// What: asserts neither branch returns `Fail`.
/// Test: this is the test.
#[test]
fn rtk_check_is_advisory_only() {
for check in [
build_rtk_check(&found("/opt/homebrew/bin/rtk"), &|_| None),
build_rtk_check(&absent, &|_| None),
] {
assert_ne!(
check.status,
CheckStatus::Fail,
"the rtk check is advisory: {}",
check.message
);
}
}
/// Why: `rtk init` / `rtk init -g` install a PreToolUse Bash hook that competes
/// with tm's own; tm invokes rtk directly and must never point an operator at
/// them. A future message edit that turns the prohibition into an instruction
/// fails here.
/// What: asserts that a message mentioning `rtk init` at all mentions it only
/// inside the "do not run" prohibition.
/// Test: this is the test.
// #7311: rtk is an install dependency; never run rtk init.
#[test]
fn rtk_messages_only_mention_rtk_init_as_a_prohibition() {
for check in [
build_rtk_check(&found("/opt/homebrew/bin/rtk"), &|_| {
Some("rtk 0.9.1".to_owned())
}),
build_rtk_check(&absent, &|_| None),
] {
if !check.message.contains("rtk init") {
continue;
}
assert_eq!(
check.message.matches("rtk init").count(),
1,
"only the prohibition may name `rtk init`: {}",
check.message
);
assert!(
check.message.contains("do not run `rtk init`"),
"`rtk init` may appear only as a prohibition: {}",
check.message
);
}
}