le-change 0.1.0

Ultra-fast Git change detection library with zero-cost abstractions
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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
//! Computed output categories from ProcessedResult

use crate::interner::StringInterner;
use crate::types::{
    ChangeType, GroupDeployAction, GroupDeployDecision, GroupDeployReason, GroupResult,
    InternedString, ProcessedResult, RebuildReasonKind,
};
use std::collections::{HashMap, HashSet};

/// All derived output categories computed in a single pass
pub struct ComputedOutputs {
    /// Filtered added file indices
    pub filtered_added: Vec<u32>,
    /// Filtered copied file indices
    pub filtered_copied: Vec<u32>,
    /// Filtered deleted file indices
    pub filtered_deleted: Vec<u32>,
    /// Filtered modified file indices
    pub filtered_modified: Vec<u32>,
    /// Filtered renamed file indices
    pub filtered_renamed: Vec<u32>,
    /// Filtered type-changed file indices
    pub filtered_type_changed: Vec<u32>,
    /// Filtered unmerged file indices
    pub filtered_unmerged: Vec<u32>,
    /// Filtered unknown file indices
    pub filtered_unknown: Vec<u32>,
    /// "Other changed" indices: ACMR not in filter
    pub other_changed: Vec<u32>,
    /// "Other modified" indices: ACMRD not in filter
    pub other_modified: Vec<u32>,
    /// "Other deleted" indices: D not in filter
    pub other_deleted: Vec<u32>,
    /// All changed and modified superset
    pub all_changed_and_modified: Vec<u32>,
    /// Rename mapping: (index, previous_path)
    pub renamed_mapping: Vec<(u32, InternedString)>,
    /// When output_renamed_as_deleted_added is true, contains (index, previous_path)
    /// for renamed files split into deleted entries. The new name goes to filtered_added.
    pub rename_split_deletions: Vec<(u32, InternedString)>,
    /// YAML group keys that had modified matches
    pub modified_keys: Vec<InternedString>,
    /// YAML group keys that had any changed matches
    pub changed_keys: Vec<InternedString>,
    /// Per-group deploy decisions (populated when YAML groups are present)
    pub group_deploy_decisions: Vec<GroupDeployDecision>,
}

impl ComputedOutputs {
    /// Single-pass computation from a ProcessedResult
    ///
    /// When `output_renamed_as_deleted_added` is true, renamed files are split:
    /// the new path goes to `filtered_added` and the old path is stored in
    /// `rename_split_deletions` (the consumer should include these in deleted output).
    ///
    /// The `interner` parameter is used to look up group keys for concurrency tracking.
    pub fn compute(result: &ProcessedResult, output_renamed_as_deleted_added: bool) -> Self {
        Self::compute_with_concurrency(result, output_renamed_as_deleted_added, None, None)
    }

    /// Compute with concurrency information from workflow check.
    ///
    /// `blocked_groups` maps group keys to blocking run IDs.
    /// `interner` resolves InternedString keys for matching.
    pub fn compute_with_concurrency(
        result: &ProcessedResult,
        output_renamed_as_deleted_added: bool,
        blocked_groups: Option<&HashMap<InternedString, Vec<u64>>>,
        _interner: Option<&StringInterner>,
    ) -> Self {
        let filtered_set: HashSet<u32> = result.filtered_indices.iter().copied().collect();
        let unmatched_set: HashSet<u32> = result.unmatched_indices.iter().copied().collect();

        let mut out = Self {
            filtered_added: Vec::new(),
            filtered_copied: Vec::new(),
            filtered_deleted: Vec::new(),
            filtered_modified: Vec::new(),
            filtered_renamed: Vec::new(),
            filtered_type_changed: Vec::new(),
            filtered_unmerged: Vec::new(),
            filtered_unknown: Vec::new(),
            other_changed: Vec::new(),
            other_modified: Vec::new(),
            other_deleted: Vec::new(),
            all_changed_and_modified: Vec::new(),
            renamed_mapping: Vec::new(),
            rename_split_deletions: Vec::new(),
            modified_keys: Vec::new(),
            changed_keys: Vec::new(),
            group_deploy_decisions: Vec::new(),
        };

        for (i, file) in result.all_files.iter().enumerate() {
            let idx = i as u32;
            let in_filter = filtered_set.contains(&idx);
            let in_unmatched = unmatched_set.contains(&idx);

            // All changed and modified includes everything
            out.all_changed_and_modified.push(idx);

            if in_filter {
                match file.change_type {
                    ChangeType::Added => out.filtered_added.push(idx),
                    ChangeType::Copied => out.filtered_copied.push(idx),
                    ChangeType::Deleted => out.filtered_deleted.push(idx),
                    ChangeType::Modified => out.filtered_modified.push(idx),
                    ChangeType::Renamed => {
                        if output_renamed_as_deleted_added {
                            // Split: new path → added, old path → deleted (stored separately)
                            out.filtered_added.push(idx);
                            if let Some(prev) = file.previous_path {
                                out.rename_split_deletions.push((idx, prev));
                            }
                        } else {
                            out.filtered_renamed.push(idx);
                            if let Some(prev) = file.previous_path {
                                out.renamed_mapping.push((idx, prev));
                            }
                        }
                    }
                    ChangeType::TypeChanged => out.filtered_type_changed.push(idx),
                    ChangeType::Unmerged => out.filtered_unmerged.push(idx),
                    ChangeType::Unknown => out.filtered_unknown.push(idx),
                }
            }

            if in_unmatched {
                // "Other changed" = ACMR not in filter
                match file.change_type {
                    ChangeType::Added
                    | ChangeType::Copied
                    | ChangeType::Modified
                    | ChangeType::Renamed => {
                        out.other_changed.push(idx);
                    }
                    _ => {}
                }

                // "Other modified" = ACMRD not in filter
                match file.change_type {
                    ChangeType::Added
                    | ChangeType::Copied
                    | ChangeType::Modified
                    | ChangeType::Renamed
                    | ChangeType::Deleted => {
                        out.other_modified.push(idx);
                    }
                    _ => {}
                }

                // "Other deleted" = D not in filter
                if file.change_type == ChangeType::Deleted {
                    out.other_deleted.push(idx);
                }
            }
        }

        // Compute group keys (InternedString is Copy — no allocation)
        for group in &result.group_results {
            if !group.matched_indices.is_empty() {
                out.changed_keys.push(group.key);

                let has_modified = group.matched_indices.iter().any(|&idx| {
                    result
                        .all_files
                        .get(idx as usize)
                        .map(|f| f.change_type == ChangeType::Modified)
                        .unwrap_or(false)
                });

                if has_modified {
                    out.modified_keys.push(group.key);
                }
            }
        }

        // Helper: look up concurrency info for a group key
        let concurrency_for = |key: InternedString| -> (bool, u32) {
            blocked_groups
                .and_then(|bg| bg.get(&key))
                .map(|ids| (true, ids.len() as u32))
                .unwrap_or((false, 0))
        };

        // Helper: resolve group matched indices to file paths
        let resolve_group_paths = |group: &GroupResult| -> Vec<InternedString> {
            group
                .matched_indices
                .iter()
                .filter_map(|&idx| result.all_files.get(idx as usize).map(|f| f.path))
                .collect()
        };

        // Compute group deploy decisions
        if !result.group_results.is_empty() {
            if let Some(ref ci) = result.ci_decision {
                // Build lookup sets from CiDecision
                let rebuild_set: HashSet<InternedString> =
                    ci.files_to_rebuild.iter().copied().collect();
                let skip_set: HashSet<InternedString> = ci.files_to_skip.iter().copied().collect();
                let reasons_map: HashMap<InternedString, RebuildReasonKind> = ci
                    .rebuild_reasons
                    .iter()
                    .map(|r| (r.file, r.kind))
                    .collect();

                for group in &result.group_results {
                    let group_paths = resolve_group_paths(group);

                    if group_paths.is_empty() {
                        continue;
                    }

                    // Partition into rebuild/skip
                    let mut group_rebuild = Vec::new();
                    let mut group_skip = Vec::new();
                    for &path in &group_paths {
                        if rebuild_set.contains(&path) {
                            group_rebuild.push(path);
                        } else if skip_set.contains(&path) {
                            group_skip.push(path);
                        } else {
                            // File not in CI decision — treat as needing rebuild
                            group_rebuild.push(path);
                        }
                    }

                    let total_files = group_paths.len() as u32;

                    let (cb, cb_by) = concurrency_for(group.key);

                    if group_rebuild.is_empty() {
                        out.group_deploy_decisions.push(GroupDeployDecision {
                            key: group.key,
                            action: GroupDeployAction::Skip,
                            reason: None,
                            files_to_rebuild: Vec::new(),
                            files_to_skip: group_skip,
                            total_files,
                            concurrency_blocked: cb,
                            concurrency_blocked_by: cb_by,
                        });
                    } else {
                        let has_new = group_rebuild.iter().any(|p| {
                            matches!(
                                reasons_map.get(p),
                                Some(RebuildReasonKind::NewChange)
                                    | Some(RebuildReasonKind::BothNewAndFailed)
                            )
                        });
                        let has_failure = group_rebuild.iter().any(|p| {
                            matches!(
                                reasons_map.get(p),
                                Some(RebuildReasonKind::PreviousFailure)
                                    | Some(RebuildReasonKind::BothNewAndFailed)
                            )
                        });

                        let reason = match (has_new, has_failure) {
                            (true, true) => GroupDeployReason::BothNewAndFailed,
                            (false, true) => GroupDeployReason::PreviousFailure,
                            _ => GroupDeployReason::NewChange,
                        };

                        out.group_deploy_decisions.push(GroupDeployDecision {
                            key: group.key,
                            action: GroupDeployAction::Deploy,
                            reason: Some(reason),
                            files_to_rebuild: group_rebuild,
                            files_to_skip: group_skip,
                            total_files,
                            concurrency_blocked: cb,
                            concurrency_blocked_by: cb_by,
                        });
                    }
                }
            } else {
                // No CI decision — all groups with files get Deploy/NewChange
                for group in &result.group_results {
                    let group_paths = resolve_group_paths(group);

                    if group_paths.is_empty() {
                        continue;
                    }

                    let total_files = group_paths.len() as u32;
                    let (cb, cb_by) = concurrency_for(group.key);
                    out.group_deploy_decisions.push(GroupDeployDecision {
                        key: group.key,
                        action: GroupDeployAction::Deploy,
                        reason: Some(GroupDeployReason::NewChange),
                        files_to_rebuild: group_paths,
                        files_to_skip: Vec::new(),
                        total_files,
                        concurrency_blocked: cb,
                        concurrency_blocked_by: cb_by,
                    });
                }
            }
        }

        out
    }

    /// Any files in the changed category (filtered)
    pub fn any_changed(&self) -> bool {
        !self.filtered_added.is_empty()
            || !self.filtered_copied.is_empty()
            || !self.filtered_modified.is_empty()
            || !self.filtered_renamed.is_empty()
    }

    /// Only one file in the changed category
    pub fn only_changed(&self) -> bool {
        let count = self.filtered_added.len()
            + self.filtered_copied.len()
            + self.filtered_modified.len()
            + self.filtered_renamed.len();
        count == 1
    }

    /// Any modified files (filtered)
    pub fn any_modified(&self) -> bool {
        !self.filtered_modified.is_empty()
    }

    /// Only one modified file
    pub fn only_modified(&self) -> bool {
        self.filtered_modified.len() == 1
            && self.filtered_added.is_empty()
            && self.filtered_copied.is_empty()
            && self.filtered_renamed.is_empty()
            && self.filtered_deleted.is_empty()
    }

    /// Any groups with Deploy action
    pub fn has_deployable_groups(&self) -> bool {
        self.group_deploy_decisions
            .iter()
            .any(|d| d.action == GroupDeployAction::Deploy)
    }

    /// Any deleted files (filtered)
    pub fn any_deleted(&self) -> bool {
        !self.filtered_deleted.is_empty()
    }

    /// Only one deleted file
    pub fn only_deleted(&self) -> bool {
        self.filtered_deleted.len() == 1
            && self.filtered_added.is_empty()
            && self.filtered_copied.is_empty()
            && self.filtered_modified.is_empty()
            && self.filtered_renamed.is_empty()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::interner::StringInterner;
    use crate::types::{ChangedFile, CiDecision, FileOrigin, GroupResult, RebuildReason};

    fn make_file(change_type: ChangeType, idx: u32) -> ChangedFile {
        ChangedFile {
            path: InternedString(idx),
            change_type,
            previous_path: None,
            is_symlink: false,
            submodule_depth: 0,
            origin: FileOrigin::default(),
        }
    }

    #[test]
    fn test_compute_basic() {
        let result = ProcessedResult {
            all_files: vec![
                make_file(ChangeType::Added, 0),
                make_file(ChangeType::Modified, 1),
                make_file(ChangeType::Deleted, 2),
            ],
            filtered_indices: vec![0, 1],
            unmatched_indices: vec![2],
            pattern_applied: true,
            group_results: Vec::new(),
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: None,
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.filtered_added, vec![0]);
        assert_eq!(outputs.filtered_modified, vec![1]);
        assert!(outputs.filtered_deleted.is_empty());
        assert_eq!(outputs.other_deleted, vec![2]);
        assert!(outputs.any_changed());
        assert!(!outputs.only_changed());
    }

    #[test]
    fn test_compute_unfiltered() {
        let result = ProcessedResult {
            all_files: vec![make_file(ChangeType::Modified, 0)],
            filtered_indices: vec![0],
            unmatched_indices: Vec::new(),
            pattern_applied: false,
            group_results: Vec::new(),
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: None,
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert!(outputs.any_modified());
        assert!(outputs.only_modified());
    }

    #[test]
    fn test_compute_rename_splitting() {
        let result = ProcessedResult {
            all_files: vec![
                ChangedFile {
                    path: InternedString(0), // new name
                    change_type: ChangeType::Renamed,
                    previous_path: Some(InternedString(10)), // old name
                    is_symlink: false,
                    submodule_depth: 0,
                    origin: FileOrigin::default(),
                },
                make_file(ChangeType::Modified, 1),
            ],
            filtered_indices: vec![0, 1],
            unmatched_indices: Vec::new(),
            pattern_applied: true,
            group_results: Vec::new(),
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: None,
        };

        // Without splitting
        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.filtered_renamed, vec![0]);
        assert!(outputs.filtered_added.is_empty());
        assert!(outputs.rename_split_deletions.is_empty());
        assert_eq!(outputs.renamed_mapping.len(), 1);

        // With splitting
        let outputs = ComputedOutputs::compute(&result, true);
        assert!(outputs.filtered_renamed.is_empty());
        assert_eq!(outputs.filtered_added, vec![0]); // new name → added
        assert_eq!(outputs.rename_split_deletions.len(), 1); // old name → deleted
        assert_eq!(outputs.rename_split_deletions[0], (0, InternedString(10)));
        assert!(outputs.renamed_mapping.is_empty());
    }

    #[test]
    fn test_group_keys() {
        let interner = StringInterner::new();
        let frontend_key = interner.intern("frontend");
        let backend_key = interner.intern("backend");

        let result = ProcessedResult {
            all_files: vec![
                make_file(ChangeType::Modified, 0),
                make_file(ChangeType::Added, 1),
            ],
            filtered_indices: vec![0, 1],
            unmatched_indices: Vec::new(),
            pattern_applied: true,
            group_results: vec![
                GroupResult {
                    key: frontend_key,
                    matched_indices: vec![0],
                },
                GroupResult {
                    key: backend_key,
                    matched_indices: vec![1],
                },
            ],
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: None,
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.changed_keys, vec![frontend_key, backend_key]);
        assert_eq!(outputs.modified_keys, vec![frontend_key]); // Only Modified type
    }

    #[test]
    fn test_deploy_decisions_with_ci_decision_mixed() {
        let interner = StringInterner::new();
        let dev_key = interner.intern("dev");
        let staging_key = interner.intern("staging");
        let prod_key = interner.intern("prod");

        let result = ProcessedResult {
            all_files: vec![
                make_file(ChangeType::Modified, 0),
                make_file(ChangeType::Modified, 1),
                make_file(ChangeType::Modified, 2),
            ],
            filtered_indices: vec![0, 1, 2],
            unmatched_indices: Vec::new(),
            pattern_applied: true,
            group_results: vec![
                GroupResult {
                    key: dev_key,
                    matched_indices: vec![0],
                },
                GroupResult {
                    key: staging_key,
                    matched_indices: vec![1],
                },
                GroupResult {
                    key: prod_key,
                    matched_indices: vec![2],
                },
            ],
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: Some(CiDecision {
                files_to_rebuild: vec![InternedString(0), InternedString(2)],
                files_to_skip: vec![InternedString(1)],
                failed_jobs: Vec::new(),
                successful_jobs: Vec::new(),
                rebuild_reasons: vec![
                    RebuildReason {
                        file: InternedString(0),
                        kind: RebuildReasonKind::NewChange,
                        failed_run_id: None,
                        failed_job_name: None,
                    },
                    RebuildReason {
                        file: InternedString(2),
                        kind: RebuildReasonKind::PreviousFailure,
                        failed_run_id: Some(100),
                        failed_job_name: None,
                    },
                ],
            }),
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.group_deploy_decisions.len(), 3);

        assert_eq!(outputs.group_deploy_decisions[0].key, dev_key);
        assert_eq!(
            outputs.group_deploy_decisions[0].action,
            GroupDeployAction::Deploy
        );
        assert_eq!(
            outputs.group_deploy_decisions[0].reason,
            Some(GroupDeployReason::NewChange)
        );

        assert_eq!(outputs.group_deploy_decisions[1].key, staging_key);
        assert_eq!(
            outputs.group_deploy_decisions[1].action,
            GroupDeployAction::Skip
        );
        assert!(outputs.group_deploy_decisions[1].reason.is_none());

        assert_eq!(outputs.group_deploy_decisions[2].key, prod_key);
        assert_eq!(
            outputs.group_deploy_decisions[2].action,
            GroupDeployAction::Deploy
        );
        assert_eq!(
            outputs.group_deploy_decisions[2].reason,
            Some(GroupDeployReason::PreviousFailure)
        );

        assert!(outputs.has_deployable_groups());
    }

    #[test]
    fn test_deploy_decisions_without_ci_decision() {
        let interner = StringInterner::new();
        let dev_key = interner.intern("dev");
        let prod_key = interner.intern("prod");

        let result = ProcessedResult {
            all_files: vec![
                make_file(ChangeType::Added, 0),
                make_file(ChangeType::Modified, 1),
            ],
            filtered_indices: vec![0, 1],
            unmatched_indices: Vec::new(),
            pattern_applied: true,
            group_results: vec![
                GroupResult {
                    key: dev_key,
                    matched_indices: vec![0],
                },
                GroupResult {
                    key: prod_key,
                    matched_indices: vec![1],
                },
            ],
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: None,
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.group_deploy_decisions.len(), 2);

        for d in &outputs.group_deploy_decisions {
            assert_eq!(d.action, GroupDeployAction::Deploy);
            assert_eq!(d.reason, Some(GroupDeployReason::NewChange));
        }
        assert!(outputs.has_deployable_groups());
    }

    #[test]
    fn test_deploy_decisions_empty_groups() {
        let result = ProcessedResult {
            all_files: vec![make_file(ChangeType::Modified, 0)],
            filtered_indices: vec![0],
            unmatched_indices: Vec::new(),
            pattern_applied: false,
            group_results: Vec::new(),
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: None,
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert!(outputs.group_deploy_decisions.is_empty());
        assert!(!outputs.has_deployable_groups());
    }

    #[test]
    fn test_deploy_decisions_both_new_and_failed() {
        let interner = StringInterner::new();
        let mixed_key = interner.intern("mixed");

        let result = ProcessedResult {
            all_files: vec![
                make_file(ChangeType::Modified, 0),
                make_file(ChangeType::Modified, 1),
            ],
            filtered_indices: vec![0, 1],
            unmatched_indices: Vec::new(),
            pattern_applied: true,
            group_results: vec![GroupResult {
                key: mixed_key,
                matched_indices: vec![0, 1],
            }],
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: Some(CiDecision {
                files_to_rebuild: vec![InternedString(0), InternedString(1)],
                files_to_skip: Vec::new(),
                failed_jobs: Vec::new(),
                successful_jobs: Vec::new(),
                rebuild_reasons: vec![
                    RebuildReason {
                        file: InternedString(0),
                        kind: RebuildReasonKind::NewChange,
                        failed_run_id: None,
                        failed_job_name: None,
                    },
                    RebuildReason {
                        file: InternedString(1),
                        kind: RebuildReasonKind::PreviousFailure,
                        failed_run_id: Some(200),
                        failed_job_name: None,
                    },
                ],
            }),
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.group_deploy_decisions.len(), 1);
        assert_eq!(
            outputs.group_deploy_decisions[0].action,
            GroupDeployAction::Deploy
        );
        assert_eq!(
            outputs.group_deploy_decisions[0].reason,
            Some(GroupDeployReason::BothNewAndFailed)
        );
        assert_eq!(outputs.group_deploy_decisions[0].files_to_rebuild.len(), 2);
    }

    #[test]
    fn test_deploy_decisions_all_skip() {
        let interner = StringInterner::new();
        let staging_key = interner.intern("staging");

        let result = ProcessedResult {
            all_files: vec![make_file(ChangeType::Modified, 0)],
            filtered_indices: vec![0],
            unmatched_indices: Vec::new(),
            pattern_applied: true,
            group_results: vec![GroupResult {
                key: staging_key,
                matched_indices: vec![0],
            }],
            additions: 0,
            deletions: 0,
            diagnostics: Vec::new(),
            workflow_result: None,
            ci_decision: Some(CiDecision {
                files_to_rebuild: Vec::new(),
                files_to_skip: vec![InternedString(0)],
                failed_jobs: Vec::new(),
                successful_jobs: Vec::new(),
                rebuild_reasons: Vec::new(),
            }),
        };

        let outputs = ComputedOutputs::compute(&result, false);
        assert_eq!(outputs.group_deploy_decisions.len(), 1);
        assert_eq!(
            outputs.group_deploy_decisions[0].action,
            GroupDeployAction::Skip
        );
        assert!(outputs.group_deploy_decisions[0].reason.is_none());
        assert!(!outputs.has_deployable_groups());
    }
}