"use strict"; /** * PRIX AI Evaluation System - Mock GitHub Layer * Intercepts GitHub API calls for local testing without external dependencies */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.MockGitHubLayer = void 0; exports.suppressGitHubCalls = suppressGitHubCalls; exports.restoreGitHubCalls = restoreGitHubCalls; const fs = __importStar(require("fs")); const path = __importStar(require("path")); class MockGitHubLayer { calls = []; comments = []; createdPRs = []; context; logFile = null; constructor(context, options) { this.context = context; if (options?.logFile) { this.logFile = options.logFile; } } /** * Create a mock Octokit-like object that captures all API calls */ createMockOctokit() { return { issues: { createComment: async (params) => { this.recordCall('POST', 'issues.createComment', params); this.comments.push({ path: params.path || 'general', line: params.line || 0, body: params.body, severity: 'info' }); this.log(`đŸ’Ŧ Comment created on ${params.path}:${params.line}`); return { data: { id: Date.now(), ...params } }; } }, pulls: { create: async (params) => { this.recordCall('POST', 'pulls.create', params); const pr = { number: Date.now(), html_url: `https://github.com/mock/repo/pull/${Date.now()}`, ...params }; this.createdPRs.push(pr); this.log(`🔀 PR created: ${pr.title} (draft: ${params.draft})`); return { data: pr }; }, update: async (params) => { this.recordCall('PATCH', 'pulls.update', params); this.log(`📝 PR #${params.pull_number} updated`); return { data: { ...params } }; }, list: async (params) => { this.recordCall('GET', 'pulls.list', params); return { data: this.createdPRs.filter(pr => pr.state === params.state) }; } }, repos: { getContent: async (params) => { this.recordCall('GET', 'repos.getContent', params); // Return mock content from local files try { const filePath = path.join(this.context.head.ref, params.path); if (fs.existsSync(filePath)) { const content = fs.readFileSync(filePath, 'utf8'); return { data: { content: Buffer.from(content).toString('base64'), encoding: 'base64' } }; } } catch (e) { // File not found, return empty } return { data: null }; } }, rest: { pulls: { listFiles: async (params) => { this.recordCall('GET', 'pulls.listFiles', params); return { data: this.context.files.map(f => ({ filename: f.filename, status: 'modified', changes: f.diff.split('\n').length, patch: f.diff })) }; } } } }; } /** * Create a mock Probot context */ createMockProbotContext() { const octokit = this.createMockOctokit(); return { log: { info: (msg) => this.log(`â„šī¸ ${msg}`), warn: (msg) => this.log(`âš ī¸ ${msg}`), error: (msg) => this.log(`❌ ${msg}`), debug: (msg) => this.log(`🐛 ${msg}`) }, octokit, payload: { pull_request: this.context, repository: { owner: { login: 'mock-owner' }, name: 'mock-repo' } }, repo: () => ({ owner: 'mock-owner', repo: 'mock-repo' }) }; } recordCall(method, endpoint, payload) { this.calls.push({ method, endpoint, payload, timestamp: Date.now() }); } log(message) { const timestamp = new Date().toISOString(); const logLine = `[${timestamp}] ${message}`; console.log(logLine); if (this.logFile) { fs.appendFileSync(this.logFile, logLine + '\n'); } } getCalls() { return [...this.calls]; } getComments() { return [...this.comments]; } getCreatedPRs() { return [...this.createdPRs]; } clear() { this.calls = []; this.comments = []; this.createdPRs = []; } generateReport() { const lines = [ '=== Mock GitHub Activity Report ===', `Total API Calls: ${this.calls.length}`, `Comments Created: ${this.comments.length}`, `PRs Created: ${this.createdPRs.length}`, '', 'API Calls:', ...this.calls.map(c => ` ${c.method} ${c.endpoint}`), '', 'Comments:', ...this.comments.map(c => ` ${c.path}:${c.line} - ${c.body.substring(0, 50)}...`), '', 'Created PRs:', ...this.createdPRs.map(pr => ` #${pr.number}: ${pr.title}`) ]; return lines.join('\n'); } } exports.MockGitHubLayer = MockGitHubLayer; /** * Utility to suppress actual GitHub calls during testing */ function suppressGitHubCalls() { // Set environment variable to disable actual GitHub integration process.env.ENABLE_AUTO_PR = 'false'; // Disable auto-PR in eval mode by default } /** * Restore GitHub calls (clear eval mode) */ function restoreGitHubCalls() { // No eval mode to clear since PRIX_EVAL_MODE is not allowed } //# sourceMappingURL=mock-github.js.map