forSnapshot($tenant, $snapshot); $run = OperationRun::factory()->create([ 'managed_environment_id' => (int) $tenant->getKey(), 'workspace_id' => (int) $tenant->workspace_id, 'user_id' => (int) $user->getKey(), 'type' => 'environment.review.compose', 'status' => OperationRunStatus::Queued->value, 'outcome' => OperationRunOutcome::Pending->value, 'created_at' => now()->subMinutes(20), 'context' => [ 'managed_environment_id' => (int) $tenant->getKey(), 'workspace_id' => (int) $tenant->workspace_id, 'evidence_snapshot_id' => (int) $snapshot->getKey(), 'review_fingerprint' => $fingerprint, ], ]); $otherRun = OperationRun::factory()->create([ 'managed_environment_id' => (int) $tenant->getKey(), 'workspace_id' => (int) $tenant->workspace_id, 'type' => 'environment.review.compose', 'status' => OperationRunStatus::Completed->value, 'outcome' => OperationRunOutcome::Succeeded->value, ]); $review = EnvironmentReview::factory()->ready()->create([ 'workspace_id' => (int) $tenant->workspace_id, 'managed_environment_id' => (int) $tenant->getKey(), 'evidence_snapshot_id' => (int) $snapshot->getKey(), 'initiated_by_user_id' => (int) $user->getKey(), 'operation_run_id' => (int) $otherRun->getKey(), 'fingerprint' => $fingerprint, ]); $change = app(AdapterRunReconciler::class)->reconcileOperationRun($run); expect($change['applied'] ?? null)->toBeTrue() ->and(data_get($run->fresh()->context, 'reconciliation.related.type'))->toBe('environment_review') ->and(data_get($run->fresh()->context, 'reconciliation.related.id'))->toBe((int) $review->getKey()); $this->actingAs($user); setAdminPanelContext($tenant); $links = OperationRunLinks::related($run->fresh(), $tenant); $sharedLinks = app(RelatedNavigationResolver::class)->operationLinks($run->fresh(), $tenant); $sharedEntry = collect(app(RelatedNavigationResolver::class)->detailEntries( CrossResourceNavigationMatrix::SOURCE_OPERATION_RUN, $run->fresh(), ))->firstWhere('key', 'environment_review'); $truth = app(ArtifactTruthPresenter::class)->forOperationRun($run->fresh()); $expected = EnvironmentReviewResource::environmentScopedUrl('view', ['record' => $review], $tenant); expect($links['ManagedEnvironment Review'] ?? null)->toBe($expected) ->and($sharedLinks['ManagedEnvironment Review'] ?? null)->toBe($expected) ->and($sharedEntry['targetUrl'] ?? null)->toBe($expected) ->and($sharedEntry['actionLabel'] ?? null)->toBe('ManagedEnvironment Review') ->and($truth->relatedArtifactUrl)->toBe($expected); });