This commit is contained in:
Your Name
2026-08-27 14:23:23 +08:00
parent b5b14516a1
commit 2fa8492c56
27 changed files with 3832 additions and 1435 deletions
@@ -95,6 +95,37 @@ $explicitOpenAi = callDifyStreamPrivate('buildRequestSpecs', [
difyStreamExpect(count($explicitDify) === 1 && $explicitDify[0]['protocol'] === 'dify', 'explicit Dify endpoint never changes protocol');
difyStreamExpect(count($explicitOpenAi) === 1 && $explicitOpenAi[0]['protocol'] === 'openai', 'explicit OpenAI endpoint never changes protocol');
$retryableStream = [
'errno' => 0,
'http_code' => 200,
'emitted' => false,
'upstream_error' => true,
'finished' => false,
];
difyStreamExpect(
callDifyStreamPrivate('shouldTryNextProtocol', [$retryableStream, true]) === true,
'a terminal-free stream error before any delta tries the alternate protocol'
);
$retryableStream['emitted'] = true;
difyStreamExpect(
callDifyStreamPrivate('shouldTryNextProtocol', [$retryableStream, true]) === false,
'an emitted delta forbids protocol retry'
);
difyStreamExpect(
callDifyStreamPrivate('shouldTryNextProtocol', [[
'errno' => 0,
'http_code' => 400,
], false]) === true,
'an ambiguous endpoint rejected before generation tries the alternate protocol'
);
difyStreamExpect(
callDifyStreamPrivate('shouldTryNextProtocol', [[
'errno' => 0,
'http_code' => 401,
], true]) === false,
'credential failures are not hidden by protocol retry'
);
$difyWire = ": ping\r\n\r\n"
. "data: {\"event\":\"message\",\"answer\":\"\",\"message_id\":\"msg-safe\"}\r\n\r\n"
. "data: {\"event\":\"agent_message\",\"answer\":\"\"}\r\n\r\n"