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
// SHIP-TWO-001 — `apr-cli-publish-v1` algorithm-level PARTIAL
// discharge for FALSIFY-PUB-CLI-002 AND FALSIFY-PUB-CLI-004.
//
// Contract: `contracts/apr-cli-publish-v1.yaml`.
// Spec: `docs/specifications/aprender-train/ship-two-models-spec.md`
// (apr CLI publish gate; cross-cutting requirement for MODEL-1 +
// MODEL-2 shipping).
//
// ## What FALSIFY-PUB-CLI-002 says
//
// rule: cargo install aprender works
// prediction: "cargo install aprender exits 0 on clean machine"
// if_fails: "golden path broken"
//
// ## What FALSIFY-PUB-CLI-004 says
//
// rule: full features compile locally
// prediction: "cargo check -p apr-cli --all-features exits 0"
// if_fails: "workspace build broken"
//
// ## What this file proves NOW (`PARTIAL_ALGORITHM_LEVEL`)
//
// Decision rule for BOTH gates: given `exit_code` of either
// `cargo install aprender` (PUB-CLI-002) or
// `cargo check -p apr-cli --all-features` (PUB-CLI-004), Pass iff:
//
// exit_code == 0
//
// Both gates share an identical verdict shape: pure exit-code
// equality. They differ only in which subprocess produces the
// exit code. Composing them into one verdict module reflects the
// shared algorithm; the integration-level wiring (which command
// to invoke, how to capture the exit) is FULL_DISCHARGE.
/// Binary verdict for `FALSIFY-PUB-CLI-002` and `FALSIFY-PUB-CLI-004`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PubCli002004Verdict {
/// `exit_code == 0` (cargo command succeeded).
Pass,
/// `exit_code != 0` (compile/install failed; possibly with
/// negative or out-of-range value indicating a panic /
/// signal-driven exit).
Fail,
}
/// Pure verdict function for `FALSIFY-PUB-CLI-002` and
/// `FALSIFY-PUB-CLI-004`.
///
/// Inputs:
/// - `exit_code`: process exit code of the relevant cargo command:
/// * PUB-CLI-002: `cargo install aprender --force`
/// * PUB-CLI-004: `cargo check -p apr-cli --all-features`
///
/// Pass iff `exit_code == 0`. Otherwise `Fail`.
///
/// # Examples
///
/// Cargo command succeeded — `Pass`:
/// ```
/// use aprender::format::pub_cli_002_004::{
/// verdict_from_cargo_command_exit, PubCli002004Verdict,
/// };
/// let v = verdict_from_cargo_command_exit(0);
/// assert_eq!(v, PubCli002004Verdict::Pass);
/// ```
///
/// Cargo command failed — `Fail`:
/// ```
/// use aprender::format::pub_cli_002_004::{
/// verdict_from_cargo_command_exit, PubCli002004Verdict,
/// };
/// let v = verdict_from_cargo_command_exit(101);
/// assert_eq!(v, PubCli002004Verdict::Fail);
/// ```
#[must_use]
pub fn verdict_from_cargo_command_exit(exit_code: i32) -> PubCli002004Verdict {
if exit_code == 0 {
PubCli002004Verdict::Pass
} else {
PubCli002004Verdict::Fail
}
}
#[cfg(test)]
mod tests {
use super::*;
// -------------------------------------------------------------------------
// Section 1: Pass band — only exit 0 passes.
// -------------------------------------------------------------------------
#[test]
fn pass_exit_zero() {
let v = verdict_from_cargo_command_exit(0);
assert_eq!(v, PubCli002004Verdict::Pass);
}
// -------------------------------------------------------------------------
// Section 2: Fail band — non-zero exit codes (cargo failure modes).
// -------------------------------------------------------------------------
#[test]
fn fail_exit_one_compile_error() {
// Cargo's typical "compile error" exit code.
let v = verdict_from_cargo_command_exit(1);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_two_clap_error() {
let v = verdict_from_cargo_command_exit(2);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_101_rustc_panic() {
// Rust panic exit code.
let v = verdict_from_cargo_command_exit(101);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_137_sigkill() {
// 128 + 9 = SIGKILL (e.g., OOM during link).
let v = verdict_from_cargo_command_exit(137);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_143_sigterm() {
// 128 + 15 = SIGTERM.
let v = verdict_from_cargo_command_exit(143);
assert_eq!(v, PubCli002004Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 3: Fail band — domain edges (negative, max).
// -------------------------------------------------------------------------
#[test]
fn fail_exit_negative_one() {
let v = verdict_from_cargo_command_exit(-1);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_i32_min() {
let v = verdict_from_cargo_command_exit(i32::MIN);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_i32_max() {
let v = verdict_from_cargo_command_exit(i32::MAX);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_255_posix_max() {
let v = verdict_from_cargo_command_exit(255);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_exit_256_above_posix_cap() {
// 256 is the post-truncation wrap of 0; in shell, this
// becomes 0. But on raw exit_code from waitpid, 256 is a
// valid distinct value indicating a signal-related state
// bit. Either way, non-zero must Fail.
let v = verdict_from_cargo_command_exit(256);
assert_eq!(v, PubCli002004Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 4: Boundary sweep — sweep around zero.
// -------------------------------------------------------------------------
#[test]
fn exit_code_sweep_around_zero() {
let probes: Vec<(i32, PubCli002004Verdict)> = vec![
(-3, PubCli002004Verdict::Fail),
(-2, PubCli002004Verdict::Fail),
(-1, PubCli002004Verdict::Fail),
(0, PubCli002004Verdict::Pass),
(1, PubCli002004Verdict::Fail),
(2, PubCli002004Verdict::Fail),
(3, PubCli002004Verdict::Fail),
];
for (exit, expected) in probes {
let v = verdict_from_cargo_command_exit(exit);
assert_eq!(v, expected, "exit={exit} expected {expected:?}");
}
}
// -------------------------------------------------------------------------
// Section 5: Property — Pass iff exit_code == 0 across all i32.
// -------------------------------------------------------------------------
#[test]
fn pass_iff_exit_is_exactly_zero_at_canonical_codes() {
// Every i32 must Fail except 0.
for exit in [
i32::MIN, -1000, -1, 0, 1, 2, 101, 137, 143, 255, 1000, i32::MAX,
] {
let v = verdict_from_cargo_command_exit(exit);
let expected = if exit == 0 {
PubCli002004Verdict::Pass
} else {
PubCli002004Verdict::Fail
};
assert_eq!(v, expected, "exit={exit}");
}
}
// -------------------------------------------------------------------------
// Section 6: Realistic — both gates' canonical scenarios.
// -------------------------------------------------------------------------
#[test]
fn pass_pub_cli_002_clean_install() {
// `cargo install aprender --force` succeeded.
let v = verdict_from_cargo_command_exit(0);
assert_eq!(v, PubCli002004Verdict::Pass);
}
#[test]
fn pass_pub_cli_004_clean_check() {
// `cargo check -p apr-cli --all-features` succeeded.
let v = verdict_from_cargo_command_exit(0);
assert_eq!(v, PubCli002004Verdict::Pass);
}
#[test]
fn fail_pub_cli_002_cyclic_dep_chain() {
// The if_fails class for PUB-CLI-002: "cargo install will
// hit cyclic dep chain". Cargo's typical exit for this.
let v = verdict_from_cargo_command_exit(101);
assert_eq!(v, PubCli002004Verdict::Fail);
}
#[test]
fn fail_pub_cli_004_workspace_build_broken() {
// The if_fails class for PUB-CLI-004: "workspace build broken".
let v = verdict_from_cargo_command_exit(1);
assert_eq!(v, PubCli002004Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 7: Symmetry — gate 002 and gate 004 share the verdict.
// -------------------------------------------------------------------------
#[test]
fn verdict_is_gate_agnostic() {
// Whether the exit_code came from PUB-CLI-002's
// `cargo install` OR PUB-CLI-004's `cargo check`,
// the verdict is identical for the same exit_code.
// This is the algorithm-level identity.
for exit in [0_i32, 1, 2, 101, 137, -1, i32::MAX] {
let v_install = verdict_from_cargo_command_exit(exit);
let v_check = verdict_from_cargo_command_exit(exit);
assert_eq!(
v_install, v_check,
"verdict must be gate-agnostic for exit={exit}"
);
}
}
}