03ccac76c7
Replace the floating approval modal (which blanked the whole UI) with an opencode-style band that takes the input bar's slot while a gate is pending: tool/tier/risk header above a side-by-side old|new diff, with the session output and event stream still visible above it. The band height adapts to the diff length. Add a unified-diff parser that aligns removals/additions into split rows (blank left cell for a create, blank right for a delete) and a two-column renderer shared by the band preview and the ^x fullscreen view. Wire plain a/r to approve/reject to match the advertised keys.
54 lines
1.9 KiB
Go
54 lines
1.9 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestParseUnifiedDiff_Create(t *testing.T) {
|
|
diff := "--- /dev/null\n+++ b/hello.sh\n@@ -0,0 +1,2 @@\n+#!/usr/bin/env bash\n+echo hi\n"
|
|
rows := parseUnifiedDiff(diff)
|
|
if len(rows) != 2 {
|
|
t.Fatalf("want 2 rows, got %d", len(rows))
|
|
}
|
|
for i, r := range rows {
|
|
if r.oldKind != diffBlank || r.oldNum != 0 || r.oldText != "" {
|
|
t.Errorf("row %d: create should have a blank left cell, got %+v", i, r)
|
|
}
|
|
if r.newKind != diffAdd {
|
|
t.Errorf("row %d: right cell should be an addition, got %+v", i, r)
|
|
}
|
|
}
|
|
if rows[0].newNum != 1 || rows[1].newNum != 2 {
|
|
t.Errorf("new line numbers should start at 1: %d, %d", rows[0].newNum, rows[1].newNum)
|
|
}
|
|
}
|
|
|
|
func TestParseUnifiedDiff_EditAlignsAndNumbers(t *testing.T) {
|
|
diff := "--- a/x\n+++ b/x\n@@ -1,3 +1,3 @@\n ctx\n-old\n+new\n more\n"
|
|
rows := parseUnifiedDiff(diff)
|
|
if len(rows) != 3 {
|
|
t.Fatalf("want 3 rows (context, change, context), got %d", len(rows))
|
|
}
|
|
// context row: both sides present, same text, line 1
|
|
if rows[0].oldNum != 1 || rows[0].newNum != 1 || rows[0].oldText != "ctx" || rows[0].newText != "ctx" {
|
|
t.Errorf("context row mis-numbered/aligned: %+v", rows[0])
|
|
}
|
|
// change row: old "old" on left, new "new" on right, both line 2
|
|
c := rows[1]
|
|
if c.oldKind != diffDel || c.newKind != diffAdd || c.oldText != "old" || c.newText != "new" {
|
|
t.Errorf("change row should pair del|add: %+v", c)
|
|
}
|
|
if c.oldNum != 2 || c.newNum != 2 {
|
|
t.Errorf("change row line numbers should be 2/2: %d/%d", c.oldNum, c.newNum)
|
|
}
|
|
// trailing context advances to line 3 on both sides
|
|
if rows[2].oldNum != 3 || rows[2].newNum != 3 {
|
|
t.Errorf("trailing context should be 3/3: %d/%d", rows[2].oldNum, rows[2].newNum)
|
|
}
|
|
}
|
|
|
|
func TestDiffTarget(t *testing.T) {
|
|
got := diffTarget("--- a/old.sh\n+++ b/dir/new.sh\n@@ -0,0 +1 @@\n+x\n")
|
|
if got != "dir/new.sh" {
|
|
t.Errorf("diffTarget = %q, want dir/new.sh", got)
|
|
}
|
|
}
|