Files
openobserve/tests/ui-testing/playwright-tests/cleanup.spec.js
T
Shrinath Rao 6650950a50 test(e2e/alpha1): fix share-link redirect origin and cloud metrics ingest auth (#13776)
## Why

The scheduled **Alpha1 (Cloud)** e2e run failed on three jobs
([o2-enterprise run
31547517666](https://github.com/openobserve/o2-enterprise/actions/runs/31547517666)):
**Logs-Features** (7), **Functions** (11), **RegressionSet** (4).
Root-caused each against a freshly-deployed alpha; two are genuine test
heals, one was pure environment skew.

## Root causes & fixes

### 1. Logs-Features — shareLink + monaco-query-prefill (7 tests) ✅
fixed
On cloud the app builds the share link from its **public** base URL
(`*.external.zinclabs.dev`), while the tests authenticate against the
ingress host (`*.internal.zinclabs.dev`). `page.goto(sharedUrl)`
navigated **cross-origin**, dropped the auth cookies, and bounced to Dex
— so every post-redirect state assertion read back `null`.

**Fix:** re-point the short URL's origin to `ZO_BASE_URL` in
`clickShareLinkAndGetUrl()` (right next to the existing HTTP→HTTPS
"maintain auth context" step). `/short/<id>` resolves identically on the
backend regardless of ingress host, so only the origin changes and the
session stays valid. Same-origin envs (localhost / matching deployed
host) are untouched.

### 2. RegressionSet — alerts Bug #9967 PromQL (1 test) ✅ fixed
`ingestMetricsData()` authenticated with `ZO_ROOT_USER_EMAIL:PASSWORD`,
but **cloud ingestion needs `email:passcode`**. The ingest silently
401'd → the `e2e_test_cpu_usage` metrics stream was never created → the
PromQL alert flow timed out selecting it.

**Fix:** build auth via `getAuthHeaders()` (passcode on cloud, root
creds on self-hosted), refresh the passcode from the live browser
session first, and poll until the stream is indexed so the wizard's
stream-select doesn't race WAL lag.

### 3. Functions — radio → segmented toggle (11 tests) — no change
needed
The page object was already migrated to the segmented toggle in #13766;
these failures were the **alpha frontend lagging the merged test code**.
Green after the redeploy with zero code change.

## Verification (against alpha, `auto_org_1`)
- `shareLink.spec.js` + `monaco-query-prefill.spec.js` → **11/11
passed**
- `alerts-regression.spec.js` (full) → **5/5 passed** (#9967, #10110,
#10899, #10872, #10472)
- `Functions/js-transform-type.spec.js` → **7/7**,
`row-expansion.spec.js` → green

## Scope
OSS-only (test files). The ENT `playwright_alpha1.yml` checks out
opensource at `main`, so merging makes the next scheduled run pick this
up. It can also be pre-verified by dispatching that workflow with
`o2_opensource_repo=test/alpha1-e2e-heals-0812`.
2026-08-12 06:35:48 +00:00

421 lines
27 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');
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_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
],
// 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_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)
],
// 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']);
// 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
[
/^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)
]
);
// 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 = [
/^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 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
];
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([
/^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(
[
/^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_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_*)
/^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>
],
// 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)
],
['default'], // protect the default traces stream
{ streamType: 'traces' }
);
// 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 test semantic groups created by correlation settings tests
// Groups: k8s-cluster, k8s-namespace, k8s-deployment, service
// These are created by ensureSemanticGroupsExist() in correlationSettingsPage.js
await pm.apiCleanup.cleanupCorrelationSettings();
// 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
);
// 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)")
]);
testLogger.info('Pre-test cleanup completed successfully');
});
});