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
//! Shared types and traits for callisto: package identity, versions, manifests, dependency
//! specs, and the versioned JSON report contract.
pub mod atomic;
pub mod permit;
pub use permit::*;
pub mod tag;
pub use tag::*;
pub mod error;
pub use error::*;
pub mod path;
pub use path::*;
pub mod identity;
pub use identity::*;
pub mod ecosystem;
pub use ecosystem::*;
pub mod version;
pub use version::*;
pub mod severity;
pub use severity::*;
pub mod package;
pub use package::*;
pub mod dependency;
pub use dependency::*;
pub mod discovery;
pub use discovery::*;
pub mod exec;
pub use exec::*;
pub mod commit;
pub use commit::*;
pub mod diagnostic;
pub use diagnostic::*;
pub mod plan;
pub use plan::*;
pub mod report;
pub use report::*;
pub mod matrix;
pub use matrix::*;
pub mod registry;
pub use registry::*;
#[cfg(test)]
mod tests {
use super::*;
fn assert_send_sync_static<T: Send + Sync + 'static>() {}
#[test]
fn test_auto_traits() {
assert_send_sync_static::<PackageId>();
assert_send_sync_static::<Version>();
assert_send_sync_static::<Severity>();
assert_send_sync_static::<Ecosystem>();
assert_send_sync_static::<Package>();
assert_send_sync_static::<PublishPlan>();
assert_send_sync_static::<PublishReport>();
assert_send_sync_static::<VersionReport>();
assert_send_sync_static::<StatusReport>();
}
/// Every source file across the workspace that declares at least one `#[diagnostic(code(E..))]`,
/// embedded at compile time via `include_str!` (paths relative to this file). This list is
/// the actual audit surface — a file added here needs no further wiring, since the scan below
/// extracts every code occurrence directly from the text.
///
/// A prior version of this test used a hand-maintained `&[&str]` list of expected codes,
/// which (a) had to be updated by hand every time a code was added anywhere in the workspace,
/// and (b) was missing two entire files (`commit.rs`, `version.rs`) and roughly a third of
/// `callisto-graph/src/error.rs`'s own codes, entirely undetected until an actual duplicate
/// (`E117` on two unrelated `callisto-graph` variants) was found by unrelated code review —
/// a hand-maintained completeness list is exactly the kind of check that silently stops
/// checking anything the moment someone forgets to update it. Scanning the real source text
/// at compile time removes the maintenance step entirely: a new file with diagnostic codes
/// simply needs adding to this array, and every code that file ever gains is covered from
/// then on with no further edits here.
const DIAGNOSTIC_CODE_SOURCE_FILES: &[(&str, &str)] = &[
("callisto-model/src/error.rs", include_str!("error.rs")),
("callisto-model/src/exec.rs", include_str!("exec.rs")),
("callisto-model/src/commit.rs", include_str!("commit.rs")),
("callisto-model/src/version.rs", include_str!("version.rs")),
(
"callisto-graph/src/locate/mod.rs",
include_str!("../../callisto-graph/src/locate/mod.rs"),
),
(
"callisto-graph/src/error.rs",
include_str!("../../callisto-graph/src/error.rs"),
),
(
"callisto-format/src/bump.rs",
include_str!("../../callisto-format/src/bump.rs"),
),
(
"callisto-format/src/changeset/mod.rs",
include_str!("../../callisto-format/src/changeset/mod.rs"),
),
(
"callisto-vcs/src/lib.rs",
include_str!("../../callisto-vcs/src/lib.rs"),
),
(
"callisto-changelog/src/error.rs",
include_str!("../../callisto-changelog/src/error.rs"),
),
];
/// Extracts every `code(E<digits>)` occurrence from `text`, in order of appearance. Deliberately
/// a hand-rolled scan rather than a `regex` dependency — the pattern is fixed-shape and simple
/// enough that adding a whole crate dependency for it isn't warranted.
fn extract_diagnostic_codes(text: &str) -> Vec<String> {
let mut codes = Vec::new();
let mut rest = text;
while let Some(start) = rest.find("code(E") {
let after_marker = &rest[start + "code(".len()..];
let digit_end = after_marker
.find(|c: char| !c.is_ascii_digit() && c != 'E')
.unwrap_or(after_marker.len());
let candidate = &after_marker[..digit_end];
// `code(` is also used for things like `code(callisto::foo)` in test-double
// diagnostics elsewhere in the workspace (out of scope for this scan, since those
// files aren't in `DIAGNOSTIC_CODE_SOURCE_FILES`) -- guard here anyway so a stray
// non-numeric match can't silently produce a bogus "code".
if candidate.len() > 1 && candidate[1..].chars().all(|c| c.is_ascii_digit()) {
codes.push(candidate.to_string());
}
rest = &after_marker[digit_end..];
}
codes
}
/// Asserts that every `#[diagnostic(code(...))]` value across every file in
/// [`DIAGNOSTIC_CODE_SOURCE_FILES`] is unique workspace-wide. Duplicate diagnostic codes are
/// a real user-facing bug (E-codes are meant to be a stable, searchable identifier for one
/// specific error condition) — see this test's doc comment on `DIAGNOSTIC_CODE_SOURCE_FILES`
/// for the collision this replaced a broken, silently-incomplete version of the check.
#[test]
fn test_all_diagnostic_codes_are_unique() {
let mut seen: std::collections::BTreeMap<String, &str> = std::collections::BTreeMap::new();
for (file, text) in DIAGNOSTIC_CODE_SOURCE_FILES {
for code in extract_diagnostic_codes(text) {
if let Some(first_file) = seen.insert(code.clone(), file) {
panic!(
"Duplicate diagnostic code {code}: declared in both {first_file} and {file}"
);
}
}
}
assert!(
seen.len() > 50,
"expected at least 50 distinct diagnostic codes across the workspace (81 at the \
time this test was written), got {} -- extract_diagnostic_codes likely stopped \
matching real source (check DIAGNOSTIC_CODE_SOURCE_FILES's include_str! paths \
still resolve)",
seen.len()
);
}
#[test]
fn extract_diagnostic_codes_finds_every_code_in_a_small_fixture() {
let text = r#"
#[diagnostic(code(E001))]
struct Foo;
#[diagnostic(
code(E042),
help("do something")
)]
struct Bar;
"#;
assert_eq!(extract_diagnostic_codes(text), vec!["E001", "E042"]);
}
#[test]
fn extract_diagnostic_codes_detects_a_duplicate_within_one_string() {
let text = "code(E001) ... code(E001)";
let codes = extract_diagnostic_codes(text);
let mut seen = std::collections::BTreeSet::new();
assert!(!codes.iter().all(|c| seen.insert(c.clone())));
}
}