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
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
use std::time::{Duration, Instant};
use criterion::Criterion;
fn ferro_bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_ferro"))
}
/// Per-PR guard (SCAF-05): scaffold the full 5-step sequence and `cargo build` the generated app
/// against the workspace `ferro` via a `[patch.crates-io]` override, so no crates.io ferro
/// download is needed and every PR catches template↔library API drift before publish.
#[test]
fn scaffold_builds_against_workspace_ferro() {
let tmp = tempfile::tempdir().expect("tempdir");
let project_dir = tmp.path().join("bench-app");
// Step 1: ferro new (CWD = parent; creates bench-app/ subdir)
let status = Command::new(ferro_bin())
.args(["new", "bench-app", "--no-interaction", "--no-git"])
.current_dir(tmp.path())
.status()
.expect("ferro new failed to spawn");
let code = status.code();
assert!(status.success(), "ferro new exited non-zero: {code:?}");
// Step 2: ferro make:auth
let status = Command::new(ferro_bin())
.args(["make:auth"])
.current_dir(&project_dir)
.status()
.expect("ferro make:auth failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:auth exited non-zero: {code:?}"
);
// Step 3a: ferro make:scaffold Article
// Flags MUST precede the positional fields: `[FIELDS]...` is a greedy
// trailing positional, so `--flags` placed after the fields are parsed
// as field names. Usage: `make:scaffold [OPTIONS] <NAME> [FIELDS]...`.
let status = Command::new(ferro_bin())
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"--api",
"Article",
"title:string",
"body:text",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Article failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Article exited non-zero: {code:?}"
);
// Step 3b: ferro make:scaffold Product
let status = Command::new(ferro_bin())
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"--api",
"Product",
"name:string",
"price:float",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Product failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Product exited non-zero: {code:?}"
);
// Step 3c: ferro make:scaffold Order
let status = Command::new(ferro_bin())
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"--api",
"Order",
"status:string",
"total:float",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Order failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Order exited non-zero: {code:?}"
);
// Step 3d: ferro make:scaffold Post (full-stack, no --api)
// This exercises scaffold_controller_template and the Inertia page templates,
// which are NOT covered by the --api-only steps above. Without this step the
// non-api template family can silently regress (which is how CR-01 survived).
let status = Command::new(ferro_bin())
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"Post",
"title:string",
"body:text",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Post failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Post (full-stack) exited non-zero: {code:?}"
);
// Step 4: ferro make:job EmailNotification
let status = Command::new(ferro_bin())
.args(["make:job", "EmailNotification"])
.current_dir(&project_dir)
.status()
.expect("ferro make:job failed to spawn");
let code = status.code();
assert!(status.success(), "ferro make:job exited non-zero: {code:?}");
// Patch the generated Cargo.toml to build against the workspace `ferro` (no crates.io
// download). CARGO_MANIFEST_DIR points to ferro-cli/; parent is workspace root.
let workspace_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("CARGO_MANIFEST_DIR has no parent")
.to_path_buf();
let framework_path = workspace_root.join("framework");
let patch_block = format!(
"\n[patch.crates-io]\nferro-rs = {{ path = \"{}\" }}\n",
framework_path.display()
);
let mut cargo_toml = std::fs::OpenOptions::new()
.append(true)
.open(project_dir.join("Cargo.toml"))
.expect("Cargo.toml must exist after scaffold");
cargo_toml
.write_all(patch_block.as_bytes())
.expect("write patch block");
// Step 5: cargo build — the scaffolded app must COMPILE against workspace ferro.
// Clear RUSTFLAGS so the generated app does not inherit a parent `-Dwarnings`
// (CI sets it globally). A freshly scaffolded starter app legitimately carries
// unused-import / dead-code warnings (handlers not yet wired to routes, imports
// for code the developer will add) — this guard checks that it *compiles*, not
// that it is warning-clean.
let status = Command::new("cargo")
.args(["build"])
.current_dir(&project_dir)
.env_remove("RUSTFLAGS")
.status()
.expect("cargo build failed to spawn");
let code = status.code();
assert!(
status.success(),
"scaffolded app failed to build against workspace ferro: {code:?}"
);
}
#[test]
#[ignore = "wall-clock benchmark; run with FERRO_BENCH=1 (builds a full project in tmpdir)"]
fn benchmark_new_project() {
if std::env::var("FERRO_BENCH").is_err() {
eprintln!("skipping: set FERRO_BENCH=1 to run benchmark");
return;
}
let mut c = Criterion::default()
.sample_size(10)
.measurement_time(Duration::from_secs(600));
c.bench_function("new_project_to_cargo_build", |b| {
b.iter_custom(|iters| {
let mut total = Duration::ZERO;
for _ in 0..iters {
let tmp = tempfile::tempdir().expect("tempdir");
let project_dir = tmp.path().join("bench-app");
// Step 1: ferro new (CWD = parent; new.rs creates a bench-app/ subdir)
let t = Instant::now();
let status = Command::new(ferro_bin())
.args(["new", "bench-app", "--no-interaction", "--no-git"])
.current_dir(tmp.path())
.status()
.expect("ferro new failed to spawn");
let code = status.code();
assert!(status.success(), "ferro new exited non-zero: {code:?}");
let step1 = t.elapsed();
// Step 2: ferro make:auth (CWD = project root)
let t = Instant::now();
let status = Command::new(ferro_bin())
.args(["make:auth"])
.current_dir(&project_dir)
.status()
.expect("ferro make:auth failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:auth exited non-zero: {code:?}"
);
let step2 = t.elapsed();
// Step 3a: ferro make:scaffold Article
let t = Instant::now();
let status = Command::new(ferro_bin())
// Flags MUST precede the positional fields: `[FIELDS]...` is a greedy
// trailing positional, so `--flags` placed after the fields are parsed
// as field names ("Invalid field name: '--no-smart-defaults'"). Usage:
// `make:scaffold [OPTIONS] <NAME> [FIELDS]...`. Discovered via the cold run.
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"--api",
"Article",
"title:string",
"body:text",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Article failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Article exited non-zero: {code:?}"
);
let step3a = t.elapsed();
// Step 3b: ferro make:scaffold Product
let t = Instant::now();
let status = Command::new(ferro_bin())
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"--api",
"Product",
"name:string",
"price:float",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Product failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Product exited non-zero: {code:?}"
);
let step3b = t.elapsed();
// Step 3c: ferro make:scaffold Order
let t = Instant::now();
let status = Command::new(ferro_bin())
.args([
"make:scaffold",
"--no-smart-defaults",
"-q",
"-y",
"--api",
"Order",
"status:string",
"total:float",
])
.current_dir(&project_dir)
.status()
.expect("ferro make:scaffold Order failed to spawn");
let code = status.code();
assert!(
status.success(),
"ferro make:scaffold Order exited non-zero: {code:?}"
);
let step3c = t.elapsed();
// Step 4: ferro make:job EmailNotification
let t = Instant::now();
let status = Command::new(ferro_bin())
.args(["make:job", "EmailNotification"])
.current_dir(&project_dir)
.status()
.expect("ferro make:job failed to spawn");
let code = status.code();
assert!(status.success(), "ferro make:job exited non-zero: {code:?}");
let step4 = t.elapsed();
// Step 5: cargo build — asserts exit 0 (SC#2)
let t = Instant::now();
let status = Command::new("cargo")
.args(["build"])
.current_dir(&project_dir)
.status()
.expect("cargo build failed to spawn");
let code = status.code();
assert!(status.success(), "cargo build exited non-zero: {code:?}");
let step5 = t.elapsed();
println!("=== COMP-04 Benchmark Results ===");
println!("Step 1 ferro new: {step1:?}");
println!("Step 2 ferro make:auth: {step2:?}");
println!("Step 3a ferro make:scaffold A: {step3a:?}");
println!("Step 3b ferro make:scaffold P: {step3b:?}");
println!("Step 3c ferro make:scaffold O: {step3c:?}");
println!("Step 4 ferro make:job: {step4:?}");
println!("Step 5 cargo build: {step5:?}");
total += step1 + step2 + step3a + step3b + step3c + step4 + step5;
// tmp drops here, cleaning up the tmpdir for each iteration
}
println!(
"Total (avg over {iters} iters): {:?}",
total / iters as u32
);
total
})
});
// criterion flushes output when c drops; final_summary() is not public API in 0.8.2
}