Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
5f67d2a2
authored
Apr 22, 2026
by
Seefs
Committed by
GitHub
Apr 22, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: use stream for codex auto test (#4325)
parent
d586a567
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
2 deletions
+38
-2
controller/channel-test.go
+38
-2
No files found.
controller/channel-test.go
View file @
5f67d2a2
...
@@ -460,7 +460,7 @@ func testChannel(channel *model.Channel, testModel string, endpointType string,
...
@@ -460,7 +460,7 @@ func testChannel(channel *model.Channel, testModel string, endpointType string,
newAPIError
:
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeReadResponseBodyFailed
,
http
.
StatusInternalServerError
),
newAPIError
:
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeReadResponseBodyFailed
,
http
.
StatusInternalServerError
),
}
}
}
}
if
bodyErr
:=
detectErrorFromTestResponseBody
(
respBody
);
bodyErr
!=
nil
{
if
bodyErr
:=
validateTestResponseBody
(
respBody
,
isStream
);
bodyErr
!=
nil
{
return
testResult
{
return
testResult
{
context
:
c
,
context
:
c
,
localErr
:
bodyErr
,
localErr
:
bodyErr
,
...
@@ -570,6 +570,42 @@ func detectErrorFromTestResponseBody(respBody []byte) error {
...
@@ -570,6 +570,42 @@ func detectErrorFromTestResponseBody(respBody []byte) error {
return
nil
return
nil
}
}
func
validateStreamTestResponseBody
(
respBody
[]
byte
)
error
{
b
:=
bytes
.
TrimSpace
(
respBody
)
if
len
(
b
)
==
0
{
return
errors
.
New
(
"stream response body is empty"
)
}
for
_
,
line
:=
range
bytes
.
Split
(
b
,
[]
byte
{
'\n'
})
{
line
=
bytes
.
TrimSpace
(
line
)
if
len
(
line
)
==
0
||
!
bytes
.
HasPrefix
(
line
,
[]
byte
(
"data:"
))
{
continue
}
payload
:=
bytes
.
TrimSpace
(
bytes
.
TrimPrefix
(
line
,
[]
byte
(
"data:"
)))
if
len
(
payload
)
==
0
||
bytes
.
Equal
(
payload
,
[]
byte
(
"[DONE]"
))
{
continue
}
return
nil
}
return
errors
.
New
(
"stream response body does not contain a valid stream event"
)
}
func
validateTestResponseBody
(
respBody
[]
byte
,
isStream
bool
)
error
{
if
bodyErr
:=
detectErrorFromTestResponseBody
(
respBody
);
bodyErr
!=
nil
{
return
bodyErr
}
if
isStream
{
return
validateStreamTestResponseBody
(
respBody
)
}
return
nil
}
func
shouldUseStreamForAutomaticChannelTest
(
channel
*
model
.
Channel
)
bool
{
return
channel
!=
nil
&&
channel
.
Type
==
constant
.
ChannelTypeCodex
}
func
detectErrorMessageFromJSONBytes
(
jsonBytes
[]
byte
)
string
{
func
detectErrorMessageFromJSONBytes
(
jsonBytes
[]
byte
)
string
{
if
len
(
jsonBytes
)
==
0
{
if
len
(
jsonBytes
)
==
0
{
return
""
return
""
...
@@ -822,7 +858,7 @@ func testAllChannels(notify bool) error {
...
@@ -822,7 +858,7 @@ func testAllChannels(notify bool) error {
}
}
isChannelEnabled
:=
channel
.
Status
==
common
.
ChannelStatusEnabled
isChannelEnabled
:=
channel
.
Status
==
common
.
ChannelStatusEnabled
tik
:=
time
.
Now
()
tik
:=
time
.
Now
()
result
:=
testChannel
(
channel
,
""
,
""
,
false
)
result
:=
testChannel
(
channel
,
""
,
""
,
shouldUseStreamForAutomaticChannelTest
(
channel
)
)
tok
:=
time
.
Now
()
tok
:=
time
.
Now
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
...
...
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