From 94350a889a9e89d886ac51f4684adcf49a52bae0 Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Mon, 17 Jun 2024 16:13:13 +0300 Subject: [PATCH 01/12] pb108 --- .../validate/sdk_validation_config.toml | 3 +- .../validate/tests/PB_validators_test.py | 52 +++++++++++++++++++ .../PB_validators/PB108_is_valid_task_id.py | 51 ++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py diff --git a/demisto_sdk/commands/validate/sdk_validation_config.toml b/demisto_sdk/commands/validate/sdk_validation_config.toml index 5ebd0189985..4383143ce0f 100644 --- a/demisto_sdk/commands/validate/sdk_validation_config.toml +++ b/demisto_sdk/commands/validate/sdk_validation_config.toml @@ -29,7 +29,7 @@ select = [ "IN100", "IN101", "IN102", "IN104", "IN106", "IN107", "IN108", "IN109", "IN110", "IN112", "IN113", "IN114", "IN115", "IN117", "IN118", "IN121", "IN122", "IN123", "IN124", "IN125", "IN126", "IN127", "IN130", "IN131", "IN134", "IN135", "IN139", "IN141", "IN142", "IN144", "IN145", "IN146", "IN149", "IN150", "IN151", "IN152", "IN153", "IN154", "IN156", "IN158", "IN159", "IN160", "IN161", "IN162", - "PB100", "PB101","PB104","PB118", "PB123", + "PB100", "PB101","PB104","PB108","PB118", "PB123", "DO100", "DO101", "DO102", "DO103", "DO104", "DO105", "DO106", "DS100", "DS107", "SC100", "SC105", "SC106", "SC109", @@ -67,6 +67,7 @@ select = [ "RP101", "IT102", "IT103", "MR100", + "PB108" ] warning = [ "IN101", diff --git a/demisto_sdk/commands/validate/tests/PB_validators_test.py b/demisto_sdk/commands/validate/tests/PB_validators_test.py index 5bf5ef94485..b80543eef01 100644 --- a/demisto_sdk/commands/validate/tests/PB_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PB_validators_test.py @@ -1,5 +1,6 @@ import pytest +from TestSuite.playbook import Playbook from demisto_sdk.commands.content_graph.objects.base_playbook import TaskConfig from demisto_sdk.commands.validate.tests.test_tools import create_playbook_object from demisto_sdk.commands.validate.validators.PB_validators.PB100_is_no_rolename import ( @@ -18,6 +19,10 @@ IsAskConditionHasUnhandledReplyOptionsValidator, ) +from demisto_sdk.commands.validate.validators.PB_validators.PB108_is_valid_task_id import ( + IsValidTaskIdValidator, +) + @pytest.mark.parametrize( "content_item, expected_result", @@ -222,3 +227,50 @@ def test_IsAskConditionHasUnhandledReplyOptionsValidator(): ) } assert IsAskConditionHasUnhandledReplyOptionsValidator().is_valid([playbook]) + + +def create_invalid_playbook(field: str): + playbook = create_playbook_object() + tasks = playbook.tasks + for task_id in tasks: + task_obj = tasks[task_id] + if field == 'taskid': + task_obj.taskid = task_obj.taskid + '1234' + else: + task_obj.task.id = task_obj.task.id + '1234' + break + return playbook + + +def test_IsValidTaskIdValidator(playbook): + """ + Given: + - A playbook + Case 1: The playbook is valid. + Case 2: The playbook isn't valid, it has invalid taskid. + Case 3: The playbook isn't valid, the 'id' under the 'task' field is invalid. + + When: + - calling IsValidTaskIdValidator.is_valid. + + Then: + - The results should be as expected: + Case 1: The playbook is valid + Case 2: The playbook is invalid + Case 3: The playbook is invalid + """ + # Case 1 + playbook_valid = create_playbook_object() + results_valid = IsValidTaskIdValidator().is_valid([playbook_valid]) + + # Case 2 + playbook_invalid_taskid = create_invalid_playbook('taskid') + results_invalid_taskid = IsValidTaskIdValidator().is_valid([playbook_invalid_taskid]) + + # Case 3 + playbook_invalid_id = create_invalid_playbook('id') + results_invalid_id = IsValidTaskIdValidator().is_valid([playbook_invalid_id]) + + assert not results_valid + assert results_invalid_taskid + assert results_invalid_id diff --git a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py new file mode 100644 index 00000000000..96f55a59ac4 --- /dev/null +++ b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py @@ -0,0 +1,51 @@ + +from __future__ import annotations + +from typing import Iterable, List + +from demisto_sdk.commands.common.constants import GitStatuses +from demisto_sdk.commands.common.tools import is_string_uuid +from demisto_sdk.commands.content_graph.objects.base_playbook import TaskConfig +from demisto_sdk.commands.content_graph.objects.playbook import Playbook +from demisto_sdk.commands.validate.validators.base_validator import ( + BaseValidator, + ValidationResult, +) + +ContentTypes = Playbook + + +class IsValidTaskIdValidator(BaseValidator[ContentTypes]): + error_code = "PB108" + description = "Validate that the task ID and the 'id' under the 'task' field are from UUID format" + rationale = "" + error_message = ("On task: {0}, the field 'taskid': {1} and the 'id' under the 'task' field: {2}, must be from " + "uuid format.") + related_field = "taskid" + is_auto_fixable = False + # expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED] + + def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: + results: List[ValidationResult] = [] + for content_item in content_items: + invalid_tasks = self.invalid_tasks(content_item.tasks) + for task_id in invalid_tasks: + taskid = invalid_tasks[task_id].taskid + inner_id = invalid_tasks[task_id].task.id + results.append(ValidationResult( + validator=self, + message=self.error_message.format(task_id, taskid, inner_id), + content_object=content_item, + )) + return results + + def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, TaskConfig]: + invalid_tasks = {} + for task_id in tasks: + task = tasks[task_id] + taskid = task.taskid + inner_id = task.task.id + is_valid_task = is_string_uuid(taskid) and is_string_uuid(inner_id) + if not is_valid_task: + invalid_tasks[task_id] = task + return invalid_tasks From 69ca6ad21cb06f352c321154914e947ebd05bcec Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Mon, 17 Jun 2024 16:24:08 +0300 Subject: [PATCH 02/12] documentation --- .../commands/validate/tests/PB_validators_test.py | 6 ++++++ .../PB_validators/PB108_is_valid_task_id.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/demisto_sdk/commands/validate/tests/PB_validators_test.py b/demisto_sdk/commands/validate/tests/PB_validators_test.py index b80543eef01..7d4bf47e3fd 100644 --- a/demisto_sdk/commands/validate/tests/PB_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PB_validators_test.py @@ -230,6 +230,12 @@ def test_IsAskConditionHasUnhandledReplyOptionsValidator(): def create_invalid_playbook(field: str): + """Create an invalid playbook that has an invalid taskid or the 'id' under the 'task' field is invalid + Args: + - field str: which field to update taskid or task.id. + Return: + - a playbook object + """ playbook = create_playbook_object() tasks = playbook.tasks for task_id in tasks: diff --git a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py index 96f55a59ac4..803669b4a60 100644 --- a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py +++ b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py @@ -26,6 +26,12 @@ class IsValidTaskIdValidator(BaseValidator[ContentTypes]): # expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED] def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: + """Check whether all playbook tasks has valid taskid and the 'id' under the 'task' field is valid as well. + Args: + - content_items (Iterable[ContentTypes]): The content items to check. + Return: + - List[ValidationResult]. List of ValidationResults objects. + """ results: List[ValidationResult] = [] for content_item in content_items: invalid_tasks = self.invalid_tasks(content_item.tasks) @@ -40,6 +46,12 @@ def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResu return results def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, TaskConfig]: + """Check which tasks has invalid taskid or the 'id' under the 'task' field is invalid + Args: + - tasks dict[str, TaskConfig]: The playbook tasks. + Return: + - dict[str, TaskConfig] that contains the invalid tasks. + """ invalid_tasks = {} for task_id in tasks: task = tasks[task_id] From 948b49224e7ce5213a47abbfc2e58cc7f53fef18 Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Mon, 17 Jun 2024 16:45:56 +0300 Subject: [PATCH 03/12] changelog and pre-commit updates --- .changelog/4359.yml | 4 ++++ .../validate/tests/PB_validators_test.py | 22 ++++++++--------- .../PB_validators/PB108_is_valid_task_id.py | 24 ++++++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 .changelog/4359.yml diff --git a/.changelog/4359.yml b/.changelog/4359.yml new file mode 100644 index 00000000000..82818427fbc --- /dev/null +++ b/.changelog/4359.yml @@ -0,0 +1,4 @@ +changes: +- description: Moved BP108 to the new validate + type: internal +pr_number: 4359 diff --git a/demisto_sdk/commands/validate/tests/PB_validators_test.py b/demisto_sdk/commands/validate/tests/PB_validators_test.py index 7d4bf47e3fd..a79d3618377 100644 --- a/demisto_sdk/commands/validate/tests/PB_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PB_validators_test.py @@ -1,6 +1,5 @@ import pytest -from TestSuite.playbook import Playbook from demisto_sdk.commands.content_graph.objects.base_playbook import TaskConfig from demisto_sdk.commands.validate.tests.test_tools import create_playbook_object from demisto_sdk.commands.validate.validators.PB_validators.PB100_is_no_rolename import ( @@ -12,6 +11,9 @@ from demisto_sdk.commands.validate.validators.PB_validators.PB104_deprecated_description import ( DeprecatedDescriptionValidator, ) +from demisto_sdk.commands.validate.validators.PB_validators.PB108_is_valid_task_id import ( + IsValidTaskIdValidator, +) from demisto_sdk.commands.validate.validators.PB_validators.PB118_is_input_key_not_in_tasks import ( IsInputKeyNotInTasksValidator, ) @@ -19,10 +21,6 @@ IsAskConditionHasUnhandledReplyOptionsValidator, ) -from demisto_sdk.commands.validate.validators.PB_validators.PB108_is_valid_task_id import ( - IsValidTaskIdValidator, -) - @pytest.mark.parametrize( "content_item, expected_result", @@ -240,10 +238,10 @@ def create_invalid_playbook(field: str): tasks = playbook.tasks for task_id in tasks: task_obj = tasks[task_id] - if field == 'taskid': - task_obj.taskid = task_obj.taskid + '1234' + if field == "taskid": + task_obj.taskid = task_obj.taskid + "1234" else: - task_obj.task.id = task_obj.task.id + '1234' + task_obj.task.id = task_obj.task.id + "1234" break return playbook @@ -270,11 +268,13 @@ def test_IsValidTaskIdValidator(playbook): results_valid = IsValidTaskIdValidator().is_valid([playbook_valid]) # Case 2 - playbook_invalid_taskid = create_invalid_playbook('taskid') - results_invalid_taskid = IsValidTaskIdValidator().is_valid([playbook_invalid_taskid]) + playbook_invalid_taskid = create_invalid_playbook("taskid") + results_invalid_taskid = IsValidTaskIdValidator().is_valid( + [playbook_invalid_taskid] + ) # Case 3 - playbook_invalid_id = create_invalid_playbook('id') + playbook_invalid_id = create_invalid_playbook("id") results_invalid_id = IsValidTaskIdValidator().is_valid([playbook_invalid_id]) assert not results_valid diff --git a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py index 803669b4a60..ea061bb254c 100644 --- a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py +++ b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py @@ -1,15 +1,13 @@ - from __future__ import annotations from typing import Iterable, List -from demisto_sdk.commands.common.constants import GitStatuses from demisto_sdk.commands.common.tools import is_string_uuid from demisto_sdk.commands.content_graph.objects.base_playbook import TaskConfig from demisto_sdk.commands.content_graph.objects.playbook import Playbook from demisto_sdk.commands.validate.validators.base_validator import ( - BaseValidator, - ValidationResult, + BaseValidator, + ValidationResult, ) ContentTypes = Playbook @@ -19,8 +17,10 @@ class IsValidTaskIdValidator(BaseValidator[ContentTypes]): error_code = "PB108" description = "Validate that the task ID and the 'id' under the 'task' field are from UUID format" rationale = "" - error_message = ("On task: {0}, the field 'taskid': {1} and the 'id' under the 'task' field: {2}, must be from " - "uuid format.") + error_message = ( + "On task: {0}, the field 'taskid': {1} and the 'id' under the 'task' field: {2}, must be from " + "uuid format." + ) related_field = "taskid" is_auto_fixable = False # expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED] @@ -38,11 +38,13 @@ def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResu for task_id in invalid_tasks: taskid = invalid_tasks[task_id].taskid inner_id = invalid_tasks[task_id].task.id - results.append(ValidationResult( - validator=self, - message=self.error_message.format(task_id, taskid, inner_id), - content_object=content_item, - )) + results.append( + ValidationResult( + validator=self, + message=self.error_message.format(task_id, taskid, inner_id), + content_object=content_item, + ) + ) return results def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, TaskConfig]: From 31a0a79c3eb972f3d6ed5d13cd892761213788d9 Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Mon, 17 Jun 2024 16:50:28 +0300 Subject: [PATCH 04/12] updated changelog --- .changelog/4359.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/4359.yml b/.changelog/4359.yml index 82818427fbc..f29b4f63cdf 100644 --- a/.changelog/4359.yml +++ b/.changelog/4359.yml @@ -1,4 +1,4 @@ changes: -- description: Moved BP108 to the new validate +- description: Moved PB108 to the new validate type: internal pr_number: 4359 From 0a65c95cbe8724d94dac3ea1e6c0156ebd2116eb Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Mon, 17 Jun 2024 18:02:51 +0300 Subject: [PATCH 05/12] cr updates --- .changelog/4359.yml | 2 +- .../PB_validators/PB108_is_valid_task_id.py | 34 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.changelog/4359.yml b/.changelog/4359.yml index f29b4f63cdf..0d91a514748 100644 --- a/.changelog/4359.yml +++ b/.changelog/4359.yml @@ -1,4 +1,4 @@ changes: -- description: Moved PB108 to the new validate +- description: Moved PB108 to the new validate format. The validate checks that the 'taskid' and the 'id' under the 'task' field are from UUID format. type: internal pr_number: 4359 diff --git a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py index ea061bb254c..771f6df0376 100644 --- a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py +++ b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py @@ -15,15 +15,11 @@ class IsValidTaskIdValidator(BaseValidator[ContentTypes]): error_code = "PB108" - description = "Validate that the task ID and the 'id' under the 'task' field are from UUID format" - rationale = "" - error_message = ( - "On task: {0}, the field 'taskid': {1} and the 'id' under the 'task' field: {2}, must be from " - "uuid format." - ) + description = "Validate that the task ID and the 'id' under the 'task' field are from UUID format." + rationale = "Validate that the task ID and the 'id' under the 'task' field are from UUID format." + error_message = "This playbook has tasks with invalid 'taskid' or invalid 'id' under the 'task' field." related_field = "taskid" is_auto_fixable = False - # expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED] def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: """Check whether all playbook tasks has valid taskid and the 'id' under the 'task' field is valid as well. @@ -35,19 +31,23 @@ def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResu results: List[ValidationResult] = [] for content_item in content_items: invalid_tasks = self.invalid_tasks(content_item.tasks) + tasks_error_message = self.error_message for task_id in invalid_tasks: - taskid = invalid_tasks[task_id].taskid - inner_id = invalid_tasks[task_id].task.id + tasks_error_message = ( + f"{tasks_error_message}\nTask {task_id} has invalid UUIDs in the fields " + f"{invalid_tasks[task_id]}." + ) + if invalid_tasks: results.append( ValidationResult( validator=self, - message=self.error_message.format(task_id, taskid, inner_id), + message=tasks_error_message, content_object=content_item, ) ) return results - def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, TaskConfig]: + def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, list]: """Check which tasks has invalid taskid or the 'id' under the 'task' field is invalid Args: - tasks dict[str, TaskConfig]: The playbook tasks. @@ -59,7 +59,13 @@ def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, TaskConfig]: task = tasks[task_id] taskid = task.taskid inner_id = task.task.id - is_valid_task = is_string_uuid(taskid) and is_string_uuid(inner_id) - if not is_valid_task: - invalid_tasks[task_id] = task + is_valid_taskid = is_string_uuid(taskid) + is_valid_inner_id = is_string_uuid(inner_id) + invalid_fields = [] + if not is_valid_taskid: + invalid_fields.append("taskid") + if not is_valid_inner_id: + invalid_fields.append("the 'id' under the 'task' field") + if invalid_fields: + invalid_tasks[task_id] = invalid_fields return invalid_tasks From 42eab4ef536463a34ae545b0fd4679ba989d8bec Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 09:23:00 +0300 Subject: [PATCH 06/12] pre-commit updates --- demisto_sdk/commands/validate/tests/PB_validators_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/commands/validate/tests/PB_validators_test.py b/demisto_sdk/commands/validate/tests/PB_validators_test.py index e83d38403ea..508467b933a 100644 --- a/demisto_sdk/commands/validate/tests/PB_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PB_validators_test.py @@ -229,7 +229,6 @@ def test_IsAskConditionHasUnhandledReplyOptionsValidator(): assert IsAskConditionHasUnhandledReplyOptionsValidator().is_valid([playbook]) -<<<<<<< HEAD def create_invalid_playbook(field: str): """Create an invalid playbook that has an invalid taskid or the 'id' under the 'task' field is invalid Args: @@ -284,6 +283,7 @@ def test_IsValidTaskIdValidator(playbook): assert results_invalid_taskid assert results_invalid_id + def test_does_playbook_have_unconnected_tasks(): """ Given: A playbook with tasks that are connected to each other. From b4a891d25954fb70c73c9ccd8a1cb0d45deca9af Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 09:27:40 +0300 Subject: [PATCH 07/12] update --- demisto_sdk/commands/validate/sdk_validation_config.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/demisto_sdk/commands/validate/sdk_validation_config.toml b/demisto_sdk/commands/validate/sdk_validation_config.toml index 0647c1e846e..e72eab16400 100644 --- a/demisto_sdk/commands/validate/sdk_validation_config.toml +++ b/demisto_sdk/commands/validate/sdk_validation_config.toml @@ -29,7 +29,6 @@ select = [ "IN100", "IN101", "IN102", "IN104", "IN106", "IN107", "IN108", "IN109", "IN110", "IN112", "IN113", "IN114", "IN115", "IN117", "IN118", "IN121", "IN122", "IN123", "IN124", "IN125", "IN126", "IN127", "IN130", "IN131", "IN134", "IN135", "IN139", "IN141", "IN142", "IN144", "IN145", "IN146", "IN149", "IN150", "IN151", "IN152", "IN153", "IN154", "IN156", "IN158", "IN159", "IN160", "IN161", "IN162", - "PB100", "PB101","PB103","PB104","PB108","PB118", "PB123", "PB100", "PB101","PB103","PB104", "PB105","PB108","PB118", "PB123", "DO100", "DO101", "DO102", "DO103", "DO104", "DO105", "DO106", "DS100", "DS101", "DS105", "DS106", "DS107", From 056d7d293d47503ca6be5f72f4e258e4310cb611 Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 09:29:29 +0300 Subject: [PATCH 08/12] fix --- demisto_sdk/commands/validate/tests/PB_validators_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/PB_validators_test.py b/demisto_sdk/commands/validate/tests/PB_validators_test.py index e79a70528bf..af29bb67f00 100644 --- a/demisto_sdk/commands/validate/tests/PB_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PB_validators_test.py @@ -15,13 +15,11 @@ from demisto_sdk.commands.validate.validators.PB_validators.PB104_deprecated_description import ( DeprecatedDescriptionValidator, ) -<<<<<<< HEAD from demisto_sdk.commands.validate.validators.PB_validators.PB108_is_valid_task_id import ( IsValidTaskIdValidator, -======= +) from demisto_sdk.commands.validate.validators.PB_validators.PB105_playbook_delete_context_all import ( PlaybookDeleteContextAllValidator, ->>>>>>> master ) from demisto_sdk.commands.validate.validators.PB_validators.PB118_is_input_key_not_in_tasks import ( IsInputKeyNotInTasksValidator, From e80ac1fc315d6e18d0116e4658b944672f52d6ad Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 09:43:42 +0300 Subject: [PATCH 09/12] pre-commit updates --- demisto_sdk/commands/validate/tests/PB_validators_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/PB_validators_test.py b/demisto_sdk/commands/validate/tests/PB_validators_test.py index af29bb67f00..a1d140dbb93 100644 --- a/demisto_sdk/commands/validate/tests/PB_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PB_validators_test.py @@ -15,12 +15,12 @@ from demisto_sdk.commands.validate.validators.PB_validators.PB104_deprecated_description import ( DeprecatedDescriptionValidator, ) -from demisto_sdk.commands.validate.validators.PB_validators.PB108_is_valid_task_id import ( - IsValidTaskIdValidator, -) from demisto_sdk.commands.validate.validators.PB_validators.PB105_playbook_delete_context_all import ( PlaybookDeleteContextAllValidator, ) +from demisto_sdk.commands.validate.validators.PB_validators.PB108_is_valid_task_id import ( + IsValidTaskIdValidator, +) from demisto_sdk.commands.validate.validators.PB_validators.PB118_is_input_key_not_in_tasks import ( IsInputKeyNotInTasksValidator, ) @@ -285,6 +285,8 @@ def test_IsValidTaskIdValidator(playbook): assert not results_valid assert results_invalid_taskid assert results_invalid_id + + def test_PlaybookDeleteContextAllValidator(): """ Given: From b6555ec1cda82f68f460c6449972f22296c70315 Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 10:00:01 +0300 Subject: [PATCH 10/12] cr updates --- .../PB_validators/PB108_is_valid_task_id.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py index 771f6df0376..7222094a330 100644 --- a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py +++ b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py @@ -17,7 +17,7 @@ class IsValidTaskIdValidator(BaseValidator[ContentTypes]): error_code = "PB108" description = "Validate that the task ID and the 'id' under the 'task' field are from UUID format." rationale = "Validate that the task ID and the 'id' under the 'task' field are from UUID format." - error_message = "This playbook has tasks with invalid 'taskid' or invalid 'id' under the 'task' field." + error_message = "This playbook has tasks with invalid 'taskid' or invalid 'id' under the 'task' field.\n{0}" related_field = "taskid" is_auto_fixable = False @@ -31,17 +31,17 @@ def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResu results: List[ValidationResult] = [] for content_item in content_items: invalid_tasks = self.invalid_tasks(content_item.tasks) - tasks_error_message = self.error_message + tasks_error_message = "" for task_id in invalid_tasks: tasks_error_message = ( - f"{tasks_error_message}\nTask {task_id} has invalid UUIDs in the fields " - f"{invalid_tasks[task_id]}." + f"{tasks_error_message}Task {task_id} has invalid UUIDs in the fields " + f"{invalid_tasks[task_id]}.\n" ) if invalid_tasks: results.append( ValidationResult( validator=self, - message=tasks_error_message, + message=self.error_message.format(tasks_error_message), content_object=content_item, ) ) @@ -55,8 +55,7 @@ def invalid_tasks(self, tasks: dict[str, TaskConfig]) -> dict[str, list]: - dict[str, TaskConfig] that contains the invalid tasks. """ invalid_tasks = {} - for task_id in tasks: - task = tasks[task_id] + for task_id, task in tasks.items(): taskid = task.taskid inner_id = task.task.id is_valid_taskid = is_string_uuid(taskid) From 405d47d1db0587f68a990da1d4989633b0c9cf87 Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 10:02:28 +0300 Subject: [PATCH 11/12] fix --- demisto_sdk/commands/validate/sdk_validation_config.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/demisto_sdk/commands/validate/sdk_validation_config.toml b/demisto_sdk/commands/validate/sdk_validation_config.toml index 41e80dc06d8..a0cbf2f95ba 100644 --- a/demisto_sdk/commands/validate/sdk_validation_config.toml +++ b/demisto_sdk/commands/validate/sdk_validation_config.toml @@ -52,11 +52,7 @@ select = [ "IN131", "IN134", "IN135", "IN139", "IN141", "IN142", "IN144", "IN145", "IN146", "IN149", "IN150", "IN151", "IN152", "IN153", "IN154", "IN156", "IN158", "IN159", "IN160", "IN161", "IN162", "LO107", -<<<<<<< HEAD - "PB100", "PB101","PB103","PB104", "PB105","PB108","PB123", -======= - "PB100", "PB101","PB103","PB104", "PB105", "PB123", "PB126", ->>>>>>> master + "PB100", "PB101","PB103","PB104", "PB105","PB108", "PB123", "PB126", "BA100", "BA101", "BA105", "BA106", "BA110", "BA111", "BA113", "BA116", "BA118", "BA119", "BA126", "DS100", "DS101", "DS105", "PA100", "PA101", "PA102", "PA103", "PA104", "PA105", "PA107", "PA108", "PA109", "PA111", "PA113", "PA115", "PA117", "PA118", "PA119", "PA120", From b95fe8abb2091812d4897d63bc9d2322b56532fd Mon Sep 17 00:00:00 2001 From: RotemAmit Date: Tue, 18 Jun 2024 10:48:26 +0300 Subject: [PATCH 12/12] updated the rationale --- .../validate/validators/PB_validators/PB108_is_valid_task_id.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py index 7222094a330..35e73f6d9c4 100644 --- a/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py +++ b/demisto_sdk/commands/validate/validators/PB_validators/PB108_is_valid_task_id.py @@ -16,7 +16,7 @@ class IsValidTaskIdValidator(BaseValidator[ContentTypes]): error_code = "PB108" description = "Validate that the task ID and the 'id' under the 'task' field are from UUID format." - rationale = "Validate that the task ID and the 'id' under the 'task' field are from UUID format." + rationale = "Each task should have a unique id in UUID format to avoid unknown behavior and breaking the playbook." error_message = "This playbook has tasks with invalid 'taskid' or invalid 'id' under the 'task' field.\n{0}" related_field = "taskid" is_auto_fixable = False