-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #753 from snyk/fix/add-code-agent-deprecation-pref…
…light-check fix: add code agent deprecation preflight check [HYB-437]
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/unit/client/checks/config/codeAgentDeprecation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
); | ||
}); | ||
}); | ||
}); |