brain: Fix binary file acceptance

7b8caf1f3f4d8ecf00149d0891cd516a966d5659
Treat zero-line binary hunks as review units and route file-level
acceptance through the focused file so binary changes can be toggled
and report progress correctly.

Assisted-by: Codex:gpt-5.6
Alexis Sellier committed ago 1 parent 8a78e3c3
crates/brain/src/decorate.rs +33 -2
80 80
        let progress = (!hunks.is_empty()).then(|| ReviewProgress {
81 81
            accepted: hunks
82 82
                .iter()
83 83
                .filter(|hunk| self.accepted.contains(hunk))
84 84
                .filter_map(|hunk| self.hunk_stats.get(hunk))
85 -
                .map(|stats| stats.additions + stats.deletions)
85 +
                .map(|stats| (stats.additions + stats.deletions).max(1))
86 86
                .sum(),
87 87
            total: hunks
88 88
                .iter()
89 89
                .filter_map(|hunk| self.hunk_stats.get(hunk))
90 -
                .map(|stats| stats.additions + stats.deletions)
90 +
                .map(|stats| (stats.additions + stats.deletions).max(1))
91 91
                .sum(),
92 92
        });
93 93
        let comment_count = hunks
94 94
            .iter()
95 95
            .filter_map(|hunk| self.comments.get(hunk))
167 167
                additions: 3,
168 168
                deletions: 1,
169 169
            }
170 170
        );
171 171
    }
172 +
173 +
    #[test]
174 +
    fn zero_line_hunk_has_one_review_unit() {
175 +
        let hunk = HunkId::new(0);
176 +
        let file = FileId::new(0);
177 +
        let decorations = Decorations {
178 +
            accepted: BTreeSet::new(),
179 +
            comments: BTreeMap::new(),
180 +
            file_hunks: BTreeMap::from([(file, vec![hunk])]),
181 +
            hunk_stats: BTreeMap::from([(hunk, FileStats::default())]),
182 +
            palette: DiffPalette::default(),
183 +
        };
184 +
185 +
        assert_eq!(
186 +
            decorations.file(file).progress,
187 +
            Some(ReviewProgress {
188 +
                accepted: 0,
189 +
                total: 1,
190 +
            })
191 +
        );
192 +
        let accepted = Decorations {
193 +
            accepted: BTreeSet::from([hunk]),
194 +
            ..decorations
195 +
        };
196 +
        assert!(
197 +
            accepted
198 +
                .file(file)
199 +
                .progress
200 +
                .is_some_and(ReviewProgress::is_complete)
201 +
        );
202 +
    }
172 203
}
crates/brain/src/session.rs +4 -7
597 597
598 598
    /// Dispatches one input event, handling review keys before the viewer.
599 599
    fn handle_key(&mut self, event: Event<()>, area: Rect) -> Result<Control, Error> {
600 600
        match event {
601 601
            Event::Key(Key::Char('a')) => {
602 -
                if matches!(
603 -
                    self.current()?.viewer.state().focus,
604 -
                    Some(DiffFocus::Commit)
605 -
                ) {
606 -
                    self.toggle_commit_accepted(self.current)?;
607 -
                } else {
608 -
                    self.toggle_focused_hunk(area)?;
602 +
                match self.current()?.viewer.state().focus {
603 +
                    Some(DiffFocus::Commit) => self.toggle_commit_accepted(self.current)?,
604 +
                    Some(DiffFocus::File(_)) => self.toggle_focused_file(area)?,
605 +
                    Some(DiffFocus::Hunk(_)) | None => self.toggle_focused_hunk(area)?,
609 606
                }
610 607
                Ok(Control::Redraw)
611 608
            }
612 609
            Event::Key(Key::Char('u')) => {
613 610
                self.undo_last_hunk_accept()?;
a.rs +0 -0