igengx
This commit is contained in:
@@ -347,6 +347,61 @@ try {
|
||||
&& $GLOBALS['tongueCalls'][0][CURLOPT_URL] === 'https://dify.fixture.test/v1/files/upload', 'existing Dify base URL forms supported');
|
||||
}
|
||||
|
||||
// 豆包直连火山方舟:同一张截图以 data URI 内联,单次 chat/completions,不经过 Dify 上传。
|
||||
$arkUrl = 'https://ark.fixture.test/api/v3/chat/completions';
|
||||
$doubaoProfile = ['api_key' => 'fixture-only-ark-secret', 'label' => '豆包', 'name' => 'doubao-fixture-model', 'base_url' => $arkUrl];
|
||||
$arkReply = static fn (string $content, int $seconds = 0): array => ['seconds' => $seconds,
|
||||
'body' => json_encode(['choices' => [['message' => ['role' => 'assistant', 'content' => $content]]]], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)];
|
||||
$reset([$arkReply($correctedAnswer)]);
|
||||
$GLOBALS['tongueConfig']['models']['doubao'] = $doubaoProfile;
|
||||
$GLOBALS['tongueReadableCa'] = __FILE__;
|
||||
$GLOBALS['tongueConfig']['required_attachment_upload']['ca_file'] = __FILE__;
|
||||
$file = $upload(); $filePath = $file->getRealPath(); $bytes = file_get_contents($filePath); $digest = hash('sha256', $bytes);
|
||||
$result = $controller(array_replace($body, ['model' => 'doubao']), ['file' => $file]);
|
||||
$expect($result['code'] === 1 && $result['data'] === ['request_id' => $body['request_id'], 'diagnosis_id' => 41,
|
||||
'image_sha256' => $digest, 'analysis' => $valid, 'model' => 'doubao', 'model_label' => '豆包'], 'doubao returns the same response contract');
|
||||
$expect(count($GLOBALS['tongueCalls']) === 1 && $GLOBALS['tongueClosed'] === 1 && !is_file($filePath), 'doubao performs one model call, no Dify upload, and removes the JPEG');
|
||||
$arkCall = $GLOBALS['tongueCalls'][0];
|
||||
$arkPayload = json_decode($arkCall[CURLOPT_POSTFIELDS], true);
|
||||
$expect($arkCall[CURLOPT_URL] === $arkUrl && in_array('Authorization: Bearer fixture-only-ark-secret', $arkCall[CURLOPT_HTTPHEADER], true)
|
||||
&& !str_contains($arkCall[CURLOPT_POSTFIELDS], 'fixture-only-secret'), 'doubao uses its own Ark endpoint and key, never the Dify credentials');
|
||||
$expect($arkPayload['model'] === 'doubao-fixture-model' && count($arkPayload['messages']) === 1
|
||||
&& $arkPayload['messages'][0]['content'][0] === ['type' => 'text', 'text' => \app\common\service\TongueScreenshotAnalysis::prompt()]
|
||||
&& $arkPayload['messages'][0]['content'][1] === ['type' => 'image_url', 'image_url' => ['url' => 'data:image/jpeg;base64,' . base64_encode($bytes)]]
|
||||
&& !isset($arkPayload['thinking']), 'exact screenshot bytes are inlined beside the fixed prompt; thinking follows the model default');
|
||||
$expect(!str_contains($arkCall[CURLOPT_POSTFIELDS], 'patient-secret') && !str_contains($arkCall[CURLOPT_POSTFIELDS], $body['request_id'])
|
||||
&& !isset($arkCall[CURLOPT_CAINFO]) && $arkCall[CURLOPT_SSL_VERIFYPEER] === true && $arkCall[CURLOPT_SSL_VERIFYHOST] === 2
|
||||
&& $arkCall[CURLOPT_FOLLOWLOCATION] === false && $arkCall[CURLOPT_PROXY] === '' && $arkCall[CURLOPT_TIMEOUT_MS] === 50000,
|
||||
'no patient identifiers; public Ark TLS ignores the private attachment CA and keeps every transport protection');
|
||||
|
||||
$reset([$arkReply($rejectedAnswer, 6), $arkReply($correctedAnswer)]);
|
||||
$GLOBALS['tongueConfig']['models']['doubao'] = $doubaoProfile + ['thinking' => 'disabled'];
|
||||
$expect($controller(array_replace($body, ['model' => 'doubao']), ['file' => $upload()])['code'] === 1
|
||||
&& count($GLOBALS['tongueCalls']) === 2, 'doubao parser rejection permits exactly one correction');
|
||||
[$arkFirst, $arkCorrection] = array_map(static fn (array $call): array => json_decode($call[CURLOPT_POSTFIELDS], true), $GLOBALS['tongueCalls']);
|
||||
$expect($arkFirst['thinking'] === ['type' => 'disabled'] && $arkCorrection['thinking'] === ['type' => 'disabled']
|
||||
&& $arkCorrection['messages'][0]['content'][1] === $arkFirst['messages'][0]['content'][1]
|
||||
&& str_starts_with($arkCorrection['messages'][0]['content'][0]['text'], $arkFirst['messages'][0]['content'][0]['text'] . "\n")
|
||||
&& !str_contains($GLOBALS['tongueCalls'][1][CURLOPT_POSTFIELDS], $rejectedMarker)
|
||||
&& $GLOBALS['tongueCalls'][1][CURLOPT_TIMEOUT_MS] === 44000, 'correction resends the same image with the fixed rules, configured thinking and the remaining deadline only');
|
||||
|
||||
foreach ([['status' => 401, 'body' => '{"error":{"message":"fixture-only-ark-secret invalid"}}'], ['body' => '{}'],
|
||||
['body' => '{"choices":[{"message":{"content":null}}]}'], ['body' => 'not-json']] as $arkFailure) {
|
||||
$reset([$arkFailure]); $GLOBALS['tongueConfig']['models']['doubao'] = $doubaoProfile;
|
||||
$file = $upload(); $failed = $controller(array_replace($body, ['model' => 'doubao']), ['file' => $file]);
|
||||
$expect($failed['code'] === 0 && count($GLOBALS['tongueCalls']) === 1 && !is_file($file->getPathname())
|
||||
&& !str_contains(json_encode($failed), 'fixture-only-ark-secret'), 'doubao transport or envelope failure is safe and never retried');
|
||||
}
|
||||
foreach ([['api_key' => ''], ['name' => ''], ['base_url' => 'https://ark.fixture.test/api/v3'],
|
||||
['base_url' => 'http://user:[EMAIL]/api/v3/chat/completions']] as $brokenDoubao) {
|
||||
$reset(); $GLOBALS['tongueConfig']['models']['doubao'] = array_replace($doubaoProfile, $brokenDoubao);
|
||||
$expect($controller(array_replace($body, ['model' => 'doubao']), ['file' => $upload()])['code'] === 0
|
||||
&& $GLOBALS['tongueCalls'] === [], 'incomplete doubao configuration fails before network');
|
||||
}
|
||||
$reset();
|
||||
$expect($controller(array_replace($body, ['model' => 'doubao']), ['file' => $upload()])['code'] === 0
|
||||
&& $GLOBALS['tongueCalls'] === [], 'an unconfigured doubao profile never falls back to Dify');
|
||||
|
||||
// Real auth middleware, with menu lookup deliberately explosive: exact shared grant only.
|
||||
$route = new class {
|
||||
public array $adminInfo = ['admin_id' => 7, 'root' => 0, 'login_ip' => '127.0.0.1'];
|
||||
|
||||
Reference in New Issue
Block a user