Add local test

This commit is contained in:
2026-06-12 16:39:34 +02:00
parent 90598d8110
commit 8cee5b506e
@@ -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);