From 8cee5b506e4d2fc680508308c53efd1a5e95fd01 Mon Sep 17 00:00:00 2001 From: kennyboy55 Date: Fri, 12 Jun 2026 16:39:34 +0200 Subject: [PATCH] Add local test --- .../gitea-searchengine/test/test-runner.js | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 engines/gitea-searchengine/test/test-runner.js diff --git a/engines/gitea-searchengine/test/test-runner.js b/engines/gitea-searchengine/test/test-runner.js new file mode 100644 index 0000000..ec91c1b --- /dev/null +++ b/engines/gitea-searchengine/test/test-runner.js @@ -0,0 +1,80 @@ +// AI generated + +// --- IMPORT YOUR ENGINE --- +// Since index.js uses default export class syntax, we import it directly +const GiteaEngine = require('../index.js').default; + +// --- CONFIGURATION --- +const TEST_GITEA_URL = "https://gitea.furb.it"; // Change to your local instance if testing real connections +const API_PATH = "/api/v1/repos/search"; + +// Create the Engine Instance +const engine = new GiteaEngine(); + +// Mock Settings (Replace with your config or local instance URL) +const settings = { + giteaUrl: TEST_GITEA_URL, + accessToken: "" + // Set accessToken to a real token if you want to test private repo search +}; + +// --- SETUP CONTEXT --- +// The degoog runtime provides these. We mock them for local testing. +const context = { + // Use global fetch (provided by node-fetch polyfill or native) + fetch: fetch, + sentinel: function(response, engineName) { + // In real degoog, this checks for network errors. + // We can log or ignore for local testing. + console.log(`[Sentinel] ${engineName} response status: ${response.status}`); + }, + engineError: function(status, message, opts) { + // Create a generic error object to match the runtime expectation + const err = new Error(message); + err.name = "EngineError"; + err.httpStatus = opts?.httpStatus || 500; + err.engine = opts?.engine || "Gitea"; + return err; + } +}; + +// --- TEST EXECUTION --- + +async function runTest() { + console.log("Initializing Gitea Engine..."); + + // 1. Configure the engine + engine.configure(settings); + console.log(`Configured Base URL: ${engine.giteaBase}`); + console.log(`Configured API Path: ${engine.giteaSearchUrl}`); + + // 2. Run the search + // Note: For a local test without a real API, you would typically need a Mock Server + // Here we will attempt a call to the real hosted Gitea to verify logic. + // Replace 'query' with a term that exists on public gitea.com + const query = "esphome"; + + console.log(`\nExecuting search for: ${query}`); + + try { + const results = await engine.executeSearch( + query, + 1, + "", + context + ); + + console.log(`\n--- Search Results (${results.length} found) ---`); + results.forEach(r => { + console.log(`[${r.title}] -> ${r.url}`); + }); + + } catch (error) { + console.error("Search Failed:", error.message); + if (error.name === "SentinelBreach") { + console.log("Request was blocked or timed out."); + } + } +} + +runTest().catch(console.error);