Skip to content

Commit

Permalink
Merge pull request #753 from snyk/fix/add-code-agent-deprecation-pref…
Browse files Browse the repository at this point in the history
…light-check

fix: add code agent deprecation preflight check [HYB-437]
  • Loading branch information
aarlaud authored May 6, 2024
2 parents ab013e7 + eb6f732 commit 078a322
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/client/checks/config/codeAgentDeprecation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Config } from '../../types/config';
import { CheckOptions, CheckResult } from '../types';

export const validateCodeAgentDeprecation = (
checkOptions: CheckOptions,
config: Config,
): CheckResult => {
if (config.GIT_CLIENT_URL && !config.DISABLE_CODE_AGENT_PREFLIGHT_CHECK) {
return {
id: checkOptions.id,
name: checkOptions.name,
status: 'warning',
output: `Code Agent is deprecated. Please move to broker only Snyk Code support.`,
} satisfies CheckResult;
}

return {
id: checkOptions.id,
name: checkOptions.name,
status: 'passing',
output: config.DISABLE_CODE_AGENT_PREFLIGHT_CHECK
? 'Code Agent Preflight Check disabled.'
: 'Code Agent not in use.',
} satisfies CheckResult;
};
16 changes: 16 additions & 0 deletions lib/client/checks/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import type { Config } from '../../types/config';
import type { Check, CheckResult } from '../types';
import { validateBrokerClientUrl } from './brokerClientUrlCheck';
import { validateAcceptFlagsConfig } from './customAcceptFile';
import { validateCodeAgentDeprecation } from './codeAgentDeprecation';
import { validateUniversalConnectionsConfig } from './universalConnectionConfigCheck';

export function getConfigChecks(config: Config): Check[] {
return [
brokerClientUrlCheck(config),
universalBrokerConnectionsCheck(config),
acceptFlagsConfigurationCheck(config),
codeAgentDeprecationCheck(config),
];
}

Expand Down Expand Up @@ -54,3 +56,17 @@ const acceptFlagsConfigurationCheck = (config: Config): Check => {
},
} satisfies Check;
};

const codeAgentDeprecationCheck = (config: Config): Check => {
return {
id: 'code-agent-deprecation-validation',
name: 'Code Agent Deprecation Check',
enabled: !config.DISABLE_CODE_AGENT_PREFLIGHT_CHECK,
check: function (): CheckResult {
return validateCodeAgentDeprecation(
{ id: this.id, name: this.name },
config,
);
},
} satisfies Check;
};
51 changes: 51 additions & 0 deletions test/unit/client/checks/config/codeAgentDeprecation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { validateCodeAgentDeprecation } from '../../../../../lib/client/checks/config/codeAgentDeprecation';
import { aConfig } from '../../../../helpers/test-factories';

describe('client/checks/config', () => {
describe('validateCodeAgentDeprecation()', () => {
it('should return pasing check result if code agent config is not detected', async () => {
const id = `check_${Date.now()}`;
const config = aConfig({});

const checkResult = validateCodeAgentDeprecation(
{ id: id, name: id },
config,
);
expect(checkResult.status).toEqual('passing');
expect(checkResult.output).toContain('Code Agent not in use.');
});

it('should return warning check result if code agent config is detected', async () => {
const id = `check_${Date.now()}`;
const config = aConfig({
GIT_CLIENT_URL: 'http://codeagent',
});

const checkResult = validateCodeAgentDeprecation(
{ id: id, name: id },
config,
);
expect(checkResult.status).toEqual('warning');
expect(checkResult.output).toContain(
'Code Agent is deprecated. Please move to broker only Snyk Code support.',
);
});

it('should return passing check result if code agent config is detected but preflight check is disabled', async () => {
const id = `check_${Date.now()}`;
const config = aConfig({
GIT_CLIENT_URL: 'http://codeagent',
DISABLE_CODE_AGENT_PREFLIGHT_CHECK: 'any value',
});

const checkResult = validateCodeAgentDeprecation(
{ id: id, name: id },
config,
);
expect(checkResult.status).toEqual('passing');
expect(checkResult.output).toContain(
'Code Agent Preflight Check disabled.',
);
});
});
});

0 comments on commit 078a322

Please sign in to comment.