1
0
Fork 0
mirror of https://github.com/imjasonh/govulncheck-action synced 2026-07-22 15:41:44 +00:00

Detect and fail on missing go.sum dependencies

Previously, if go.sum was out of date or missing, govulncheck would fail
to analyze the code but the action would report "no vulnerabilities found"
which is misleading and dangerous.

This change:
- Detects specific error patterns in govulncheck stderr that indicate
  missing dependencies (missing go.sum entry, could not import, invalid package name)
- Throws a clear error message telling users to run 'go mod tidy'
- Prevents false "no vulnerabilities" reports when govulncheck can't analyze the code

Added tests to verify the behavior for both missing go.sum and import errors.

Fixes the issue where vulnerabilities could be missed due to dependency problems.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jason Hall 2025-06-07 02:08:43 -04:00
parent 8007311738
commit 24718a7114
Failed to extract signature
3 changed files with 42 additions and 0 deletions

View file

@ -174,6 +174,34 @@ describe('GitHub Action Integration', () => {
);
});
it('should fail when go.sum is missing', async () => {
mockGovulncheck.run.mockResolvedValue({
output: '{"config": {}}',
errorOutput: 'missing go.sum entry for module providing package golang.org/x/net/html',
exitCode: 1
});
await expect(run({
govulncheck: mockGovulncheck,
parser: mockParser,
annotator: mockAnnotator
})).rejects.toThrow('govulncheck failed due to missing dependencies');
});
it('should fail when imports cannot be resolved', async () => {
mockGovulncheck.run.mockResolvedValue({
output: '{"config": {}}',
errorOutput: 'could not import golang.org/x/net/html (invalid package name: "")',
exitCode: 1
});
await expect(run({
govulncheck: mockGovulncheck,
parser: mockParser,
annotator: mockAnnotator
})).rejects.toThrow('govulncheck failed due to missing dependencies');
});
it('should handle errors and set action as failed', async () => {
const error = new Error('Failed to install govulncheck');
mockGovulncheck.install.mockRejectedValue(error);