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
#!/usr/bin/env python3
"""Whether one file's change between two revisions ships nothing.
The release gate exempts "docs / CI / test-only changes" and encodes that as a
path list, so `src/app/tests.rs` and `tests/` are exempt while a change
confined to a `#[cfg(test)] mod tests` inside a shipped file is not (#461).
croft keeps most unit tests beside the code they cover, so that is the ordinary
shape of a test-only fix here: the release binary is byte-identical, and the
only way to satisfy the gate is to bump a version and write user-facing notes
for a change the binary does not contain.
The two ways to be wrong are not symmetric. Waiving a bump that was needed puts
two different binaries on one version, which is the thing the gate exists to
prevent; asking for a bump that was not needed costs a version number. So every
uncertainty resolves to "ships": a module whose opening brace is not on the
`mod` line, a `#[cfg(test)]` on anything other than a module, a file that is not
Rust.
Usage: ships_nothing.py <base> <head> <path>
Exit 0 when the change ships nothing, 1 when it ships something.
"""
# The attribute on its own line, which is what rustfmt produces and what every
# test module in this repo has. `#[cfg(test)] mod tests {` on one line is legal
# and is deliberately not matched: it is not a shape that occurs here, and
# missing it only costs a version bump.
=
=
=
"""Run git, tolerating "that path is not in that revision" only where the
caller says a missing path is a legitimate answer.
Opt-in for the same reason `check_doc_ownership.git` is: tolerating it
everywhere lets an invalid revision or a malformed object read as empty
content, and empty content is the WAIVING answer here.
"""
=
return
return
# A `/*` that opens mid-line. `BlockTracker` strips strings, chars and `//`
# but not block comments, so a brace inside one is counted as structure and a
# span can swallow the shipped code below it. Rare enough (no instance in
# `src/` today) that refusing to answer is better than parsing it.
=
"""Line numbers (1-indexed) that sit INSIDE a multi-line string literal.
A blank line is only whitespace when it is code. Inside a raw string it is
content: croft's model prompt and its tree-sitter queries are multi-line
literals, and adding or removing a blank line there changes what the
binary does. `BlockTracker` already tracks the open-literal state for its
brace counting, so this reads it rather than re-deriving it.
"""
=
=
=
=
return
"""Line spans (1-indexed, inclusive) of every `#[cfg(test)]` module.
The span starts at the attribute rather than at the `mod` line, so a diff
that only edits the attribute itself still reads as test-only. Braces are
counted through `BlockTracker`, which removes string and char literals
first: a `format!("{}")` inside a test would otherwise close the module
early and leave the rest of the file looking like shipped code.
"""
=
=
return
=
=
= None
= None
=
, =
= None
continue
=
continue
continue
# Blank lines, comments, doc comments and further attributes all
# sit legally between `#[cfg(test)]` and the module it applies
# to. `classify` labels `///` DOC rather than SKIP, and a
# documented test module is an ordinary shape: missing it loses
# the exemption silently rather than waiving wrongly.
continue
=
= None
# A module still open at EOF is a miscount or a truncated file. Reporting
# it as a range would exempt everything below the attribute.
return
"""(lines removed from base, lines added at head, the raw diff), 1-indexed.
The diff text comes back because "no hunk headers" has two causes: the
file did not change, and git did not describe the change. `git diff -U0`
on a file git treats as binary prints `Binary files ... differ` and no
`@@` line at all, and inferring "unchanged" from that waives a bump.
"""
=
, = ,
=
continue
, , , =
return , ,
return
"""True when every line this change touches is inside a test module.
Both sides of the diff are read. A deletion leaves no line at the head to
inspect, so a head-only check would waive the removal of shipped code as
readily as the removal of a test.
"""
return False
=
=
, , =
# git described a change it did not give hunk headers for - a file it
# treats as binary. Nothing here can read that, so it ships.
return False
# An empty diff means "nothing changed" for a path that exists at both
# ends, and "git could not resolve that pathspec" otherwise. Only the
# first is a reason to waive a bump, and the second is reachable: a
# path that matches nothing makes `git diff` exit 0 with no output.
return and
=
=
=
=
=
=
"""A line that carries no CODE cannot change the binary, whichever
side of the diff it is on: adding or removing the blank line above a
new test module is the common case. Inside a string literal it is not
whitespace at all but content, and croft has 42 such lines in `src/`
- the model's system prompt and the tree-sitter queries - where a
blank line changes what the binary does."""
return 1 <= <= and not and not in
=
=
return False
return False
# The `#[cfg(test)]` line is what DECIDES whether the module compiles, and
# it sits inside the span it opens, so a diff that only adds or removes it
# falls inside the span and would be waived. Both directions change the
# binary: adding the attribute takes a shipping module out, removing it
# puts a test module in. A touched attribute is therefore only test-only
# when its WHOLE module moved with it, which is what a test module added
# or deleted in one piece looks like.
return and
"""True unless a span's attribute line was touched without the rest.
Blank lines inside the span are not required to have moved: they were
already dropped from `touched` above, and every one of the 159
`#[cfg(test)]` modules in `src/` contains at least one, so demanding them
made a whole module added or deleted in one piece - the case this
exemption exists for - unreachable for any module shaped like the ones
already here.
"""
=
return
, , =
return 0