FrankYang0529 commented on code in PR #69320:
URL: https://github.com/apache/airflow/pull/69320#discussion_r3576319746


##########
airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py:
##########
@@ -737,11 +737,63 @@ def test_apply_datamodel_defaults_other_datamodel(self):
         # Should return params unchanged for other datamodels
         assert result == params, "Params should be unchanged for 
non-TriggerDAGRunPostBody datamodels"
 
+    def test_tasks_clear_args_follow_datamodel_defaults(self):
+        """Bool flags of ``tasks clear`` keep the ClearTaskInstancesBody 
defaults so a bare invocation only dry-runs."""
+        command_factory = CommandFactory()
+        tasks_group = next(
+            group_command for group_command in command_factory.group_commands 
if group_command.name == "tasks"
+        )
+        clear_command = next(
+            sub_command for sub_command in tasks_group.subcommands if 
sub_command.name == "clear"
+        )
+        args_by_flag = {arg.flags[0]: arg for arg in clear_command.args}
+
+        assert "dag_id" in args_by_flag, "required path parameter should be 
positional"
+        assert args_by_flag["--dry-run"].kwargs["action"] == 
BooleanOptionalAction
+        assert args_by_flag["--dry-run"].kwargs["default"] is True
+        assert args_by_flag["--only-failed"].kwargs["default"] is True
+        assert args_by_flag["--reset-dag-runs"].kwargs["default"] is True
+        assert args_by_flag["--only-running"].kwargs["default"] is False
+        assert args_by_flag["--run-on-latest-version"].kwargs["default"] is 
None
+        assert args_by_flag["--task-ids"].kwargs["type"] is str
+        assert "--output" in args_by_flag
+
+    @pytest.mark.parametrize(
+        ("raw_task_ids", "expected_task_ids"),
+        [
+            ("task_1", ["task_1"]),
+            ("task_1,task_2", ["task_1", "task_2"]),
+            (" task_1 , task_2 ,", ["task_1", "task_2"]),
+            ('["task_1", ["mapped_task", 0]]', ["task_1", ["mapped_task", 0]]),
+            (None, None),
+        ],
+    )
+    def test_apply_datamodel_defaults_clear_task_instances_task_ids(self, 
raw_task_ids, expected_task_ids):
+        """Test _apply_datamodel_defaults parses --task-ids strings for 
ClearTaskInstancesBody."""
+        from airflowctl.api.datamodels.generated import ClearTaskInstancesBody

Review Comment:
   Moved it. Thanks.



##########
airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py:
##########
@@ -737,11 +737,63 @@ def test_apply_datamodel_defaults_other_datamodel(self):
         # Should return params unchanged for other datamodels
         assert result == params, "Params should be unchanged for 
non-TriggerDAGRunPostBody datamodels"
 
+    def test_tasks_clear_args_follow_datamodel_defaults(self):
+        """Bool flags of ``tasks clear`` keep the ClearTaskInstancesBody 
defaults so a bare invocation only dry-runs."""
+        command_factory = CommandFactory()
+        tasks_group = next(
+            group_command for group_command in command_factory.group_commands 
if group_command.name == "tasks"
+        )
+        clear_command = next(
+            sub_command for sub_command in tasks_group.subcommands if 
sub_command.name == "clear"
+        )
+        args_by_flag = {arg.flags[0]: arg for arg in clear_command.args}
+
+        assert "dag_id" in args_by_flag, "required path parameter should be 
positional"
+        assert args_by_flag["--dry-run"].kwargs["action"] == 
BooleanOptionalAction
+        assert args_by_flag["--dry-run"].kwargs["default"] is True
+        assert args_by_flag["--only-failed"].kwargs["default"] is True
+        assert args_by_flag["--reset-dag-runs"].kwargs["default"] is True
+        assert args_by_flag["--only-running"].kwargs["default"] is False
+        assert args_by_flag["--run-on-latest-version"].kwargs["default"] is 
None
+        assert args_by_flag["--task-ids"].kwargs["type"] is str
+        assert "--output" in args_by_flag
+
+    @pytest.mark.parametrize(
+        ("raw_task_ids", "expected_task_ids"),
+        [
+            ("task_1", ["task_1"]),
+            ("task_1,task_2", ["task_1", "task_2"]),
+            (" task_1 , task_2 ,", ["task_1", "task_2"]),
+            ('["task_1", ["mapped_task", 0]]', ["task_1", ["mapped_task", 0]]),
+            (None, None),
+        ],
+    )
+    def test_apply_datamodel_defaults_clear_task_instances_task_ids(self, 
raw_task_ids, expected_task_ids):
+        """Test _apply_datamodel_defaults parses --task-ids strings for 
ClearTaskInstancesBody."""
+        from airflowctl.api.datamodels.generated import ClearTaskInstancesBody
+
+        command_factory = CommandFactory()
+        result = command_factory._apply_datamodel_defaults(
+            ClearTaskInstancesBody, {"task_ids": raw_task_ids, "dry_run": True}
+        )
+
+        assert result["task_ids"] == expected_task_ids
+        assert result["dry_run"] is True
+
+    def 
test_apply_datamodel_defaults_clear_task_instances_invalid_json_task_ids(self):
+        """Test _apply_datamodel_defaults rejects malformed JSON lists passed 
to --task-ids."""
+        from airflowctl.api.datamodels.generated import ClearTaskInstancesBody

Review Comment:
   Moved it. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to