Add Telegram file upload directive

This commit is contained in:
Codex
2026-06-08 01:44:48 +00:00
parent 739b6cd870
commit ac8d5c2803
3 changed files with 108 additions and 9 deletions

View File

@@ -252,6 +252,24 @@ func TestSplitAssistantMessageSegmentsWithPhotoDirective(t *testing.T) {
}
}
func TestSplitAssistantMessageSegmentsWithFileDirective(t *testing.T) {
filePath := filepath.Join(string(filepath.Separator), "workspace", "report.pdf")
text := fmt.Sprintf("before\n<!-- telegram-file {\"path\":%q,\"caption\":\"report\"} -->\nafter", filePath)
segments := splitAssistantMessageSegments(text)
if len(segments) != 3 {
t.Fatalf("segments = %d, want 3: %#v", len(segments), segments)
}
if segments[0].Text != "before\n" || segments[0].File != nil {
t.Fatalf("unexpected first segment: %#v", segments[0])
}
if segments[1].File == nil || segments[1].File.Path != filePath || segments[1].File.Caption != "report" {
t.Fatalf("unexpected file segment: %#v", segments[1])
}
if segments[2].Text != "after" || segments[2].File != nil {
t.Fatalf("unexpected final segment: %#v", segments[2])
}
}
func TestInvalidPhotoDirectiveStaysVisible(t *testing.T) {
text := "<!-- telegram-photo not-json -->"
segments := splitAssistantMessageSegments(text)
@@ -261,7 +279,7 @@ func TestInvalidPhotoDirectiveStaysVisible(t *testing.T) {
}
func TestAssistantStreamPreviewHidesDirectives(t *testing.T) {
text := "before\n<!-- telegram-photo {\"path\":\"/workspace/photo.jpg\"} -->\nafter\n<!-- codex-thread-rename "
text := "before\n<!-- telegram-file {\"path\":\"/workspace/report.pdf\"} -->\n<!-- telegram-photo {\"path\":\"/workspace/photo.jpg\"} -->\nafter\n<!-- codex-thread-rename "
got := assistantStreamPreview(text)
want := "before\nafter\n"
if got != want {