-
Notifications
You must be signed in to change notification settings - Fork 518
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
fix: test_output_json2 failures in test_output_engine.py #4905
base: main
Are you sure you want to change the base?
fix: test_output_json2 failures in test_output_engine.py #4905
Conversation
88b7edf
to
9b1ee35
Compare
entries = row[1] | ||
data_entries[source] = entries | ||
|
||
# Initialize with defaults for all required keys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coding data entries in not a bad idea, but I'm afraid they might introduce some breaking changes specially if new data sources are added. Also, modifying core logic just to fix a failing test is not always the most optimal approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented dynamic source detection in db_entries_count(), which automatically includes all sources with zero counts initially. The test is failing because our JSON schema requires specific fields like "NVD," but our function is more flexible.
Rather than hard-coding sources in the core function, we should either:
- Update the schema to make these fields optional
- Add a post-processing step before validation
Let's keep the database function focused on its purpose and handle schema compliance separately. This approach will maintain flexibility as we add new data sources without requiring constant code updates.
However, if changing mandates in the JSON schema is fine, I can make that change as well, however I am waiting on feedback from @terriko as that may impact production build rather than internal test changes which isn't ideal
also @JigyasuRajput, while running tests on the file, did you face something like this:
FAILED test/test_output_engine.py::TestOutputEngine::test_output_with_unset_fields - AssertionError: OutputEngine.output_cves raised an exception when 'sbom_serial_number' was unset: cannot unpack non-iterable NoneType object
9b1ee35
to
96bca57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Why do you think the required things include OSV, GAD, and REDHAT? Those are not actually required during runtime unless we screwed something up recently (and I'm fairly sure we didn't, as a lot of people are turning off OSV for memory issues right now). We need to make sure that everything except NVD can be turned off (and ideally we'll make it so NVD can be disabled as well, but that's going to take more work.)
2700e3f
to
45e3da6
Compare
@terriko required changes have been made please take a look |
Summary
This PR resolves failures in TestOutputEngine.test_output_json2 caused by missing expected database entries and improves error handling in json_output.py. Additionally, it ensures generate.py properly handles VEX generation failures by providing a fallback mechanism when parsing issues occur.
Changes Introduced
Backward Compatibility
✅ The changes ensure backward compatibility with existing behavior.
✅ Maintains compatibility with Python 3.8+ and does not introduce breaking changes.
Checklist
Steps to Test
Run the following:
LONG_TESTS=1 pytest test/test_output_engine.py
Verify:
✅ TestOutputEngine.test_output_json2 passes successfully.
✅ No errors related to missing database entries in json_output.py.
✅ No crashes due to NoneType unpacking in generate.py.
Related Issues
Fixes #4903
Additional Notes
The improved error logging in json_output.py enhances traceability when database queries fail.
The new fallback mechanism in generate.py ensures robustness when parsing issues arise in VEX generation.
🚀 This update enhances test reliability and improves error handling for better maintainability. 🛠️