From d03909c54108d11f8ace581ba1faf5bf7b50b92e Mon Sep 17 00:00:00 2001 From: AlanRockefeller Date: Mon, 4 May 2026 12:01:16 -0700 Subject: [PATCH] Tightened the backup-token regex so only hyphen-delimited trailing backups match, which prevents a bare backup.jpg stem from collapsing into an empty group key. --- faststack/io/variants.py | 2 +- faststack/tests/test_variants_logic.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/faststack/io/variants.py b/faststack/io/variants.py index af02b7a..8922ef7 100644 --- a/faststack/io/variants.py +++ b/faststack/io/variants.py @@ -17,7 +17,7 @@ ) # Trailing `-backup(\d+)?` token at end of (stripped) stem. -_BACKUP_TRAILING_RE = re.compile(r"(?:^|-)([Bb][Aa][Cc][Kk][Uu][Pp])(\d+)?$") +_BACKUP_TRAILING_RE = re.compile(r"-([Bb][Aa][Cc][Kk][Uu][Pp])(\d+)?$") @dataclass diff --git a/faststack/tests/test_variants_logic.py b/faststack/tests/test_variants_logic.py index 5870a8d..4cabdbe 100644 --- a/faststack/tests/test_variants_logic.py +++ b/faststack/tests/test_variants_logic.py @@ -66,6 +66,17 @@ def test_backup_sorting(self): self.assertEqual(group.backup_paths[2].name, "img-backup2.jpg") self.assertEqual(group.backup_paths[10].name, "img-backup10.jpg") + def test_plain_backup_filename_is_not_variant(self): + """A literal backup.jpg filename should not create an empty group key.""" + groups = build_variant_map([Path("backup.jpg")]) + + self.assertIn("backup", groups) + self.assertNotIn("", groups) + + group = groups["backup"] + self.assertEqual(group.main_path.name, "backup.jpg") + self.assertEqual(group.backup_paths, {}) + def test_developed_backup_handling(self): """Verify developed backups are handled correctly.""" # Policy: developed-backup is "developed" candidate, AND "backup" candidate.