Files
openobserve/tests/ui-testing/playwright-tests/cleanup.spec.js
T

504 lines
33 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { test } = require('./utils/enhanced-baseFixtures.js');
const PageManager = require('../pages/page-manager.js');
const testLogger = require('./utils/test-logger.js');
const { E2E_LOCATION_ID } = require('./utils/synthetics-helpers.js');
test.describe("Pre-Test Cleanup", () => {
/**
* This cleanup test runs before all UI integration tests
* It removes all test data from previous runs using API calls
* This ensures a clean state for all subsequent tests
*/
test('Clean up all test data via API', {
tag: ['@cleanup', '@all']
}, async ({ page }) => {
testLogger.info('Starting pre-test cleanup');
const pm = new PageManager(page);
// Run complete cascade cleanup for alert destinations, templates, and folders
await pm.apiCleanup.completeCascadeCleanup(
// Destination prefixes to clean up
[
'auto_',
'newdest_',
'sanitydest-',
'rbac_basic_dest_',
'rbac_editor_create_dest_',
'rbac_403_test_dest_',
'rbac_sql_dest_',
'rbac_user_delete_dest_',
'rbac_user_update_dest_',
'rbac_viewer_delete_dest_',
'rbac_viewer_update_dest_',
'incident_e2e_dest_',
'e2e_incid_', // alerts-incident-correlation.spec.js (incident correlation tests)
'e2e_promql_', // alerts-regression.spec.js (Bug #9967 PromQL tests)
'e2e_vrl_', // alerts-vrl-encoding.spec.js (VRL encoding tests)
'e2e_sched_', // alerts-scheduled-features.spec.js (scheduled alert tests)
'e2e_alert_11167_', // alerts-query-editor-search-endpoint.spec.js (#11167)
'e2e_metrics_', // alerts-metrics-notification.spec.js (metrics notification tests)
'e2e_alertfv_', // alerts-form-validation.spec.js (seeded prerequisite destinations)
'test_fv_alerts_dest_', // alerts-form-validation.spec.js (custom destinations created by the test cases)
'test_fv_alerts_slack_', // alerts-form-validation.spec.js (slack destination created by the test cases)
/^destination\d{1,3}$/, // destination4, destination44, destination444, etc.
'wf_auto_dest_', // Workflows v1 test destinations
'wf_auto_', // Workflows v1 generic test destinations
'pw_lib_dest_' // alert-library.spec.js (Alert Library e2e destinations)
],
// Template prefixes to clean up
[
'auto_',
'sanitytemp-',
'newtemp_',
'email_tmpl_',
'rbac_403_test_tmpl_',
'rbac_basic_tmpl_',
'rbac_del_tmpl_',
'rbac_editor_create_tmpl_',
'rbac_editor_update_tmpl_',
'rbac_sql_tmpl_',
'rbac_user_delete_tmpl_',
'rbac_viewer_delete_tmpl_',
'rbac_viewer_update_tmpl_',
'incident_e2e_template_',
'e2e_incid_', // alerts-incident-correlation.spec.js (incident correlation tests)
'e2e_promql_', // alerts-regression.spec.js (Bug #9967 PromQL tests)
'e2e_vrl_', // alerts-vrl-encoding.spec.js (VRL encoding tests)
'e2e_sched_', // alerts-scheduled-features.spec.js (scheduled alert tests)
'e2e_alert_11167_', // alerts-query-editor-search-endpoint.spec.js (#11167)
'e2e_metrics_', // alerts-metrics-notification.spec.js (metrics notification tests)
'e2e_alertfv_', // alerts-form-validation.spec.js (seeded prerequisite templates)
'test_fv_alerts_tmpl_', // alerts-form-validation.spec.js (templates created by the test cases)
'pw_lib_tmpl_' // alert-library.spec.js (Alert Library e2e templates)
],
// Folder prefixes to clean up
['auto_', 'incident_e2e_folder_', 'E2E Incidents ', 'E2E Scheduled ', 'wf_auto_']
// NOTE: 4th arg (workflowPrefixes) defaults to ['wf_auto_'] inside completeCascadeCleanup;
// STEP 5 there deletes workflows AFTER their linked alerts are removed (delete-protection).
);
// Clean up Workflows-feature functions & streams in the ACTIVE org (ORGNAME).
// Workflows E2E specs run in their own org; completeCascadeCleanup already handled
// alerts/destinations/folders/workflows there, but functions & streams need explicit sweeps.
const { getOrgIdentifier } = require('./utils/cloud-auth.js');
const activeOrg = getOrgIdentifier();
await pm.apiCleanup.cleanupFunctionsInOrg(activeOrg, [/^wf_auto_fn_/, /^wf_auto_/]);
await pm.apiCleanup.cleanupStreams([/^wf_auto_stream_/, /^wf_auto_sink_/], ['default']);
// metrics-14238-stale-nodata.spec.js seeds one METRICS stream per run, named with a
// timestamp so parallel runs cannot collide — which also means nothing ever reuses
// them. Harmless on CI's throwaway server, but they pile up on a shared dev env.
await pm.apiCleanup.cleanupStreams([/^e2e_14238_/], [], { streamType: 'metrics' });
// The logs coverage specs for #15086 each seed their own log stream, suffixed per run
// so parallel workers cannot collide — which also means nothing ever reuses them.
// logs-highlighting, logs-default-columns and logs-search-around-multistream.
await pm.apiCleanup.cleanupStreams(
[
/^e2e_hl_filters_/,
/^e2e_svc_cols_/,
/^e2e_svc_none_/,
/^e2e_sa_one_/,
/^e2e_sa_two_/,
],
['default'],
);
// Clean up all reports owned by automation user
await pm.apiCleanup.cleanupReports();
// Clean up all dashboards owned by automation user
// This includes: Joins_Test_* (dashboard joins parallel tests), and other test dashboards
await pm.apiCleanup.cleanupDashboards();
// Clean up all pipelines for e2e_automate streams
await pm.apiCleanup.cleanupPipelines(
// Stream names to match
[
'e2e_automate',
'e2e_automate1',
'e2e_automate2',
'e2e_automate3',
'e2e_conditions_validation_precedence_src',
'e2e_conditions_validation_nested_and_src',
'e2e_conditions_validation_nested_or_src',
'e2e_conditions_validation_numeric_src',
'e2e_conditions_validation_contains_src',
'e2e_conditions_validation_deep_src',
'e2e_conditions_basic',
'e2e_conditions_groups',
'e2e_conditions_validation',
'e2e_conditions_precedence',
'e2e_conditions_multiple',
'e2e_conditions_delete',
'e2e_conditions_operators'
],
// Source stream patterns to match
[
/^e2e_precedence_src_\d+$/,
/^e2e_multiple_or_src_\d+$/,
/^e2e_nested_or_src_\d+$/,
/^e2e_numeric_src_\d+$/,
/^e2e_multiple_and_src_\d+$/,
/^e2e_deep_src_\d+$/,
/^e2e_not_operator_src_\d+$/,
/^e2e_impossible_src_\d+$/,
/^e2e_universal_src_\d+$/,
/^e2e_4level_src_\d+$/,
/^simple_src_\d+$/,
/^manual_debug_src_/,
/^manual_verify_src_/
],
// Pipeline name patterns to match
[
/^e2e-12647-/, // pipeline-preview-bounds.spec.js (#12647)
/^e2e7030/, // pipeline-export.spec.js (#7030)
/^validation-precedence-\d+$/,
/^validation-multiple-or-\d+$/,
/^validation-nested-or-\d+$/,
/^validation-numeric-\d+$/,
/^validation-multiple-and-\d+$/,
/^validation-deep-nested-\d+$/,
/^validation-not-operator-\d+$/,
/^validation-impossible-\d+$/,
/^validation-universal-\d+$/,
/^validation-4level-\d+$/,
/^simple-test-\d+$/,
/^or-root-test-\d+$/,
/^manual-debug-pipeline-/,
/^manual-verify-pipeline-/,
/^scheurl\d+$/, // scheurl556, scheurl149, etc. (pipelineImport.spec.js)
/^schefile\d+$/, // schefile399, schefile971, etc. (pipelineImport.spec.js)
/^realurl\d+$/, // realurl822, etc. (pipelineImport.spec.js)
/^realfile\d+$/, // realfile123, etc. (pipelineImport.spec.js) - was missing!
/^metrics-pipeline-/, // metrics-pipeline-* (scheduled pipeline tests)
/^traces-pipeline-/, // traces-pipeline-* (scheduled pipeline tests)
/^condition-pipeline-/, // condition-pipeline-* (scheduled pipeline tests)
/^metrics-condition-pipeline-/, // metrics-condition-pipeline-* (scheduled pipeline tests)
/^e2e_backfill_test_\d+$/, // e2e_backfill_test_<timestamp> (pipeline-backfill.spec.js)
/^fn_e2e_pl_/, // functions-import-export.spec.js (pipeline holding an imported function)
/^pl_bundle_/, // pipeline-function-bundling.spec.js (exported and re-imported pipelines)
/^ui_auto_pfb_/ // pipeline-function-bundling-rbac.spec.js (enterprise shard)
]
);
// Clean up pipeline destinations matching test patterns
await pm.apiCleanup.cleanupPipelineDestinations([
/^destination\d{1,3}$/ // destination4, destination44, destination444, etc.
]);
// Clean up functions matching test patterns
// Patterns from sanity/pipeline tests (default org only)
const sanityFunctionPatterns = [
/^e2e_2812_/, // function-delete-confirm.spec.js (#2812)
/^Pipeline\d{1,3}$/, // Pipeline1, Pipeline12, Pipeline123
/^first\d{1,3}$/, // first0, first1, first99
/^second\d{1,3}$/, // second0, second1, second99
/^sanitytest_/, // sanitytest_a3f2, etc.
/^e2eautomatefunctions_/, // e2eautomatefunctions_x9y2, etc.
/^vrl_func_/, // vrl_func_* (pipeline-core.spec.js VRL function tests)
/^vrl_traces_func_/, // vrl_traces_func_* (pipeline VRL function tests for traces)
/^vrl_metrics_func_/ // vrl_metrics_func_* (pipeline VRL function tests for metrics)
];
// Patterns from Functions folder tests (js-transform-type.spec.js)
const jsFunctionPatterns = [
/^test_js_fn_/, // JS function creation tests
/^test_js_validate_/, // JS validation tests
/^test_js_exec_/, // JS execution tests
/^test_js_error_/, // JS error handling tests
/^test_js_syntax_err_/, // JS syntax error tests
/^test_js_empty_/, // JS empty function tests
/^meta_js_fn_/, // Meta org JS function tests
/^default_vrl_fn_/ // Default org VRL function tests
];
// Patterns from the function import/export specs
// (Functions/functions-import-export.spec.js and
// RegressionSet/Pipelines/function-import-non-object-entry.spec.js)
const importExportFunctionPatterns = [
/^fn_e2e_/, // imported, round-tripped and renamed functions
/^fn_export_/, // single, bulk and narrow-viewport export fixtures
/^fn_clash_/, // seeded functions used to provoke a name clash
/^fn_regr_nonobj_/, // non-object entry repaired by the inline fixers
/^fn_regr_reject_/, // rejections that cannot be fixed inline (#15069)
/^fn_bundle_/, // pipeline-function-bundling.spec.js (bundled functions and their _N copies)
/^ui_auto_pfb_/ // pipeline-function-bundling-rbac.spec.js (enterprise shard)
];
// Patterns from Functions folder tests (row-expansion.spec.js)
const rowExpansionPatterns = [
/^vrl_row_expand_/, // VRL row expansion tests
/^js_row_expand_/, // JS row expansion tests
/^vrl_empty_expand_/, // VRL empty expansion tests
/^js_empty_expand_/, // JS empty expansion tests
/^vrl_single_expand_/, // VRL single element tests
/^js_single_expand_/, // JS single element tests
/^js_complex_expand_/, // JS complex transformation tests
/^vrl_compare_/, // VRL comparison tests
/^js_compare_/, // JS comparison tests
/^pipeline_expand_fn_/, // Pipeline integration tests
/^invalid_expand_/ // Invalid expansion tests
];
// Clean up functions in default org (sanity tests + VRL functions from Functions folder)
const defaultOrgPatterns = [
...sanityFunctionPatterns,
...jsFunctionPatterns, // default_vrl_fn_* created in default org
...rowExpansionPatterns, // vrl_* patterns created in default org
...importExportFunctionPatterns // fn_* patterns from the import/export specs
];
await pm.apiCleanup.cleanupFunctionsInOrg('default', defaultOrgPatterns);
// Clean up functions in _meta org (JS functions only work there)
const metaOrgFunctionPatterns = [
...jsFunctionPatterns, // test_js_*, meta_js_fn_* created in _meta org
...rowExpansionPatterns // js_* patterns created in _meta org
];
await pm.apiCleanup.cleanupFunctionsInOrg('_meta', metaOrgFunctionPatterns);
// Clean up file-based enrichment tables matching test patterns
// These are tables uploaded via file and tracked in /api/{org}/streams?type=enrichment_tables
await pm.apiCleanup.cleanupFileEnrichmentTables([
/^e2e_2937_/, // enrichment-lifecycle.spec.js (#2937)
/^e2e_2067_/, // enrichment-lifecycle.spec.js (#2067)
/^e2e_enrich_/, // enrichment-explore-context.spec.js (#7346, #6645)
/^protocols_[a-f0-9]{8}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{12}_csv$/, // protocols_<uuid>_csv (VRL test)
/^enrichment_info_[a-f0-9]{8}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{12}_csv$/, // enrichment_info_<uuid>_csv (upload test)
/^append_[a-f0-9]{8}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{12}_csv$/, // append_<uuid>_csv (append test)
/^search_test_[a-f0-9]{8}/, // search_test_<uuid>* (search filter test - matches both old short and new full UUID patterns)
/^edit_test_[a-f0-9]{8}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{12}_csv$/, // edit_test_<uuid>_csv (edit workflow test)
/^delete_test_[a-f0-9]{8}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{4}_[a-f0-9]{12}_csv$/, // delete_test_<uuid>_csv (delete confirmation test)
// URL-based enrichment table tests (enrichment-table-url.spec.js) - uses UUID first segment (8 hex chars)
/^url_lifecycle_[a-f0-9]{8}$/, // url_lifecycle_<uuid> (full lifecycle test)
/^invalid_url_[a-f0-9]{8}$/, // invalid_url_<uuid> (URL format validation test)
/^cancel_test_[a-f0-9]{8}$/, // cancel_test_<uuid> (cancel form test)
/^toggle_test_[a-f0-9]{8}$/, // toggle_test_<uuid> (source toggle test)
/^edit_form_[a-f0-9]{8}$/, // edit_form_<uuid> (edit form test)
/^schema_view_[a-f0-9]{8}$/, // schema_view_<uuid> (schema view test, legacy prefix)
/^view_schema_[a-f0-9]{8}$/, // view_schema_<uuid> (schema view test — renamed: "schema" prefix hits backend not-an-ingester bug)
/^duplicate_test_[a-f0-9]{8}$/, // duplicate_test_<uuid> (duplicate name test)
/^empty_url_[a-f0-9]{8}$/, // empty_url_<uuid> (empty URL validation test)
/^url_404_[a-f0-9]{8}$/, // url_404_<uuid> (invalid URL 404 test)
/^schema_mismatch_[a-f0-9]{8}$/, // schema_mismatch_<uuid> (schema mismatch test, legacy prefix)
/^mismatch_schema_[a-f0-9]{8}$/, // mismatch_schema_<uuid> (schema mismatch test — renamed off "schema" prefix)
// Pytest API tests (test_enrichment_table_url.py) - uses api_url_<test>_<uuid8> naming
/^api_url_create_[a-f0-9]{8}$/, // api_url_create_<uuid> (create test)
/^api_url_status_[a-f0-9]{8}$/, // api_url_status_<uuid> (status test)
/^api_url_delete_[a-f0-9]{8}$/, // api_url_delete_<uuid> (delete test)
/^api_url_empty_[a-f0-9]{8}$/, // api_url_empty_<uuid> (empty URL test)
/^api_url_scheme_[a-f0-9]{8}$/, // api_url_scheme_<uuid> (invalid scheme test)
/^api_url_localhost_[a-f0-9]{8}$/, // api_url_localhost_<uuid> (localhost test)
/^api_url_private_[a-f0-9]{8}$/, // api_url_private_<uuid> (private IP test)
/^api_url_aws_[a-f0-9]{8}$/, // api_url_aws_<uuid> (AWS metadata test)
/^api_url_404_[a-f0-9]{8}$/, // api_url_404_<uuid> (404 error test)
/^api_url_append_[a-f0-9]{8}$/, // api_url_append_<uuid> (append test)
/^api_url_retry_[a-f0-9]{8}$/, // api_url_retry_<uuid> (retry test)
/^api_url_schema_[a-f0-9]{8}$/, // api_url_schema_<uuid> (schema mismatch test)
/^api_test_manual_\d+$/, // api_test_manual_<timestamp> (manual curl tests)
// o2-enterprise RBAC enrichment table tests
/^editor_create_test_[a-f0-9]+$/, // editor_create_test_<hash> (RBAC editor tests)
/^enrich_basic_[a-f0-9]+$/, // enrich_basic_<hash> (RBAC basic enrichment tests)
/^enrich_duplicate_[a-f0-9]+$/, // enrich_duplicate_<hash> (RBAC duplicate tests)
/^enrich_invalid_[a-f0-9]+$/, // enrich_invalid_<hash> (RBAC invalid tests)
/^enrich_protocols_[a-f0-9]+$/, // enrich_protocols_<hash> (RBAC protocols tests)
/^enrich_table_[a-f0-9]+$/, // enrich_table_<hash> (RBAC table tests)
/^enrich_update_append_[a-f0-9]+$/, // enrich_update_append_<hash> (RBAC update append tests)
/^enrich_update_replace_[a-f0-9]+$/, // enrich_update_replace_<hash> (RBAC update replace tests)
/^viewer_created_et_[a-f0-9]+$/, // viewer_created_et_<hash> (RBAC viewer create ET tests - test_basic_rbac.py:653)
/^partial_access_et_[a-f0-9]+$/, // partial_access_et_<hash> (RBAC partial access ET tests - test_basic_rbac.py:793)
/^health_check_[a-f0-9]+$/ // health_check_<hash> (scheduled health check tables - orphaned)
]);
// Clean up URL-based enrichment tables (those showing "NaN MB" in UI)
// These are tracked separately in /api/{org}/enrichment_tables/status
await pm.apiCleanup.cleanupUrlEnrichmentTables([
/^schema_mismatch_[a-f0-9]{8}$/, // schema_mismatch_<uuid> (schema mismatch URL tests, legacy prefix)
/^mismatch_schema_[a-f0-9]{8}$/, // mismatch_schema_<uuid> (schema mismatch URL tests, renamed)
/^schema_view_[a-f0-9]{8}$/, // schema_view_<uuid> (schema view URL tests, legacy prefix)
/^view_schema_[a-f0-9]{8}$/, // view_schema_<uuid> (schema view URL tests, renamed)
/^url_404_[a-f0-9]{8}$/, // url_404_<uuid> (404 error URL tests)
/^url_lifecycle_[a-f0-9]{8}$/, // url_lifecycle_<uuid> (lifecycle URL tests)
/^invalid_url_[a-f0-9]{8}$/, // invalid_url_<uuid> (invalid URL tests)
/^cancel_test_[a-f0-9]{8}$/, // cancel_test_<uuid> (cancel URL tests)
/^toggle_test_[a-f0-9]{8}$/, // toggle_test_<uuid> (toggle URL tests)
/^edit_form_[a-f0-9]{8}$/ // edit_form_<uuid> (edit form URL tests)
]);
// Clean up streams matching test patterns
await pm.apiCleanup.cleanupStreams(
[
/^e2e_slo_14269_/, // slo-error-messages.spec.js (#14269) seeded stream
/^cloud_api_smoke$/, // Cloud/cloudApiSmoke.spec.js seed stream (re-seeded each run)
/^e2e_13354_/, // logs-field-value-rendering.spec.js (#13354)
/^e2e_13896_/, // logs-result-display.spec.js (#13896)
/^e2e_13990_other_/, // logs-bugs.spec.js (#13990)
/^e2e_sev_str_/, // logs-histogram-severity.spec.js (#11353)
/^e2e_sev_num_/, // logs-histogram-severity.spec.js (#11441)
/^e2e_ms7332_/, // logs-multistream-share-url.spec.js (#7332)
/^e2e_12647_dest_/, // pipeline-preview-bounds.spec.js (#12647) destination stream
/^e2e7030[a-z0-9]+-(alpha|beta)_dest$/, // pipeline-export.spec.js (#7030) destination streams
/^e2e_10602_/, // logs-v040-limit-and-stream-list.spec.js (#10602)
/^sanitylogstream_/, // sanitylogstream_61hj, etc.
/^test\d+$/, // test1, test2, test3, etc.
/^stress_test/, // stress_test*, stress_test_<runId>_w0, stress_test1, etc.
/^sdr_/, // sdr_* (SDR logs test streams; traces SDR streams are swept separately by type below)
/^e2e_join_/, // e2e_join_* (UNION test streams)
/^e2e_conditions_/, // e2e_conditions_* (Pipeline conditions UI test streams)
/^e2e_apostrophe_/, // e2e_apostrophe_* (Bug #9475 apostrophe test streams from logs-regression.spec.js)
/^e2e_highlighting_test$/, // e2e_highlighting_test (Bug #9754 logs highlighting test stream from logs-9754.spec.js)
/^e2e_streamcreation_/, // e2e_streamcreation_* (Stream creation UI test streams)
/^e2e_qp_more_stream_/, // e2e_qp_more_stream_* (logsQuickPick.spec.js more-footer seed streams)
/^e2e_MyUpperStream/i, // e2e_MyUpperStream* (Stream name casing test streams)
/^e2e_mylowerstream/i, // e2e_mylowerstream* (Stream name casing test streams)
/^[a-z]{8,9}$/, // Random 8-9 char lowercase strings
/^e2e_cond_prec_(src|dest)_\d+$/, // Test 1: Operator precedence test streams
/^e2e_multiple_or_(src|dest)_\d+$/, // Test 2: Multiple OR test streams
/^e2e_nested_or_(src|dest)_\d+$/, // Test 3: Nested OR test streams
/^e2e_numeric_(src|dest)_\d+$/, // Test 4: Numeric comparison test streams
/^e2e_multiple_and_(src|dest)_\d+$/, // Test 5: Multiple AND test streams
/^e2e_deep_(src|dest)_\d+$/, // Test 6: Deeply nested test streams
/^e2e_not_operator_(src|dest)_\d+$/, // Test 7: NOT operator test streams
/^e2e_impossible_(src|dest)_\d+$/, // Test 8: Impossible condition test streams
/^e2e_universal_(src|dest)_\d+$/, // Test 9: Universal condition test streams
/^e2e_4level_(src|dest)_\d+$/, // Test 10: 4-level nested test streams
/^stream\d{13}$/, // stream1765164273471, etc. (timestamp-based test streams)
/^e2e_http_patterns/, // Pattern tests stream (searchPatterns.spec.js) — prefix covers the unique per-run e2e_http_patterns_<token> names
/^e2e_multi_patterns/, // Multi-stream patterns guard streams (searchPatternsMultiStream.spec.js)
/^e2e_stream_(a|b)_\d+$/, // Regression test streams (e2e_stream_a_*, e2e_stream_b_*)
/^join_[a-z0-9]+_(requests|users|sessions)$/, // Dashboard joins test streams (join_<testId>_requests, etc.)
/^join_[a-z0-9]+_[a-z0-9]+_(requests|users|sessions)$/, // Dashboard joins test streams with extra segment (join_<id1>_<id2>_requests, etc.)
/^func_test_[a-z0-9]+$/, // Dashboard functions test streams (func_test_<testId>)
/^join_manual_test$/, // Manual join test stream
/^test_app_users$/, // Test app users stream
/^test_sessions$/, // Test sessions stream
/^test_web_requests$/, // Test web requests stream
/^alert_trigger_validation$/, // Alert trigger validation stream (self-referential POC)
/^alert_val_[a-zA-Z0-9]+$/, // Unique validation streams per test (alert_val_<suffix>)
/^severity_test_\d+$/, // Severity test streams (severity_test_<timestamp>)
/^alert_e2e_/, // Alert e2e test streams (alert_e2e_*)
/^alert_import_/, // Alert import test streams (alert_import_*)
/^alert_chart_missing_/, // Alert chart error-state test streams (alerts-chart-error-state.spec.js #14519)
/^dedup_test_/, // Dedup test streams (dedup_test_*)
/^dedup_src_/, // Dedup source streams (dedup_src_*)
/^alert_validation_stream$/, // Alert validation stream
/^auto_pw_stream_/, // Per-run alerts-ui-operations streams (auto_pw_stream_<suffix>)
/^incident_e2e_/, // Incident e2e test streams (incident_e2e_*)
/ellipsis_testing/, // Bug #7468 ellipsis test streams (long stream names)
/^e2e_test_cpu_usage$/, // Pipeline regression test metrics stream (Issue #9901)
/^e2e_test_traces$/, // Pipeline regression test traces stream (Issue #9901)
/^e2e_traces_pipeline_test$/, // Pipeline test traces stream
/^e2e_traces_\d+_[a-z0-9]+$/, // Dynamic traces streams (e2e_traces_<timestamp>_<suffix>)
/^backfill_source_\d+$/, // Backfill source streams (backfill_source_<number>)
/^backfill_dest_\d+$/, // Backfill dest streams (backfill_dest_<number>)
/^e2e_backfill_dest_\d+$/, // e2e_backfill_dest_<timestamp> (pipeline-backfill.spec.js)
/^e2e_time_test_\d+$/, // e2e_time_test_<timestamp>
/^pw_lib_(ready|absent)_/, // alert-library.spec.js (Alert Library e2e readiness streams)
/^e2e_panel_notices_/ // panelNotices.spec.js (high-cardinality series-cap streams)
],
// Protected streams to never delete
['default', 'sensitive', 'important', 'critical', 'production', 'staging', 'automation', 'e2e_automate', 'k8s_json']
);
// Clean up TRACES streams created by the traces SDR suite (sdr_traces_* — one
// per run, unique testRunId suffix). These are type=traces, so the logs sweep
// above (type=logs) never lists them; sweep them with streamType: 'traces'.
await pm.apiCleanup.cleanupStreams(
[
/^sdr_traces_/, // sdr_traces_* (traces SDR test streams: redact/drop/hash × ingestion/query)
/^trace_genai_parts_/, // trace_genai_parts_* (GenAI v5 parts rendering test streams)
/^e2e_prof_trace_/, // Profiles/profiles-navigation-entry.spec.js linked-span traces stream
],
['default'], // protect the default traces stream
{ streamType: 'traces' }
);
// Profiles specs delete their e2e_prof_* streams in afterAll; this sweeps what a crashed run left behind.
await pm.apiCleanup.cleanupStreams([/^e2e_prof_/], ['default'], { streamType: 'profiles' });
// Note: Pipeline regression test streams (e2e_test_cpu_usage for metrics, e2e_test_traces for traces)
// are created by pipeline-regression.spec.js for Issue #9901 regression tests.
// Custom traces stream uses "stream-name" header (ZO_GRPC_STREAM_HEADER_KEY config).
// Since streams are re-used with fresh timestamps each test run, cleanup is not strictly required.
// Clean up all service accounts matching pattern "email*@gmail.com"
await pm.apiCleanup.cleanupServiceAccounts();
// Clean up all users matching patterns "email*@gmail.com" and "duplicate*@gmail.com"
await pm.apiCleanup.cleanupUsers();
// Clean up regex patterns matching test data
await pm.apiCleanup.cleanupRegexPatterns();
// Clean up custom logo from _meta organization
await pm.apiCleanup.cleanupLogo();
// Clean up all search jobs
await pm.apiCleanup.cleanupSearchJobs();
// Clean up saved views matching test patterns
await pm.apiCleanup.cleanupSavedViews();
// Clean up metrics streams matching test patterns
// Metrics tests use OTLP ingestion which may create test-specific streams
await pm.apiCleanup.cleanupMetricsStreams(
[
/^test_.*_metrics$/, // test_*_metrics streams (general test streams)
/^e2e_metrics_/, // e2e_metrics_* (E2E test streams)
/^otlp_test_/, // otlp_test_* (OTLP ingestion test streams)
/^metrics_test_/, // metrics_test_* (Metrics-specific test streams)
/^prom_test_/, // prom_test_* (Prometheus test streams)
/^temp_metrics_/ // temp_metrics_* (Temporary test streams)
],
// Protected metrics streams - never delete
['default', 'e2e_test_metrics'] // 'default' is the primary metrics stream, 'e2e_test_metrics' used by scheduled-pipeline-query-builder.spec.js
);
// Note: Stream deletion waiting is no longer needed here because:
// 1. Pipeline conditions tests now use worker-specific stream names (e.g., e2e_conditions_basic_<runId>_w0)
// 2. Schemaload/stress tests now use unique stream names (e.g., stress_test_<runId>_w0)
// This avoids conflicts both within a test run (parallelIndex) and across test runs (testRunId)
// The cleanup patterns above will clean up old test streams via regex matching
// Clean up service graph test screenshots
const path = require('path');
const screenshotDir = path.join(__dirname, '..', 'test-results', 'screenshots');
await pm.apiCleanup.cleanupScreenshots(
['service-graph-', 'tree-view-', 'graph-view-', 'graph-debug'],
screenshotDir
);
// The shared location is named explicitly because per-worker cleanup never removes it
await pm.apiCleanup.cleanupSynthetics(['synth_e2e_'], { locationIds: [E2E_LOCATION_ID] });
// Clean up model pricing test records (mp_* names and cloned built-in "(Copy)" org models)
await pm.apiCleanup.cleanupModelPricingModels([
'mp_', // all test models created by model-pricing.spec.js
'E2E Pricing Verifier ', // cost-verification models (Journeys 12/13)
/^.+\s\(Copy\)$/ // cloned built-in models (source=org, name ends with " (Copy)")
]);
// IAM leftovers from a CRASHED run: roles, groups, users and service accounts under
// the `ui_auto` prefix the IAM specs use.
//
// This is the ONLY place that sweeps them. Each IAM spec now deletes exactly what it
// created (makeTracker in IAM/iam-fixtures.js) rather than everything matching the
// prefix — doing the latter in every spec's beforeAll is what had them deleting each
// other's fixtures mid-test and flaking the ENT crosscheck gate. A sweep is still
// needed for artifacts an aborted run orphaned, but it belongs here, once, before
// anything else starts.
//
// Enterprise-only (rbac_enabled): on an OSS build /roles answers 4xx, so this skips
// quietly rather than failing the cleanup every other suite depends on.
await pm.apiCleanup.cleanupIamArtifacts('ui_auto');
// Fleet management leftovers (Fleet/*.spec.js); enterprise-only, quiet on OSS.
await pm.apiCleanup.cleanupFleetArtifacts(['fl_auto_'], ['fl-auto-']);
testLogger.info('Pre-test cleanup completed successfully');
});
});