fix(vision): 图像 URL 取回失败的 WARN 带来源主机(可诊断且不外泄路径/查询串/凭据)
- loop 解析点用结构断言取 SourceFailure 的主机(errors.As 穿透 %w 包装), 不导入 vision 包、不引入方向性依赖;拿不到来源时留空串而不编造。 - 新增 TestImageSourceHost 四例(nil/普通错误/包装后来源/空主机), 变异验证:把返回值改成 "" 该用例必红(已复跑确认)。
This commit is contained in:
1 parent
910d154d35
commit
127c32b440
2 files changed
+52
-1
No files matched your search
@@ -2,11 +2,46 @@ package loop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
||||
)
|
||||
|
||||
// fakeSourceErr 模拟 vision 包的 SourceFailure:错误链上能报出来源主机。
|
||||
type fakeSourceErr struct{ host string }
|
||||
|
||||
func (e *fakeSourceErr) Error() string { return "取回失败" }
|
||||
func (e *fakeSourceErr) ImageSourceHost() string {
|
||||
return e.host
|
||||
}
|
||||
|
||||
// TestImageSourceHost 钉住「日志能定位到来源主机」这条契约:错误链上
|
||||
// 带 ImageSourceHost 的证据要穿透 %w 包装被取出;其它错误一律空串
|
||||
// (空串表示无从定位,而不是假装有来源)。
|
||||
func TestImageSourceHost(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
name string
|
||||
err error
|
||||
want string
|
||||
}{
|
||||
{name: "nil 错误", err: nil, want: ""},
|
||||
{name: "普通错误", err: errors.New("解析失败"), want: ""},
|
||||
{name: "包装后的来源错误", err: fmt.Errorf("resolve: %w", &fakeSourceErr{host: "cdn.example.com"}), want: "cdn.example.com"},
|
||||
{name: "包装但主机为空", err: fmt.Errorf("resolve: %w", &fakeSourceErr{}), want: ""},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := imageSourceHost(c.err); got != c.want {
|
||||
t.Fatalf("imageSourceHost = %q, want %q", got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun_ImageResolverFoldsToText(t *testing.T) {
|
||||
t.Parallel()
|
||||
ad := &mockAdapter{chat: []mgResp{{resp: model.Response{Model: "m", Content: "Done."}}}}
|
||||
|
||||
Reference in new issue
Block a user