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
//! What: The repository content the dependent-version planner reads, behind one small
//! interface, and the two ways planning can fail to finish.
//! Why: The planner is pure with respect to the repository: it never starts Git and never
//! reads the filesystem. The policy's wiring answers from the wrapper's candidate
//! layer, the release path from the worktree, and tests from memory. Failures are
//! reported by cause: content that could not be read is `content-unavailable`;
//! content that was read but that the planner cannot use is `policy-incomplete`.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! // interface WorkspaceContent { trackedPaths(): TrackedPath[]; candidateBytes(path): Uint8Array; baseBytes(path): Uint8Array | undefined }
//! ```
/// What: The Git file mode of a tracked path. An `enum` is a closed set of named
/// alternatives; `#[derive(...)]` generates copying, debug printing and `==`.
/// Why: Only ordinary files can receive a full-content patch, so the policy drops a
/// bump whose manifest is a symbolic link or a submodule, as the incumbent does
/// (`dependent-version-bump-policy.ts:209`).
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type TrackedMode = 'regular' | 'executable' | 'symlink' | 'submodule';
/// ```
/// What: One tracked path in the candidate state. `Vec<u8>` is an owned list of bytes;
/// Git paths are bytes, not necessarily UTF-8.
/// Why: The planner selects manifests, the registry configuration and source files from
/// this list itself, so the provider needs no knowledge of what the planner reads.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type TrackedPath = { path: Uint8Array; mode: TrackedMode };
/// ```
/// What: Something the provider could not read. `Option<Vec<u8>>` is "a path, or
/// nothing" (nothing when the tracked-path listing itself failed); `String` is
/// owned UTF-8 text.
/// Why: The engine reports this as `content-unavailable`: the policy is intact, its
/// input is missing.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type ContentUnavailable = { path?: Uint8Array; reason: string };
/// ```
/// What: The repository facts the planner reads. A `trait` is a named set of methods a
/// type promises to provide, like a TS `interface`; `&mut self` lends the provider
/// for writing, because it may remember what it read; `&[u8]` borrows a path.
/// Why: The planner asks only for what it needs: every manifest at both states, the
/// registry configuration once a version was raised, and source files of the
/// dependents whose bundled imports decide an edge.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// interface WorkspaceContent { trackedPaths(): TrackedPath[]; candidateBytes(path: Uint8Array): Uint8Array; baseBytes(path: Uint8Array): Uint8Array | undefined }
/// ```
/// What: Why the planner's own machinery could not finish although its input was read.
/// Why: The engine reports each of these as `policy-incomplete`. `ManifestShape` carries
/// the incumbent's `ManifestShapeError` text exactly, so both implementations can
/// be compared message for message.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type PolicyIncomplete = { kind: 'not-utf8'; path } | { kind: 'manifest-syntax'; path; detail } | { kind: 'manifest-shape'; path; problem } | { kind: 'duplicate-name'; name; first; second };
/// ```
/// What: Any failure to finish planning. `From` conversions below let `?` lift either
/// cause into this type.
/// Why: The wiring maps the two variants to the two engine failure codes.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type PlanError = { kind: 'content-unavailable'; error: ContentUnavailable } | { kind: 'policy-incomplete'; error: PolicyIncomplete };
/// ```
/// What: Lift an unreadable-content failure into a planning failure. `impl Trait for Type`
/// gives a type the methods a trait requires.
/// Why: Lets the planner write `content.candidate_bytes(path)?`.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const failure: PlanError = { kind: 'content-unavailable', error };
/// ```
/// What: Lift a machinery failure into a planning failure.
/// Why: Lets the planner write `read_manifest_facts(...)?`.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const failure: PlanError = { kind: 'policy-incomplete', error };
/// ```
/// What: Show a repository path as text. `String::from_utf8_lossy` replaces bytes that are
/// not UTF-8 with U+FFFD; `.into_owned()` makes the result an owned `String`.
/// Why: Messages and finding paths are text; Git paths are bytes.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const shown = new TextDecoder().decode(path);
/// ```
/// The escape hatch named in every remedy.
const HATCH: &str = "--no-enforce-mono/dependent-version-bump";
/// What: The complete diagnostic for a planning failure, naming the input and every way
/// forward.
/// Why: The person who ran the command must be able to act without reading the source.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function planErrorMessage(error: PlanError): string;
/// ```
/// What: The cause part of a `policy-incomplete` diagnostic.
/// Why: Each cause names the file and what is wrong with it.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function incompleteReason(error: PolicyIncomplete): string;
/// ```
/// Error conversions and diagnostics.