|
5 | 5 | namespace Tests\Feature\V2; |
6 | 6 |
|
7 | 7 | use Illuminate\Support\Facades\Queue; |
| 8 | +use Tests\Fixtures\V2\TestDeprecatedPatchWorkflow; |
| 9 | +use Tests\Fixtures\V2\TestPatchedWorkflow; |
8 | 10 | use Tests\Fixtures\V2\TestVersionAfterSignalWorkflow; |
9 | 11 | use Tests\Fixtures\V2\TestVersionBeforeSignalWorkflow; |
10 | 12 | use Tests\Fixtures\V2\TestVersionMinSupportedWorkflow; |
@@ -136,6 +138,95 @@ public function testVersionMarkersReuseRecordedHistoryValue(): void |
136 | 138 | $this->assertSame('v2_result', $workflow->output()['result']); |
137 | 139 | } |
138 | 140 |
|
| 141 | + public function testPatchedRecordsMarkerAndResolvesTrueForCurrentRuns(): void |
| 142 | + { |
| 143 | + Queue::fake(); |
| 144 | + |
| 145 | + $workflow = WorkflowStub::make(TestPatchedWorkflow::class, 'patched-current'); |
| 146 | + $workflow->start(); |
| 147 | + |
| 148 | + $this->drainReadyTasks(); |
| 149 | + |
| 150 | + $this->assertTrue($workflow->refresh()->completed()); |
| 151 | + $this->assertSame([ |
| 152 | + 'patched' => true, |
| 153 | + 'branch' => 'patched', |
| 154 | + ], $workflow->output()); |
| 155 | + |
| 156 | + /** @var WorkflowHistoryEvent $marker */ |
| 157 | + $marker = WorkflowHistoryEvent::query() |
| 158 | + ->where('workflow_run_id', $workflow->runId()) |
| 159 | + ->where('event_type', HistoryEventType::VersionMarkerRecorded->value) |
| 160 | + ->firstOrFail(); |
| 161 | + |
| 162 | + $this->assertSame('patch-1', $marker->payload['change_id'] ?? null); |
| 163 | + $this->assertSame(1, $marker->payload['version'] ?? null); |
| 164 | + $this->assertSame(WorkflowStub::DEFAULT_VERSION, $marker->payload['min_supported'] ?? null); |
| 165 | + $this->assertSame(1, $marker->payload['max_supported'] ?? null); |
| 166 | + } |
| 167 | + |
| 168 | + public function testPatchedResolvesFalseForRecordedLegacyMarker(): void |
| 169 | + { |
| 170 | + Queue::fake(); |
| 171 | + |
| 172 | + $workflow = WorkflowStub::make(TestPatchedWorkflow::class, 'patched-legacy'); |
| 173 | + $workflow->start(); |
| 174 | + |
| 175 | + /** @var WorkflowRun $run */ |
| 176 | + $run = WorkflowRun::query()->findOrFail($workflow->runId()); |
| 177 | + |
| 178 | + WorkflowHistoryEvent::query()->create([ |
| 179 | + 'workflow_run_id' => $run->id, |
| 180 | + 'sequence' => 3, |
| 181 | + 'event_type' => HistoryEventType::VersionMarkerRecorded->value, |
| 182 | + 'payload' => [ |
| 183 | + 'sequence' => 1, |
| 184 | + 'change_id' => 'patch-1', |
| 185 | + 'version' => WorkflowStub::DEFAULT_VERSION, |
| 186 | + 'min_supported' => WorkflowStub::DEFAULT_VERSION, |
| 187 | + 'max_supported' => 1, |
| 188 | + ], |
| 189 | + 'recorded_at' => now(), |
| 190 | + ]); |
| 191 | + |
| 192 | + $run->forceFill([ |
| 193 | + 'last_history_sequence' => 3, |
| 194 | + ])->save(); |
| 195 | + |
| 196 | + $this->drainReadyTasks(); |
| 197 | + |
| 198 | + $this->assertTrue($workflow->refresh()->completed()); |
| 199 | + $this->assertSame([ |
| 200 | + 'patched' => false, |
| 201 | + 'branch' => 'legacy', |
| 202 | + ], $workflow->output()); |
| 203 | + } |
| 204 | + |
| 205 | + public function testDeprecatePatchRecordsMarkerAndReturnsNull(): void |
| 206 | + { |
| 207 | + Queue::fake(); |
| 208 | + |
| 209 | + $workflow = WorkflowStub::make(TestDeprecatedPatchWorkflow::class, 'patch-deprecated'); |
| 210 | + $workflow->start(); |
| 211 | + |
| 212 | + $this->drainReadyTasks(); |
| 213 | + |
| 214 | + $this->assertTrue($workflow->refresh()->completed()); |
| 215 | + $this->assertSame([ |
| 216 | + 'marker_result' => null, |
| 217 | + 'branch' => 'patched', |
| 218 | + ], $workflow->output()); |
| 219 | + |
| 220 | + /** @var WorkflowHistoryEvent $marker */ |
| 221 | + $marker = WorkflowHistoryEvent::query() |
| 222 | + ->where('workflow_run_id', $workflow->runId()) |
| 223 | + ->where('event_type', HistoryEventType::VersionMarkerRecorded->value) |
| 224 | + ->firstOrFail(); |
| 225 | + |
| 226 | + $this->assertSame('patch-1', $marker->payload['change_id'] ?? null); |
| 227 | + $this->assertSame(1, $marker->payload['version'] ?? null); |
| 228 | + } |
| 229 | + |
139 | 230 | public function testVersionMarkersFailRunWhenRecordedVersionIsNotSupported(): void |
140 | 231 | { |
141 | 232 | Queue::fake(); |
|
0 commit comments