mattermost-mobile-upstream/detox/provision/provision.ts
yasser khan 75a3cf2bf5
Some checks are pending
ci / lint-typecheck (push) Waiting to run
ci / detox-lint-typecheck (push) Waiting to run
ci / test (push) Waiting to run
E2E: apply one server baseline at provisioning (#10258)
* MM-71189 Preserve feature flags in Detox config patches

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* Guard getFeatureFlags against empty config responses

Return an error instead of treating a missing config body as an empty
flag set, so a dropped GET does not patch only the requested flags.

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* Retrigger CI after Detox iOS and iPad E2E flakes

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* test(e2e): apply one declared server baseline at provisioning

Provisioning drives each test server to one declared baseline: the config keys E2E
needs and the full FeatureFlags map, written read-modify-write so no flag is reset.
Env-pinned keys are reported, not patched, and leftover E2E policies, remote clusters
and property fields are removed. Provisioning also disables stray plugins once.

* test(e2e): assert the server baseline instead of patching config in specs

These specs patched server-wide settings (CRT, archived channels, auto-replies, ...) and
restored them while other shards depended on them. They now assert the provisioned
baseline instead.

* test(e2e): split CI servers into pool and mutation roles; remove the locks

Each platform's server A becomes a read-only pool for 27 shards (and iPad and Maestro);
server B (and on iOS part of SITE_3) runs one serial mutation shard with the specs in
detox/e2e/server_mutation_specs.json. The classification, server and SITE_3 locks go.

- split-tests.js places mutation specs by the manifest and packs the pool by duration;
  a spec that needs B never falls back to the shared SITE_3.
- A pool request guard, an ESLint rule and a manifest checker keep server-wide writes
  off the pool. Mutation shards re-apply the baseline before each spec file.
- Mutating tests move to their own spec files; ABAC specs use channel-scoped
  permission policies; MFA and Terms of Service run on the mutation server.
- Pool shards no longer disable provisioned plugins, so the Agents specs run.

* fix(e2e): fail a spec when the baseline cannot be applied locally

* fix(e2e): keep transport retries for feature-flag and baseline reads

Restore the retry in getFeatureFlags, which apiEnableFeatureFlags calls directly, and
retry the baseline assertion's GET requests on transport failures.

* test(e2e): cover retries of dropped config and baseline reads

* test(e2e): apply one declared server baseline at provisioning

Provisioning drives each test server to one declared baseline: the config keys E2E
needs and the full FeatureFlags map, written read-modify-write so no flag is reset.
Env-pinned keys are reported, not patched, and leftover E2E policies, remote clusters
and property fields are removed. Provisioning also disables stray plugins once.

* test(e2e): assert the server baseline instead of patching config in specs

These specs patched server-wide settings (CRT, archived channels, auto-replies, ...) and
restored them while other shards depended on them. They now assert the provisioned
baseline instead.

* fix(e2e): fail a spec when the baseline cannot be applied locally

* fix(e2e): keep transport retries for feature-flag and baseline reads

Restore the retry in getFeatureFlags, which apiEnableFeatureFlags calls directly, and
retry the baseline assertion's GET requests on transport failures.

* test(e2e): cover retries of dropped config and baseline reads

* E2E: stop burn-on-read spec turning other feature flags off

Its partial FeatureFlags patch reset every other flag on the shared server,
which turned ChannelAttributes off under channel_attributes on another shard.
Enable only the missing flags, as redacted_files and upload_permission do,
and do the same for the dialog spec. Also tap the attach button the app
actually renders in MM-T339_1.

* E2E: route flag-off spec to B on iOS; tap the real attach button in the max-size spec

* test(e2e): apply one declared server baseline at provisioning

Provisioning drives each test server to one declared baseline: the config keys E2E
needs and the full FeatureFlags map, written read-modify-write so no flag is reset.
Env-pinned keys are reported, not patched, and leftover E2E policies, remote clusters
and property fields are removed. Provisioning also disables stray plugins once.

* test(e2e): assert the server baseline instead of patching config in specs

These specs patched server-wide settings (CRT, archived channels, auto-replies, ...) and
restored them while other shards depended on them. They now assert the provisioned
baseline instead.

* fix(e2e): fail a spec when the baseline cannot be applied locally

* fix(e2e): keep transport retries for feature-flag and baseline reads

Restore the retry in getFeatureFlags, which apiEnableFeatureFlags calls directly, and
retry the baseline assertion's GET requests on transport failures.

* test(e2e): cover retries of dropped config and baseline reads

* E2E: stop burn-on-read spec turning other feature flags off

Its partial FeatureFlags patch reset every other flag on the shared server,
which turned ChannelAttributes off under channel_attributes on another shard.
Enable only the missing flags, as redacted_files and upload_permission do,
and do the same for the dialog spec. Also tap the attach button the app
actually renders in MM-T339_1.

* E2E: wait for the results service before retrying a shard upload

upload-artifact does not retry network errors (ENOTFOUND, ETIMEDOUT), and the
retry fired ~30 ms after the first failure, inside the same DNS outage. A shard
whose specs all passed was then reported as "spec did not run". Each retry now
waits (bounded, 120 s) for the results host to answer, with a second retry.

* E2E: run the specs a killed iOS Jest never started; record why it died

When Jest is killed between spec files (exit code = null) it writes no report, and the
specs after that point never run. Run only those once in a fresh Jest and merge the
results; specs that ran keep their own result, so a spec that crashes Jest stays red.
Also sample memory and collect jetsam/crash reports so the next kill names its cause.

* E2E: keep the demo plugin off the shared servers; 32 shards

The demo plugin posts into every team on every server event and inside every config
save, and on our servers each of those posts fails. Only the two dialog specs use it,
so install it only on mutation server B, disable it everywhere else (failing
provisioning if it stays on), and route both dialog specs to B. Drop the
DialogOnlyMode setting, which v0.12.1 does not have. Raise Detox shards 28 -> 32.

* E2E: give the demo plugin a settings entry on the servers that install it

Demo plugin v0.12.1's ConfigurationWillBeSaved hands the whole config back when it
has no settings entry, and that round trip resets settings it does not know, or that
are false, to their defaults. With DialogOnlyMode gone from the baseline, fresh B
servers had no entry, so ChannelAttributesRequired=true and EnableMobileUpload=false
were reverted inside the save. An empty entry keeps the hook out of the save.

---------

Co-authored-by: mattermost-code <matty-code@mattermost.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: yasserfaraazkhan <yasser.khan@mattermost.com>
2026-10-21 23:36:31 +05:30

81 lines
3.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {AGENTS_PLUGIN_ID, DEMO_PLUGIN_ID, DEMO_PLUGIN_REQUIREMENT, REQUIRED_PLUGINS} from './constants';
import {ensureCustomProfileAttributeFields} from './custom-profile-attributes';
import {createMattermostClient, login} from './http-client';
import {ensureTrialLicense} from './license';
import {logInfo, logWarn} from './log';
import {assertDemoPluginAbsent, disableStrayPlugins, ensureAgentsPlugin, ensureDemoPluginReady, ensureDemoPluginSettingsEntry, installRequiredPlugin} from './plugins';
import {applyProvisionBaseline, getServerMmVersion, verifyProvisionBaseline} from './server-config';
import type {MattermostClient, ProvisionCredentials} from './types';
type AgentsStatusResponse = {available?: boolean};
async function verifyAgentsSetup(client: MattermostClient, token: string): Promise<boolean> {
const statusRes = await client.request<AgentsStatusResponse>('GET', '/api/v4/agents/status', undefined, token);
if (statusRes.data?.available === true) {
return true;
}
logWarn('Agents not available — agents tests may be skipped.');
return false;
}
export async function provisionServer(serverUrl: string, credentials: ProvisionCredentials, {demoPlugin}: {demoPlugin: boolean}): Promise<void> {
const client = createMattermostClient(serverUrl);
const token = await login(client, credentials);
const serverMmVersion = await getServerMmVersion(client, token);
logInfo(`Mattermost server version: ${serverMmVersion}`);
await ensureTrialLicense(client, token);
const provisioned = demoPlugin ? [...REQUIRED_PLUGINS, DEMO_PLUGIN_REQUIREMENT] : REQUIRED_PLUGINS;
// Before the baseline so its writes do not fan out through a stray or unwanted demo plugin. An
// active demo plugin on B is left alone here; the install loop below replaces a wrong version.
await disableStrayPlugins(client, token, provisioned);
// Before any further config write: a demo plugin already running on a reused server would otherwise
// reset settings the baseline and specs write.
if (demoPlugin) {
await ensureDemoPluginSettingsEntry(client, token);
}
await applyProvisionBaseline(client, token, serverUrl, serverMmVersion);
await ensureAgentsPlugin(client, token);
/* eslint-disable no-await-in-loop -- install required plugins one at a time for clear provisioning logs */
for (const plugin of provisioned) {
if (plugin.id === AGENTS_PLUGIN_ID) {
continue;
}
await installRequiredPlugin(client, token, plugin);
if (plugin.id === DEMO_PLUGIN_ID) {
try {
await ensureDemoPluginReady(client, token);
} catch (error) {
logWarn(`Demo plugin readiness check failed: ${error instanceof Error ? error.message : String(error)} — dialog-dependent tests may be skipped.`);
}
}
}
/* eslint-enable no-await-in-loop */
await assertDemoPluginAbsent(client, token, demoPlugin);
await verifyProvisionBaseline(client, token, serverUrl);
const agentsOk = await verifyAgentsSetup(client, token);
if (!agentsOk) {
logWarn('Agents E2E setup verification failed — agents tests may be skipped.');
}
if (!await ensureCustomProfileAttributeFields(client, token)) {
logWarn('Custom profile attribute setup incomplete.');
}
logInfo('Server provisioning complete.');
}