:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(tasks): split pure validation tests out of ai run defaults (#103604)
posthog[bot]a42f7a09f3cb
diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex acbf9fc175dd..653b176ac6bf 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -356,7 +356,6 @@ products/tasks/backend/temporal/slack_relay/tests/test_activities.py::TestSplitTproducts/tasks/backend/tests/test_agentsh.py::TestBuildAuditQueryCommandproducts/tasks/backend/tests/test_agentsh.py::TestBuildExecPrefixproducts/tasks/backend/tests/test_agentsh.py::TestGenerateConfigYaml-products/tasks/backend/tests/test_ai_run_defaults.py::TestRunCreateSerializerModeWithoutAdapterproducts/tasks/backend/tests/test_api.py::TestTaskRunRedisStreamKeepaliveproducts/tasks/backend/tests/test_api.py::TestUsageLimitResponseproducts/tasks/backend/tests/test_facade.py::TestAppendLogAgentActivitydiff --git a/products/tasks/backend/tests/test_ai_run_defaults.py b/products/tasks/backend/tests/test_ai_run_defaults.pyindex a7aba0603796..ca9fbb5129d6 100644--- a/products/tasks/backend/tests/test_ai_run_defaults.py+++ b/products/tasks/backend/tests/test_ai_run_defaults.py@@ -1,11 +1,8 @@from typing import Any-import pytestfrom posthog.test.base import APIBaseTestfrom unittest.mock import patch-from django.core.exceptions import ValidationError-from parameterized import parameterizedfrom posthog.models import Integration, Organization, Team, User@@ -20,10 +17,8 @@ from products.tasks.backend.logic.services.ai_run_defaults import (resolve_ai_run_selection,update_team_ai_run_preferences,update_user_ai_run_preferences,- validate_ai_run_preferences,)from products.tasks.backend.models import Task, TaskRun, TeamTasksConfig, UserTasksConfig-from products.tasks.backend.presentation.serializers import TaskRunCreateRequestSerializerFACADE = "products.tasks.backend.facade.api"@@ -204,51 +199,6 @@ class TestResolveAIRunDefaults(APIBaseTest):)-class TestValidateAIRunPreferences:- """The write-path guard. The config endpoints reject most of this at the serializer, so- these call it directly: the admin form and any future writer reach it with no serializer- in front."""-- @parameterized.expand(- [- ("pi_with_an_adapter", "pi", "codex", "gpt-5.6-terra", None),- ("pi_without_a_model", "pi", None, None, "high"),- ("pi_with_a_value_that_is_not_a_depth", "pi", None, "gpt-5.6-terra", "deep"),- ("pi_with_a_depth_it_cannot_run", "pi", None, "gpt-5.6-terra", "ultracode"),- ("acp_with_a_value_that_is_not_a_depth", None, "codex", "gpt-5.6-terra", "deep"),- ("acp_with_a_model_and_no_adapter", None, None, "gpt-5.6-terra", None),- ]- )- def test_rejects(self, _name, runtime, runtime_adapter, model, reasoning_effort):- with pytest.raises(ValidationError):- validate_ai_run_preferences(runtime_adapter, model, reasoning_effort, runtime=runtime)-- @parameterized.expand(- [- ("a_pi_pair", "pi", None, "gpt-5.6-terra", "off"),- ("an_acp_triple", None, "codex", "gpt-5.6-terra", "high"),- ("an_all_null_clear", None, None, None, None),- ]- )- def test_accepts(self, _name, runtime, runtime_adapter, model, reasoning_effort):- validate_ai_run_preferences(runtime_adapter, model, reasoning_effort, runtime=runtime)---class TestRunCreateSerializerModeWithoutAdapter(APIBaseTest):- # A composer that pins nothing must still be able to state the launch mode — the- # server resolves the runtime from the stored default and clamps the mode to it.- def test_mode_without_adapter_is_accepted(self):- serializer = TaskRunCreateRequestSerializer(data={"initial_permission_mode": "plan"})- assert serializer.is_valid(), serializer.errors-- def test_mode_outside_the_pinned_adapters_vocabulary_is_still_rejected(self):- serializer = TaskRunCreateRequestSerializer(- data={"runtime_adapter": "codex", "model": "gpt-5.5", "initial_permission_mode": "acceptEdits"}- )- assert not serializer.is_valid()- assert "initial_permission_mode" in serializer.errors--class TestModelAccessGating(APIBaseTest):GATED = "claude-opus-4-8"diff --git a/products/tasks/backend/tests/test_ai_run_defaults_unit.py b/products/tasks/backend/tests/test_ai_run_defaults_unit.pynew file mode 100644index 000000000000..874565473f61--- /dev/null+++ b/products/tasks/backend/tests/test_ai_run_defaults_unit.py@@ -0,0 +1,53 @@+import pytest++from django.core.exceptions import ValidationError++from parameterized import parameterized++from products.tasks.backend.logic.services.ai_run_defaults import validate_ai_run_preferences+from products.tasks.backend.presentation.serializers import TaskRunCreateRequestSerializer+++class TestValidateAIRunPreferences:+ """The write-path guard. The config endpoints reject most of this at the serializer, so+ these call it directly: the admin form and any future writer reach it with no serializer+ in front."""++ @parameterized.expand(+ [+ ("pi_with_an_adapter", "pi", "codex", "gpt-5.6-terra", None),+ ("pi_without_a_model", "pi", None, None, "high"),+ ("pi_with_a_value_that_is_not_a_depth", "pi", None, "gpt-5.6-terra", "deep"),+ ("pi_with_a_depth_it_cannot_run", "pi", None, "gpt-5.6-terra", "ultracode"),+ ("acp_with_a_value_that_is_not_a_depth", None, "codex", "gpt-5.6-terra", "deep"),+ ("acp_with_a_model_and_no_adapter", None, None, "gpt-5.6-terra", None),+ ]+ )+ def test_rejects(self, _name, runtime, runtime_adapter, model, reasoning_effort):+ with pytest.raises(ValidationError):+ validate_ai_run_preferences(runtime_adapter, model, reasoning_effort, runtime=runtime)++ @parameterized.expand(+ [+ ("a_pi_pair", "pi", None, "gpt-5.6-terra", "off"),+ ("an_acp_triple", None, "codex", "gpt-5.6-terra", "high"),+ ("an_all_null_clear", None, None, None, None),+ ]+ )+ def test_accepts(self, _name, runtime, runtime_adapter, model, reasoning_effort):+ validate_ai_run_preferences(runtime_adapter, model, reasoning_effort, runtime=runtime)+++class TestRunCreateSerializerModeWithoutAdapter:+ # A composer that pins nothing must still be able to state the launch mode — the+ # server resolves the runtime from the stored default and clamps the mode to it.+ def test_mode_without_adapter_is_accepted(self):+ serializer = TaskRunCreateRequestSerializer(data={"initial_permission_mode": "plan"})+ assert serializer.is_valid(), serializer.errors++ def test_mode_outside_the_pinned_adapters_vocabulary_is_still_rejected(self):+ serializer = TaskRunCreateRequestSerializer(+ data={"runtime_adapter": "codex", "model": "gpt-5.5", "initial_permission_mode": "acceptEdits"}+ )+ assert not serializer.is_valid()+ assert "initial_permission_mode" in serializer.errors