|
12 | 12 | REFACTORED_CODE_COMMIT_MESSAGE, |
13 | 13 | add_all_files_and_commit, |
14 | 14 | diff, |
| 15 | + get_last_finished_frid, |
15 | 16 | init_git_repo, |
16 | 17 | revert_changes, |
17 | 18 | revert_to_commit_with_frid, |
@@ -456,3 +457,73 @@ def test_revert_to_base_folder_no_commit(temp_repo): |
456 | 457 | assert repo.active_branch.name == "main" |
457 | 458 | assert len(list(repo.iter_commits())) == 1 # initial commit |
458 | 459 | assert not file_path.exists() |
| 460 | + |
| 461 | + |
| 462 | +def test_get_last_finished_frid_non_existent_path(): |
| 463 | + """Return (None, None) when the repo path doesn't exist.""" |
| 464 | + assert get_last_finished_frid("/path/that/does/not/exist") == (None, None) |
| 465 | + |
| 466 | + |
| 467 | +def test_get_last_finished_frid_empty_repo(empty_repo): |
| 468 | + """Return (None, None) when no FRID-finished commit exists.""" |
| 469 | + assert get_last_finished_frid(empty_repo) == (None, None) |
| 470 | + |
| 471 | + |
| 472 | +def test_get_last_finished_frid_returns_latest(empty_repo): |
| 473 | + """Return the module name and frid from the most recent finished-frid commit.""" |
| 474 | + file_path = Path(empty_repo) / "a.txt" |
| 475 | + file_path.write_text("v1") |
| 476 | + add_all_files_and_commit( |
| 477 | + empty_repo, |
| 478 | + FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("1"), |
| 479 | + module_name="module_a", |
| 480 | + frid="1", |
| 481 | + ) |
| 482 | + |
| 483 | + file_path.write_text("v2") |
| 484 | + add_all_files_and_commit( |
| 485 | + empty_repo, |
| 486 | + FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("2"), |
| 487 | + module_name="module_a", |
| 488 | + frid="2", |
| 489 | + ) |
| 490 | + |
| 491 | + assert get_last_finished_frid(empty_repo) == ("module_a", "2") |
| 492 | + |
| 493 | + |
| 494 | +def test_get_last_finished_frid_ignores_non_finished_commits(empty_repo): |
| 495 | + """Commits that aren't finished-frid checkpoints must be skipped.""" |
| 496 | + file_path = Path(empty_repo) / "a.txt" |
| 497 | + file_path.write_text("v1") |
| 498 | + add_all_files_and_commit( |
| 499 | + empty_repo, |
| 500 | + FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("1"), |
| 501 | + module_name="module_a", |
| 502 | + frid="1", |
| 503 | + ) |
| 504 | + |
| 505 | + # A refactor commit (not a finished-frid checkpoint) comes after. |
| 506 | + file_path.write_text("v2") |
| 507 | + add_all_files_and_commit( |
| 508 | + empty_repo, |
| 509 | + REFACTORED_CODE_COMMIT_MESSAGE.format("2"), |
| 510 | + module_name="module_a", |
| 511 | + frid="2", |
| 512 | + ) |
| 513 | + |
| 514 | + # The last *finished* FRID is still 1 |
| 515 | + assert get_last_finished_frid(empty_repo) == ("module_a", "1") |
| 516 | + |
| 517 | + |
| 518 | +def test_get_last_finished_frid_without_module_name(empty_repo): |
| 519 | + """If the commit omits the module name line, return None for the module.""" |
| 520 | + file_path = Path(empty_repo) / "a.txt" |
| 521 | + file_path.write_text("v1") |
| 522 | + add_all_files_and_commit( |
| 523 | + empty_repo, |
| 524 | + FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("7"), |
| 525 | + module_name=None, |
| 526 | + frid="7", |
| 527 | + ) |
| 528 | + |
| 529 | + assert get_last_finished_frid(empty_repo) == (None, "7") |
0 commit comments