toBe('95th Percentile|nth_percentile:95:traffic_in:aggregate_current'); }); test('COMMENT pipeline: SIMILAR max produces aggregate_current_peak', function () { $input = '95th Percentile|nth_percentile:95:traffic_in:max'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('95th Percentile|nth_percentile:95:traffic_in:aggregate_current_peak'); }); test('COMMENT pipeline: ALL current produces aggregate_sum', function () { $input = '95th Percentile|nth_percentile:95:traffic_in:current'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_ALL); expect($result)->toBe('95th Percentile|nth_percentile:95:traffic_in:aggregate_sum'); }); test('COMMENT pipeline: ALL max produces aggregate_sum_peak', function () { $input = '95th Percentile|nth_percentile:95:traffic_in:max'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_ALL); expect($result)->toBe('95th Percentile|nth_percentile:95:traffic_in:aggregate_sum_peak'); }); // --- HRULE pipeline: same replacement pattern --- test('HRULE pipeline: SIMILAR current produces aggregate_current', function () { $input = '#FF5722|nth_percentile:95:traffic_out:current'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('#FF5722|nth_percentile:95:traffic_out:aggregate_current'); }); test('HRULE pipeline: SIMILAR max produces aggregate_current_peak', function () { $input = '#FF5722|nth_percentile:95:traffic_out:max'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('#FF5722|nth_percentile:95:traffic_out:aggregate_current_peak'); }); test('HRULE pipeline: ALL max produces aggregate_sum_peak', function () { $input = '#FF5722|nth_percentile:95:traffic_out:max'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_ALL); expect($result)->toBe('#FF5722|nth_percentile:95:traffic_out:aggregate_sum_peak'); }); // --- SIMILAR must never produce summed values --- test('SIMILAR COMMENT never produces aggregate_sum for current', function () { $input = '95th Percentile|nth_percentile:95:traffic_in:current'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->not->toContain('aggregate_sum:') ->and($result)->not->toContain(':aggregate_sum'); }); test('SIMILAR HRULE never produces aggregate_sum_peak for max', function () { $input = '#FF5722|nth_percentile:95:traffic_in:max'; $result = process_ptile_pparts($input, AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->not->toContain('aggregate_sum_peak'); }); // --- text_format pipeline: full string with ISP billing context --- test('text_format: SIMILAR with :current: in bandwidth label', function () { $result = process_text_format('95th In :current: bps', AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('95th In :aggregate_current: bps'); }); test('text_format: SIMILAR with :max: in bandwidth label', function () { $result = process_text_format('95th Peak :max: bps', AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('95th Peak :aggregate_current_peak: bps'); }); test('text_format: ALL with :current: in bandwidth label', function () { $result = process_text_format('95th Total :current: bps', AGGREGATE_TOTAL_TYPE_ALL); expect($result)->toBe('95th Total :aggregate_sum: bps'); }); test('text_format: ALL with :max: produces aggregate_sum_peak not aggregate_sum', function () { // This is the secondary fix: ALL+max was using aggregate_sum instead of // aggregate_sum_peak, mismatching the COMMENT/HRULE paths $result = process_text_format('95th Peak :max: bps', AGGREGATE_TOTAL_TYPE_ALL); expect($result)->toBe('95th Peak :aggregate_sum_peak: bps') ->and($result)->not->toContain(':aggregate_sum:'); }); // --- Edge cases --- test('pparts with no pipe delimiter returns unchanged', function () { $result = process_ptile_pparts('no pipes here', AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('no pipes here'); }); test('pparts with fewer than 4 colon parts returns unchanged', function () { $result = process_ptile_pparts('label|nth_percentile:95:traffic_in', AGGREGATE_TOTAL_TYPE_SIMILAR); expect($result)->toBe('label|nth_percentile:95:traffic_in'); }); test('unknown total type leaves pparts unchanged', function () { $input = '95th Percentile|nth_percentile:95:traffic_in:current'; $result = process_ptile_pparts($input, 99); expect($result)->toBe($input); }); test('unknown total type leaves text_format unchanged', function () { $result = process_text_format('95th :current: bps', 99); expect($result)->toBe('95th :current: bps'); }); // --- Inbound vs Outbound: verify both data sources handled independently --- test('SIMILAR handles traffic_in and traffic_out independently', function () { $in_result = process_ptile_pparts('In|nth_percentile:95:traffic_in:current', AGGREGATE_TOTAL_TYPE_SIMILAR); $out_result = process_ptile_pparts('Out|nth_percentile:95:traffic_out:current', AGGREGATE_TOTAL_TYPE_SIMILAR); expect($in_result)->toBe('In|nth_percentile:95:traffic_in:aggregate_current') ->and($out_result)->toBe('Out|nth_percentile:95:traffic_out:aggregate_current') ->and($in_result)->not->toBe($out_result); });