Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { existsSync } from 'fs';

import { runSnykCLI } from '../../util/runSnykCLI';
import { getFixturePath } from '../../util/getFixturePath';

jest.setTimeout(1000 * 300);

const SBOM_FILE_PATH = getFixturePath('sbom/snyk-goof-sbom.json');
const ASSET_NAME = 'cli-sbom-monitor-user-journey';

// Marker to make this user-journey test easy to locate in CI output.
const LOG_TAG = '[sbom-monitor-user-journey]';

const dragonflyEnv = {
...process.env,
SNYK_API: process.env.TEST_SNYK_API_DEV,
SNYK_TOKEN: process.env.TEST_SNYK_TOKEN_DEV,
INTERNAL_SNYK_CLI_ROLLOUT_DFLY_SBOM_MONITOR: 'true',
};

const describeIfPreProd = process.env.TEST_SNYK_TOKEN_DEV
? describe
: describe.skip;

beforeAll(() => {
if (!existsSync(SBOM_FILE_PATH)) {
throw new Error(
`SBOM fixture not found at ${SBOM_FILE_PATH}. Please ensure test fixtures are properly set up.`,
);
}
});

describeIfPreProd('snyk sbom test --report', () => {
it('should successfully test an SBOM', async () => {
const command = `sbom test --report --experimental --file=${SBOM_FILE_PATH} --asset-name=${ASSET_NAME}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Bug: Wrong command is being executed

The test is intended to test snyk sbom monitor (per the file name, describe block, test name, and PR description), but the command actually executes sbom test instead:

const command = `sbom test --report --experimental --file=${SBOM_FILE_PATH} --asset-name=${ASSET_NAME}`;

This should be:

const command = `sbom monitor --experimental --file=${SBOM_FILE_PATH} --asset-name=${ASSET_NAME}`;

The --report flag is not needed for sbom monitor as monitoring inherently reports to the server. This bug causes the test to validate the wrong CLI functionality entirely, making it fail to test the Dragonfly SBOM monitor flow as intended.

Suggested change
const command = `sbom test --report --experimental --file=${SBOM_FILE_PATH} --asset-name=${ASSET_NAME}`;
const command = `sbom monitor --experimental --file=${SBOM_FILE_PATH} --asset-name=${ASSET_NAME}`;

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

console.log(`${LOG_TAG} running: snyk ${command}`);

const { code, stdout, stderr } = await runSnykCLI(command, {
env: dragonflyEnv,
});

// Emit the full CLI result so the run is verifiable from the CI logs even
// when the assertions pass silently.
console.log(`${LOG_TAG} exit code: ${code}`);
console.log(`${LOG_TAG} stdout:\n${stdout}`);
console.log(`${LOG_TAG} stderr:\n${stderr}`);

expect(stderr).toBe('');
expect(stdout).toContain('View your asset(s) at:');
// The goof SBOM fixture contains known vulnerabilities, so the CLI exits 1.
expect(code).toBe(1);
});
});