Bake in thread directives
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -28,6 +30,17 @@ func TestChunkText(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTelegramClientRedactsToken(t *testing.T) {
|
||||
client := NewClient("secret-token")
|
||||
err := client.redactError(fmt.Errorf("Post %q: context canceled", client.baseURL+"/sendMessage"))
|
||||
if strings.Contains(err.Error(), "secret-token") {
|
||||
t.Fatalf("token was not redacted: %v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "<telegram-token>") {
|
||||
t.Fatalf("redacted token marker missing: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApprovalCallbackData(t *testing.T) {
|
||||
data := ApprovalCallbackData(12, "accept")
|
||||
id, decision, ok := ParseApprovalCallbackData(data)
|
||||
@@ -78,7 +91,8 @@ func TestParseCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSplitAssistantMessageSegmentsWithPhotoDirective(t *testing.T) {
|
||||
text := "before\n<!-- telegram-photo {\"path\":\"/tmp/photo.jpg\",\"caption\":\"hello\"} -->\nafter"
|
||||
photoPath := filepath.Join(string(filepath.Separator), "workspace", "photo.jpg")
|
||||
text := fmt.Sprintf("before\n<!-- telegram-photo {\"path\":%q,\"caption\":\"hello\"} -->\nafter", photoPath)
|
||||
segments := splitAssistantMessageSegments(text)
|
||||
if len(segments) != 3 {
|
||||
t.Fatalf("segments = %d, want 3: %#v", len(segments), segments)
|
||||
@@ -86,7 +100,7 @@ func TestSplitAssistantMessageSegmentsWithPhotoDirective(t *testing.T) {
|
||||
if segments[0].Text != "before\n" || segments[0].Photo != nil {
|
||||
t.Fatalf("unexpected first segment: %#v", segments[0])
|
||||
}
|
||||
if segments[1].Photo == nil || segments[1].Photo.Path != "/tmp/photo.jpg" || segments[1].Photo.Caption != "hello" {
|
||||
if segments[1].Photo == nil || segments[1].Photo.Path != photoPath || segments[1].Photo.Caption != "hello" {
|
||||
t.Fatalf("unexpected photo segment: %#v", segments[1])
|
||||
}
|
||||
if segments[2].Text != "after" || segments[2].Photo != nil {
|
||||
@@ -102,6 +116,21 @@ func TestInvalidPhotoDirectiveStaysVisible(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitAssistantMessageSegmentsWithThreadDirectives(t *testing.T) {
|
||||
cwd := filepath.Join(string(filepath.Separator), "workspace", "project")
|
||||
text := fmt.Sprintf("<!-- codex-thread-rename {\"title\":\" A Better Thread Title \"} -->\n<!-- codex-thread-cwd {\"cwd\":%q} -->", cwd)
|
||||
segments := splitAssistantMessageSegments(text)
|
||||
if len(segments) != 2 {
|
||||
t.Fatalf("segments = %d, want 2: %#v", len(segments), segments)
|
||||
}
|
||||
if segments[0].ThreadRename == nil || segments[0].ThreadRename.Title != "A Better Thread Title" {
|
||||
t.Fatalf("unexpected rename segment: %#v", segments[0])
|
||||
}
|
||||
if segments[1].ThreadCWD == nil || segments[1].ThreadCWD.CWD != cwd {
|
||||
t.Fatalf("unexpected cwd segment: %#v", segments[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderCodexCommandExecutionItem(t *testing.T) {
|
||||
output := "line 1\nline 2"
|
||||
exitCode := 0
|
||||
|
||||
Reference in New Issue
Block a user