|
9 | 9 | PreprodArtifact,
|
10 | 10 | PreprodArtifactSizeComparison,
|
11 | 11 | PreprodArtifactSizeMetrics,
|
| 12 | + PreprodBuildConfiguration, |
12 | 13 | )
|
13 | 14 | from sentry.preprod.size_analysis.tasks import (
|
14 | 15 | _run_size_analysis_comparison,
|
@@ -371,6 +372,136 @@ def test_compare_preprod_artifact_size_analysis_cannot_compare_metrics(self):
|
371 | 372 | # Should not call _run_size_analysis_comparison due to incompatible metrics
|
372 | 373 | mock_run_comparison.assert_not_called()
|
373 | 374 |
|
| 375 | + def test_compare_preprod_artifact_size_analysis_different_build_configurations_as_head(self): |
| 376 | + """Test compare_preprod_artifact_size_analysis with different build configurations when artifact is head.""" |
| 377 | + # Create commit comparisons |
| 378 | + head_commit = CommitComparison.objects.create( |
| 379 | + organization_id=self.organization.id, |
| 380 | + head_sha="a" * 40, |
| 381 | + base_sha="b" * 40, |
| 382 | + provider="github", |
| 383 | + head_repo_name="owner/repo", |
| 384 | + base_repo_name="owner/repo", |
| 385 | + ) |
| 386 | + base_commit = CommitComparison.objects.create( |
| 387 | + organization_id=self.organization.id, |
| 388 | + head_sha="b" * 40, |
| 389 | + base_sha="c" * 40, |
| 390 | + provider="github", |
| 391 | + head_repo_name="owner/repo", |
| 392 | + base_repo_name="owner/repo", |
| 393 | + ) |
| 394 | + |
| 395 | + # Create build configurations |
| 396 | + debug_config = PreprodBuildConfiguration.objects.create(project=self.project, name="debug") |
| 397 | + release_config = PreprodBuildConfiguration.objects.create( |
| 398 | + project=self.project, name="release" |
| 399 | + ) |
| 400 | + |
| 401 | + # Create artifacts with different build configurations |
| 402 | + head_artifact = PreprodArtifact.objects.create( |
| 403 | + project=self.project, |
| 404 | + commit_comparison=head_commit, |
| 405 | + app_id="com.example.app", |
| 406 | + build_version="1.0.0", |
| 407 | + build_number=1, |
| 408 | + build_configuration=debug_config, |
| 409 | + state=PreprodArtifact.ArtifactState.PROCESSED, |
| 410 | + ) |
| 411 | + base_artifact = PreprodArtifact.objects.create( |
| 412 | + project=self.project, |
| 413 | + commit_comparison=base_commit, |
| 414 | + app_id="com.example.app", |
| 415 | + build_version="1.0.0", |
| 416 | + build_number=1, |
| 417 | + build_configuration=release_config, |
| 418 | + state=PreprodArtifact.ArtifactState.PROCESSED, |
| 419 | + ) |
| 420 | + |
| 421 | + with ( |
| 422 | + patch( |
| 423 | + "sentry.preprod.size_analysis.tasks._run_size_analysis_comparison" |
| 424 | + ) as mock_run_comparison, |
| 425 | + patch("sentry.preprod.size_analysis.tasks.logger") as mock_logger, |
| 426 | + ): |
| 427 | + compare_preprod_artifact_size_analysis( |
| 428 | + project_id=self.project.id, |
| 429 | + org_id=self.organization.id, |
| 430 | + artifact_id=head_artifact.id, |
| 431 | + ) |
| 432 | + |
| 433 | + # Should log different build configurations and not run comparison |
| 434 | + mock_logger.info.assert_called_with( |
| 435 | + "preprod.size_analysis.compare.artifact_different_build_configurations", |
| 436 | + extra={"head_artifact_id": head_artifact.id, "base_artifact_id": base_artifact.id}, |
| 437 | + ) |
| 438 | + mock_run_comparison.assert_not_called() |
| 439 | + |
| 440 | + def test_compare_preprod_artifact_size_analysis_different_build_configurations_as_base(self): |
| 441 | + """Test compare_preprod_artifact_size_analysis with different build configurations when artifact is base.""" |
| 442 | + # Create commit comparison |
| 443 | + base_commit = CommitComparison.objects.create( |
| 444 | + organization_id=self.organization.id, |
| 445 | + head_sha="a" * 40, |
| 446 | + base_sha="b" * 40, |
| 447 | + provider="github", |
| 448 | + head_repo_name="owner/repo", |
| 449 | + base_repo_name="owner/repo", |
| 450 | + ) |
| 451 | + head_commit = CommitComparison.objects.create( |
| 452 | + organization_id=self.organization.id, |
| 453 | + head_sha="c" * 40, |
| 454 | + base_sha="a" * 40, |
| 455 | + provider="github", |
| 456 | + head_repo_name="owner/repo", |
| 457 | + base_repo_name="owner/repo", |
| 458 | + ) |
| 459 | + |
| 460 | + # Create build configurations |
| 461 | + debug_config = PreprodBuildConfiguration.objects.create(project=self.project, name="debug") |
| 462 | + release_config = PreprodBuildConfiguration.objects.create( |
| 463 | + project=self.project, name="release" |
| 464 | + ) |
| 465 | + |
| 466 | + # Create artifacts with different build configurations |
| 467 | + base_artifact = PreprodArtifact.objects.create( |
| 468 | + project=self.project, |
| 469 | + commit_comparison=base_commit, |
| 470 | + app_id="com.example.app", |
| 471 | + build_version="1.0.0", |
| 472 | + build_number=1, |
| 473 | + build_configuration=debug_config, |
| 474 | + state=PreprodArtifact.ArtifactState.PROCESSED, |
| 475 | + ) |
| 476 | + head_artifact = PreprodArtifact.objects.create( |
| 477 | + project=self.project, |
| 478 | + commit_comparison=head_commit, |
| 479 | + app_id="com.example.app", |
| 480 | + build_version="1.0.0", |
| 481 | + build_number=1, |
| 482 | + build_configuration=release_config, |
| 483 | + state=PreprodArtifact.ArtifactState.PROCESSED, |
| 484 | + ) |
| 485 | + |
| 486 | + with ( |
| 487 | + patch( |
| 488 | + "sentry.preprod.size_analysis.tasks._run_size_analysis_comparison" |
| 489 | + ) as mock_run_comparison, |
| 490 | + patch("sentry.preprod.size_analysis.tasks.logger") as mock_logger, |
| 491 | + ): |
| 492 | + compare_preprod_artifact_size_analysis( |
| 493 | + project_id=self.project.id, |
| 494 | + org_id=self.organization.id, |
| 495 | + artifact_id=base_artifact.id, |
| 496 | + ) |
| 497 | + |
| 498 | + # Should log different build configurations and not run comparison |
| 499 | + mock_logger.info.assert_called_with( |
| 500 | + "preprod.size_analysis.compare.head_artifact_different_build_configurations", |
| 501 | + extra={"head_artifact_id": head_artifact.id, "base_artifact_id": base_artifact.id}, |
| 502 | + ) |
| 503 | + mock_run_comparison.assert_not_called() |
| 504 | + |
374 | 505 |
|
375 | 506 | class ManualSizeAnalysisComparisonTest(TestCase):
|
376 | 507 | def setUp(self):
|
|
0 commit comments