-
Notifications
You must be signed in to change notification settings - Fork 664
Fix stack-dependent related_integrations.version export #6208
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
Open
Mikaayenson
wants to merge
12
commits into
main
Choose a base branch
from
5601-bug-improper-prebuilt-rule-version-usage-in-security_detection_engine-package-versions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+457
−91
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
728e8f6
fix(integrations): emit stack-invariant OR ranges for related_integra…
Mikaayenson 6d88831
fix(integrations): emit stack-invariant OR ranges for related_integra…
Mikaayenson 73c0780
fix(integrations): satisfy ruff SIM110 in _major_has_compatible_stack
Mikaayenson 07cd5a0
fix(integrations): address review feedback for stack-major resolution
Mikaayenson 2ac6605
Merge branch 'main' into 5601-bug-improper-prebuilt-rule-version-usag…
Mikaayenson 1d9fae1
fix(integrations): tighten stack-major overlap and anchor resolution
Mikaayenson 2302006
fix(integrations): annotate majors_to_check for pyright
Mikaayenson 76e0369
fix(integrations): rebase #6208 onto main with #6251 schema-aware OR …
Mikaayenson eef18f2
style(rule): apply ruff format for CI code-checks
Mikaayenson 6ae62b1
fix(integrations): address PR review on version range export
Mikaayenson adc4f10
fix(integrations): anchor RI export to shipped stack backports only
Mikaayenson 655cffc
refactor(integrations): simplify version range export helpers
Mikaayenson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,8 @@ | |
| _parse_clause, | ||
| _parse_kibana_range, | ||
| _satisfies_kibana_range, | ||
| find_compatible_version_range, | ||
| find_latest_compatible_version, | ||
| find_least_compatible_version, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -215,45 +215,88 @@ def test_unknown_package_raises(self): | |
| find_latest_compatible_version("missing", "missing", Version(9, 1, 0), {}) | ||
|
|
||
|
|
||
| class TestFindLeastCompatibleVersion(unittest.TestCase): | ||
| """Behavior coverage for ``find_least_compatible_version``.""" | ||
| class TestFindCompatibleVersionRange(unittest.TestCase): | ||
| """Behavior coverage for ``find_compatible_version_range``.""" | ||
|
|
||
| def test_picks_oldest_compatible_in_latest_major(self): | ||
| """Returns the oldest manifest in the latest major whose range admits the stack.""" | ||
| def test_emits_or_range_across_majors(self): | ||
| """Emits oldest anchor per major plus a forward-looking next-major anchor.""" | ||
| manifests = { | ||
| "pkg": { | ||
| "1.0.0": _manifest("^8.12.0"), | ||
| "1.5.0": _manifest("^8.12.0"), | ||
| "2.0.0": _manifest("^9.0.0"), | ||
| "2.1.0": _manifest("^9.1.0"), | ||
| "2.5.0": _manifest("^9.1.0"), | ||
| "1.0.0": _manifest("^1.0.0"), | ||
| "1.5.0": _manifest("^1.5.0"), | ||
| "2.0.0": _manifest("^2.0.0"), | ||
| "2.5.0": _manifest("^2.1.0"), | ||
| } | ||
| } | ||
| # 2.0.0 (^9.0.0) is the oldest 9.x manifest that admits a 9.1.0 stack. | ||
| self.assertEqual(find_least_compatible_version("pkg", "pkg", "9.1.0", manifests), "^2.0.0") | ||
| result = find_compatible_version_range("pkg", manifests) | ||
| self.assertEqual(result.range, "^1.0.0 || ^2.0.0 || ^3.0.0") | ||
| self.assertEqual(result.anchors, ["1.0.0", "2.0.0"]) | ||
| self.assertEqual(result.forward_anchor, "3.0.0") | ||
|
|
||
| def test_no_compatible_in_any_major_raises(self): | ||
| """When neither the latest nor any prior major admits the stack, raise.""" | ||
| def test_stack_invariance(self): | ||
| """Range result does not depend on build stack version.""" | ||
| manifests = { | ||
| "pkg": { | ||
| "1.0.0": _manifest("^8.12.0"), | ||
| "2.0.0": _manifest("^9.4.0"), | ||
| "1.0.0": _manifest("^1.0.0"), | ||
| "2.0.0": _manifest("^2.0.0"), | ||
| } | ||
| } | ||
| with self.assertRaises(ValueError): | ||
| find_least_compatible_version("pkg", "pkg", "9.1.0", manifests) | ||
| first = find_compatible_version_range("pkg", manifests) | ||
| second = find_compatible_version_range("pkg", manifests) | ||
| self.assertEqual(first, second) | ||
|
|
||
| def test_single_major_appends_forward_anchor(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit. Akin to https://github.com/elastic/detection-rules/pull/6208/changes#r3325352838, if the goal is to support unbounded upper ranges like |
||
| """A single integration major still appends the forward-looking anchor.""" | ||
| manifests = {"pkg": {"9.0.0": _manifest("^9.0.0")}} | ||
| result = find_compatible_version_range("pkg", manifests) | ||
| self.assertEqual(result.range, "^9.0.0 || ^10.0.0") | ||
| self.assertEqual(result.anchors, ["9.0.0"]) | ||
| self.assertEqual(result.forward_anchor, "10.0.0") | ||
|
|
||
| def test_three_majors_endpoint_shape(self): | ||
| """Synthetic endpoint-like majors mirror the #5601 reproducer shape.""" | ||
| manifests = { | ||
| "endpoint": { | ||
| "7.17.0": _manifest("^7.17.0"), | ||
| "8.2.0": _manifest("^8.2.0"), | ||
| "9.0.0": _manifest("^9.0.0"), | ||
| } | ||
| } | ||
| result = find_compatible_version_range("endpoint", manifests) | ||
| self.assertEqual(result.range, "^7.17.0 || ^8.2.0 || ^9.0.0 || ^10.0.0") | ||
| self.assertEqual(result.anchors, ["7.17.0", "8.2.0", "9.0.0"]) | ||
| self.assertEqual(result.forward_anchor, "10.0.0") | ||
|
|
||
| def test_cross_major_fallback(self): | ||
| """Falls back to an earlier major when the latest major is incompatible.""" | ||
| def test_skips_majors_with_no_overlap(self): | ||
| """Majors without stack overlap are omitted from anchors.""" | ||
| manifests = { | ||
| "pkg": { | ||
| "1.0.0": _manifest("^8.12.0"), | ||
| "2.0.0": _manifest("^9.4.0"), | ||
| "7.10.0": _manifest("^7.10.0"), | ||
| "9.4.0": _manifest("=9.4.0"), | ||
| } | ||
| } | ||
| self.assertEqual(find_least_compatible_version("pkg", "pkg", "8.12.0", manifests), "^1.0.0") | ||
| result = find_compatible_version_range("pkg", manifests) | ||
| self.assertEqual(result.range, "^7.10.0 || ^9.4.0 || ^10.0.0") | ||
| self.assertEqual(result.anchors, ["7.10.0", "9.4.0"]) | ||
|
|
||
| def test_or_clause(self): | ||
| """OR'd clauses are honored by the least-compatible search.""" | ||
| manifests = {"pkg": {"1.0.0": _manifest("^8.12.0 || ^9.0.0")}} | ||
| self.assertEqual(find_least_compatible_version("pkg", "pkg", "9.1.0", manifests), "^1.0.0") | ||
| def test_raises_when_no_compatible_major(self): | ||
| """When no stack line can be resolved, raise.""" | ||
| manifests = { | ||
| "pkg": { | ||
| "1.0.0": _manifest(">=99.0.0 <99.0.0"), | ||
| } | ||
| } | ||
| with self.assertRaises(ValueError): | ||
| find_compatible_version_range("pkg", manifests) | ||
|
|
||
| def test_returns_anchor_list_for_policy_template_lookup(self): | ||
| """Anchors and forward anchor are exposed for policy template union.""" | ||
| manifests = { | ||
| "pkg": { | ||
| "1.0.0": _manifest("^1.0.0"), | ||
| "2.0.0": _manifest("^2.0.0"), | ||
| } | ||
| } | ||
| result = find_compatible_version_range("pkg", manifests) | ||
| self.assertEqual(result.anchors, ["1.0.0", "2.0.0"]) | ||
| self.assertEqual(result.forward_anchor, "3.0.0") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.