test(platform): 修 Windows 上平台脆弱的断言(不削弱测试意图)
- trace/task: 亚 tick 耗时合法读到 0(本机时钟步长约 0.44ms),改为断言非负且 Duration == EndedAt-StartedAt - user/runtimeconfig: Windows 无法表示普通文件的 POSIX 权限位(Stat 恒 0666),0600 断言仅在非 Windows 生效,注释写明实现确实请求 0600 - exec: MSYS pwd 把同一目录渲染成 /tmp/...;改用「标记文件相对名解析」+「与显式 root 的 pwd 输出逐字相等」两条跨平台断言 + 变异验证 - 只读排查全仓同类脆弱断言,结果记入 DevDocs/工作小结
This commit is contained in:
1 parent
fbbfcc95ee
commit
29aa60d0eb
6 files changed
+89
-21
No files matched your search
@@ -72,8 +72,15 @@ func TestSpan_Lifecycle(t *testing.T) {
|
||||
if sp.EndedAt.Before(before) {
|
||||
t.Fatalf("EndedAt %v is before snapshot %v", sp.EndedAt, before)
|
||||
}
|
||||
if sp.Duration <= 0 {
|
||||
t.Fatalf("Duration = %v, want > 0", sp.Duration)
|
||||
// The monotonic clock may be too coarse to tick between StartedAt and
|
||||
// EndedAt, so a sub-tick span legitimately reads Duration == 0. Assert the
|
||||
// platform-independent invariant instead: Duration is non-negative and is
|
||||
// exactly the delta of the two stamps.
|
||||
if sp.Duration < 0 {
|
||||
t.Fatalf("Duration = %v, want >= 0", sp.Duration)
|
||||
}
|
||||
if want := sp.EndedAt.Sub(sp.StartedAt); sp.Duration != want {
|
||||
t.Fatalf("Duration = %v, want EndedAt-StartedAt = %v", sp.Duration, want)
|
||||
}
|
||||
if len(sp.Events) != 1 || sp.Events[0].Type != "token" {
|
||||
t.Fatalf("Events = %+v, want one 'token' event", sp.Events)
|
||||
@@ -241,8 +248,13 @@ func TestJSONRecorder_Output(t *testing.T) {
|
||||
if childRec.Status != SpanStatusOK {
|
||||
t.Fatalf("childRec.Status = %q, want ok", childRec.Status)
|
||||
}
|
||||
if childRec.Duration <= 0 {
|
||||
t.Fatalf("childRec.Duration = %v, want > 0", childRec.Duration)
|
||||
// As in TestSpan_Lifecycle: a sub-tick span reads Duration == 0 on platforms
|
||||
// with a coarse monotonic clock, so assert the recorded delta invariant.
|
||||
if childRec.Duration < 0 {
|
||||
t.Fatalf("childRec.Duration = %v, want >= 0", childRec.Duration)
|
||||
}
|
||||
if want := childRec.EndedAt.Sub(childRec.StartedAt); childRec.Duration != want {
|
||||
t.Fatalf("childRec.Duration = %v, want EndedAt-StartedAt = %v", childRec.Duration, want)
|
||||
}
|
||||
if childRec.Props["model"] != "gpt-test" {
|
||||
t.Fatalf("childRec.Props = %+v, want model key", childRec.Props)
|
||||
|
||||
Reference in new issue
Block a user