From 14650edf05c282010dffada541a3b1dbec83e5cd Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sun, 8 Jun 2025 12:53:38 +0100 Subject: [PATCH] cleanup: remove temporary test files from main repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit šŸ¤– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- testBackupHealthFix.html | 153 ----------------------------------- timestamp-validation-test.js | 105 ------------------------ webhook-integration-test.js | 132 ------------------------------ 3 files changed, 390 deletions(-) delete mode 100644 testBackupHealthFix.html delete mode 100644 timestamp-validation-test.js delete mode 100644 webhook-integration-test.js diff --git a/testBackupHealthFix.html b/testBackupHealthFix.html deleted file mode 100644 index 93aa9f107..000000000 --- a/testBackupHealthFix.html +++ /dev/null @@ -1,153 +0,0 @@ - - - - Test Backup Health Fix - - - -

Backup Health Fix Test

- -
-

Instructions:

-
    -
  1. Start the Pulse server: npm run dev
  2. -
  3. Open this file in a browser
  4. -
  5. Open the browser console to see debug logs
  6. -
  7. Click "Connect to Pulse" below
  8. -
  9. Look for "[Backup Health Debug]" messages in the console
  10. -
-
- - - -
- - - - \ No newline at end of file diff --git a/timestamp-validation-test.js b/timestamp-validation-test.js deleted file mode 100644 index 217a239f4..000000000 --- a/timestamp-validation-test.js +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env node - -/** - * Timestamp Validation Test - * Simple test to verify our timestamp validation logic works correctly - */ - -const AlertManager = require('./server/alertManager'); - -function testTimestampValidation() { - console.log('šŸ” Testing Timestamp Validation Logic...\n'); - - const alertManager = new AlertManager(); - - try { - console.log('1. Testing with valid triggeredAt...'); - const alertWithTriggeredAt = { - triggeredAt: 1640995200000, - lastUpdate: 1640995260000 - }; - const timestamp1 = alertManager.getValidTimestamp(alertWithTriggeredAt); - console.log(` Result: ${timestamp1} (should be ${alertWithTriggeredAt.triggeredAt})`); - if (timestamp1 !== alertWithTriggeredAt.triggeredAt) { - throw new Error('Should use triggeredAt when available'); - } - console.log('āœ… PASS'); - - console.log('\n2. Testing with missing triggeredAt (should use lastUpdate)...'); - const alertWithLastUpdate = { - lastUpdate: 1640995260000 - }; - const timestamp2 = alertManager.getValidTimestamp(alertWithLastUpdate); - console.log(` Result: ${timestamp2} (should be ${alertWithLastUpdate.lastUpdate})`); - if (timestamp2 !== alertWithLastUpdate.lastUpdate) { - throw new Error('Should use lastUpdate when triggeredAt is missing'); - } - console.log('āœ… PASS'); - - console.log('\n3. Testing with both timestamps missing (should use current time)...'); - const alertWithoutTimestamps = {}; - const before = Date.now(); - const timestamp3 = alertManager.getValidTimestamp(alertWithoutTimestamps); - const after = Date.now(); - console.log(` Result: ${timestamp3} (should be between ${before} and ${after})`); - if (timestamp3 < before || timestamp3 > after) { - throw new Error('Should use current time when both timestamps are missing'); - } - console.log('āœ… PASS'); - - console.log('\n4. Testing with invalid timestamps (should use current time)...'); - const alertWithInvalidTimestamps = { - triggeredAt: 'invalid-date', - lastUpdate: null - }; - const before2 = Date.now(); - const timestamp4 = alertManager.getValidTimestamp(alertWithInvalidTimestamps); - const after2 = Date.now(); - console.log(` Result: ${timestamp4} (should be between ${before2} and ${after2})`); - if (timestamp4 < before2 || timestamp4 > after2) { - throw new Error('Should use current time when timestamps are invalid'); - } - console.log('āœ… PASS'); - - console.log('\n5. Testing ISO string generation (the original error)...'); - const testTimestamps = [ - 1640995200000, // Valid timestamp - 'invalid-date', // Invalid string - null, // Null - undefined, // Undefined - NaN // NaN - ]; - - testTimestamps.forEach((testTs, index) => { - const testAlert = { triggeredAt: testTs }; - const validTs = alertManager.getValidTimestamp(testAlert); - try { - const isoString = new Date(validTs).toISOString(); - console.log(` Test ${index + 1}: ${testTs} → ${validTs} → ${isoString} āœ…`); - } catch (error) { - throw new Error(`Failed to generate ISO string for ${testTs}: ${error.message}`); - } - }); - console.log('āœ… PASS - No RangeError exceptions thrown'); - - console.log('\nšŸŽ‰ All Timestamp Validation Tests Passed!'); - console.log(' āœ… Valid timestamps are preserved'); - console.log(' āœ… Invalid timestamps fall back to current time'); - console.log(' āœ… ISO string generation never throws RangeError'); - console.log(' āœ… Teams webhook "Time Value Error" is completely fixed'); - - console.log('\nšŸ“ Summary:'); - console.log(' - The original bug was caused by undefined alert.timestamp'); - console.log(' - Our fix adds robust validation with proper fallbacks'); - console.log(' - The getValidTimestamp() method ensures valid dates always'); - console.log(' - Teams webhook notifications will now work reliably'); - - } catch (error) { - console.error('āŒ Test failed:', error.message); - process.exit(1); - } finally { - alertManager.destroy(); - } -} - -testTimestampValidation(); \ No newline at end of file diff --git a/webhook-integration-test.js b/webhook-integration-test.js deleted file mode 100644 index ee4cd4010..000000000 --- a/webhook-integration-test.js +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env node - -/** - * Webhook Integration Test - * This script tests the webhook functionality by simulating alert triggers - */ - -const axios = require('axios'); - -const PULSE_API_BASE = 'http://localhost:7655/api'; -const WEBHOOK_SERVER = 'http://localhost:3001/webhook'; - -async function testWebhookIntegration() { - console.log('šŸ” Testing Webhook Integration...\n'); - - try { - // 1. Check if Pulse server is running - console.log('1. Checking Pulse server status...'); - const healthResponse = await axios.get(`${PULSE_API_BASE}/health`); - console.log('āœ… Pulse server is running'); - - // 2. Check if webhook server is running - console.log('\n2. Checking webhook server status...'); - const webhookTestResponse = await axios.post(WEBHOOK_SERVER, { - test: true, - message: 'Integration test ping' - }); - console.log('āœ… Webhook server is responding'); - - // 3. Get current alert configuration - console.log('\n3. Fetching current alert configuration...'); - const alertsResponse = await axios.get(`${PULSE_API_BASE}/alerts`); - const alertData = alertsResponse.data; - - console.log(`šŸ“Š Alert System Status:`); - console.log(` - Active alerts: ${alertData.stats.active}`); - console.log(` - Total rules: ${alertData.stats.totalRules}`); - console.log(` - Webhook channel enabled: ${alertData.stats.channels.find(c => c.id === 'default')?.enabled}`); - - // 4. Test webhook using Pulse's built-in test endpoint - console.log('\n4. Testing webhook using Pulse API...'); - const testWebhookApiResponse = await axios.post(`${PULSE_API_BASE}/test-webhook`, { - url: WEBHOOK_SERVER, - enabled: true - }); - - if (testWebhookApiResponse.data.success) { - console.log('āœ… Webhook test via Pulse API succeeded'); - } else { - console.log('āŒ Webhook test via Pulse API failed:', testWebhookApiResponse.data.error); - } - - // 5. Test webhook payload format - console.log('\n5. Testing webhook payload format...'); - const testPayload = { - timestamp: new Date().toISOString(), - alert: { - id: "test_alert_" + Date.now(), - rule: { - name: "Webhook Integration Test", - description: "Test alert to verify webhook functionality", - severity: "warning", - metric: "cpu" - }, - guest: { - name: "test-webhook-guest", - id: "999", - type: "test", - node: "test-node", - status: "running" - }, - value: 92, - threshold: 85, - emoji: "āš ļø" - }, - embeds: [{ - title: "āš ļø Webhook Integration Test", - description: "Test alert to verify webhook functionality", - color: 15844367, - fields: [ - { - name: "Test Type", - value: "Integration Test", - inline: true - }, - { - name: "Status", - value: "SUCCESS", - inline: true - } - ], - footer: { - text: "Pulse Monitoring System - Test Mode" - } - }] - }; - - const testWebhookResponse = await axios.post(WEBHOOK_SERVER, testPayload, { - headers: { - 'Content-Type': 'application/json', - 'User-Agent': 'Pulse-Monitoring/1.0' - } - }); - - console.log('āœ… Webhook payload test successful'); - - console.log('\nšŸŽ‰ Webhook Integration Test Results:'); - console.log(' āœ… Pulse server: Running'); - console.log(' āœ… Webhook server: Running'); - console.log(' āœ… Alert system: Configured'); - console.log(' āœ… Webhook channel: Enabled'); - console.log(' āœ… Payload format: Valid'); - - console.log('\nšŸ“ Next Steps:'); - console.log(' 1. Monitor the test-webhook.js console for incoming webhooks'); - console.log(' 2. Check if alerts are triggered naturally by your system metrics'); - console.log(' 3. If needed, temporarily lower alert thresholds to test real alerts'); - console.log(' 4. Webhook URL configured in .env: http://localhost:3001/webhook'); - - } catch (error) { - console.error('āŒ Webhook integration test failed:', error.message); - - if (error.code === 'ECONNREFUSED') { - console.log('\nšŸ’” Troubleshooting:'); - console.log(' - Make sure both Pulse (port 7655) and test-webhook.js (port 3001) are running'); - console.log(' - Check that WEBHOOK_URL is set in .env file'); - } - } -} - -// Run the test -testWebhookIntegration(); \ No newline at end of file