Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
ee01f80d
Commit
ee01f80d
authored
Feb 06, 2026
by
yangjianbo
Browse files
test(backend): 修复 usage 类型断言未检查
parent
98671a73
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/gateway_cached_tokens_test.go
View file @
ee01f80d
...
@@ -163,11 +163,9 @@ func TestStreamingReconcile_MessageDelta(t *testing.T) {
...
@@ -163,11 +163,9 @@ func TestStreamingReconcile_MessageDelta(t *testing.T) {
require
.
Equal
(
t
,
"message_delta"
,
eventType
)
require
.
Equal
(
t
,
"message_delta"
,
eventType
)
// 模拟 processSSEEvent 中的 reconcile 逻辑
// 模拟 processSSEEvent 中的 reconcile 逻辑
if
u
,
ok
:=
event
[
"usage"
]
.
(
map
[
string
]
any
);
ok
{
usage
,
ok
:=
event
[
"usage"
]
.
(
map
[
string
]
any
)
reconcileCachedTokens
(
u
)
require
.
True
(
t
,
ok
)
}
reconcileCachedTokens
(
usage
)
usage
:=
event
[
"usage"
]
.
(
map
[
string
]
any
)
assert
.
Equal
(
t
,
float64
(
15
),
usage
[
"cache_read_input_tokens"
])
assert
.
Equal
(
t
,
float64
(
15
),
usage
[
"cache_read_input_tokens"
])
}
}
...
@@ -183,11 +181,9 @@ func TestStreamingReconcile_MessageDelta_NativeClaude(t *testing.T) {
...
@@ -183,11 +181,9 @@ func TestStreamingReconcile_MessageDelta_NativeClaude(t *testing.T) {
var
event
map
[
string
]
any
var
event
map
[
string
]
any
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
eventJSON
),
&
event
))
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
eventJSON
),
&
event
))
if
u
,
ok
:=
event
[
"usage"
]
.
(
map
[
string
]
any
);
ok
{
usage
,
ok
:=
event
[
"usage"
]
.
(
map
[
string
]
any
)
reconcileCachedTokens
(
u
)
require
.
True
(
t
,
ok
)
}
reconcileCachedTokens
(
usage
)
usage
:=
event
[
"usage"
]
.
(
map
[
string
]
any
)
_
,
hasCacheRead
:=
usage
[
"cache_read_input_tokens"
]
_
,
hasCacheRead
:=
usage
[
"cache_read_input_tokens"
]
assert
.
False
(
t
,
hasCacheRead
,
"不应为原生 Claude 响应注入 cache_read_input_tokens"
)
assert
.
False
(
t
,
hasCacheRead
,
"不应为原生 Claude 响应注入 cache_read_input_tokens"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment