Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(language-server): integrate LS #5633

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/snyk/go-application-framework v0.0.0-20241218075424-470703ebd741
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20241217120918-faa47b5debb3
github.com/snyk/snyk-ls v0.0.0-20241219134446-6804ba14978a
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ github.com/snyk/policy-engine v0.31.3 h1:FepCg6QN/X8uvxYjF+WwB2aiBPJB+NENDgKQeI/
github.com/snyk/policy-engine v0.31.3/go.mod h1:Z9/hcngz+2txX4QfQRwfODk8F7w4mr/IQOvCtIosnLo=
github.com/snyk/snyk-iac-capture v0.6.5 h1:992DXCAJSN97KtUh8T5ndaWwd/6ZCal2bDkRXqM1u/E=
github.com/snyk/snyk-iac-capture v0.6.5/go.mod h1:e47i55EmM0F69ZxyFHC4sCi7vyaJW6DLoaamJJCzWGk=
github.com/snyk/snyk-ls v0.0.0-20241217120918-faa47b5debb3 h1:FzPQqAaxFel9rPPLYhlArduotH2kD/y8hEQ7V6VSduY=
github.com/snyk/snyk-ls v0.0.0-20241217120918-faa47b5debb3/go.mod h1:M6Mx5LLHzDThChYUkH7Ce5puv+Hhf1o6nC1To+RcgTI=
github.com/snyk/snyk-ls v0.0.0-20241219134446-6804ba14978a h1:hs+wPGwl/4o30NbytVQfWz2AhhqL49Q/27yR8X7EIF4=
github.com/snyk/snyk-ls v0.0.0-20241219134446-6804ba14978a/go.mod h1:gtzbhJtrTmxdTL+OA+5wv1iVNhqBwZkx5e/amVLAYFE=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd h1:Dq5WSzWsP1TbVi10zPWBI5LKEBDg4Y1OhWEph1wr5WQ=
Expand Down
5 changes: 5 additions & 0 deletions src/lib/snyk-test/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface LegacyVulnApiResult extends BasicResultData {
filesystemPolicy?: boolean;
uniqueCount?: any;
remediation?: RemediationChanges;
depGraph?: depGraphLib.DepGraphData;
}

export interface BaseImageRemediation {
Expand Down Expand Up @@ -452,6 +453,10 @@ function convertTestDepGraphResultToLegacy(
remediation: result.remediation,
};

if (options['print-deps'] && options['json-file-output']) {
legacyRes.depGraph = depGraph.toJSON();
}

return legacyRes;
}

Expand Down
42 changes: 42 additions & 0 deletions test/jest/acceptance/cli-json-file-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createProjectFromWorkspace } from '../util/createProject';
import { runSnykCLI } from '../util/runSnykCLI';
import { humanFileSize } from '../../utils';
import { getServerPort } from '../util/getServerPort';
import * as depGraphLib from '@snyk/dep-graph';

jest.setTimeout(1000 * 60);

Expand Down Expand Up @@ -112,4 +113,45 @@ describe('test --json-file-output', () => {
expect(fileExists).toBeFalsy();
expect(code).toEqual(0);
});

describe('print-deps and json-file-output', () => {
it('saves JSON output to file with depGraph when --print-deps and --json-file-output are being used', async () => {
const project = await createProjectFromWorkspace('maven-app');
const outputPath = 'json-file-output.json';

const { code } = await runSnykCLI(
`test --print-deps --json-file-output=${outputPath}`,
{
cwd: project.path(),
env,
},
);

expect(code).toEqual(0);
const json = await project.readJSON(outputPath);
expect(json.depGraph).toBeTruthy();
const depGraph = depGraphLib.createFromJSON(json.depGraph);
expect(depGraph.getPkgs()).toContainEqual({
name: 'axis:axis',
version: '1.4',
});
});

it('saves JSON output to file without a depGraph when --print-deps is not used', async () => {
const project = await createProjectFromWorkspace('maven-app');
const outputPath = 'json-file-output.json';

const { code } = await runSnykCLI(
`test --json-file-output=${outputPath}`,
{
cwd: project.path(),
env,
},
);

expect(code).toEqual(0);
const json = await project.readJSON(outputPath);
expect(json.depGraph).toBeUndefined();
});
});
});
Loading