Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions internal/tui/approval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tui

import (
"context"
"regexp"
"strconv"
"strings"
"testing"
Expand All @@ -27,8 +28,11 @@ func TestApprovalDefaultsToDenyAndShowsExactRequest(t *testing.T) {
t.Fatalf("mode=%v allow=%v", m.mode, m.approvalAllow)
}
view := m.View().Content
for _, want := range []string{strconv.Quote(command), `guest workdir: "src/path with space"`, "timeout: 37s", "[Deny]"} {
if !strings.Contains(view, want) {
// The dialog wraps to the panel width, so compare against a flattened
// rendering: the exact quoted request must still be recoverable.
flat := flattenApproval(view)
for _, want := range []string{strconv.Quote(command), strconv.Quote("src/path with space"), "37s", "[Deny]"} {
if !strings.Contains(flat, flattenApproval(want)) {
t.Fatalf("approval view missing %q:\n%s", want, view)
}
}
Expand Down Expand Up @@ -152,3 +156,18 @@ func approvalRequest(ctx context.Context, params protocol.RunCommandApprovalPara
settled: make(chan struct{}),
}
}

var ansiPattern = regexp.MustCompile("\x1b\\[[0-9;]*m")

// flattenApproval strips styling, panel chrome, and layout whitespace so an
// assertion can read the dialog's content across wrapped lines.
func flattenApproval(view string) string {
return strings.Map(func(r rune) rune {
switch r {
case '\u250f', '\u2513', '\u2517', '\u251b', '\u2503', '\u2502', '\u2501', '\u2500',
'\u2521', '\u2529', '\u2514', '\u2518', ' ', '\n', '\t':
return -1
}
return r
}, ansiPattern.ReplaceAllString(view, ""))
}
Loading
Loading