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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
// `apr-docs-v1` algorithm-level PARTIAL discharge for the 5
// FALSIFY-README gates (install command, apr run example, no apr-cli
// reference, no stale repos, mdbook build).
//
// Contract: `contracts/apr-docs-v1.yaml`.
//
// ## Disambiguation
//
// `readme-claims-v1.yaml` (task #256) is a sibling contract that pins
// quantitative claims (crate count, contract count, CLI command count,
// cookbook link). Despite both contracts sharing the FALSIFY-README-*
// prefix in some descriptions, the two contracts cover different
// invariants. This file binds `apr-docs-v1` only.
//
// ## What this file proves NOW (`PARTIAL_ALGORITHM_LEVEL`)
//
// Five pure decision predicates over the README text and an mdbook exit
// code. Live discharge is `make tier3` running the falsification tests
// directly (`grep -q "cargo install aprender" README.md`, `mdbook build
// book/`). Algorithm-level pinning prevents drift on the install-command
// brand and the no-stale-repos invariant.
/// Required install command per FALSIFY-README-001.
pub const AC_DOCS_REQUIRED_INSTALL: &str = "cargo install aprender";
/// Required CLI usage example per FALSIFY-README-002.
pub const AC_DOCS_REQUIRED_USAGE: &str = "apr run";
/// Forbidden install command per FALSIFY-README-003.
pub const AC_DOCS_FORBIDDEN_INSTALL: &str = "cargo install apr-cli";
/// Repo names that MUST NOT appear as `cargo install <name>` per
/// FALSIFY-README-004 (post-APR-MONO-consolidation).
pub const AC_DOCS_FORBIDDEN_REPOS: [&str; 4] = ["trueno", "realizar", "entrenar", "batuta"];
// =============================================================================
// FALSIFY-README-001 — `cargo install aprender` present
// =============================================================================
/// Verdict for FALSIFY-README-001.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InstallCommandVerdict {
/// README contains `cargo install aprender`.
Pass,
/// String absent.
Fail,
}
#[must_use]
pub fn verdict_from_install_command(readme: &str) -> InstallCommandVerdict {
if readme.contains(AC_DOCS_REQUIRED_INSTALL) {
InstallCommandVerdict::Pass
} else {
InstallCommandVerdict::Fail
}
}
// =============================================================================
// FALSIFY-README-002 — `apr run` example present
// =============================================================================
/// Verdict for FALSIFY-README-002.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AprRunExampleVerdict {
/// README contains `apr run`.
Pass,
/// String absent.
Fail,
}
#[must_use]
pub fn verdict_from_apr_run_example(readme: &str) -> AprRunExampleVerdict {
if readme.contains(AC_DOCS_REQUIRED_USAGE) {
AprRunExampleVerdict::Pass
} else {
AprRunExampleVerdict::Fail
}
}
// =============================================================================
// FALSIFY-README-003 — `cargo install apr-cli` ABSENT
// =============================================================================
/// Verdict for FALSIFY-README-003.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NoAprCliInstallVerdict {
/// README does NOT contain `cargo install apr-cli`.
Pass,
/// Forbidden string is present.
Fail,
}
#[must_use]
pub fn verdict_from_no_apr_cli_install(readme: &str) -> NoAprCliInstallVerdict {
if readme.contains(AC_DOCS_FORBIDDEN_INSTALL) {
NoAprCliInstallVerdict::Fail
} else {
NoAprCliInstallVerdict::Pass
}
}
// =============================================================================
// FALSIFY-README-004 — no stale repo install commands
// =============================================================================
/// Verdict for FALSIFY-README-004.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NoStaleReposVerdict {
/// README does not contain `cargo install <stale_repo>` for any of
/// {trueno, realizar, entrenar, batuta}.
Pass,
/// At least one stale repo `cargo install` reference present.
Fail,
}
#[must_use]
pub fn verdict_from_no_stale_repos(readme: &str) -> NoStaleReposVerdict {
for repo in AC_DOCS_FORBIDDEN_REPOS {
let needle = format!("cargo install {repo}");
// Match the gate's `\b` boundary: `cargo install batuta-something` MUST
// not trigger; only `cargo install batuta` (followed by whitespace,
// newline, or end-of-text) does.
if let Some(pos) = readme.find(&needle) {
let after = &readme[pos + needle.len()..];
// Word boundary: next char is not alphanumeric, underscore, or hyphen.
let boundary_ok = after
.chars()
.next()
.is_none_or(|c| !c.is_ascii_alphanumeric() && c != '_' && c != '-');
if boundary_ok {
return NoStaleReposVerdict::Fail;
}
}
}
NoStaleReposVerdict::Pass
}
// =============================================================================
// FALSIFY-README-005 — `mdbook build book/` exits 0
// =============================================================================
/// Verdict for FALSIFY-README-005.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MdbookBuildVerdict {
/// `mdbook build book/` exited 0.
Pass,
/// Non-zero exit.
Fail,
}
#[must_use]
pub fn verdict_from_mdbook_build(exit_code: i32) -> MdbookBuildVerdict {
if exit_code == 0 {
MdbookBuildVerdict::Pass
} else {
MdbookBuildVerdict::Fail
}
}
#[cfg(test)]
mod tests {
use super::*;
// -------------------------------------------------------------------------
// Section 1: Provenance pins.
// -------------------------------------------------------------------------
#[test]
fn provenance_install_command_string() {
assert_eq!(AC_DOCS_REQUIRED_INSTALL, "cargo install aprender");
}
#[test]
fn provenance_required_usage_string() {
assert_eq!(AC_DOCS_REQUIRED_USAGE, "apr run");
}
#[test]
fn provenance_forbidden_install_string() {
assert_eq!(AC_DOCS_FORBIDDEN_INSTALL, "cargo install apr-cli");
}
#[test]
fn provenance_forbidden_repos_count_4() {
assert_eq!(AC_DOCS_FORBIDDEN_REPOS.len(), 4);
assert!(AC_DOCS_FORBIDDEN_REPOS.contains(&"trueno"));
assert!(AC_DOCS_FORBIDDEN_REPOS.contains(&"realizar"));
assert!(AC_DOCS_FORBIDDEN_REPOS.contains(&"entrenar"));
assert!(AC_DOCS_FORBIDDEN_REPOS.contains(&"batuta"));
}
// -------------------------------------------------------------------------
// Section 2: README-001 install command.
// -------------------------------------------------------------------------
#[test]
fn r001_pass_install_present() {
let r = "## Install\n```bash\ncargo install aprender\n```\n";
assert_eq!(verdict_from_install_command(r), InstallCommandVerdict::Pass);
}
#[test]
fn r001_fail_install_absent() {
let r = "## Install\nDownload the binary from releases.\n";
assert_eq!(verdict_from_install_command(r), InstallCommandVerdict::Fail);
}
#[test]
fn r001_fail_empty_readme() {
assert_eq!(verdict_from_install_command(""), InstallCommandVerdict::Fail);
}
// -------------------------------------------------------------------------
// Section 3: README-002 apr run example.
// -------------------------------------------------------------------------
#[test]
fn r002_pass_apr_run_present() {
let r = "## Quickstart\n```bash\napr run hf://Qwen/Qwen3-Coder-30B-A3B\n```";
assert_eq!(verdict_from_apr_run_example(r), AprRunExampleVerdict::Pass);
}
#[test]
fn r002_fail_apr_run_absent() {
let r = "## Quickstart\nSee the docs site for usage.";
assert_eq!(verdict_from_apr_run_example(r), AprRunExampleVerdict::Fail);
}
// -------------------------------------------------------------------------
// Section 4: README-003 no apr-cli install.
// -------------------------------------------------------------------------
#[test]
fn r003_pass_no_apr_cli_install() {
let r = "## Install\n`cargo install aprender`\n";
assert_eq!(verdict_from_no_apr_cli_install(r), NoAprCliInstallVerdict::Pass);
}
#[test]
fn r003_fail_apr_cli_install_present() {
let r = "## Install\n`cargo install apr-cli`\n";
assert_eq!(verdict_from_no_apr_cli_install(r), NoAprCliInstallVerdict::Fail);
}
#[test]
fn r003_pass_apr_cli_mentioned_but_not_installed() {
// The crate name appears in module paths but not as a cargo install.
let r = "The internal `apr-cli` crate provides command logic.";
assert_eq!(verdict_from_no_apr_cli_install(r), NoAprCliInstallVerdict::Pass);
}
// -------------------------------------------------------------------------
// Section 5: README-004 no stale repos.
// -------------------------------------------------------------------------
#[test]
fn r004_pass_only_aprender() {
let r = "## Install\n`cargo install aprender`";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Pass);
}
#[test]
fn r004_fail_install_trueno() {
let r = "## Install\n`cargo install trueno`";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Fail);
}
#[test]
fn r004_fail_install_realizar() {
let r = "Install: cargo install realizar";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Fail);
}
#[test]
fn r004_fail_install_entrenar() {
let r = "$ cargo install entrenar\n";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Fail);
}
#[test]
fn r004_fail_install_batuta() {
let r = "## Install\n```bash\ncargo install batuta\n```";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Fail);
}
#[test]
fn r004_pass_stale_name_in_history_context() {
// Migration/history context — the gate explicitly allows stale names
// to appear; only `cargo install <name>\b` is forbidden.
let r = "Pre-APR-MONO, separate crates trueno, realizar, entrenar, batuta were installed individually.";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Pass);
}
#[test]
fn r004_pass_stale_name_with_suffix() {
// Word boundary: `cargo install trueno-foo` MUST pass.
let r = "cargo install trueno-extras";
assert_eq!(verdict_from_no_stale_repos(r), NoStaleReposVerdict::Pass);
}
// -------------------------------------------------------------------------
// Section 6: README-005 mdbook build.
// -------------------------------------------------------------------------
#[test]
fn r005_pass_exit_zero() {
assert_eq!(verdict_from_mdbook_build(0), MdbookBuildVerdict::Pass);
}
#[test]
fn r005_fail_exit_nonzero() {
assert_eq!(verdict_from_mdbook_build(1), MdbookBuildVerdict::Fail);
}
#[test]
fn r005_fail_exit_signal() {
assert_eq!(verdict_from_mdbook_build(137), MdbookBuildVerdict::Fail);
}
#[test]
fn r005_fail_exit_negative() {
assert_eq!(verdict_from_mdbook_build(-1), MdbookBuildVerdict::Fail);
}
// -------------------------------------------------------------------------
// Section 7: Realistic — a healthy README + clean book build passes all 5.
// -------------------------------------------------------------------------
#[test]
fn realistic_full_healthy_readme_passes_all_5() {
let readme = "\
# aprender
Next-generation ML framework in pure Rust.
## Install
```bash
cargo install aprender
```
## Quickstart
```bash
apr run hf://Qwen/Qwen3-Coder-30B-A3B
```
## History
Pre-APR-MONO, the framework was split across trueno, realizar, entrenar,
and batuta. These are now subsumed by aprender.
";
assert_eq!(verdict_from_install_command(readme), InstallCommandVerdict::Pass);
assert_eq!(verdict_from_apr_run_example(readme), AprRunExampleVerdict::Pass);
assert_eq!(verdict_from_no_apr_cli_install(readme), NoAprCliInstallVerdict::Pass);
assert_eq!(verdict_from_no_stale_repos(readme), NoStaleReposVerdict::Pass);
assert_eq!(verdict_from_mdbook_build(0), MdbookBuildVerdict::Pass);
}
#[test]
fn realistic_pre_fix_all_5_failures() {
// The exact regression class: bad README + book builds broken.
let bad = "## Install\n`cargo install apr-cli`\n## Train\n`cargo install trueno`";
assert_eq!(verdict_from_install_command(bad), InstallCommandVerdict::Fail);
assert_eq!(verdict_from_apr_run_example(bad), AprRunExampleVerdict::Fail);
assert_eq!(verdict_from_no_apr_cli_install(bad), NoAprCliInstallVerdict::Fail);
assert_eq!(verdict_from_no_stale_repos(bad), NoStaleReposVerdict::Fail);
assert_eq!(verdict_from_mdbook_build(1), MdbookBuildVerdict::Fail);
}
}