Skip to content

Commit

Permalink
Merge pull request #1229 from snyk/feat/change-snyk-test-prune-logic
Browse files Browse the repository at this point in the history
feat: update snyk test prune logic
  • Loading branch information
anthogez committed Jun 23, 2020
2 parents ab748bb + cc1d4cf commit 32c3dd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/lib/prune.ts
Expand Up @@ -23,17 +23,19 @@ export async function pruneGraph(
debug('rootPkg', depGraph.rootPkg);
debug('prePrunePathsCount: ' + prePrunePathsCount);
debug('isDenseGraph', isDenseGraph);
analytics.add('prePrunePathsCount', prePrunePathsCount);
analytics.add('prePrunedPathsCount', prePrunePathsCount);
if (isDenseGraph || pruneIsRequired) {
debug('Trying to prune the graph');
const prunedTree = (await graphToDepTree(depGraph, packageManager, {
deduplicateWithinTopLevelDeps: true,
})) as DepTree;
const prunedGraph = await depTreeToGraph(prunedTree, packageManager);
const postPrunePathsCount = countPathsToGraphRoot(prunedGraph);
analytics.add('postPrunePathsCount', postPrunePathsCount);
analytics.add('postPrunedPathsCount', postPrunePathsCount);
debug('postPrunePathsCount' + postPrunePathsCount);
if (postPrunePathsCount > config.MAX_PATH_COUNT) {
debug('Too many vulnerable paths to process the project');
debug('Too many paths to process the project');
//TODO replace the throw below with TooManyPaths we do not calculate vuln paths there
throw new TooManyVulnPaths();
}
return prunedGraph;
Expand Down
11 changes: 1 addition & 10 deletions src/lib/snyk-test/run-test.ts
Expand Up @@ -48,7 +48,6 @@ import { extractPackageManager } from '../plugins/extract-package-manager';
import { getSubProjectCount } from '../plugins/get-sub-project-count';
import { serializeCallGraphWithMetrics } from '../reachable-vulns';
import { validateOptions } from '../options-validator';
import { countPathsToGraphRoot } from '../utils';
import { findAndLoadPolicy } from '../policy';

const debug = debugModule('snyk');
Expand Down Expand Up @@ -487,20 +486,12 @@ async function assembleLocalPayloads(

const pruneIsRequired = options['prune-repeated-subdependencies'];

if (pruneIsRequired && packageManager) {
debug('Trying to prune the graph');
const prePruneDepCount = countPathsToGraphRoot(depGraph);
debug('pre prunedPathsCount: ' + prePruneDepCount);

if (packageManager) {
depGraph = await pruneGraph(
depGraph,
packageManager,
pruneIsRequired,
);
analytics.add('prePrunedPathsCount', prePruneDepCount);
const postPruneDepCount = countPathsToGraphRoot(depGraph);
debug('post prunedPathsCount: ' + postPruneDepCount);
analytics.add('postPrunedPathsCount', postPruneDepCount);
}
body.depGraph = depGraph;
}
Expand Down

0 comments on commit 32c3dd7

Please sign in to comment.