@zimezone/z-command 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/package.json +4 -1
  2. package/templates/agents/api-documenter.agent.md +161 -0
  3. package/templates/agents/architect-review.agent.md +146 -0
  4. package/templates/agents/arm-cortex-expert.agent.md +288 -0
  5. package/templates/agents/backend-architect.agent.md +309 -0
  6. package/templates/agents/backend-security-coder.agent.md +152 -0
  7. package/templates/agents/bash-pro.agent.md +285 -0
  8. package/templates/agents/c-pro.agent.md +35 -0
  9. package/templates/agents/c4-code.agent.md +320 -0
  10. package/templates/agents/c4-component.agent.md +227 -0
  11. package/templates/agents/c4-container.agent.md +248 -0
  12. package/templates/agents/c4-context.agent.md +235 -0
  13. package/templates/agents/conductor-validator.agent.md +245 -0
  14. package/templates/agents/csharp-pro.agent.md +38 -0
  15. package/templates/agents/customer-support.agent.md +148 -0
  16. package/templates/agents/database-admin.agent.md +142 -0
  17. package/templates/agents/database-architect.agent.md +238 -0
  18. package/templates/agents/database-optimizer.agent.md +144 -0
  19. package/templates/agents/debugger.agent.md +30 -0
  20. package/templates/agents/deployment-engineer.agent.md +0 -0
  21. package/templates/agents/devops-troubleshooter.agent.md +138 -0
  22. package/templates/agents/django-pro.agent.md +159 -0
  23. package/templates/agents/docs-architect.agent.md +77 -0
  24. package/templates/agents/dotnet-architect.agent.md +175 -0
  25. package/templates/agents/dx-optimizer.agent.md +63 -0
  26. package/templates/agents/elixir-pro.agent.md +38 -0
  27. package/templates/agents/error-detective.agent.md +32 -0
  28. package/templates/agents/event-sourcing-architect.agent.md +42 -0
  29. package/templates/agents/fastapi-pro.agent.md +171 -0
  30. package/templates/agents/firmware-analyst.agent.md +330 -0
  31. package/templates/agents/frontend-security-coder.agent.md +149 -0
  32. package/templates/agents/haskell-pro.agent.md +37 -0
  33. package/templates/agents/hr-pro.agent.md +105 -0
  34. package/templates/agents/incident-responder.agent.md +190 -0
  35. package/templates/agents/ios-developer.agent.md +198 -0
  36. package/templates/agents/java-pro.agent.md +156 -0
  37. package/templates/agents/javascript-pro.agent.md +35 -0
  38. package/templates/agents/julia-pro.agent.md +187 -0
  39. package/templates/agents/legal-advisor.agent.md +49 -0
  40. package/templates/agents/malware-analyst.agent.md +272 -0
  41. package/templates/agents/mermaid-expert.agent.md +39 -0
  42. package/templates/agents/minecraft-bukkit-pro.agent.md +104 -0
  43. package/templates/agents/mobile-security-coder.agent.md +163 -0
  44. package/templates/agents/monorepo-architect.agent.md +44 -0
  45. package/templates/agents/observability-engineer.agent.md +228 -0
  46. package/templates/agents/performance-engineer.agent.md +167 -0
  47. package/templates/agents/php-pro.agent.md +43 -0
  48. package/templates/agents/posix-shell-pro.agent.md +284 -0
  49. package/templates/agents/quant-analyst.agent.md +32 -0
  50. package/templates/agents/reference-builder.agent.md +167 -0
  51. package/templates/agents/reverse-engineer.agent.md +202 -0
  52. package/templates/agents/risk-manager.agent.md +41 -0
  53. package/templates/agents/ruby-pro.agent.md +35 -0
  54. package/templates/agents/rust-pro.agent.md +156 -0
  55. package/templates/agents/sales-automator.agent.md +35 -0
  56. package/templates/agents/scala-pro.agent.md +60 -0
  57. package/templates/agents/search-specialist.agent.md +59 -0
  58. package/templates/agents/security-auditor.agent.md +138 -0
  59. package/templates/agents/seo-authority-builder.agent.md +116 -0
  60. package/templates/agents/seo-cannibalization-detector.agent.md +103 -0
  61. package/templates/agents/seo-content-auditor.agent.md +63 -0
  62. package/templates/agents/seo-content-planner.agent.md +88 -0
  63. package/templates/agents/seo-content-refresher.agent.md +98 -0
  64. package/templates/agents/seo-content-writer.agent.md +76 -0
  65. package/templates/agents/seo-keyword-strategist.agent.md +75 -0
  66. package/templates/agents/seo-meta-optimizer.agent.md +72 -0
  67. package/templates/agents/seo-snippet-hunter.agent.md +94 -0
  68. package/templates/agents/seo-structure-architect.agent.md +88 -0
  69. package/templates/agents/service-mesh-expert.agent.md +41 -0
  70. package/templates/agents/sql-pro.agent.md +146 -0
  71. package/templates/agents/tdd-orchestrator.agent.md +183 -0
  72. package/templates/agents/temporal-python-pro.agent.md +349 -0
  73. package/templates/agents/terraform-specialist.agent.md +137 -0
  74. package/templates/agents/test-automator.agent.md +203 -0
  75. package/templates/agents/threat-modeling-expert.agent.md +44 -0
  76. package/templates/agents/tutorial-engineer.agent.md +118 -0
  77. package/templates/agents/ui-ux-designer.agent.md +188 -0
  78. package/templates/agents/ui-visual-validator.agent.md +192 -0
  79. package/templates/agents/vector-database-engineer.agent.md +43 -0
  80. package/templates/skills/angular-migration/SKILL.md +410 -0
  81. package/templates/skills/api-design-principles/SKILL.md +528 -0
  82. package/templates/skills/api-design-principles/assets/api-design-checklist.md +155 -0
  83. package/templates/skills/api-design-principles/assets/rest-api-template.py +182 -0
  84. package/templates/skills/api-design-principles/references/graphql-schema-design.md +583 -0
  85. package/templates/skills/api-design-principles/references/rest-best-practices.md +408 -0
  86. package/templates/skills/architecture-decision-records/SKILL.md +428 -0
  87. package/templates/skills/architecture-patterns/SKILL.md +494 -0
  88. package/templates/skills/async-python-patterns/SKILL.md +694 -0
  89. package/templates/skills/auth-implementation-patterns/SKILL.md +634 -0
  90. package/templates/skills/changelog-automation/SKILL.md +552 -0
  91. package/templates/skills/code-review-excellence/SKILL.md +520 -0
  92. package/templates/skills/competitive-landscape/SKILL.md +479 -0
  93. package/templates/skills/context-driven-development/SKILL.md +385 -0
  94. package/templates/skills/cost-optimization/SKILL.md +274 -0
  95. package/templates/skills/cqrs-implementation/SKILL.md +554 -0
  96. package/templates/skills/data-quality-frameworks/SKILL.md +587 -0
  97. package/templates/skills/data-storytelling/SKILL.md +453 -0
  98. package/templates/skills/database-migration/SKILL.md +424 -0
  99. package/templates/skills/dbt-transformation-patterns/SKILL.md +561 -0
  100. package/templates/skills/debugging-strategies/SKILL.md +527 -0
  101. package/templates/skills/defi-protocol-templates/SKILL.md +454 -0
  102. package/templates/skills/dependency-upgrade/SKILL.md +409 -0
  103. package/templates/skills/deployment-pipeline-design/SKILL.md +359 -0
  104. package/templates/skills/distributed-tracing/SKILL.md +438 -0
  105. package/templates/skills/dotnet-backend-patterns/SKILL.md +815 -0
  106. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
  107. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
  108. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
  109. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
  110. package/templates/skills/e2e-testing-patterns/SKILL.md +547 -0
  111. package/templates/skills/employment-contract-templates/SKILL.md +507 -0
  112. package/templates/skills/error-handling-patterns/SKILL.md +636 -0
  113. package/templates/skills/event-store-design/SKILL.md +437 -0
  114. package/templates/skills/fastapi-templates/SKILL.md +567 -0
  115. package/templates/skills/git-advanced-workflows/SKILL.md +400 -0
  116. package/templates/skills/github-actions-templates/SKILL.md +333 -0
  117. package/templates/skills/go-concurrency-patterns/SKILL.md +655 -0
  118. package/templates/skills/grafana-dashboards/SKILL.md +369 -0
  119. package/templates/skills/helm-chart-scaffolding/SKILL.md +544 -0
  120. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  121. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  122. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  123. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  124. package/templates/skills/javascript-testing-patterns/SKILL.md +1025 -0
  125. package/templates/skills/langchain-architecture/SKILL.md +338 -0
  126. package/templates/skills/llm-evaluation/SKILL.md +471 -0
  127. package/templates/skills/microservices-patterns/SKILL.md +595 -0
  128. package/templates/skills/modern-javascript-patterns/SKILL.md +911 -0
  129. package/templates/skills/monorepo-management/SKILL.md +622 -0
  130. package/templates/skills/nextjs-app-router-patterns/SKILL.md +544 -0
  131. package/templates/skills/nodejs-backend-patterns/SKILL.md +1020 -0
  132. package/templates/skills/nx-workspace-patterns/SKILL.md +452 -0
  133. package/templates/skills/openapi-spec-generation/SKILL.md +1028 -0
  134. package/templates/skills/paypal-integration/SKILL.md +467 -0
  135. package/templates/skills/pci-compliance/SKILL.md +466 -0
  136. package/templates/skills/postgresql/SKILL.md +204 -0
  137. package/templates/skills/projection-patterns/SKILL.md +490 -0
  138. package/templates/skills/prometheus-configuration/SKILL.md +392 -0
  139. package/templates/skills/prompt-engineering-patterns/SKILL.md +201 -0
  140. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
  141. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
  142. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
  143. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
  144. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
  145. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
  146. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
  147. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
  148. package/templates/skills/python-packaging/SKILL.md +870 -0
  149. package/templates/skills/python-performance-optimization/SKILL.md +869 -0
  150. package/templates/skills/python-testing-patterns/SKILL.md +907 -0
  151. package/templates/skills/rag-implementation/SKILL.md +403 -0
  152. package/templates/skills/react-modernization/SKILL.md +513 -0
  153. package/templates/skills/react-native-architecture/SKILL.md +671 -0
  154. package/templates/skills/react-state-management/SKILL.md +429 -0
  155. package/templates/skills/risk-metrics-calculation/SKILL.md +555 -0
  156. package/templates/skills/rust-async-patterns/SKILL.md +517 -0
  157. package/templates/skills/secrets-management/SKILL.md +346 -0
  158. package/templates/skills/security-requirement-extraction/SKILL.md +677 -0
  159. package/templates/skills/shellcheck-configuration/SKILL.md +454 -0
  160. package/templates/skills/similarity-search-patterns/SKILL.md +558 -0
  161. package/templates/skills/slo-implementation/SKILL.md +329 -0
  162. package/templates/skills/sql-optimization-patterns/SKILL.md +493 -0
  163. package/templates/skills/stripe-integration/SKILL.md +442 -0
  164. package/templates/skills/tailwind-design-system/SKILL.md +666 -0
  165. package/templates/skills/temporal-python-testing/SKILL.md +158 -0
  166. package/templates/skills/temporal-python-testing/resources/integration-testing.md +455 -0
  167. package/templates/skills/temporal-python-testing/resources/local-setup.md +553 -0
  168. package/templates/skills/temporal-python-testing/resources/replay-testing.md +462 -0
  169. package/templates/skills/temporal-python-testing/resources/unit-testing.md +328 -0
  170. package/templates/skills/terraform-module-library/SKILL.md +249 -0
  171. package/templates/skills/terraform-module-library/references/aws-modules.md +63 -0
  172. package/templates/skills/threat-mitigation-mapping/SKILL.md +745 -0
  173. package/templates/skills/track-management/SKILL.md +593 -0
  174. package/templates/skills/typescript-advanced-types/SKILL.md +717 -0
  175. package/templates/skills/uv-package-manager/SKILL.md +831 -0
  176. package/templates/skills/vector-index-tuning/SKILL.md +521 -0
  177. package/templates/skills/wcag-audit-patterns/SKILL.md +555 -0
  178. package/templates/skills/workflow-orchestration-patterns/SKILL.md +316 -0
  179. package/templates/skills/workflow-patterns/SKILL.md +623 -0
  180. package/templates/agents/game-developer.agent.md +0 -57
  181. package/templates/agents/kubernetes-specialist.agent.md +0 -56
  182. package/templates/agents/market-researcher.agent.md +0 -47
@@ -0,0 +1,158 @@
1
+ ---
2
+ name: temporal-python-testing
3
+ description: Test Temporal workflows with pytest, time-skipping, and mocking strategies. Covers unit testing, integration testing, replay testing, and local development setup. Use when implementing Temporal workflow tests or debugging test failures.
4
+ ---
5
+
6
+ # Temporal Python Testing Strategies
7
+
8
+ Comprehensive testing approaches for Temporal workflows using pytest, progressive disclosure resources for specific testing scenarios.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - **Unit testing workflows** - Fast tests with time-skipping
13
+ - **Integration testing** - Workflows with mocked activities
14
+ - **Replay testing** - Validate determinism against production histories
15
+ - **Local development** - Set up Temporal server and pytest
16
+ - **CI/CD integration** - Automated testing pipelines
17
+ - **Coverage strategies** - Achieve ≥80% test coverage
18
+
19
+ ## Testing Philosophy
20
+
21
+ **Recommended Approach** (Source: docs.temporal.io/develop/python/testing-suite):
22
+
23
+ - Write majority as integration tests
24
+ - Use pytest with async fixtures
25
+ - Time-skipping enables fast feedback (month-long workflows → seconds)
26
+ - Mock activities to isolate workflow logic
27
+ - Validate determinism with replay testing
28
+
29
+ **Three Test Types**:
30
+
31
+ 1. **Unit**: Workflows with time-skipping, activities with ActivityEnvironment
32
+ 2. **Integration**: Workers with mocked activities
33
+ 3. **End-to-end**: Full Temporal server with real activities (use sparingly)
34
+
35
+ ## Available Resources
36
+
37
+ This skill provides detailed guidance through progressive disclosure. Load specific resources based on your testing needs:
38
+
39
+ ### Unit Testing Resources
40
+
41
+ **File**: `resources/unit-testing.md`
42
+ **When to load**: Testing individual workflows or activities in isolation
43
+ **Contains**:
44
+
45
+ - WorkflowEnvironment with time-skipping
46
+ - ActivityEnvironment for activity testing
47
+ - Fast execution of long-running workflows
48
+ - Manual time advancement patterns
49
+ - pytest fixtures and patterns
50
+
51
+ ### Integration Testing Resources
52
+
53
+ **File**: `resources/integration-testing.md`
54
+ **When to load**: Testing workflows with mocked external dependencies
55
+ **Contains**:
56
+
57
+ - Activity mocking strategies
58
+ - Error injection patterns
59
+ - Multi-activity workflow testing
60
+ - Signal and query testing
61
+ - Coverage strategies
62
+
63
+ ### Replay Testing Resources
64
+
65
+ **File**: `resources/replay-testing.md`
66
+ **When to load**: Validating determinism or deploying workflow changes
67
+ **Contains**:
68
+
69
+ - Determinism validation
70
+ - Production history replay
71
+ - CI/CD integration patterns
72
+ - Version compatibility testing
73
+
74
+ ### Local Development Resources
75
+
76
+ **File**: `resources/local-setup.md`
77
+ **When to load**: Setting up development environment
78
+ **Contains**:
79
+
80
+ - Docker Compose configuration
81
+ - pytest setup and configuration
82
+ - Coverage tool integration
83
+ - Development workflow
84
+
85
+ ## Quick Start Guide
86
+
87
+ ### Basic Workflow Test
88
+
89
+ ```python
90
+ import pytest
91
+ from temporalio.testing import WorkflowEnvironment
92
+ from temporalio.worker import Worker
93
+
94
+ @pytest.fixture
95
+ async def workflow_env():
96
+ env = await WorkflowEnvironment.start_time_skipping()
97
+ yield env
98
+ await env.shutdown()
99
+
100
+ @pytest.mark.asyncio
101
+ async def test_workflow(workflow_env):
102
+ async with Worker(
103
+ workflow_env.client,
104
+ task_queue="test-queue",
105
+ workflows=[YourWorkflow],
106
+ activities=[your_activity],
107
+ ):
108
+ result = await workflow_env.client.execute_workflow(
109
+ YourWorkflow.run,
110
+ args,
111
+ id="test-wf-id",
112
+ task_queue="test-queue",
113
+ )
114
+ assert result == expected
115
+ ```
116
+
117
+ ### Basic Activity Test
118
+
119
+ ```python
120
+ from temporalio.testing import ActivityEnvironment
121
+
122
+ async def test_activity():
123
+ env = ActivityEnvironment()
124
+ result = await env.run(your_activity, "test-input")
125
+ assert result == expected_output
126
+ ```
127
+
128
+ ## Coverage Targets
129
+
130
+ **Recommended Coverage** (Source: docs.temporal.io best practices):
131
+
132
+ - **Workflows**: ≥80% logic coverage
133
+ - **Activities**: ≥80% logic coverage
134
+ - **Integration**: Critical paths with mocked activities
135
+ - **Replay**: All workflow versions before deployment
136
+
137
+ ## Key Testing Principles
138
+
139
+ 1. **Time-Skipping** - Month-long workflows test in seconds
140
+ 2. **Mock Activities** - Isolate workflow logic from external dependencies
141
+ 3. **Replay Testing** - Validate determinism before deployment
142
+ 4. **High Coverage** - ≥80% target for production workflows
143
+ 5. **Fast Feedback** - Unit tests run in milliseconds
144
+
145
+ ## How to Use Resources
146
+
147
+ **Load specific resource when needed**:
148
+
149
+ - "Show me unit testing patterns" → Load `resources/unit-testing.md`
150
+ - "How do I mock activities?" → Load `resources/integration-testing.md`
151
+ - "Setup local Temporal server" → Load `resources/local-setup.md`
152
+ - "Validate determinism" → Load `resources/replay-testing.md`
153
+
154
+ ## Additional References
155
+
156
+ - Python SDK Testing: docs.temporal.io/develop/python/testing-suite
157
+ - Testing Patterns: github.com/temporalio/temporal/blob/main/docs/development/testing.md
158
+ - Python Samples: github.com/temporalio/samples-python
@@ -0,0 +1,455 @@
1
+ # Integration Testing with Mocked Activities
2
+
3
+ Comprehensive patterns for testing workflows with mocked external dependencies, error injection, and complex scenarios.
4
+
5
+ ## Activity Mocking Strategy
6
+
7
+ **Purpose**: Test workflow orchestration logic without calling real external services
8
+
9
+ ### Basic Mock Pattern
10
+
11
+ ```python
12
+ import pytest
13
+ from temporalio.testing import WorkflowEnvironment
14
+ from temporalio.worker import Worker
15
+ from unittest.mock import Mock
16
+
17
+ @pytest.mark.asyncio
18
+ async def test_workflow_with_mocked_activity(workflow_env):
19
+ """Mock activity to test workflow logic"""
20
+
21
+ # Create mock activity
22
+ mock_activity = Mock(return_value="mocked-result")
23
+
24
+ @workflow.defn
25
+ class WorkflowWithActivity:
26
+ @workflow.run
27
+ async def run(self, input: str) -> str:
28
+ result = await workflow.execute_activity(
29
+ process_external_data,
30
+ input,
31
+ start_to_close_timeout=timedelta(seconds=10),
32
+ )
33
+ return f"processed: {result}"
34
+
35
+ async with Worker(
36
+ workflow_env.client,
37
+ task_queue="test",
38
+ workflows=[WorkflowWithActivity],
39
+ activities=[mock_activity], # Use mock instead of real activity
40
+ ):
41
+ result = await workflow_env.client.execute_workflow(
42
+ WorkflowWithActivity.run,
43
+ "test-input",
44
+ id="wf-mock",
45
+ task_queue="test",
46
+ )
47
+ assert result == "processed: mocked-result"
48
+ mock_activity.assert_called_once()
49
+ ```
50
+
51
+ ### Dynamic Mock Responses
52
+
53
+ **Scenario-Based Mocking**:
54
+
55
+ ```python
56
+ @pytest.mark.asyncio
57
+ async def test_workflow_multiple_mock_scenarios(workflow_env):
58
+ """Test different workflow paths with dynamic mocks"""
59
+
60
+ # Mock returns different values based on input
61
+ def dynamic_activity(input: str) -> str:
62
+ if input == "error-case":
63
+ raise ApplicationError("Validation failed", non_retryable=True)
64
+ return f"processed-{input}"
65
+
66
+ @workflow.defn
67
+ class DynamicWorkflow:
68
+ @workflow.run
69
+ async def run(self, input: str) -> str:
70
+ try:
71
+ result = await workflow.execute_activity(
72
+ dynamic_activity,
73
+ input,
74
+ start_to_close_timeout=timedelta(seconds=10),
75
+ )
76
+ return f"success: {result}"
77
+ except ApplicationError as e:
78
+ return f"error: {e.message}"
79
+
80
+ async with Worker(
81
+ workflow_env.client,
82
+ task_queue="test",
83
+ workflows=[DynamicWorkflow],
84
+ activities=[dynamic_activity],
85
+ ):
86
+ # Test success path
87
+ result_success = await workflow_env.client.execute_workflow(
88
+ DynamicWorkflow.run,
89
+ "valid-input",
90
+ id="wf-success",
91
+ task_queue="test",
92
+ )
93
+ assert result_success == "success: processed-valid-input"
94
+
95
+ # Test error path
96
+ result_error = await workflow_env.client.execute_workflow(
97
+ DynamicWorkflow.run,
98
+ "error-case",
99
+ id="wf-error",
100
+ task_queue="test",
101
+ )
102
+ assert "Validation failed" in result_error
103
+ ```
104
+
105
+ ## Error Injection Patterns
106
+
107
+ ### Testing Transient Failures
108
+
109
+ **Retry Behavior**:
110
+
111
+ ```python
112
+ @pytest.mark.asyncio
113
+ async def test_workflow_transient_errors(workflow_env):
114
+ """Test retry logic with controlled failures"""
115
+
116
+ attempt_count = 0
117
+
118
+ @activity.defn
119
+ async def transient_activity() -> str:
120
+ nonlocal attempt_count
121
+ attempt_count += 1
122
+
123
+ if attempt_count < 3:
124
+ raise Exception(f"Transient error {attempt_count}")
125
+ return "success-after-retries"
126
+
127
+ @workflow.defn
128
+ class RetryWorkflow:
129
+ @workflow.run
130
+ async def run(self) -> str:
131
+ return await workflow.execute_activity(
132
+ transient_activity,
133
+ start_to_close_timeout=timedelta(seconds=10),
134
+ retry_policy=RetryPolicy(
135
+ initial_interval=timedelta(milliseconds=10),
136
+ maximum_attempts=5,
137
+ backoff_coefficient=1.0,
138
+ ),
139
+ )
140
+
141
+ async with Worker(
142
+ workflow_env.client,
143
+ task_queue="test",
144
+ workflows=[RetryWorkflow],
145
+ activities=[transient_activity],
146
+ ):
147
+ result = await workflow_env.client.execute_workflow(
148
+ RetryWorkflow.run,
149
+ id="retry-wf",
150
+ task_queue="test",
151
+ )
152
+ assert result == "success-after-retries"
153
+ assert attempt_count == 3
154
+ ```
155
+
156
+ ### Testing Non-Retryable Errors
157
+
158
+ **Business Validation Failures**:
159
+
160
+ ```python
161
+ @pytest.mark.asyncio
162
+ async def test_workflow_non_retryable_error(workflow_env):
163
+ """Test handling of permanent failures"""
164
+
165
+ @activity.defn
166
+ async def validation_activity(input: dict) -> str:
167
+ if not input.get("valid"):
168
+ raise ApplicationError(
169
+ "Invalid input",
170
+ non_retryable=True, # Don't retry validation errors
171
+ )
172
+ return "validated"
173
+
174
+ @workflow.defn
175
+ class ValidationWorkflow:
176
+ @workflow.run
177
+ async def run(self, input: dict) -> str:
178
+ try:
179
+ return await workflow.execute_activity(
180
+ validation_activity,
181
+ input,
182
+ start_to_close_timeout=timedelta(seconds=10),
183
+ )
184
+ except ApplicationError as e:
185
+ return f"validation-failed: {e.message}"
186
+
187
+ async with Worker(
188
+ workflow_env.client,
189
+ task_queue="test",
190
+ workflows=[ValidationWorkflow],
191
+ activities=[validation_activity],
192
+ ):
193
+ result = await workflow_env.client.execute_workflow(
194
+ ValidationWorkflow.run,
195
+ {"valid": False},
196
+ id="validation-wf",
197
+ task_queue="test",
198
+ )
199
+ assert "validation-failed" in result
200
+ ```
201
+
202
+ ## Multi-Activity Workflow Testing
203
+
204
+ ### Sequential Activity Pattern
205
+
206
+ ```python
207
+ @pytest.mark.asyncio
208
+ async def test_workflow_sequential_activities(workflow_env):
209
+ """Test workflow orchestrating multiple activities"""
210
+
211
+ activity_calls = []
212
+
213
+ @activity.defn
214
+ async def step_1(input: str) -> str:
215
+ activity_calls.append("step_1")
216
+ return f"{input}-step1"
217
+
218
+ @activity.defn
219
+ async def step_2(input: str) -> str:
220
+ activity_calls.append("step_2")
221
+ return f"{input}-step2"
222
+
223
+ @activity.defn
224
+ async def step_3(input: str) -> str:
225
+ activity_calls.append("step_3")
226
+ return f"{input}-step3"
227
+
228
+ @workflow.defn
229
+ class SequentialWorkflow:
230
+ @workflow.run
231
+ async def run(self, input: str) -> str:
232
+ result_1 = await workflow.execute_activity(
233
+ step_1,
234
+ input,
235
+ start_to_close_timeout=timedelta(seconds=10),
236
+ )
237
+ result_2 = await workflow.execute_activity(
238
+ step_2,
239
+ result_1,
240
+ start_to_close_timeout=timedelta(seconds=10),
241
+ )
242
+ result_3 = await workflow.execute_activity(
243
+ step_3,
244
+ result_2,
245
+ start_to_close_timeout=timedelta(seconds=10),
246
+ )
247
+ return result_3
248
+
249
+ async with Worker(
250
+ workflow_env.client,
251
+ task_queue="test",
252
+ workflows=[SequentialWorkflow],
253
+ activities=[step_1, step_2, step_3],
254
+ ):
255
+ result = await workflow_env.client.execute_workflow(
256
+ SequentialWorkflow.run,
257
+ "start",
258
+ id="seq-wf",
259
+ task_queue="test",
260
+ )
261
+ assert result == "start-step1-step2-step3"
262
+ assert activity_calls == ["step_1", "step_2", "step_3"]
263
+ ```
264
+
265
+ ### Parallel Activity Pattern
266
+
267
+ ```python
268
+ @pytest.mark.asyncio
269
+ async def test_workflow_parallel_activities(workflow_env):
270
+ """Test concurrent activity execution"""
271
+
272
+ @activity.defn
273
+ async def parallel_task(task_id: int) -> str:
274
+ return f"task-{task_id}"
275
+
276
+ @workflow.defn
277
+ class ParallelWorkflow:
278
+ @workflow.run
279
+ async def run(self, task_count: int) -> list[str]:
280
+ # Execute activities in parallel
281
+ tasks = [
282
+ workflow.execute_activity(
283
+ parallel_task,
284
+ i,
285
+ start_to_close_timeout=timedelta(seconds=10),
286
+ )
287
+ for i in range(task_count)
288
+ ]
289
+ return await asyncio.gather(*tasks)
290
+
291
+ async with Worker(
292
+ workflow_env.client,
293
+ task_queue="test",
294
+ workflows=[ParallelWorkflow],
295
+ activities=[parallel_task],
296
+ ):
297
+ result = await workflow_env.client.execute_workflow(
298
+ ParallelWorkflow.run,
299
+ 3,
300
+ id="parallel-wf",
301
+ task_queue="test",
302
+ )
303
+ assert result == ["task-0", "task-1", "task-2"]
304
+ ```
305
+
306
+ ## Signal and Query Testing
307
+
308
+ ### Signal Handlers
309
+
310
+ ```python
311
+ @pytest.mark.asyncio
312
+ async def test_workflow_signals(workflow_env):
313
+ """Test workflow signal handling"""
314
+
315
+ @workflow.defn
316
+ class SignalWorkflow:
317
+ def __init__(self) -> None:
318
+ self._status = "initialized"
319
+
320
+ @workflow.run
321
+ async def run(self) -> str:
322
+ # Wait for completion signal
323
+ await workflow.wait_condition(lambda: self._status == "completed")
324
+ return self._status
325
+
326
+ @workflow.signal
327
+ async def update_status(self, new_status: str) -> None:
328
+ self._status = new_status
329
+
330
+ @workflow.query
331
+ def get_status(self) -> str:
332
+ return self._status
333
+
334
+ async with Worker(
335
+ workflow_env.client,
336
+ task_queue="test",
337
+ workflows=[SignalWorkflow],
338
+ ):
339
+ # Start workflow
340
+ handle = await workflow_env.client.start_workflow(
341
+ SignalWorkflow.run,
342
+ id="signal-wf",
343
+ task_queue="test",
344
+ )
345
+
346
+ # Verify initial state via query
347
+ initial_status = await handle.query(SignalWorkflow.get_status)
348
+ assert initial_status == "initialized"
349
+
350
+ # Send signal
351
+ await handle.signal(SignalWorkflow.update_status, "processing")
352
+
353
+ # Verify updated state
354
+ updated_status = await handle.query(SignalWorkflow.get_status)
355
+ assert updated_status == "processing"
356
+
357
+ # Complete workflow
358
+ await handle.signal(SignalWorkflow.update_status, "completed")
359
+ result = await handle.result()
360
+ assert result == "completed"
361
+ ```
362
+
363
+ ## Coverage Strategies
364
+
365
+ ### Workflow Logic Coverage
366
+
367
+ **Target**: ≥80% coverage of workflow decision logic
368
+
369
+ ```python
370
+ # Test all branches
371
+ @pytest.mark.parametrize("condition,expected", [
372
+ (True, "branch-a"),
373
+ (False, "branch-b"),
374
+ ])
375
+ async def test_workflow_branches(workflow_env, condition, expected):
376
+ """Ensure all code paths are tested"""
377
+ # Test implementation
378
+ pass
379
+ ```
380
+
381
+ ### Activity Coverage
382
+
383
+ **Target**: ≥80% coverage of activity logic
384
+
385
+ ```python
386
+ # Test activity edge cases
387
+ @pytest.mark.parametrize("input,expected", [
388
+ ("valid", "success"),
389
+ ("", "empty-input-error"),
390
+ (None, "null-input-error"),
391
+ ])
392
+ async def test_activity_edge_cases(activity_env, input, expected):
393
+ """Test activity error handling"""
394
+ # Test implementation
395
+ pass
396
+ ```
397
+
398
+ ## Integration Test Organization
399
+
400
+ ### Test Structure
401
+
402
+ ```
403
+ tests/
404
+ ├── integration/
405
+ │ ├── conftest.py # Shared fixtures
406
+ │ ├── test_order_workflow.py # Order processing tests
407
+ │ ├── test_payment_workflow.py # Payment tests
408
+ │ └── test_fulfillment_workflow.py
409
+ ├── unit/
410
+ │ ├── test_order_activities.py
411
+ │ └── test_payment_activities.py
412
+ └── fixtures/
413
+ └── test_data.py # Test data builders
414
+ ```
415
+
416
+ ### Shared Fixtures
417
+
418
+ ```python
419
+ # conftest.py
420
+ import pytest
421
+ from temporalio.testing import WorkflowEnvironment
422
+
423
+ @pytest.fixture(scope="session")
424
+ async def workflow_env():
425
+ """Session-scoped environment for integration tests"""
426
+ env = await WorkflowEnvironment.start_time_skipping()
427
+ yield env
428
+ await env.shutdown()
429
+
430
+ @pytest.fixture
431
+ def mock_payment_service():
432
+ """Mock external payment service"""
433
+ return Mock()
434
+
435
+ @pytest.fixture
436
+ def mock_inventory_service():
437
+ """Mock external inventory service"""
438
+ return Mock()
439
+ ```
440
+
441
+ ## Best Practices
442
+
443
+ 1. **Mock External Dependencies**: Never call real APIs in tests
444
+ 2. **Test Error Scenarios**: Verify compensation and retry logic
445
+ 3. **Parallel Testing**: Use pytest-xdist for faster test runs
446
+ 4. **Isolated Tests**: Each test should be independent
447
+ 5. **Clear Assertions**: Verify both results and side effects
448
+ 6. **Coverage Target**: ≥80% for critical workflows
449
+ 7. **Fast Execution**: Use time-skipping, avoid real delays
450
+
451
+ ## Additional Resources
452
+
453
+ - Mocking Strategies: docs.temporal.io/develop/python/testing-suite
454
+ - pytest Best Practices: docs.pytest.org/en/stable/goodpractices.html
455
+ - Python SDK Samples: github.com/temporalio/samples-python