feat(dingtalk): enable secure multimodal image QA

This commit is contained in:
姚章浩
2026-07-16 00:17:16 +08:00
parent 4022040e98
commit c9c4f0aaa5
59 changed files with 3279 additions and 429 deletions
@@ -0,0 +1,43 @@
package dingtalk
import (
"context"
"errors"
"net/http"
"testing"
"time"
"github.com/Tencent/WeKnora/internal/im"
)
type failingCardRoundTripper struct{}
func (failingCardRoundTripper) RoundTrip(*http.Request) (*http.Response, error) {
return nil, errors.New("simulated delivery failure")
}
func TestFinalizeStreamPropagatesCardDeliveryFailure(t *testing.T) {
oldClient := httpClient
httpClient = &http.Client{Transport: failingCardRoundTripper{}, Timeout: time.Second}
t.Cleanup(func() { httpClient = oldClient })
adapter := &Adapter{
clientID: "robot",
token: "cached-token",
tokenExpAt: time.Now().Add(time.Hour),
}
streamID := "dt:fail-closed-test"
streamsMu.Lock()
dStreams[streamID] = &streamState{outTrackID: "track-id", createdAt: time.Now()}
streamsMu.Unlock()
t.Cleanup(func() {
streamsMu.Lock()
delete(dStreams, streamID)
streamsMu.Unlock()
})
err := adapter.FinalizeStream(context.Background(), &im.IncomingMessage{}, streamID, "image recognition failed")
if err == nil {
t.Fatal("expected final card delivery failure to propagate")
}
}