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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// SHIP-TWO-001 — `apr-cli-publish-v1` algorithm-level PARTIAL
// discharge for FALSIFY-PUB-CLI-001.
//
// 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-001 says
//
// rule: default features don't pull old deps
// prediction: "default features contain no inference/training/code/cuda"
// test: "grep '^default = ' crates/apr-cli/Cargo.toml |
// grep -qvE 'inference|training|code|cuda'"
// if_fails: "cargo install aprender will hit cyclic dep chain"
//
// ## What this file proves NOW (`PARTIAL_ALGORITHM_LEVEL`)
//
// Decision rule: given the bytes of the `default = […]` line from
// `apr-cli/Cargo.toml`, Pass iff:
//
// default_line is non-empty AND
// default_line does NOT contain ANY of:
// - "inference"
// - "training"
// - "code"
// - "cuda"
//
// Substring containment matches the contract's
// `grep -qvE 'inference|training|code|cuda'` semantics. Even one
// of the four forbidden tokens trips the gate — they each pull a
// heavy/cyclic dep chain that breaks `cargo install aprender`.
/// Forbidden substrings in the `default = […]` features line.
///
/// Per contract: each of these triggers a cyclic or heavy-binary
/// dep chain when included in the published `aprender` crate's
/// default features. They MUST be opt-in, never default.
pub const AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS: &[&[u8]] = &[
b"inference",
b"training",
b"code",
b"cuda",
];
/// Binary verdict for `FALSIFY-PUB-CLI-001`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PubCli001Verdict {
/// `default = […]` line is non-empty AND contains none of the
/// four forbidden substrings.
Pass,
/// One or more of:
/// - `default_line.is_empty()` (caller error — Cargo.toml
/// parsing produced no default-features line).
/// - `default_line` contains any of `inference`, `training`,
/// `code`, or `cuda` (regression — published crate would
/// pull cyclic/heavy deps).
Fail,
}
/// Pure verdict function for `FALSIFY-PUB-CLI-001`.
///
/// Inputs:
/// - `default_line`: bytes of the literal `default = […]` line
/// from `crates/apr-cli/Cargo.toml`. The caller is expected to
/// extract this line via `grep '^default = '` or equivalent.
///
/// Pass iff:
/// 1. `!default_line.is_empty()`,
/// 2. `default_line` does NOT contain any of the four forbidden
/// substrings (case-sensitive byte match).
///
/// Otherwise `Fail`.
///
/// # Examples
///
/// Clean default features — `Pass`:
/// ```
/// use aprender::format::pub_cli_001::{
/// verdict_from_default_features_string, PubCli001Verdict,
/// };
/// let line = b"default = [\"format\", \"pull\", \"qa\"]";
/// let v = verdict_from_default_features_string(line);
/// assert_eq!(v, PubCli001Verdict::Pass);
/// ```
///
/// `inference` snuck into defaults (cyclic dep risk) — `Fail`:
/// ```
/// use aprender::format::pub_cli_001::{
/// verdict_from_default_features_string, PubCli001Verdict,
/// };
/// let line = b"default = [\"format\", \"inference\", \"pull\"]";
/// let v = verdict_from_default_features_string(line);
/// assert_eq!(v, PubCli001Verdict::Fail);
/// ```
#[must_use]
pub fn verdict_from_default_features_string(default_line: &[u8]) -> PubCli001Verdict {
if default_line.is_empty() {
return PubCli001Verdict::Fail;
}
for forbidden in AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS {
if contains_subsequence(default_line, forbidden) {
return PubCli001Verdict::Fail;
}
}
PubCli001Verdict::Pass
}
/// Returns `true` iff `needle` appears as a contiguous subsequence
/// of `haystack`. Same primitive as in `pull_dataset_001` and
/// `pull_dataset_005`.
#[must_use]
fn contains_subsequence(haystack: &[u8], needle: &[u8]) -> bool {
if needle.len() > haystack.len() {
return false;
}
haystack.windows(needle.len()).any(|w| w == needle)
}
#[cfg(test)]
mod tests {
use super::*;
// -------------------------------------------------------------------------
// Section 1: Provenance pin — the four forbidden substrings.
// -------------------------------------------------------------------------
#[test]
fn provenance_forbidden_substrings_count_is_four() {
assert_eq!(AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS.len(), 4);
}
#[test]
fn provenance_forbidden_substrings_are_canonical() {
assert_eq!(AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS[0], b"inference");
assert_eq!(AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS[1], b"training");
assert_eq!(AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS[2], b"code");
assert_eq!(AC_PUB_CLI_001_FORBIDDEN_SUBSTRINGS[3], b"cuda");
}
// -------------------------------------------------------------------------
// Section 2: Pass band — clean default features.
// -------------------------------------------------------------------------
#[test]
fn pass_minimal_default_features() {
let line = b"default = [\"format\", \"qa\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Pass);
}
#[test]
fn pass_canonical_apr_default_features() {
// Realistic clean defaults: format readers, pull, qa, tools.
let line = b"default = [\"format\", \"pull\", \"qa\", \"tools\", \"validate\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Pass);
}
#[test]
fn pass_empty_array_default() {
let line = b"default = []";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Pass);
}
// -------------------------------------------------------------------------
// Section 3: Fail band — each forbidden substring (one at a time).
// -------------------------------------------------------------------------
#[test]
fn fail_inference_in_defaults() {
let line = b"default = [\"format\", \"inference\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(
v,
PubCli001Verdict::Fail,
"inference in default features must Fail (cyclic dep risk)"
);
}
#[test]
fn fail_training_in_defaults() {
let line = b"default = [\"training\", \"format\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
#[test]
fn fail_code_in_defaults() {
let line = b"default = [\"format\", \"code\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
#[test]
fn fail_cuda_in_defaults() {
let line = b"default = [\"format\", \"cuda\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 4: Fail band — multiple forbidden substrings.
// -------------------------------------------------------------------------
#[test]
fn fail_inference_and_cuda() {
let line = b"default = [\"inference\", \"cuda\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
#[test]
fn fail_all_four_forbidden() {
let line = b"default = [\"inference\", \"training\", \"code\", \"cuda\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 5: Fail band — empty input (caller error).
// -------------------------------------------------------------------------
#[test]
fn fail_empty_line() {
let v = verdict_from_default_features_string(&[]);
assert_eq!(
v,
PubCli001Verdict::Fail,
"empty line must Fail (Cargo.toml parsing failed)"
);
}
// -------------------------------------------------------------------------
// Section 6: Edge cases — substring matches anywhere in the line.
// -------------------------------------------------------------------------
#[test]
fn fail_inference_as_dep_value() {
// Even as a non-features dep value (unusual but possible),
// any substring match trips the gate.
let line = b"default = [\"realizar-inference-stub\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(
v,
PubCli001Verdict::Fail,
"substring match anywhere in line trips gate"
);
}
#[test]
fn fail_code_as_part_of_other_token() {
// "qcode" or "decode" both contain "code" as substring.
// This is an intentional conservative match — anything
// resembling 'code' is suspect in default features per
// contract.
let line = b"default = [\"qcode\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
#[test]
fn fail_cuda_as_dep_path() {
let line = b"default = [\"realizar/cuda-kernels\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
// -------------------------------------------------------------------------
// Section 7: Realistic — actual apr-cli/Cargo.toml format.
// -------------------------------------------------------------------------
#[test]
fn pass_realistic_with_long_features_array() {
// Plausible long but clean defaults.
let line = b"default = [\"format\", \"pull\", \"qa\", \"validate\", \"diff\", \"inspect\", \"tensors\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Pass);
}
#[test]
fn fail_realistic_with_inference_added() {
// The exact regression class: realistic defaults + inference.
let line = b"default = [\"format\", \"pull\", \"qa\", \"inference\", \"validate\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Fail);
}
#[test]
fn pass_features_with_safe_substrings() {
// "format" and "validate" don't contain any forbidden tokens.
let line = b"default = [\"format\", \"validate-strict\"]";
let v = verdict_from_default_features_string(line);
assert_eq!(v, PubCli001Verdict::Pass);
}
}