ralph-workflow 0.7.18

PROMPT-driven multi-agent orchestrator for git repos
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
use crate::checkpoint::state::calculate_file_checksum_with_workspace;
use crate::checkpoint::{
    checkpoint_exists_with_workspace, clear_checkpoint_with_workspace,
    load_checkpoint_with_workspace, save_checkpoint_with_workspace, AgentConfigSnapshot,
    CheckpointParams, CliArgsSnapshot, PipelineCheckpoint, PipelinePhase, RebaseState,
};
use crate::workspace::{MemoryWorkspace, Workspace};
use serde_json;
use std::path::Path;

/// Helper function to create a checkpoint for workspace tests.
fn make_test_checkpoint_for_workspace(phase: PipelinePhase, iteration: u32) -> PipelineCheckpoint {
    let cli_args = CliArgsSnapshot::new(5, 2, None, true, 2, false, None);
    let dev_config =
        AgentConfigSnapshot::new("claude".into(), "cmd".into(), "-o".into(), None, true);
    let rev_config =
        AgentConfigSnapshot::new("codex".into(), "cmd".into(), "-o".into(), None, true);
    let run_id = uuid::Uuid::new_v4().to_string();
    PipelineCheckpoint::from_params(CheckpointParams {
        phase,
        iteration,
        total_iterations: 5,
        reviewer_pass: 0,
        total_reviewer_passes: 2,
        developer_agent: "claude",
        reviewer_agent: "codex",
        cli_args,
        developer_agent_config: dev_config,
        reviewer_agent_config: rev_config,
        rebase_state: RebaseState::default(),
        git_user_name: None,
        git_user_email: None,
        run_id: &run_id,
        parent_run_id: None,
        resume_count: 0,
        actual_developer_runs: iteration,
        actual_reviewer_runs: 0,
        working_dir: "/test/repo".to_string(),
        prompt_md_checksum: None,
        config_path: None,
        config_checksum: None,
    })
}

#[test]
fn test_calculate_file_checksum_with_workspace() {
    let workspace = MemoryWorkspace::new_test().with_file("test.txt", "test content");

    let checksum = calculate_file_checksum_with_workspace(&workspace, Path::new("test.txt"));
    assert!(checksum.is_some());

    // Same content should give same checksum
    let workspace2 = MemoryWorkspace::new_test().with_file("other.txt", "test content");
    let checksum2 = calculate_file_checksum_with_workspace(&workspace2, Path::new("other.txt"));
    assert_eq!(checksum, checksum2);
}

#[test]
fn test_calculate_file_checksum_with_workspace_different_content() {
    let workspace1 = MemoryWorkspace::new_test().with_file("test.txt", "content A");
    let workspace2 = MemoryWorkspace::new_test().with_file("test.txt", "content B");

    let checksum1 = calculate_file_checksum_with_workspace(&workspace1, Path::new("test.txt"));
    let checksum2 = calculate_file_checksum_with_workspace(&workspace2, Path::new("test.txt"));

    assert!(checksum1.is_some());
    assert!(checksum2.is_some());
    assert_ne!(checksum1, checksum2);
}

#[test]
fn test_calculate_file_checksum_with_workspace_nonexistent() {
    let workspace = MemoryWorkspace::new_test();

    let checksum = calculate_file_checksum_with_workspace(&workspace, Path::new("nonexistent.txt"));
    assert!(checksum.is_none());
}

#[test]
fn test_save_checkpoint_with_workspace() {
    let workspace = MemoryWorkspace::new_test();
    let checkpoint = make_test_checkpoint_for_workspace(PipelinePhase::Development, 2);

    save_checkpoint_with_workspace(&workspace, &checkpoint).unwrap();

    assert!(workspace.exists(Path::new(".agent/checkpoint.json")));
}

#[test]
fn test_checkpoint_exists_with_workspace() {
    let workspace = MemoryWorkspace::new_test();

    assert!(!checkpoint_exists_with_workspace(&workspace));

    let checkpoint = make_test_checkpoint_for_workspace(PipelinePhase::Development, 1);
    save_checkpoint_with_workspace(&workspace, &checkpoint).unwrap();

    assert!(checkpoint_exists_with_workspace(&workspace));
}

#[test]
fn test_load_checkpoint_with_workspace_nonexistent() {
    let workspace = MemoryWorkspace::new_test();

    let result = load_checkpoint_with_workspace(&workspace).unwrap();
    assert!(result.is_none());
}

#[test]
fn test_save_and_load_checkpoint_with_workspace() {
    let workspace = MemoryWorkspace::new_test();
    let checkpoint = make_test_checkpoint_for_workspace(PipelinePhase::Review, 5);

    save_checkpoint_with_workspace(&workspace, &checkpoint).unwrap();

    let loaded = load_checkpoint_with_workspace(&workspace)
        .unwrap()
        .expect("checkpoint should exist");

    assert_eq!(loaded.phase, PipelinePhase::Review);
    assert_eq!(loaded.iteration, 5);
    assert_eq!(loaded.developer_agent, "claude");
    assert_eq!(loaded.reviewer_agent, "codex");
}

#[test]
fn test_clear_checkpoint_with_workspace() {
    let workspace = MemoryWorkspace::new_test();
    let checkpoint = make_test_checkpoint_for_workspace(PipelinePhase::Development, 1);

    save_checkpoint_with_workspace(&workspace, &checkpoint).unwrap();
    assert!(checkpoint_exists_with_workspace(&workspace));

    clear_checkpoint_with_workspace(&workspace).unwrap();
    assert!(!checkpoint_exists_with_workspace(&workspace));
}

#[test]
fn test_clear_checkpoint_with_workspace_nonexistent() {
    let workspace = MemoryWorkspace::new_test();

    // Should not error when checkpoint doesn't exist
    clear_checkpoint_with_workspace(&workspace).unwrap();
}

#[test]
fn test_load_checkpoint_rejects_v1_format() {
    // Test that loading a v1 checkpoint is rejected (legacy migration removed)
    let json = r#"{
        "version": 1,
        "phase": "Development",
        "iteration": 1,
        "total_iterations": 1,
        "reviewer_pass": 0,
        "total_reviewer_passes": 0,
        "timestamp": "2024-01-01 12:00:00",
        "developer_agent": "test-agent",
        "reviewer_agent": "test-agent",
        "cli_args": {
            "developer_iters": 1,
            "reviewer_reviews": 0,
            "commit_msg": "",
            "review_depth": null
        },
        "developer_agent_config": {
            "name": "test-agent",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "reviewer_agent_config": {
            "name": "test-agent",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "rebase_state": "NotStarted",
        "config_path": null,
        "config_checksum": null,
        "working_dir": "/some/other/directory",
        "prompt_md_checksum": null,
        "git_user_name": null,
        "git_user_email": null
    }"#;

    let workspace = MemoryWorkspace::new_test().with_file(".agent/checkpoint.json", json);

    let result = load_checkpoint_with_workspace(&workspace);
    assert!(
        result.is_err(),
        "v1 checkpoint should be rejected: {result:?}"
    );
    let err = result.unwrap_err();
    assert!(
        err.to_string().contains("no longer supported"),
        "Error should mention legacy not supported: {err}"
    );
}

#[test]
fn test_load_checkpoint_migrates_v2_to_v3() {
    // v2 checkpoints are still structurally compatible with v3 and can be
    // migrated in-memory by bumping the version while leaving v3-only fields empty.
    let json = r#"{
        "version": 2,
        "phase": "Development",
        "iteration": 2,
        "total_iterations": 3,
        "reviewer_pass": 0,
        "total_reviewer_passes": 1,
        "timestamp": "2026-02-13 12:00:00",
        "developer_agent": "claude",
        "reviewer_agent": "codex",
        "cli_args": {
            "developer_iters": 3,
            "reviewer_reviews": 1,
            "review_depth": null,
            "isolation_mode": true,
            "verbosity": 2,
            "show_streaming_metrics": false,
            "reviewer_json_parser": null
        },
        "developer_agent_config": {
            "name": "claude",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "reviewer_agent_config": {
            "name": "codex",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "rebase_state": "NotStarted",
        "config_path": null,
        "config_checksum": null,
        "working_dir": "/tmp",
        "prompt_md_checksum": null,
        "git_user_name": null,
        "git_user_email": null,
        "run_id": "run-test",
        "parent_run_id": null,
        "resume_count": 0,
        "actual_developer_runs": 1,
        "actual_reviewer_runs": 0
    }"#;

    let workspace = MemoryWorkspace::new_test().with_file(".agent/checkpoint.json", json);

    let loaded = load_checkpoint_with_workspace(&workspace)
        .unwrap()
        .expect("checkpoint should exist");

    assert_eq!(loaded.version, 3, "v2 checkpoint should be migrated to v3");
    assert_eq!(loaded.phase, PipelinePhase::Development);
    assert_eq!(loaded.iteration, 2);
    assert_eq!(loaded.total_iterations, 3);
    assert_eq!(loaded.run_id, "run-test");
    assert!(loaded.execution_history.is_none());
    assert!(loaded.file_system_state.is_none());
}

#[test]
fn test_load_checkpoint_rejects_newer_checkpoint_versions() {
    let json = r#"{
        "version": 4,
        "phase": "Development",
        "iteration": 1,
        "total_iterations": 1,
        "reviewer_pass": 0,
        "total_reviewer_passes": 0,
        "timestamp": "2026-02-13 12:00:00",
        "developer_agent": "claude",
        "reviewer_agent": "codex",
        "cli_args": {
            "developer_iters": 1,
            "reviewer_reviews": 0,
            "review_depth": null,
            "isolation_mode": true,
            "verbosity": 2,
            "show_streaming_metrics": false,
            "reviewer_json_parser": null
        },
        "developer_agent_config": {
            "name": "claude",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "reviewer_agent_config": {
            "name": "codex",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "rebase_state": "NotStarted",
        "config_path": null,
        "config_checksum": null,
        "working_dir": "/tmp",
        "prompt_md_checksum": null,
        "git_user_name": null,
        "git_user_email": null,
        "run_id": "run-test",
        "parent_run_id": null,
        "resume_count": 0,
        "actual_developer_runs": 1,
        "actual_reviewer_runs": 0
    }"#;

    let workspace = MemoryWorkspace::new_test().with_file(".agent/checkpoint.json", json);

    let result = load_checkpoint_with_workspace(&workspace);
    assert!(
        result.is_err(),
        "newer checkpoint versions must be rejected"
    );
    let err = result.unwrap_err();
    assert!(
        err.to_string().contains("newer") || err.to_string().contains("upgrade"),
        "error should suggest upgrading: {err}"
    );
}

#[test]
fn test_load_checkpoint_rejects_legacy_phase_variants() {
    let base_json = r#"{
        "version": 3,
        "phase": "%PHASE%",
        "iteration": 1,
        "total_iterations": 1,
        "reviewer_pass": 0,
        "total_reviewer_passes": 0,
        "timestamp": "2024-01-01 12:00:00",
        "developer_agent": "test-agent",
        "reviewer_agent": "test-agent",
        "cli_args": {
            "developer_iters": 1,
            "reviewer_reviews": 0,
            "commit_msg": "",
            "review_depth": null
        },
        "developer_agent_config": {
            "name": "test-agent",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "reviewer_agent_config": {
            "name": "test-agent",
            "cmd": "echo",
            "output_flag": "",
            "yolo_flag": null,
            "can_commit": false,
            "model_override": null,
            "provider_override": null,
            "context_level": 1
        },
        "rebase_state": "NotStarted",
        "config_path": null,
        "config_checksum": null,
        "working_dir": "/some/other/directory",
        "prompt_md_checksum": null,
        "git_user_name": null,
        "git_user_email": null
    }"#;

    ["Fix", "ReviewAgain"].iter().for_each(|phase_label| {
        let json = base_json.replace("%PHASE%", phase_label);
        let workspace = MemoryWorkspace::new_test().with_file(".agent/checkpoint.json", &json);

        let result = load_checkpoint_with_workspace(&workspace);
        assert!(
            result.is_err(),
            "Legacy phase '{phase_label}' should be rejected"
        );
        let err = result.unwrap_err();
        assert!(
            err.to_string().contains("no longer supported"),
            "Error for '{phase_label}' should mention 'no longer supported': {err}"
        );
    });
}

#[test]
fn test_pipeline_phase_deserialize_rejects_legacy_variants() {
    let fix_result: Result<PipelinePhase, _> = serde_json::from_str("\"Fix\"");
    assert!(fix_result.is_err(), "Fix phase should be rejected");
    let err = fix_result.unwrap_err().to_string();
    assert!(
        err.contains("no longer supported"),
        "Error should mention 'no longer supported': {err}"
    );

    let review_again_result: Result<PipelinePhase, _> = serde_json::from_str("\"ReviewAgain\"");
    assert!(
        review_again_result.is_err(),
        "ReviewAgain phase should be rejected"
    );
    let err = review_again_result.unwrap_err().to_string();
    assert!(
        err.contains("no longer supported"),
        "Error should mention 'no longer supported': {err}"
    );
}

// =========================================================================
// Optimized checkpoint serialization tests (Step 11)
// =========================================================================

#[test]
fn test_optimized_serialization_produces_compact_json() {
    use crate::checkpoint::execution_history::{ExecutionHistory, ExecutionStep, StepOutcome};

    let workspace = MemoryWorkspace::new_test();
    let outcome = StepOutcome::success(Some("test".to_string()), vec![]);
    let step = ExecutionStep::new("Planning", 1, "plan", outcome);
    let history = ExecutionHistory {
        steps: std::collections::VecDeque::from([step]),
        file_snapshots: std::collections::HashMap::new(),
    };
    let checkpoint = PipelineCheckpoint {
        execution_history: Some(history),
        ..make_test_checkpoint_for_workspace(PipelinePhase::Development, 2)
    };

    save_checkpoint_with_workspace(&workspace, &checkpoint).unwrap();

    let saved_json = workspace.read(Path::new(".agent/checkpoint.json")).unwrap();

    // Verify compact JSON: should NOT have pretty-printing indentation
    // (we allow some minimal spaces for JSON structure, but no multi-line pretty formatting)
    let line_count = saved_json.lines().count();
    // Compact JSON should be just a few lines (not hundreds)
    assert!(
        line_count < 10,
        "Compact JSON should have minimal lines, got {line_count}"
    );
}

#[test]
fn test_optimized_serialization_round_trip_preserves_data() {
    use crate::checkpoint::execution_history::{ExecutionHistory, ExecutionStep, StepOutcome};

    let workspace = MemoryWorkspace::new_test();

    let steps: std::collections::VecDeque<ExecutionStep> = (0..10)
        .map(|i| {
            let outcome = StepOutcome::Success {
                output: Some(format!("output{i}").into()),
                files_modified: Some(vec![format!("file{i}.rs")].into_boxed_slice()),
                exit_code: Some(0),
            };
            ExecutionStep::new(&format!("Phase{i}"), i, &format!("step{i}"), outcome)
                .with_agent(&format!("agent{i}"))
                .with_duration(100 + u64::from(i))
        })
        .collect();
    let history = ExecutionHistory {
        steps,
        file_snapshots: std::collections::HashMap::new(),
    };
    let checkpoint = PipelineCheckpoint {
        execution_history: Some(history),
        ..make_test_checkpoint_for_workspace(PipelinePhase::Review, 3)
    };

    // Save with optimized serialization
    save_checkpoint_with_workspace(&workspace, &checkpoint).unwrap();

    // Load and verify data preservation
    let loaded = load_checkpoint_with_workspace(&workspace)
        .unwrap()
        .expect("checkpoint should exist");

    assert_eq!(loaded.phase, checkpoint.phase);
    assert_eq!(loaded.iteration, checkpoint.iteration);
    assert_eq!(loaded.developer_agent, checkpoint.developer_agent);

    // Verify execution history preservation
    let loaded_history = loaded.execution_history.expect("history should exist");
    assert_eq!(loaded_history.steps.len(), 10);

    loaded_history
        .steps
        .iter()
        .enumerate()
        .for_each(|(i, step)| {
            assert_eq!(step.phase.as_ref(), format!("Phase{i}"));
            assert_eq!(step.iteration, u32::try_from(i).expect("value fits in u32"));
            assert_eq!(step.step_type.as_ref(), format!("step{i}"));
            assert_eq!(
                step.agent.as_ref().map(std::convert::AsRef::as_ref),
                Some(format!("agent{i}").as_str())
            );
            assert_eq!(step.duration_secs, Some(100 + i as u64));

            if let StepOutcome::Success {
                output,
                files_modified,
                exit_code,
            } = &step.outcome
            {
                assert_eq!(
                    output.as_ref().map(std::convert::AsRef::as_ref),
                    Some(format!("output{i}").as_str())
                );
                assert_eq!(
                    files_modified.as_ref().map(|f| f
                        .iter()
                        .map(std::string::String::as_str)
                        .collect::<Vec<_>>()),
                    Some(vec![format!("file{i}.rs").as_str()])
                );
                assert_eq!(exit_code, &Some(0));
            } else {
                panic!("Expected Success outcome");
            }
        });
}

const MAX_CHECKPOINT_ESTIMATE_BYTES: usize = 2_097_152;

fn estimate_checkpoint_size(checkpoint: &PipelineCheckpoint) -> usize {
    serde_json::to_string(checkpoint)
        .map(|json| json.len())
        .unwrap_or_default()
}

fn estimate_checkpoint_size_from_history_len(history_len: usize) -> usize {
    history_len
        .saturating_mul(1_000)
        .min(MAX_CHECKPOINT_ESTIMATE_BYTES)
}

#[test]
fn test_estimate_checkpoint_size_is_reasonable() {
    use crate::checkpoint::execution_history::{ExecutionHistory, ExecutionStep, StepOutcome};

    let workspace = MemoryWorkspace::new_test();

    // Test with empty history
    let checkpoint_empty = make_test_checkpoint_for_workspace(PipelinePhase::Planning, 1);
    save_checkpoint_with_workspace(&workspace, &checkpoint_empty).unwrap();
    let empty_json = workspace.read(Path::new(".agent/checkpoint.json")).unwrap();
    let empty_size = empty_json.len();

    let empty_estimate = estimate_checkpoint_size(&checkpoint_empty);
    assert!(
        empty_estimate >= empty_size,
        "estimate should be conservative for empty checkpoints"
    );

    // Base size should be within 50% of actual (conservative estimate)
    assert!(
        empty_size <= 15_000,
        "Empty checkpoint should be < 15KB, got {empty_size}"
    );

    // Test with 100 entries
    let steps: std::collections::VecDeque<ExecutionStep> = (0..100)
        .map(|i| {
            let outcome = StepOutcome::Success {
                output: Some("test output".to_string().into()),
                files_modified: Some(vec!["file.rs".to_string()].into_boxed_slice()),
                exit_code: Some(0),
            };
            ExecutionStep::new("Development", i, "test", outcome)
                .with_agent("agent")
                .with_duration(100)
        })
        .collect();
    let history = ExecutionHistory {
        steps,
        file_snapshots: std::collections::HashMap::new(),
    };
    let checkpoint_100 = PipelineCheckpoint {
        execution_history: Some(history),
        ..make_test_checkpoint_for_workspace(PipelinePhase::Development, 5)
    };

    save_checkpoint_with_workspace(&workspace, &checkpoint_100).unwrap();
    let json_100 = workspace.read(Path::new(".agent/checkpoint.json")).unwrap();
    let size_100 = json_100.len();

    let estimate_100 = estimate_checkpoint_size(&checkpoint_100);
    assert!(
        estimate_100 >= size_100,
        "estimate should be conservative for 100-entry checkpoints"
    );

    assert!(
        estimate_100 <= size_100.saturating_mul(4).saturating_add(10_000),
        "estimate should not over-allocate excessively"
    );

    // Growth should roughly scale with history length.
    assert!(
        size_100 > empty_size,
        "serialized checkpoint should grow with execution history"
    );
}

#[test]
fn test_estimate_checkpoint_size_is_overflow_safe_and_capped() {
    let capped = estimate_checkpoint_size_from_history_len(usize::MAX);
    assert_eq!(capped, MAX_CHECKPOINT_ESTIMATE_BYTES);
}

#[test]
fn test_backward_compatibility_with_pretty_printed_checkpoints() {
    // Verify that we can still load pretty-printed JSON from older versions
    // (even though we now save compact JSON)
    let pretty_json = r#"{
  "version": 3,
  "phase": "Development",
  "iteration": 1,
  "total_iterations": 5,
  "reviewer_pass": 0,
  "total_reviewer_passes": 2,
  "timestamp": "2024-01-01 12:00:00",
  "developer_agent": "claude",
  "reviewer_agent": "codex",
  "cli_args": {
    "developer_iters": 5,
    "reviewer_reviews": 2,
    "commit_msg": null,
    "isolation_mode": true,
    "verbosity": 2,
    "show_streaming_metrics": false,
    "review_depth": null,
    "reviewer_json_parser": null
  },
  "developer_agent_config": {
    "name": "claude",
    "cmd": "cmd",
    "output_flag": "-o",
    "yolo_flag": null,
    "can_commit": true
  },
  "reviewer_agent_config": {
    "name": "codex",
    "cmd": "cmd",
    "output_flag": "-o",
    "yolo_flag": null,
    "can_commit": true
  },
  "rebase_state": "NotStarted",
  "config_path": null,
  "config_checksum": null,
  "working_dir": "/test/repo",
  "prompt_md_checksum": null,
  "git_user_name": null,
  "git_user_email": null,
  "run_id": "test-run-id",
  "parent_run_id": null,
  "resume_count": 0,
  "actual_developer_runs": 1,
  "actual_reviewer_runs": 0
}"#;

    let workspace = MemoryWorkspace::new_test().with_file(".agent/checkpoint.json", pretty_json);

    let loaded = load_checkpoint_with_workspace(&workspace)
        .unwrap()
        .expect("pretty-printed checkpoint should load");

    assert_eq!(loaded.version, 3);
    assert_eq!(loaded.phase, PipelinePhase::Development);
    assert_eq!(loaded.iteration, 1);
    assert_eq!(loaded.developer_agent, "claude");
    assert_eq!(loaded.reviewer_agent, "codex");
}