mattermost-mobile-upstream/detox/e2e/support/classification_test_helper.ts
yasser khan f3af9dbe99
Fix/detox hittest cluster (#10023)
fix(e2e): stabilize Detox and Maestro test suite

Restore main features, and harden the E2E harness against flaky UI, network, retry, synchronization, and classification-lock failures.

Stabilize channel creation, saved messages, bookmarks, search, deep links, keyboard dismissal, and post verification.
Bound network, transport, health-check, synchronization, and lock retries by elapsed time.
Fix iOS and Android Maestro/Detox races and flaky interaction flows.
Restore Session Attributes and deep-link fixes lost during merge.
Improve test isolation, global-setting cleanup, and Jest/TSIO reporting.
Enforce Maestro flow-header validation in local and CI checks.
2026-08-27 08:58:03 +05:30

63 lines
2.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import System from '@support/server_api/system';
import {timeouts} from '@support/utils';
const FLAG_PATCH_ATTEMPTS = 3;
const observedFlagValues = async (baseUrl: string) => {
const {config: serverConfig} = await System.apiGetConfig(baseUrl);
const {config: clientConfig} = await System.apiGetClientConfigOld(baseUrl);
return {
server: serverConfig?.FeatureFlags?.ClassificationMarkings,
client: clientConfig?.FeatureFlagClassificationMarkings,
};
};
export const enableClassificationMarkings = async (baseUrl: string): Promise<void> => {
// Idempotent flag patch. CI cloud often drops the TCP response (axios 30s → status 0).
let lastObserved: {server?: unknown; client?: unknown} = {};
/* eslint-disable no-await-in-loop -- sequential re-patch until client config catches up */
for (let attempt = 1; attempt <= FLAG_PATCH_ATTEMPTS; attempt++) {
// No transport-retry wrapper here: apiPatchConfig already retries the patch
// internally, and this loop re-patches on top of that. Stacking a third layer
// is what let a single stalled request consume a whole 300s hook budget.
const patchResult = await System.apiPatchConfig(baseUrl, {
FeatureFlags: {
ClassificationMarkings: true,
},
});
if (patchResult.error) {
throw new Error(`enableClassificationMarkings: failed to patch server config: ${JSON.stringify(patchResult.error)}`);
}
const enabled = await System.waitForClientConfigFlag(
baseUrl,
'FeatureFlagClassificationMarkings',
'true',
{maxAttempts: 30, pollMs: timeouts.ONE_SEC},
);
if (enabled) {
return;
}
lastObserved = await observedFlagValues(baseUrl);
// eslint-disable-next-line no-console
console.warn(
`[enableClassificationMarkings] attempt ${attempt}/${FLAG_PATCH_ATTEMPTS} ` +
`server=${String(lastObserved.server)} client=${String(lastObserved.client)}`,
);
}
/* eslint-enable no-await-in-loop */
throw new Error(
'enableClassificationMarkings: FeatureFlagClassificationMarkings did not become true. ' +
`Last observed server=${String(lastObserved.server)} client=${String(lastObserved.client)}. ` +
'Either the server license or configuration blocks this feature flag, or another ' +
'suite turned it off concurrently — classification suites must never unset it ' +
'(see the invariant in global_classification_banner.e2e.ts).',
);
};