mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Hide task runner warning if Code node is disabled (#14801)
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { captor, mock } from 'jest-mock-extended';
|
||||
import type { Logger } from 'n8n-core';
|
||||
|
||||
import config from '@/config';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
|
||||
import { DeprecationService } from '../deprecation.service';
|
||||
|
||||
describe('DeprecationService', () => {
|
||||
const logger = mock<Logger>();
|
||||
const deprecationService = new DeprecationService(logger);
|
||||
const globalConfig = mockInstance(GlobalConfig, { nodes: { exclude: [] } });
|
||||
const deprecationService = new DeprecationService(logger, globalConfig);
|
||||
|
||||
beforeEach(() => {
|
||||
// Ignore environment variables coming in from the environment when running
|
||||
@@ -109,6 +112,20 @@ describe('DeprecationService', () => {
|
||||
])('should handle value: %s', (value, mustWarn) => {
|
||||
toTest(envVar, value, mustWarn);
|
||||
});
|
||||
|
||||
test('should not warn when Code node is excluded', () => {
|
||||
process.env[envVar] = 'false';
|
||||
|
||||
const globalConfig = mockInstance(GlobalConfig, {
|
||||
nodes: {
|
||||
exclude: ['n8n-nodes-base.code'],
|
||||
},
|
||||
});
|
||||
|
||||
new DeprecationService(logger, globalConfig).warn();
|
||||
|
||||
expect(logger.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS', () => {
|
||||
@@ -127,7 +144,7 @@ describe('DeprecationService', () => {
|
||||
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is false', () => {
|
||||
process.env[envVar] = 'false';
|
||||
|
||||
const service = new DeprecationService(logger);
|
||||
const service = new DeprecationService(logger, globalConfig);
|
||||
service.warn();
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
||||
@@ -138,7 +155,7 @@ describe('DeprecationService', () => {
|
||||
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is empty', () => {
|
||||
process.env[envVar] = '';
|
||||
|
||||
const service = new DeprecationService(logger);
|
||||
const service = new DeprecationService(logger, globalConfig);
|
||||
service.warn();
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
||||
@@ -149,7 +166,7 @@ describe('DeprecationService', () => {
|
||||
test('should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true', () => {
|
||||
process.env[envVar] = 'true';
|
||||
|
||||
const service = new DeprecationService(logger);
|
||||
const service = new DeprecationService(logger, globalConfig);
|
||||
service.warn();
|
||||
|
||||
expect(logger.warn).not.toHaveBeenCalled();
|
||||
@@ -158,7 +175,7 @@ describe('DeprecationService', () => {
|
||||
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined', () => {
|
||||
delete process.env[envVar];
|
||||
|
||||
const service = new DeprecationService(logger);
|
||||
const service = new DeprecationService(logger, globalConfig);
|
||||
service.warn();
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
||||
@@ -175,7 +192,7 @@ describe('DeprecationService', () => {
|
||||
});
|
||||
process.env[envVar] = 'false';
|
||||
|
||||
const service = new DeprecationService(logger);
|
||||
const service = new DeprecationService(logger, globalConfig);
|
||||
service.warn();
|
||||
|
||||
expect(logger.warn).not.toHaveBeenCalled();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { Service } from '@n8n/di';
|
||||
import { Logger } from 'n8n-core';
|
||||
|
||||
@@ -20,6 +21,9 @@ type Deprecation = {
|
||||
|
||||
/** Whether a config value is required to trigger a deprecation warning. */
|
||||
matchConfig?: boolean;
|
||||
|
||||
/** Function to run to check whether to disable this deprecation warning. */
|
||||
disableIf?: () => boolean;
|
||||
};
|
||||
|
||||
const SAFE_TO_REMOVE = 'Remove this environment variable; it is no longer needed.';
|
||||
@@ -52,6 +56,7 @@ export class DeprecationService {
|
||||
'Running n8n without task runners is deprecated. Task runners will be turned on by default in a future version. Please set `N8N_RUNNERS_ENABLED=true` to enable task runners now and avoid potential issues in the future. Learn more: https://docs.n8n.io/hosting/configuration/task-runners/',
|
||||
checkValue: (value?: string) => value?.toLowerCase() !== 'true' && value !== '1',
|
||||
warnIfMissing: true,
|
||||
disableIf: () => this.globalConfig.nodes.exclude.includes('n8n-nodes-base.code'),
|
||||
},
|
||||
{
|
||||
envVar: 'OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS',
|
||||
@@ -76,10 +81,18 @@ export class DeprecationService {
|
||||
/** Runtime state of deprecation-related env vars. */
|
||||
private readonly state: Map<Deprecation, { mustWarn: boolean }> = new Map();
|
||||
|
||||
constructor(private readonly logger: Logger) {}
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly globalConfig: GlobalConfig,
|
||||
) {}
|
||||
|
||||
warn() {
|
||||
this.deprecations.forEach((d) => {
|
||||
if (d.disableIf?.()) {
|
||||
this.state.set(d, { mustWarn: false });
|
||||
return;
|
||||
}
|
||||
|
||||
const envValue = process.env[d.envVar];
|
||||
|
||||
const matchConfig = d.matchConfig === true || d.matchConfig === undefined;
|
||||
|
||||
Reference in New Issue
Block a user