const { extractJobIdFromFileName, getSupportedPatterns } = require('./helpers/satloc_util'); /** * Test Job ID extraction from various filename patterns * Covers all supported SatLoc naming conventions */ function testJobIdExtraction() { console.log('=== Testing Job ID Extraction from Filenames ===\n'); // Test cases: [filename, expectedJobId, description] const testCases = [ // Pattern 1: JOB prefix ['JOB146 HK4704.log', '146', 'Direct JOB prefix pattern'], ['JOB789_field1.log', '789_field1', 'JOB prefix with underscore (captures full jobId)'], ['job123.log', '123', 'Lowercase job prefix'], // Pattern 2: [10 digits yymmddhhmm][separator][jobId] for Falcon/G4 ['2507140724SatlocG4_b4ef.log', 'b4ef', 'Falcon G4 with timestamp and underscore'], ['2507140724SatlocG4_test123.log', 'test123', 'Falcon G4 with alphanumeric jobId'], ['2507140724_myJob.log', 'myJob', 'Timestamp with underscore separator'], // Pattern 3: [8 digits date]_JOB[jobId] for Bantom2 system ['20250915_JOB789.log', '789', 'Bantom2 date prefix with JOB'], ['20231201_JOBfield1.log', 'field1', 'Bantom2 with alphanumeric jobId'], // Pattern 4: [10 digits with space] [jobId] for Falcon system ['2025091512 CROP001.log', 'CROP001', 'Falcon with space separator'], ['2507140724 TestJob.log', 'TestJob', 'Timestamp with space and jobId'], // Pattern 5: Falcon [jobId]-Log* format (loosened pattern) ['150-12-06-2025-Log_251209_0.log', '150-12-06-2025', 'Falcon job with Log suffix'], ['150-12-06-2025-Log.log', '150-12-06-2025', 'Falcon job with just -Log'], ['150-12-06-2025-Log', '150-12-06-2025', 'Falcon job with just -Log without extension'], ['MyJob-123-LogExtra.log', 'MyJob-123', 'Custom job with -LogExtra'], ['ABC-01-02-2025-Log_999999_5.log', 'ABC-01-02-2025', 'Alphanumeric prefix with date'], // Pattern 6: Falcon jobId only (date-like pattern) ['150-12-06-2025.log', '150-12-06-2025', 'Falcon job ID only'], ['999-01-01-2024.log', '999-01-01-2024', 'Another date-like job ID'], // Edge cases - should return null ['Liquid_IF2_G4.log', null, 'No recognizable job ID pattern'], ['NoJobId.log', null, 'Simple filename without pattern'], ['random_data.log', null, 'Random filename'], ['12345.log', null, 'Just numbers (not 10 digits)'], ]; let passed = 0; let failed = 0; for (const [filename, expectedJobId, description] of testCases) { const extractedJobId = extractJobIdFromFileName(filename); const isMatch = extractedJobId === expectedJobId; if (isMatch) { passed++; console.log(`✅ PASS: "${filename}"`); console.log(` → Expected: ${expectedJobId === null ? 'null' : `"${expectedJobId}"`}, Got: ${extractedJobId === null ? 'null' : `"${extractedJobId}"`}`); console.log(` → ${description}\n`); } else { failed++; console.log(`❌ FAIL: "${filename}"`); console.log(` → Expected: ${expectedJobId === null ? 'null' : `"${expectedJobId}"`}, Got: ${extractedJobId === null ? 'null' : `"${extractedJobId}"`}`); console.log(` → ${description}\n`); } } console.log('='.repeat(50)); console.log(`\n📊 Results: ${passed} passed, ${failed} failed out of ${testCases.length} tests\n`); // Print supported patterns for reference console.log('📋 Supported Filename Patterns:'); const patterns = getSupportedPatterns(); patterns.forEach((p, i) => { console.log(` ${i + 1}. ${p.name}`); console.log(` Format: ${p.format}`); console.log(` Example: ${p.example}`); }); console.log('\n📋 Priority Order:'); console.log(' 1. Job ID from filename (if valid and non-null)'); console.log(' 2. jobLongLabelName from SWATHING_SETUP_120 record'); console.log(' 3. satlocJobId from JOB_INFO_STRING_151 or JOB_INFO_NAME_STRING_152'); console.log(' 4. "unknown" (fallback)'); // Exit with error code if any test failed if (failed > 0) { console.log(`\n⚠️ ${failed} test(s) failed!`); process.exit(1); } else { console.log('\n✅ All tests passed!'); process.exit(0); } } // Run tests testJobIdExtraction();