eval-magic 0.5.0

One-stop CLI for running skill evals — measure whether an agent skill actually shifts behavior.
Documentation
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
//! Guard install/teardown, workspace reclamation, run-nonce namespacing,
//! bootstrap framing, and `--only` filtering.

use crate::helpers::*;
use predicates::prelude::PredicateBooleanExt;
use predicates::str::contains;
use std::fs;
use std::path::Path;

#[test]
fn guard_installs_pretooluse_hook_under_env() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    // The guard arms inside each per-(group, condition) env — the agent-under-test's cwd.
    let settings = cli_env_dir(&cwd, "g1", "with_skill").join(".claude/settings.local.json");

    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--guard"])
        .assert()
        .success();
    assert!(settings.exists());
    let parsed = read_json(&settings);
    assert!(
        parsed["hooks"]["PreToolUse"][0]["matcher"]
            .as_str()
            .unwrap()
            .contains("Write")
    );
    // Nothing is armed at the invocation cwd anymore.
    assert!(!cwd.join(".claude/settings.local.json").exists());

    // `teardown-guard` operates at the invocation cwd, so it does not reach the
    // env-scoped guard: this is a transitional no-op, reconciled when the loop runs
    // inside the env session / teardown is reworked. The env is disposable
    // and the guard auto-expires (6h TTL); full `teardown` reclaims it (see
    // `teardown_reclaims_workspace_and_env_guard`).
    skill_eval()
        .current_dir(&cwd)
        .args(["teardown-guard", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review"])
        .assert()
        .success();
    assert!(settings.exists(), "env guard survives a cwd teardown-guard");
}

#[test]
fn finalize_warns_about_armed_per_env_guard_for_default_run() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    // The bare default run is hybrid: `--guard` arms a marker in each per-(group,
    // condition) env. `finalize` runs from the invocation cwd, not inside any env, but
    // the reworked finalize walks the per-env markers, so it reminds the operator the
    // guard is still armed. (finalize only warns; `teardown` disarms — the marker
    // survives finalize.)
    let marker =
        cli_env_dir(&cwd, "g1", "with_skill").join(".claude/skills/.slow-powers-eval-guard.json");

    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--guard"])
        .assert()
        .success();
    assert!(marker.exists());

    skill_eval()
        .current_dir(&cwd)
        .args(["finalize", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--iteration", "1"])
        .assert()
        .success()
        .stdout(contains("Guard still armed"));

    assert!(marker.exists());
}

#[test]
fn finalize_does_not_warn_when_guard_is_not_armed() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);

    // The guard auto-arms on a bare claude-code run, so opting out takes
    // --no-guard.
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--no-guard"])
        .assert()
        .success();

    skill_eval()
        .current_dir(&cwd)
        .args(["finalize", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--iteration", "1"])
        .assert()
        .success()
        .stdout(contains("Finalize complete"))
        .stdout(contains("Guard still armed").not());
}

#[test]
fn teardown_reclaims_workspace_and_env_guard() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    let settings = cli_env_dir(&cwd, "g1", "with_skill").join(".claude/settings.local.json");
    let staged = cli_env_dir(&cwd, "g1", "with_skill").join(".claude/skills");

    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--guard"])
        .assert()
        .success();
    assert!(settings.exists());
    assert!(staged.exists());

    // Full `teardown` reclaims the workspace iteration; the env (and its guard) lives
    // inside it, so removing the workspace removes the env guard too — this is what makes
    // deferring the cwd teardown-guard rework safe.
    skill_eval()
        .current_dir(&cwd)
        .args(["teardown", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review"])
        .assert()
        .success();
    assert!(!cwd.join(".eval-magic").exists());
    assert!(!settings.exists());
    assert!(!staged.exists());
    assert!(!cwd.join(".claude").exists());
}

#[test]
fn teardown_preserves_iteration_with_uncommitted_results() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);

    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill"])
        .assert()
        .success();

    // Simulate a graded-but-not-promoted run.
    fs::write(
        iteration_dir(&cwd).join("benchmark.json"),
        "{\"delta\":{\"pass_rate\":0.4}}\n",
    )
    .unwrap();

    skill_eval()
        .current_dir(&cwd)
        .args(["teardown", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review"])
        .assert()
        .success()
        .stderr(contains("iteration-1"))
        .stderr(contains("promote-baseline"));

    assert!(iteration_dir(&cwd).exists());
}

#[test]
fn dry_run_skips_guard_install() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--dry-run"])
        .assert()
        .success();
    // Auto-arm applies, but --dry-run skips the install itself.
    assert!(!cwd.join(".claude/settings.local.json").exists());
    assert!(
        !cli_env_dir(&cwd, "g1", "with_skill")
            .join(".claude/settings.local.json")
            .exists()
    );
}

#[test]
fn default_run_auto_arms_guard_in_each_env() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    // No guard flag at all: the harness declares guard support, so the run
    // arms it automatically (#126 — enhancements are provided, not opted into).
    let assert = skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill"])
        .assert()
        .success();
    let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
    assert!(
        stdout.contains("guard: armed"),
        "the run plan reports the armed guard: {stdout}"
    );
    for condition in ["with_skill", "without_skill"] {
        let env = cli_env_dir(&cwd, "g1", condition);
        assert!(
            env.join(".claude/settings.local.json").exists(),
            "guard hook staged in env-g1-{condition}"
        );
        assert!(
            env.join(".claude/skills/.slow-powers-eval-guard.json")
                .exists(),
            "guard marker armed in env-g1-{condition}"
        );
    }
}

#[test]
fn no_guard_run_installs_no_guard() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--no-guard"])
        .assert()
        .success();
    let env = cli_env_dir(&cwd, "g1", "with_skill");
    assert!(!env.join(".claude/settings.local.json").exists());
    assert!(
        !env.join(".claude/skills/.slow-powers-eval-guard.json")
            .exists()
    );
}

#[test]
fn namespaces_agent_description_and_records_run_nonce() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--dry-run"])
        .assert()
        .success();

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    let nonce = dispatch["run_nonce"].as_str().unwrap();
    assert!(!nonce.is_empty());
    for task in dispatch["tasks"].as_array().unwrap() {
        let condition = task["condition"].as_str().unwrap();
        let desc = task["agent_description"].as_str().unwrap();
        assert!(desc.ends_with(&format!(":{condition}:i1-{nonce}")));
    }
    let conditions = read_json(&iteration_dir(&cwd).join("conditions.json"));
    assert_eq!(conditions["run_nonce"].as_str().unwrap(), nonce);
}

#[test]
fn records_operator_declared_models_and_label_in_manifests() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--dry-run"])
        .args(["--agent-model", "claude-haiku-4-5-20251001"])
        .args(["--judge-model", "claude-opus-4-8"])
        .args(["--label", "canonical-run"])
        .assert()
        .success();

    let conditions = read_json(&iteration_dir(&cwd).join("conditions.json"));
    assert_eq!(
        conditions["agent_model"].as_str().unwrap(),
        "claude-haiku-4-5-20251001"
    );
    assert_eq!(
        conditions["judge_model"].as_str().unwrap(),
        "claude-opus-4-8"
    );
    assert_eq!(conditions["label"].as_str().unwrap(), "canonical-run");

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    assert_eq!(
        dispatch["agent_model"].as_str().unwrap(),
        "claude-haiku-4-5-20251001"
    );
    assert_eq!(dispatch["judge_model"].as_str().unwrap(), "claude-opus-4-8");
    assert_eq!(dispatch["label"].as_str().unwrap(), "canonical-run");
}

#[test]
fn omitted_models_and_label_are_absent_from_conditions() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--dry-run"])
        .assert()
        .success();

    let conditions = read_json(&iteration_dir(&cwd).join("conditions.json"));
    assert!(conditions.get("agent_model").is_none());
    assert!(conditions.get("judge_model").is_none());
    assert!(conditions.get("label").is_none());
}

#[test]
fn bootstrap_content_prepended_before_available_skills() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    let bootstrap = cwd.join("my-bootstrap.md");
    fs::write(&bootstrap, "MY CUSTOM EVAL FRAMING").unwrap();

    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--bootstrap"])
        .arg(&bootstrap)
        .arg("--dry-run")
        .assert()
        .success();

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    let task = dispatch["tasks"]
        .as_array()
        .unwrap()
        .iter()
        .find(|t| t["condition"] == "with_skill")
        .unwrap();
    let prompt = read_str(Path::new(task["dispatch_prompt_path"].as_str().unwrap()));
    let boot_idx = prompt.find("MY CUSTOM EVAL FRAMING").unwrap();
    let list_idx = prompt
        .find("The following skills are available for use with the Skill tool:")
        .unwrap();
    assert!(list_idx > boot_idx);
}

#[test]
fn runs_flag_expands_dispatches_into_run_dirs() {
    let tmp = tempfile::TempDir::new().unwrap();
    let evals = r#"{ "skill_name": "mr-review", "evals": [
        { "id": "e1", "prompt": "review MR 1", "expected_output": "a review" },
        { "id": "e2", "prompt": "review MR 2", "expected_output": "a review" } ] }"#;
    let (skill_dir, cwd) = setup(tmp.path(), evals);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--mode",
            "new-skill",
            "--runs",
            "2",
            "--dry-run",
        ])
        .assert()
        .success()
        .stdout(contains(
            "8 dispatches required (2 evals × 2 conditions × 2 runs)",
        ));

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    assert_eq!(dispatch["runs"], serde_json::json!(2));
    let tasks = dispatch["tasks"].as_array().unwrap();
    assert_eq!(tasks.len(), 8);

    let mut descriptions = std::collections::HashSet::new();
    for task in tasks {
        let k = task["run_index"].as_u64().unwrap();
        assert!(k == 1 || k == 2);
        let run_seg = format!("/run-{k}/");
        assert!(
            task["run_record_path"].as_str().unwrap().contains(&run_seg),
            "run.json not under its run dir: {}",
            task["run_record_path"]
        );
        // Outputs live inside the env, namespaced per run so concurrent
        // same-batch subagents can't collide; run-<k> is the leaf segment.
        let outputs_dir = task["outputs_dir"].as_str().unwrap();
        assert!(
            outputs_dir.contains(".eval-magic-outputs/")
                && outputs_dir.ends_with(&format!("run-{k}")),
            "outputs not namespaced under env per run: {outputs_dir}"
        );
        let desc = task["agent_description"].as_str().unwrap();
        assert!(
            desc.contains(&format!(":r{k}:")),
            "missing run segment in description: {desc}"
        );
        assert!(descriptions.insert(desc.to_string()), "duplicate: {desc}");
    }
    for eval in ["e1", "e2"] {
        for cond in ["with_skill", "without_skill"] {
            for k in [1, 2] {
                // Meta run dir (run.json / timing.json) above the env.
                let run_dir = iteration_dir(&cwd)
                    .join(format!("eval-{eval}"))
                    .join(cond)
                    .join(format!("run-{k}"));
                assert!(run_dir.is_dir(), "missing meta run dir {run_dir:?}");
                // Per-run outputs dir inside the condition's env.
                let out_dir = cli_env_dir(&cwd, "g1", cond)
                    .join(".eval-magic-outputs")
                    .join(format!("eval-{eval}"))
                    .join(cond)
                    .join(format!("run-{k}"));
                assert!(out_dir.is_dir(), "missing env outputs dir {out_dir:?}");
            }
        }
    }
}

#[test]
fn runs_one_keeps_flat_single_run_layout() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--mode",
            "new-skill",
            "--runs",
            "1",
            "--dry-run",
        ])
        .assert()
        .success();

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    for task in dispatch["tasks"].as_array().unwrap() {
        assert!(task.get("run_index").is_none(), "run_index on single run");
        assert!(!task["run_record_path"].as_str().unwrap().contains("/run-"));
    }
    // Flat single-run layout: the meta cond dir exists, with no run-1/ nesting.
    let cond_dir = iteration_dir(&cwd).join("eval-e1").join("with_skill");
    assert!(cond_dir.is_dir());
    assert!(!cond_dir.join("run-1").exists());
    // Outputs live inside the condition's env, flat (no run-1/ segment) for a
    // single-run cell.
    let out_dir =
        cli_env_dir(&cwd, "g1", "with_skill").join(".eval-magic-outputs/eval-e1/with_skill");
    assert!(out_dir.is_dir());
    assert!(!out_dir.join("run-1").exists());
}

#[test]
fn runs_zero_is_rejected() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--mode",
            "new-skill",
            "--runs",
            "0",
            "--dry-run",
        ])
        .assert()
        .failure();
}

#[test]
fn per_eval_runs_overrides_the_flag() {
    let tmp = tempfile::TempDir::new().unwrap();
    let evals = r#"{ "skill_name": "mr-review", "evals": [
        { "id": "e1", "prompt": "review MR 1", "expected_output": "a review", "runs": 3 },
        { "id": "e2", "prompt": "review MR 2", "expected_output": "a review" } ] }"#;
    let (skill_dir, cwd) = setup(tmp.path(), evals);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--mode", "new-skill", "--dry-run"])
        .assert()
        .success();

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    let tasks = dispatch["tasks"].as_array().unwrap();
    assert_eq!(tasks.len(), 8, "3 runs × 2 conds for e1 + 1 run × 2 for e2");
    let e1_indices: Vec<u64> = tasks
        .iter()
        .filter(|t| t["eval_id"] == "e1" && t["condition"] == "with_skill")
        .map(|t| t["run_index"].as_u64().unwrap())
        .collect();
    assert_eq!(e1_indices, vec![1, 2, 3]);
    for task in tasks.iter().filter(|t| t["eval_id"] == "e2") {
        assert!(task.get("run_index").is_none());
        assert!(!task["run_record_path"].as_str().unwrap().contains("/run-"));
    }
}

#[test]
fn only_restricts_dispatches_to_named_ids() {
    let tmp = tempfile::TempDir::new().unwrap();
    let evals = r#"{ "skill_name": "mr-review", "evals": [
        { "id": "e1", "prompt": "review MR 1", "expected_output": "a review" },
        { "id": "e2", "prompt": "review MR 2", "expected_output": "a review" } ] }"#;
    let (skill_dir, cwd) = setup(tmp.path(), evals);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--mode",
            "new-skill",
            "--only",
            "e1",
            "--dry-run",
        ])
        .assert()
        .success()
        .stdout(contains("1 evals × 2 conditions"));

    let dispatch = read_json(&iteration_dir(&cwd).join("dispatch.json"));
    let ids: Vec<&str> = dispatch["tasks"]
        .as_array()
        .unwrap()
        .iter()
        .map(|t| t["eval_id"].as_str().unwrap())
        .collect();
    assert_eq!(ids, vec!["e1", "e1"]);
}

#[test]
fn only_with_unknown_id_exits_nonzero() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--mode",
            "new-skill",
            "--only",
            "nope",
            "--dry-run",
        ])
        .assert()
        .failure()
        .stderr(contains("unknown eval id(s): nope"));
}

#[test]
fn teardown_disarms_per_group_condition_cli_guards() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);

    // CLI dispatch materializes one env per (group, condition); `--guard` arms a marker
    // in each. The human runs teardown from the iteration dir, not from inside any env,
    // so the cwd-only disarm never reaches these per-env markers.
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--harness",
            "claude-code",
            "--guard",
        ])
        .assert()
        .success();

    let with_marker =
        cli_env_dir(&cwd, "g1", "with_skill").join(".claude/skills/.slow-powers-eval-guard.json");
    let without_marker = cli_env_dir(&cwd, "g1", "without_skill")
        .join(".claude/skills/.slow-powers-eval-guard.json");
    assert!(with_marker.exists());
    assert!(without_marker.exists());

    // Keep the iteration (simulate uncommitted results) so the env dirs survive
    // teardown's reclaim and we can assert the markers themselves were disarmed.
    fs::write(
        iteration_dir(&cwd).join("benchmark.json"),
        "{\"delta\":{\"pass_rate\":0.4}}\n",
    )
    .unwrap();

    skill_eval()
        .current_dir(&cwd)
        .args(["teardown", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review"])
        .assert()
        .success()
        .stdout(contains("write guard disarmed"));

    assert!(
        iteration_dir(&cwd).exists(),
        "iteration kept (uncommitted results)"
    );
    assert!(!with_marker.exists(), "with_skill env guard disarmed");
    assert!(!without_marker.exists(), "without_skill env guard disarmed");
}

#[test]
fn finalize_warns_about_armed_cli_per_env_guard() {
    let tmp = tempfile::TempDir::new().unwrap();
    let (skill_dir, cwd) = setup(tmp.path(), DEFAULT_EVALS);

    // CLI dispatch arms a guard in each per-(group, condition) env. finalize runs from
    // the iteration dir, not an env, so the cwd-only check misses them; it must walk the
    // per-env markers and remind the operator.
    skill_eval()
        .current_dir(&cwd)
        .args(["run", "--skill-dir"])
        .arg(&skill_dir)
        .args([
            "--skill",
            "mr-review",
            "--harness",
            "claude-code",
            "--guard",
        ])
        .assert()
        .success();

    skill_eval()
        .current_dir(&cwd)
        .args(["finalize", "--skill-dir"])
        .arg(&skill_dir)
        .args(["--skill", "mr-review", "--iteration", "1"])
        .assert()
        .success()
        .stdout(contains("Guard still armed"));
}