Skip to content

Commit 3d716f2

Browse files
fix(transition): experimental queries get NonGraceffulyTransition transition type (#7809)
* experimental queries getting NonGracefullyTransition type * some changes * gofmt changes * fix function declaration exceding 140 characters * gofmt changes * fixed golint problems * just to check something * trying to fix e2e_070 test problems * changed the result for the E2E_CLI_070 test case * fixed identation * fixed identation * added new line
1 parent 67c75db commit 3d716f2

File tree

4 files changed

+52
-27
lines changed

4 files changed

+52
-27
lines changed

e2e/fixtures/E2E_CLI_070_RESULT.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"total_counter": 2,
2222
"total_bom_resources": 0,
23-
"start": "2024-05-28T13:18:56.6040425+01:00",
24-
"end": "2024-05-28T13:18:56.948862+01:00",
23+
"start": "2025-11-05T12:30:29.616176853Z",
24+
"end": "2025-11-05T12:30:30.07811478Z",
2525
"paths": [
2626
"/path/test/fixtures/experimental_test/sample",
2727
"/path/test/fixtures/experimental_test/queries"
@@ -41,7 +41,7 @@
4141
"files": [
4242
{
4343
"file_name": "path\\test\\fixtures\\experimental_test\\sample\\sample.tf",
44-
"similarity_id": "4e651f5c005de96ab66f25419b1f160d9e0eecae83181edfcd1b72b3afbe9f69",
44+
"similarity_id": "efa296e727d250c75a82c32c397e4e78d4b87434373312b34d970ec260f0aa15",
4545
"line": 4,
4646
"resource_type": "aws_elasticache_cluster",
4747
"resource_name": "cluster-example",

pkg/engine/vulnerability_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func generateSimilaritiesID(ctx *QueryContext, resolvedFile, subDocumentIdx, que
219219
searchKey, oldSimilarityIDLineInfo string, kicsComputeNewSimID bool, logWithFields *zerolog.Logger, tracker Tracker,
220220
kicsMigrationQueryInfo map[string]TransitionQueryInfo,
221221
) (similarityID, oldSimilarityID *string) {
222-
transitionType := checkQueryTransitionType(kicsMigrationQueryInfo, queryID)
222+
transitionType := checkQueryTransitionType(kicsMigrationQueryInfo, queryID, ctx.Query.Metadata.Experimental)
223223
// only will generate pair of similarity IDs if the scan flag is enabled and the transition type is not YetToBeChecked
224224
// or if the scan flag is disabled and the transition type is NonGracefullyTransition
225225
if kicsComputeNewSimID && transitionType != YetToBeChecked ||

pkg/engine/vulnerability_builder_transition.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ type TransitionQueryInfo struct {
2828
Observation string `yaml:"observation"`
2929
}
3030

31-
func checkQueryTransitionType(changeList map[string]TransitionQueryInfo, queryID string) VulnerabilityBuilderTransition {
31+
func checkQueryTransitionType(
32+
changeList map[string]TransitionQueryInfo,
33+
queryID string,
34+
isExperimental bool,
35+
) VulnerabilityBuilderTransition {
3236
if change, ok := changeList[queryID]; ok {
3337
return change.Transition
3438
}
39+
if isExperimental {
40+
return NonGracefullyTransition
41+
}
3542
return YetToBeChecked
3643
}

pkg/engine/vulnerability_builder_transition_test.go

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,68 @@ var testTransitionQueryInfo = map[string]TransitionQueryInfo{
3131
QueryName: "Query4",
3232
Transition: 4,
3333
},
34+
"b9b7ada8-3868-4a35-854e-6100a2bb863d": {
35+
QueryID: "b9b7ada8-3868-4a35-854e-6100a2bb863d",
36+
QueryName: "Query6",
37+
Transition: 1,
38+
},
3439
}
3540

3641
func TestCheckQueryTransitionType(t *testing.T) {
3742

3843
tests := []struct {
39-
name string
40-
changeID string
41-
expected VulnerabilityBuilderTransition
44+
name string
45+
changeID string
46+
experimental bool
47+
expected VulnerabilityBuilderTransition
4248
}{
4349
{
44-
name: "Query with transition type 3 - AddedSearchValue ",
45-
changeID: "1828a670-5957-4bc5-9974-47da228f75e2",
46-
expected: AddedSearchValue,
50+
name: "Query with transition type 3 - AddedSearchValue ",
51+
changeID: "1828a670-5957-4bc5-9974-47da228f75e2",
52+
experimental: false,
53+
expected: AddedSearchValue,
54+
},
55+
{
56+
name: "Query with transition type 5 - AddedSearchValueAndAddedSearchLine",
57+
changeID: "cf34805e-3872-4c08-bf92-6ff7bb0cfadb",
58+
experimental: false,
59+
expected: AddedSearchValueAndAddedSearchLine,
4760
},
4861
{
49-
name: "Query with transition type 5 - AddedSearchValueAndAddedSearchLine",
50-
changeID: "cf34805e-3872-4c08-bf92-6ff7bb0cfadb",
51-
expected: AddedSearchValueAndAddedSearchLine,
62+
name: "Query with transition type 1 - NonGracefullyTransition",
63+
changeID: "c3162390-7f18-4f31-8c73-da1d86c8a11e",
64+
experimental: false,
65+
expected: NonGracefullyTransition,
5266
},
5367
{
54-
name: "Query with transition type 1 - NonGracefullyTransition",
55-
changeID: "c3162390-7f18-4f31-8c73-da1d86c8a11e",
56-
expected: NonGracefullyTransition,
68+
name: "Query with transition type 2 - TransitionWithoutChanges",
69+
changeID: "788996a7-4359-4568-9a91-1ad0c4112818",
70+
experimental: false,
71+
expected: TransitionWithoutChanges,
5772
},
5873
{
59-
name: "Query with transition type 2 - TransitionWithoutChanges",
60-
changeID: "788996a7-4359-4568-9a91-1ad0c4112818",
61-
expected: TransitionWithoutChanges,
74+
name: "Query with transition type 4 - AddedSearchLine",
75+
changeID: "77f5d46e-7244-4606-80c6-18478627aa9e",
76+
experimental: false,
77+
expected: AddedSearchLine,
6278
},
6379
{
64-
name: "Query with transition type 4 - AddedSearchLine",
65-
changeID: "77f5d46e-7244-4606-80c6-18478627aa9e",
66-
expected: AddedSearchLine,
80+
name: "Query with transition type 0 - YetToBeChecked",
81+
changeID: "non-existing-query-id",
82+
experimental: false,
83+
expected: YetToBeChecked,
6784
},
6885
{
69-
name: "Query with transition type 0 - YetToBeChecked",
70-
changeID: "non-existing-query-id",
71-
expected: YetToBeChecked,
86+
name: "Query with transition type 1 - NonGracefullyTransition (experimental query)",
87+
changeID: "b9b7ada8-3868-4a35-854e-6100a2bb863d",
88+
experimental: true,
89+
expected: NonGracefullyTransition,
7290
},
7391
}
7492

7593
for _, tt := range tests {
7694
t.Run(tt.name, func(t *testing.T) {
77-
result := checkQueryTransitionType(testTransitionQueryInfo, tt.changeID)
95+
result := checkQueryTransitionType(testTransitionQueryInfo, tt.changeID, tt.experimental)
7896
require.Equal(t, tt.expected, result)
7997
})
8098
}

0 commit comments

Comments
 (0)