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
// SHIP-TWO-001 — `apr-cli-qa-v1` algorithm-level PARTIAL discharge
// for FALSIFY-QA-008.
//
// Contract: `contracts/apr-cli-qa-v1.yaml`.
// Spec: `docs/specifications/aprender-train/ship-two-models-spec.md`
// (apr CLI QA gates).
//
// ## What FALSIFY-QA-008 says
//
// rule: no phantom subcommands
// prediction: "all advertised commands have real implementations"
// test: `apr --help | awk '/^ [a-z]/{print $1}' |
// while read c; do
// apr $c --help >/dev/null 2>&1 || echo PHANTOM:$c
// done | grep -q PHANTOM && exit 1 || exit 0`
// if_fails: "subcommand listed but not implemented"
//
// ## What this file proves NOW (`PARTIAL_ALGORITHM_LEVEL`)
//
// Decision rule: given (`commands_advertised`, `phantom_count`),
// Pass iff:
//
// commands_advertised > 0 AND
// phantom_count == 0 AND
// phantom_count <= commands_advertised
//
// Zero-tolerance: a single phantom subcommand (advertised but
// without a real `--help`-responding implementation) is enough to
// trip the gate. Distinct from QA-001 which checks the registered
// count matches 58 — QA-008 checks the *registry-vs-impl* gap.
/// Binary verdict for `FALSIFY-QA-008`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Qa008Verdict {
/// `commands_advertised > 0` AND zero phantom subcommands
/// observed.
Pass,
/// One or more of:
/// - `commands_advertised == 0` (caller error — apr --help
/// listed no subcommands).
/// - `phantom_count > 0` (one or more advertised commands
/// has no working --help).
/// - `phantom_count > commands_advertised` (counter
/// corruption — partition violation).
Fail,
}
/// Pure verdict function for `FALSIFY-QA-008`.
///
/// Inputs:
/// - `commands_advertised`: count of subcommand names extracted
/// from `apr --help` output (line awk pattern).
/// - `phantom_count`: count of those subcommands whose
/// `apr <name> --help` exited non-zero.
///
/// Pass iff:
/// 1. `commands_advertised > 0`,
/// 2. `phantom_count == 0`,
/// 3. `phantom_count <= commands_advertised` (counter sanity).
///
/// Otherwise `Fail`.
///
/// # Examples
///
/// 58 commands advertised, all real — `Pass`:
/// ```
/// use aprender::format::qa_008::{
/// verdict_from_phantom_scan, Qa008Verdict,
/// };
/// let v = verdict_from_phantom_scan(58, 0);
/// assert_eq!(v, Qa008Verdict::Pass);
/// ```
///
/// 1 phantom in 58 — `Fail` (one is enough):
/// ```
/// use aprender::format::qa_008::{
/// verdict_from_phantom_scan, Qa008Verdict,
/// };
/// let v = verdict_from_phantom_scan(58, 1);
/// assert_eq!(v, Qa008Verdict::Fail);
/// ```
#[must_use]
pub fn verdict_from_phantom_scan(
commands_advertised: u64,
phantom_count: u64,
) -> Qa008Verdict {
if commands_advertised == 0 {
return Qa008Verdict::Fail;
}
if phantom_count > commands_advertised {
return Qa008Verdict::Fail;
}
if phantom_count == 0 {
Qa008Verdict::Pass
} else {
Qa008Verdict::Fail
}
}
#[cfg(test)]
mod tests {
use super::*;
// -------------------------------------------------------------------------
// Section 1: Pass band — clean implementations.
// -------------------------------------------------------------------------
#[test]
fn pass_canonical_58_no_phantoms() {
let v = verdict_from_phantom_scan(58, 0);
assert_eq!(v, Qa008Verdict::Pass);
}
#[test]
fn pass_one_command_zero_phantoms() {
// Minimal CLI with one advertised command.
let v = verdict_from_phantom_scan(1, 0);
assert_eq!(v, Qa008Verdict::Pass);
}
#[test]
fn pass_huge_clean_cli() {
let v = verdict_from_phantom_scan(1_000_000, 0);
assert_eq!(v, Qa008Verdict::Pass);
}
// -------------------------------------------------------------------------
// Section 2: Fail band — phantom subcommands (zero-tolerance).
// -------------------------------------------------------------------------
#[test]
fn fail_one_phantom_in_58() {
let v = verdict_from_phantom_scan(58, 1);
assert_eq!(
v,
Qa008Verdict::Fail,
"one phantom must Fail (no tolerance)"
);
}
#[test]
fn fail_handful_of_phantoms() {
let v = verdict_from_phantom_scan(58, 5);
assert_eq!(v, Qa008Verdict::Fail);
}
#[test]
fn fail_half_phantoms() {
let v = verdict_from_phantom_scan(58, 29);
assert_eq!(v, Qa008Verdict::Fail);
}
#[test]
fn fail_all_phantoms() {
// Catastrophic: every advertised command is phantom.
let v = verdict_from_phantom_scan(58, 58);
assert_eq!(v, Qa008Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 3: Fail band — empty advertised (caller error).
// -------------------------------------------------------------------------
#[test]
fn fail_zero_advertised() {
// `apr --help` listed no subcommands — registry empty.
let v = verdict_from_phantom_scan(0, 0);
assert_eq!(
v,
Qa008Verdict::Fail,
"zero advertised must Fail (vacuous Pass refused)"
);
}
#[test]
fn fail_zero_advertised_with_phantoms() {
// Counter corruption: zero advertised, nonzero phantoms.
let v = verdict_from_phantom_scan(0, 5);
assert_eq!(v, Qa008Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 4: Fail band — partition violations.
// -------------------------------------------------------------------------
#[test]
fn fail_phantoms_exceed_advertised() {
let v = verdict_from_phantom_scan(58, 100);
assert_eq!(
v,
Qa008Verdict::Fail,
"phantoms > advertised must Fail (partition violation)"
);
}
#[test]
fn fail_huge_phantoms_with_smaller_advertised() {
let v = verdict_from_phantom_scan(58, u64::MAX);
assert_eq!(v, Qa008Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 5: Boundary sweep — phantom-count sweep at 58 advertised.
// -------------------------------------------------------------------------
#[test]
fn phantom_count_sweep_at_58_advertised() {
let advertised = 58_u64;
let probes: Vec<(u64, Qa008Verdict)> = vec![
(0, Qa008Verdict::Pass),
(1, Qa008Verdict::Fail),
(5, Qa008Verdict::Fail),
(29, Qa008Verdict::Fail),
(57, Qa008Verdict::Fail),
(58, Qa008Verdict::Fail),
(59, Qa008Verdict::Fail), // partition violation
];
for (phantoms, expected) in probes {
let v = verdict_from_phantom_scan(advertised, phantoms);
assert_eq!(
v, expected,
"advertised=58 phantoms={phantoms} expected {expected:?}"
);
}
}
// -------------------------------------------------------------------------
// Section 6: Domain — zero-tolerance property.
// -------------------------------------------------------------------------
#[test]
fn pass_iff_phantom_count_is_exactly_zero() {
for advertised in [1_u64, 10, 58, 100, 1_000_000] {
let v_pass = verdict_from_phantom_scan(advertised, 0);
assert_eq!(v_pass, Qa008Verdict::Pass, "advertised={advertised}");
let v_fail = verdict_from_phantom_scan(advertised, 1);
assert_eq!(
v_fail,
Qa008Verdict::Fail,
"advertised={advertised} with one phantom"
);
}
}
// -------------------------------------------------------------------------
// Section 7: Realistic — apr CLI scenarios.
// -------------------------------------------------------------------------
#[test]
fn pass_apr_clean_canonical_release() {
// Canonical 58-command release with no phantoms.
let v = verdict_from_phantom_scan(58, 0);
assert_eq!(v, Qa008Verdict::Pass);
}
#[test]
fn fail_apr_with_unwired_subcommand() {
// Realistic regression: a subcommand was added to the
// registry but the dispatch arm was forgotten — `apr <cmd>`
// returns "unimplemented" exit 1.
let v = verdict_from_phantom_scan(58, 1);
assert_eq!(v, Qa008Verdict::Fail);
}
#[test]
fn pass_minimal_features_build() {
// Minimal-features build advertises fewer commands but all
// are real.
let v = verdict_from_phantom_scan(20, 0);
assert_eq!(v, Qa008Verdict::Pass);
}
}