79 lines
5.2 KiB
PHP
79 lines
5.2 KiB
PHP
<?php
|
|
// Read-only acceptance test AFTER the separately approved plugin restart.
|
|
// Run on the Emby host. No tokens or episode paths are printed.
|
|
$config = $argv[1] ?? '/mnt/nvme-storage/appdata/Emby/plugins/configurations/eMCPy.xml';
|
|
$x = simplexml_load_file($config);
|
|
if (!$x) throw new RuntimeException('Cannot read local plugin configuration');
|
|
$calls = 0;
|
|
function rpc($method, $params) {
|
|
global $x, $calls;
|
|
$calls++;
|
|
$c = curl_init('http://127.0.0.1:'.(int)$x->McpPort.'/mcp');
|
|
curl_setopt_array($c, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_POST=>true,
|
|
CURLOPT_HTTPHEADER=>['Content-Type: application/json','X-Api-Key: '.(string)$x->ApiKey],
|
|
CURLOPT_POSTFIELDS=>json_encode(['jsonrpc'=>'2.0','id'=>$calls,'method'=>$method,'params'=>$params]),CURLOPT_TIMEOUT=>60]);
|
|
$body = curl_exec($c); $code = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c);
|
|
if ($code !== 200) throw new RuntimeException('MCP request failed: HTTP '.$code);
|
|
$r = json_decode($body,true,512,JSON_THROW_ON_ERROR);
|
|
if (isset($r['error'])) throw new RuntimeException('MCP JSON-RPC error');
|
|
return $r['result'];
|
|
}
|
|
function requireTrue($ok,$message) { if (!$ok) throw new RuntimeException($message); }
|
|
function callTool($name,$args,$expectError=false) {
|
|
$r=rpc('tools/call',['name'=>$name,'arguments'=>$args]);
|
|
if ($expectError) {requireTrue(!empty($r['isError']), 'Expected MCP tool error');return null;}
|
|
requireTrue(empty($r['isError']), 'MCP tool failed: '.$name);
|
|
return json_decode($r['content'][0]['text'],true,512,JSON_THROW_ON_ERROR);
|
|
}
|
|
$init=rpc('initialize',(object)[]);
|
|
requireTrue(in_array($init['serverInfo']['version'],['1.4.0','1.4.1'],true),'Expected loaded eMCPy 1.4.0');
|
|
$tools=rpc('tools/list',(object)[]);
|
|
requireTrue(count($tools['tools'])===37,'Expected 37 tools');
|
|
$diagnostics=callTool('emby_server_diagnostics',(object)[]);
|
|
requireTrue($diagnostics['services']['library'] && $diagnostics['services']['dto'],'Required services missing');
|
|
$folders=callTool('emby_library_folders',(object)[]);
|
|
$docs=array_values(array_filter($folders['folders'],fn($f)=>$f['name']==='Dokumentationen'));
|
|
requireTrue(count($docs)===1,'Expected unique documentary library');
|
|
$id=(string)$docs[0]['itemId'];
|
|
$summary=[];
|
|
foreach(['emby_image_audit','emby_rating_audit','emby_metadata_audit','emby_track_audit','emby_search_advanced'] as $name) {
|
|
$result=callTool($name,['libraryId'=>$id,'limit'=>5]);
|
|
$page=$name==='emby_rating_audit'?$result['page']:$result;
|
|
requireTrue($page['scanned']<=5 && $page['returned']===count($page['items']),'Invalid page');
|
|
$summary[$name]=['candidates'=>$page['totalCandidates'],'scanned'=>$page['scanned'],'returned'=>$page['returned']];
|
|
if($page['hasMore']) {
|
|
$next=callTool($name,['libraryId'=>$id,'limit'=>5,'start'=>$page['nextStart'],'expectedRevision'=>$page['inventoryRevision']]);
|
|
$next=$name==='emby_rating_audit'?$next['page']:$next;
|
|
requireTrue($next['start']===$page['nextStart'],'Bad next page');
|
|
}
|
|
}
|
|
$search=callTool('emby_search_advanced',['libraryId'=>$id,'limit'=>2]);
|
|
$ids=array_column($search['items'],'id');
|
|
if($ids) {
|
|
$batch=callTool('emby_batch_details',['ids'=>$ids]);requireTrue($batch['returned']===count($ids),'Batch mismatch');
|
|
$image=rpc('tools/call',['name'=>'emby_image_review','arguments'=>['ids'=>$ids]]);
|
|
requireTrue(empty($image['isError']),'Image review failed');
|
|
$summary['imagePreviewCount']=count(array_filter($image['content'],fn($c)=>$c['type']==='image'));
|
|
$localPrimary=false;foreach($batch['items'] as $entry)foreach($entry['images']??[] as $pic)if($pic['type']==='Primary'&&$pic['isLocalFile'])$localPrimary=true;
|
|
if($localPrimary)requireTrue($summary['imagePreviewCount']>0,'Local primary images exist but none could be rendered');
|
|
}
|
|
callTool('emby_library_changes',['libraryId'=>$id,'since'=>'2026-10-01T00:00:00Z','limit'=>5]);
|
|
callTool('emby_users',(object)[]);
|
|
callTool('emby_playback_diagnostics',(object)[]);
|
|
callTool('emby_scan_library',['libraryId'=>$id]); // default preview ONLY
|
|
$movie=callTool('emby_search_advanced',['types'=>['Movie'],'limit'=>1]);
|
|
if($movie['items']) {
|
|
$m=$movie['items'][0];
|
|
$rating=callTool('emby_set_rating',['id'=>$m['id'],'rating'=>'FSK-12','expectedOfficialRating'=>$m['officialRating'],
|
|
'expectedCustomRating'=>$m['customRating'],'sourceUrl'=>'https://www.fsk.de',
|
|
'evidence'=>'Technischer Vorschautest, keine recherchierte Freigabe; nichts speichern.']);
|
|
requireTrue($rating['dryRun']===true,'Rating must be preview');
|
|
$after=callTool('emby_batch_details',['ids'=>[$m['id']],'include'=>['basic']]);
|
|
requireTrue($after['items'][0]['officialRating']===$m['officialRating']&&$after['items'][0]['customRating']===$m['customRating'],'Preview changed rating');
|
|
callTool('emby_refresh_item',['id'=>$m['id']]); // default preview ONLY
|
|
}
|
|
callTool('emby_search_advanced',['libraryId'=>'invalid'],true);
|
|
callTool('emby_image_review',[],true);
|
|
echo json_encode(['version'=>$init['serverInfo']['version'],'calls'=>$calls,'results'=>$summary,'mutationsExecuted'=>0,
|
|
'note'=>'Snapshots, provider episode retrieval, duplicates and real writes tested separately with SDK doubles; no live write executed.'],JSON_PRETTY_PRINT).PHP_EOL;
|