-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] Extend the /upgrade/_review
endpoint contract and functionality
#187770
[Security Solution] Extend the /upgrade/_review
endpoint contract and functionality
#187770
Conversation
/ci |
2 similar comments
/ci |
/ci |
b83a88c
to
7654ea7
Compare
/ci |
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
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.
@@ -19,6 +19,12 @@ import type { ThreeWayMergeOutcome } from './three_way_merge_outcome'; | |||
export const MissingVersion = Symbol('MissingVersion'); | |||
export type MissingVersion = typeof MissingVersion; | |||
|
|||
export enum ThreeWayDiffConflictResolutionResult { | |||
NO = 'NO', |
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.
Should this be something like NO_CONFLICT
? I guess NO
makes sense in the conflict: no
assignment but it does look a bit weird standalone
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.
Updated the enum for clarity
@banderror @nikitaindik @dplumlee Thanks for the review. I've addressed your feedback, and included in the changes of this PR the handling of scenarios with a missing base version, with the "compromise" solution we had decided here. Please take a look when you can. |
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.
Thanks for the updates to PR @jpdjere! I have only reviewed changes related to MissingVersion
- they look good to me!
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.
The new changes look great to me @jpdjere, thanks for incorporating all this into the existing diff work! I do like the idea you mentioned here, not sure if there's a reason we didn't incorporate this before other than not really having any special logic needs for those cases with the initial implementation
@@ -144,10 +138,11 @@ describe('multiLineStringDiffAlgorithm', () => { | |||
|
|||
expect(result).toEqual( | |||
expect.objectContaining({ | |||
has_base_version: false, | |||
base_version: undefined, |
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.
👍
case ThreeWayDiffOutcome.StockValueNoUpdate: // Scenarios AAA and -AA | ||
case ThreeWayDiffOutcome.CustomizedValueNoUpdate: // Scenario ABA | ||
case ThreeWayDiffOutcome.CustomizedValueSameUpdate: // Scenario ABB |
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.
Nice idea to put these scenarios in here, I think I'll incorporate this into some other diff files as well
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.
@dplumlee I ended up removing these, since now each scenario has its own ThreeWayDiffOutcome
and there's no case like // Scenarios AAA and -AA
anymore.
...mon/api/detection_engine/prebuilt_rules/model/diff/three_way_diff/three_way_merge_outcome.ts
Outdated
Show resolved
Hide resolved
@banderror Reintroduced @dplumlee While introducing/modifying the integration tests for scenarios For example, the assertion in the case of the const reviewResponse = await reviewPrebuiltRulesToUpgrade(supertest);
expect(reviewResponse.rules[0].diff.fields).toEqual({
version: {
current_version: 1,
target_version: 2,
merged_version: 2,
diff_outcome: ThreeWayDiffOutcome.StockValueCanUpdate,
merge_outcome: ThreeWayMergeOutcome.Target,
has_conflict: false,
has_update: true,
},
}); which in my opinion creates cognitive dissonance because the reader of the test is expecting to see So I went ahead and simplified all integration tests, now doing assertions only on the field that should/shouldn't be part of the So now the focus of each test is exclusively on the field that corresponds to the algorithm type. |
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.
Thanks @jpdjere, I left a couple more comments. Approving in advance 👍
} | ||
|
||
const addedCurrent = difference(dedupedCurrentVersion, dedupedBaseVersion); | ||
const addedCurrent = difference(dedupedCurrentVersion, dedupedBaseVersion as TValue[]); |
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.
We always try to avoid as
casting in production code, can we try to rewrite this algorithm in a type-safe way?
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.
Fixed
const removedCurrent = difference(dedupedBaseVersion, dedupedCurrentVersion); | ||
|
||
const addedTarget = difference(dedupedTargetVersion, dedupedBaseVersion); | ||
const addedTarget = difference(dedupedTargetVersion, dedupedBaseVersion as TValue[]); |
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.
Same here
const mergedVersion = merge(currentVersion, baseVersion, targetVersion, { | ||
// TS does not realize that in ABC scenario, baseVersion cannot be missing | ||
// Missing baseVersion scenarios were handled as -AA and -AB. | ||
const mergedVersion = merge(currentVersion, baseVersion as string, targetVersion, { |
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.
Same here
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: cc @jpdjere |
Resolves: #180153
Resolves: #188277
Summary
Extend the POST /upgrade/_review API endpoint's contract and functionality
Changes
has_conflict
property within each rule field'sThreeWayDiff
fromboolean
toenum
with possible values:NONE
: no conflicts in three way diffSOLVABLE
: conflict detected but was successfully resolved by our algorithmsNON_SOLVABLE
: conflict detected and could not be resolved by our algorithms.Adds
has_base_version
boolean field within each field diff calculation. Has values:The possible values for
has_conflict
for each concrete diff algorithm are:NO
,NON_SOLVABLE
NO
,SOLVABLE
,NON_SOLVABLE
NO
,NON_SOLVABLE
NO
,SOLVABLE
Adds new logic to handle [Security Solution] Updates diff outcome logic to return
CustomizedValueCanUpdate
on scenario-AB
#186435 (comment)For maintainers