Skip to main content
Glama
test-phase2.tsโ€ข9.03 kB
#!/usr/bin/env tsx /** * Test script for Phase 2 SABnzbd integration * This script tests the SABnzbd service adapter and Download Status tool */ import { SabnzbdService } from "../src/services/downloaders/sabnzbd.js"; import { serviceRegistry } from "../src/services/registry.js"; import { SonarrService } from "../src/services/arr/sonarr.js"; import { RadarrService } from "../src/services/arr/radarr.js"; interface TestConfig { sabnzbd?: { baseUrl: string; apiKey: string; name?: string; }; sonarr?: { baseUrl: string; apiKey: string; }; radarr?: { baseUrl: string; apiKey: string; }; } async function loadTestConfig(): Promise<TestConfig> { const config: TestConfig = {}; // Load from environment variables only if (process.env.SABNZBD_URL && process.env.SABNZBD_API_KEY) { config.sabnzbd = { baseUrl: process.env.SABNZBD_URL, apiKey: process.env.SABNZBD_API_KEY, name: "Test SABnzbd", }; } if (process.env.SONARR_URL && process.env.SONARR_API_KEY) { config.sonarr = { baseUrl: process.env.SONARR_URL, apiKey: process.env.SONARR_API_KEY, }; } if (process.env.RADARR_URL && process.env.RADARR_API_KEY) { config.radarr = { baseUrl: process.env.RADARR_URL, apiKey: process.env.RADARR_API_KEY, }; } return config; } async function testSabnzbdService(config: TestConfig) { console.log("\n๐Ÿ”ง Testing SABnzbd Service..."); if (!config.sabnzbd) { console.log("โŒ No SABnzbd configuration found"); return false; } const sabnzbd = new SabnzbdService(config.sabnzbd); try { // Test server stats console.log("๐Ÿ“Š Testing server stats..."); const statsResult = await sabnzbd.serverStats(); if (statsResult.ok) { console.log("โœ… Server stats:", { name: statsResult.data?.name, version: statsResult.data?.version, isHealthy: statsResult.data?.isHealthy, paused: statsResult.data?.paused, totalSlots: statsResult.data?.totalSlots, }); } else { console.log("โŒ Server stats failed:", statsResult.error); return false; } // Test queue list console.log("๐Ÿ“‹ Testing queue list..."); const queueResult = await sabnzbd.queueList(); if (queueResult.ok) { console.log("โœ… Queue list:", { total: queueResult.data?.total, paused: queueResult.data?.paused, items: queueResult.data?.items.length, totalSizeMB: queueResult.data?.totalSizeMB, remainingSizeMB: queueResult.data?.remainingSizeMB, }); if (queueResult.data?.items.length > 0) { console.log(" Sample items:"); queueResult.data.items.slice(0, 3).forEach((item, i) => { console.log( ` ${i + 1}. ${item.title} (${item.status}, ${item.progressPct}%)`, ); }); } } else { console.log("โŒ Queue list failed:", queueResult.error); return false; } // Test history list console.log("๐Ÿ“œ Testing history list..."); const historyResult = await sabnzbd.historyList(5); if (historyResult.ok) { console.log(`โœ… History list: ${historyResult.data?.length || 0} items`); if (historyResult.data && historyResult.data.length > 0) { console.log(" Recent items:"); historyResult.data.slice(0, 3).forEach((item, i) => { console.log(` ${i + 1}. ${item.name} (${item.status})`); }); } } else { console.log("โŒ History list failed:", historyResult.error); } // Test title correlation console.log("๐Ÿ”— Testing title correlation..."); const testArrTitles = [ "Generic.TV.Show.S01E01.1080p.WEB-DL", "Sample.Movie.2023.1080p.BluRay.x264", "Example.Series.S02E05.720p.HDTV", ]; if (queueResult.ok && queueResult.data?.items) { const correlations = sabnzbd.correlateTitles( queueResult.data.items, testArrTitles, ); console.log(`โœ… Correlation test: ${correlations.length} items analyzed`); correlations.forEach((corr, i) => { if (corr.confidence > 0.6) { console.log( ` High confidence match: "${corr.sabItem.title}" โ†” "${corr.arrTitle}" (${Math.round(corr.confidence * 100)}%)`, ); } }); } return true; } catch (error) { console.log("โŒ SABnzbd service test failed:", error); return false; } } async function testDownloadStatus(config: TestConfig) { console.log("\n๐Ÿ“ฅ Testing Download Status integration..."); // Set up services if (config.sonarr) { const sonarr = new SonarrService("test-sonarr", config.sonarr); serviceRegistry.clear(); serviceRegistry.register("test-sonarr", config.sonarr); } if (config.radarr) { const radarr = new RadarrService("test-radarr", config.radarr); serviceRegistry.register("test-radarr", config.radarr); } if (config.sabnzbd) { serviceRegistry.registerDownloader("test-sabnzbd", config.sabnzbd); } try { // Simulate Download Status tool logic const serviceNames = serviceRegistry.getAllNames(); const downloaderNames = serviceRegistry.getAllDownloaderNames(); console.log(`๐Ÿ“Š Services available: ${serviceNames.join(", ")}`); console.log(`๐Ÿ“ฅ Downloaders available: ${downloaderNames.join(", ")}`); let totalQueued = 0; let totalDownloading = 0; let totalCompletedPending = 0; // Get arr service queue data for (const serviceName of serviceNames) { const service = serviceRegistry.get(serviceName); if (!service) continue; try { const queueResult = await service.queueList(); if (queueResult.ok && queueResult.data) { const queueData = queueResult.data; console.log( ` ${serviceName}: ${queueData.total} items (${queueData.mediaKind})`, ); totalQueued += queueData.total; const downloading = queueData.items.filter( (item) => item.status.toLowerCase().includes("downloading") || item.status.toLowerCase().includes("grabbing"), ).length; const pending = queueData.items.filter( (item) => item.status.toLowerCase().includes("completed") || item.status.toLowerCase().includes("pending"), ).length; totalDownloading += downloading; totalCompletedPending += pending; } } catch (error) { console.log(` โŒ Failed to get queue for ${serviceName}:`, error); } } // Get downloader data let downloaderItems = 0; if (downloaderNames.length > 0) { const downloader = serviceRegistry.getDownloader(downloaderNames[0]); if (downloader) { try { const queueResult = await downloader.queueList(); if (queueResult.ok && queueResult.data) { downloaderItems = queueResult.data.items.length; console.log( ` ${downloaderNames[0]}: ${downloaderItems} downloads active`, ); } } catch (error) { console.log(` โŒ Failed to get downloader queue:`, error); } } } // Calculate correlation ratio const correlationRatio = downloaderItems > 0 ? Math.min(1.0, totalQueued / downloaderItems) : null; console.log("\nโœ… Download Status Summary:"); console.log(` Total Queued: ${totalQueued}`); console.log(` Currently Downloading: ${totalDownloading}`); console.log(` Completed/Pending Import: ${totalCompletedPending}`); console.log(` Downloader Items: ${downloaderItems}`); if (correlationRatio !== null) { console.log( ` Correlation Ratio: ${Math.round(correlationRatio * 100)}%`, ); } return true; } catch (error) { console.log("โŒ Download Status test failed:", error); return false; } } async function main() { console.log("๐Ÿš€ Phase 2 SABnzbd Integration Test"); console.log("===================================="); const config = await loadTestConfig(); console.log("\n๐Ÿ“‹ Configuration Check:"); console.log(` SABnzbd: ${config.sabnzbd ? "โœ… Configured" : "โŒ Missing"}`); console.log(` Sonarr: ${config.sonarr ? "โœ… Configured" : "โŒ Missing"}`); console.log(` Radarr: ${config.radarr ? "โœ… Configured" : "โŒ Missing"}`); if (!config.sabnzbd) { console.log("\nโŒ SABnzbd configuration required for Phase 2 testing"); console.log(" Set SABNZBD_URL and SABNZBD_API_KEY environment variables"); console.log( " Or use FLIX_BRIDGE_ENV_MAPPING to point to custom env var names", ); process.exit(1); } let allTestsPassed = true; // Test SABnzbd service const sabnzbdTestPassed = await testSabnzbdService(config); allTestsPassed = allTestsPassed && sabnzbdTestPassed; // Test Download Status integration const downloadStatusTestPassed = await testDownloadStatus(config); allTestsPassed = allTestsPassed && downloadStatusTestPassed; console.log("\n" + "=".repeat(50)); if (allTestsPassed) { console.log("โœ… All Phase 2 tests passed!"); console.log(" SABnzbd integration is working correctly"); console.log(" Download Status tool is functional"); process.exit(0); } else { console.log("โŒ Some Phase 2 tests failed"); console.log(" Check the error messages above for details"); process.exit(1); } } if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { console.error("๐Ÿ’ฅ Test script failed:", error); process.exit(1); }); }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/thesammykins/FlixBridge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server