fix(outboundtext): keep resource handles intact when normalizing formulas
This commit is contained in:
@@ -30,4 +30,4 @@ func TestEffectiveDownloadCodesEmpty(t *testing.T) {
|
||||
if codes := effectiveDownloadCodes(BotCallback{}); len(codes) != 0 {
|
||||
t.Fatalf("codes=%v, want empty", codes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,4 +77,4 @@ func TestPublishQuestionImageFailsClosedWithoutURL(t *testing.T) {
|
||||
if got := h2.publishQuestionImage(context.Background(), image); got != "" {
|
||||
t.Fatalf("expected empty URL on publish error, got %q", got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/outboundimage"
|
||||
)
|
||||
|
||||
type diagFetcher struct{}
|
||||
|
||||
func (diagFetcher) Fetch(ctx context.Context, ref string) ([]byte, string, error) {
|
||||
return []byte("PNGDATA"), "image/png", nil
|
||||
}
|
||||
|
||||
type diagPublisher struct{}
|
||||
|
||||
func (diagPublisher) Publish(ctx context.Context, data []byte, contentType string) (string, error) {
|
||||
return "https://weknora-api-test.dobot.cn/dingtalk/i/a87f73b8-15cb-546e-ba53-bf93dade916f", nil
|
||||
}
|
||||
|
||||
// The outbound rewrite must publish a resource image and keep it in the card
|
||||
// body. A reference whose handle contains "_x" (…ZM_pltQ) used to be mangled by
|
||||
// the math normalizer, which made the image unpublishable and the sanitizer
|
||||
// drop the whole line.
|
||||
func TestRewriteOutboundContentKeepsPublishedImage(t *testing.T) {
|
||||
content := "\n\n公式:$r = \\sqrt{X^2 + Y^2}$\n"
|
||||
h := &Handler{
|
||||
outboundRewriter: outboundimage.NewRewriter(diagFetcher{}, diagPublisher{}, 50),
|
||||
groupTablesFinal: true,
|
||||
}
|
||||
out := h.rewriteOutboundContent(context.Background(), content)
|
||||
if !strings.Contains(out, " {
|
||||
t.Fatalf("published image missing from card content: %q", out)
|
||||
}
|
||||
if !strings.Contains(out, "r = √(X² + Y²)") {
|
||||
t.Fatalf("formula not converted: %q", out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user