Skip to content

Commit 51c93f6

Browse files
committed
feat: TEST_MODE='api' to suppress deprecation throws in API tests
TEST_MODE now accepts: - 'true' (default for unit/UI/storybook): deprecation logger throws on call, rate limiter bypass and short-cache behaviors are active. - 'api' (API end-to-end suite): same test-mode behaviors as 'true' (rate-limiter bypass, short cache TTLs, etc.) but the deprecation logger only logs, does not throw. The API suite intentionally exercises deprecated DDP methods through /v1/method.call/:method. - unset: production behavior. Changes: - apps/meteor/app/lib/server/lib/deprecationWarningLogger.ts: a shouldThrowOnDeprecation() helper replaces the seven inline if (process.env.TEST_MODE === 'true') throw blocks. Only 'true' triggers the throw; 'api' falls through to the warn-only log. - Every other strict TEST_MODE === 'true' check across the codebase (rate limiter, livechat schedulers, settings cache, marketplace isTesting, registerUser, initialData, serverRunning, twilio integration, authorization service cache, mongo-config, client queryClient, CachedSettings) becomes (... === 'true' || ... === 'api') so the test-mode shortcuts keep firing for the API suite. - docker-compose-ci.yml: rocketchat + omnichannel-transcript now accept the value from the shell via TEST_MODE=\${TEST_MODE:-true}. Default stays 'true' for any job that does not override. - .github/workflows/ci-test-e2e.yml: the Start containers step sets TEST_MODE: 'api' when inputs.type == 'api' or 'api-livechat', otherwise leaves the docker-compose default. Setting the env on the test step did not work because the container was already running with the variable undefined.
1 parent 1f90a39 commit 51c93f6

21 files changed

Lines changed: 51 additions & 27 deletions

File tree

.github/workflows/ci-test-e2e.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ jobs:
175175
176176
- name: Start containers for CE
177177
if: inputs.release == 'ce'
178+
env:
179+
# API tests intentionally invoke deprecated DDP methods through
180+
# /v1/method.call/:method. TEST_MODE='api' keeps every other test
181+
# behavior on (rate-limiter bypass, short cache TTLs) while letting
182+
# the deprecation logger log without throwing. Other suites use the
183+
# docker-compose default of TEST_MODE='true'.
184+
TEST_MODE: ${{ (inputs.type == 'api' || inputs.type == 'api-livechat') && 'api' || 'true' }}
178185
run: |
179186
# when we are testing CE, we only need to start the rocketchat container
180187
DEBUG_LOG_LEVEL=${DEBUG_LOG_LEVEL:-0} docker compose -f docker-compose-ci.yml up -d rocketchat --wait
@@ -185,6 +192,7 @@ jobs:
185192
ENTERPRISE_LICENSE: ${{ inputs.enterprise-license }}
186193
TRANSPORTER: ${{ inputs.transporter }}
187194
COMPOSE_PROFILES: ${{ inputs.type == 'api' && 'api' || '' }}
195+
TEST_MODE: ${{ (inputs.type == 'api' || inputs.type == 'api-livechat') && 'api' || 'true' }}
188196
run: |
189197
DEBUG_LOG_LEVEL=${DEBUG_LOG_LEVEL:-0} docker compose -f docker-compose-ci.yml up -d --wait
190198

apps/meteor/app/lib/server/lib/RateLimiter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
22

33
export const RateLimiterClass = new (class {
44
limitMethod(methodName, numRequests, timeInterval, matchers) {
5-
if (process.env.TEST_MODE === 'true') {
5+
if (process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api') {
66
return;
77
}
88
const match = {

apps/meteor/app/lib/server/lib/deprecationWarningLogger.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ const compareVersions = (version: string, message: string) => {
2626

2727
export type DeprecationLoggerNextPlannedVersion = '9.0.0';
2828

29+
// `TEST_MODE=true` makes the logger throw so accidental usage of a deprecated
30+
// method/endpoint surfaces immediately in the test run. The API end-to-end
31+
// suite sets `TEST_MODE=api` instead — every other test-mode behavior stays on
32+
// (rate limiter bypass, short cache TTLs, etc.) but the deprecation logger
33+
// only logs because the suite intentionally exercises deprecated DDP methods
34+
// through `/v1/method.call/:method` and the streamer.
35+
const shouldThrowOnDeprecation = process.env.TEST_MODE === 'true';
36+
2937
export const apiDeprecationLogger = ((logger) => {
3038
return {
3139
endpoint: (endpoint: string, version: DeprecationLoggerNextPlannedVersion, res: Response, info = '') => {
3240
const message = `The endpoint "${endpoint}" is deprecated and will be removed on version ${version}${info ? ` (${info})` : ''}`;
3341

34-
if (process.env.TEST_MODE === 'true') {
42+
if (shouldThrowOnDeprecation) {
3543
throw new Error(message);
3644
}
3745

@@ -59,7 +67,7 @@ export const apiDeprecationLogger = ((logger) => {
5967
}) ?? `The parameter "${parameter}" in the endpoint "${endpoint}" is deprecated and will be removed on version ${version}`;
6068
compareVersions(version, message);
6169

62-
if (process.env.TEST_MODE === 'true') {
70+
if (shouldThrowOnDeprecation) {
6371
throw new Error(message);
6472
}
6573

@@ -87,7 +95,7 @@ export const apiDeprecationLogger = ((logger) => {
8795
version,
8896
}) ?? `The usage of the endpoint "${endpoint}" is deprecated and will be removed on version ${version}`;
8997

90-
if (process.env.TEST_MODE === 'true') {
98+
if (shouldThrowOnDeprecation) {
9199
throw new Error(message);
92100
}
93101

@@ -114,7 +122,7 @@ export const methodDeprecationLogger = ((logger) => {
114122
const paths = infoArray.map((p) => (typeof p === 'string' && p.startsWith('/') ? `"${p}"` : p)).join(' or ');
115123
const replacement = infoArray.length > 0 ? `Use the ${paths} endpoint${infoArray.length > 1 ? 's' : ''} instead` : '';
116124
const message = `The method "${method}" is deprecated and will be removed on version ${version}${replacement ? ` (${replacement})` : ''}`;
117-
if (process.env.TEST_MODE === 'true') {
125+
if (shouldThrowOnDeprecation) {
118126
throw new Error(message);
119127
}
120128
compareVersions(version, message);
@@ -124,7 +132,7 @@ export const methodDeprecationLogger = ((logger) => {
124132
},
125133
parameter: (method: string, parameter: string, version: DeprecationLoggerNextPlannedVersion) => {
126134
const message = `The parameter "${parameter}" in the method "${method}" is deprecated and will be removed on version ${version}`;
127-
if (process.env.TEST_MODE === 'true') {
135+
if (shouldThrowOnDeprecation) {
128136
throw new Error(message);
129137
}
130138

@@ -149,7 +157,7 @@ export const methodDeprecationLogger = ((logger) => {
149157
version,
150158
}) ?? `The usage of the method "${method}" is deprecated and will be removed on version ${version}`;
151159

152-
if (process.env.TEST_MODE === 'true') {
160+
if (shouldThrowOnDeprecation) {
153161
throw new Error(message);
154162
}
155163

@@ -162,7 +170,7 @@ export const methodDeprecationLogger = ((logger) => {
162170
},
163171
/** @deprecated */
164172
warn: (message: string) => {
165-
if (process.env.TEST_MODE === 'true') {
173+
if (shouldThrowOnDeprecation) {
166174
throw new Error(message);
167175
}
168176

apps/meteor/app/livechat/server/api/v1/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { RoutingManager } from '../../lib/RoutingManager';
88
import { online } from '../../lib/service-status';
99
import { settings, findOpenRoom, getExtraConfigInfo, findAgent, findGuestWithoutActivity } from '../lib/livechat';
1010

11-
const cachedSettings = mem(settings, { maxAge: process.env.TEST_MODE === 'true' ? 1 : 1000, cacheKey: JSON.stringify });
11+
const cachedSettings = mem(settings, {
12+
maxAge: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api' ? 1 : 1000,
13+
cacheKey: JSON.stringify,
14+
});
1215

1316
API.v1.addRoute(
1417
'livechat/config',

apps/meteor/app/livechat/server/lib/AnalyticsTyped.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { OmnichannelAnalytics } from '@rocket.chat/core-services';
22
import mem from 'mem';
33

44
export const getAgentOverviewDataCached = mem(OmnichannelAnalytics.getAgentOverviewData, {
5-
maxAge: process.env.TEST_MODE === 'true' ? 1 : 60000,
5+
maxAge: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api' ? 1 : 60000,
66
cacheKey: JSON.stringify,
77
});
88
// Agent overview data on realtime is cached for 5 seconds
@@ -12,6 +12,6 @@ export const getAnalyticsOverviewDataCached = mem(OmnichannelAnalytics.getAnalyt
1212
cacheKey: JSON.stringify,
1313
});
1414
export const getAnalyticsOverviewDataCachedForRealtime = mem(OmnichannelAnalytics.getAnalyticsOverviewData, {
15-
maxAge: process.env.TEST_MODE === 'true' ? 1 : 5000,
15+
maxAge: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api' ? 1 : 5000,
1616
cacheKey: JSON.stringify,
1717
});

apps/meteor/app/livechat/server/livechat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ function parseExtraAttributes(widgetData: string): string {
3838
return doc.documentElement.innerHTML;
3939
}
4040

41-
const memoizedParseExtraAttributes = mem(parseExtraAttributes, { maxAge: process.env.TEST_MODE === 'true' ? 1 : 60000 });
41+
const memoizedParseExtraAttributes = mem(parseExtraAttributes, {
42+
maxAge: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api' ? 1 : 60000,
43+
});
4244

4345
WebApp.connectHandlers.use('/livechat', (req, res, next) => {
4446
if (!req.url) {

apps/meteor/app/livechat/server/startup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Meteor.startup(async () => {
120120
}
121121
await businessHourManager.stopManager();
122122
},
123-
process.env.TEST_MODE === 'true'
123+
process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api'
124124
? {
125125
debounce: 10,
126126
}

apps/meteor/app/settings/server/CachedSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class CachedSettings
183183
}
184184

185185
const mergeFunction =
186-
process.env.TEST_MODE !== 'true'
186+
process.env.TEST_MODE !== 'true' && process.env.TEST_MODE !== 'api'
187187
? _.debounce((): void => {
188188
callback(_id.map((id) => this.store.get(id)?.value) as T[]);
189189
}, 100)

apps/meteor/client/lib/queryClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const queryClient = new QueryClient({
44
defaultOptions: {
55
queries: {
66
refetchOnWindowFocus: false,
7-
retry: process.env.TEST_MODE === 'true',
7+
retry: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api',
88
},
99
mutations: {
1010
onError: console.warn,

apps/meteor/ee/app/livechat-enterprise/server/lib/AutoCloseOnHoldScheduler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class AutoCloseOnHoldSchedulerClass {
3333
mongo: (MongoInternals.defaultRemoteCollectionDriver().mongo as any).client.db(),
3434
db: { collection: SCHEDULER_NAME },
3535
defaultConcurrency: 1,
36-
processEvery: process.env.TEST_MODE === 'true' ? '3 seconds' : '1 minute',
36+
processEvery: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api' ? '3 seconds' : '1 minute',
3737
});
3838

3939
await this.scheduler.start();

0 commit comments

Comments
 (0)