@@ -345,8 +345,9 @@ def test_import_keep_last_gc_removes_old_backups(fake_root, dest_root, age_keys,
345345
346346 remaining = sorted (p .name for p in backup_root .iterdir ())
347347 assert len (remaining ) == 3
348- # 最新 3 個に絞られる: 既存の 20260101-000003, 000004, 加えて新規 backup
349- assert remaining [- 1 ].startswith ('20' )
348+ # 最新 3 個に絞られる: 既存の旧フォーマット 2 個 + dbenv- prefix 付き新規 backup
349+ # 新規 backup は dbenv- prefix 付き (ソート順で末尾)
350+ assert remaining [- 1 ].startswith ('dbenv-' )
350351
351352
352353def test_import_include_project_filter (fake_root , dest_root , age_keys , tmp_path ):
@@ -476,7 +477,7 @@ def test_gc_backups_only_removes_timestamp_dirs(fake_root, dest_root, age_keys,
476477 # 関係ないファイル
477478 unrelated_file = custom_backup_root / "readme.txt"
478479 unrelated_file .write_text ("must not be deleted" )
479- # devbase 命名の古い backup を keep_last 超に置く
480+ # devbase 命名 (旧フォーマット) の古い backup を keep_last 超に置く
480481 for i in range (5 ):
481482 (custom_backup_root / f"20240101-00000{ i } " ).mkdir ()
482483
@@ -497,6 +498,37 @@ def test_gc_backups_only_removes_timestamp_dirs(fake_root, dest_root, age_keys,
497498 assert len (timestamp_dirs ) == 3
498499
499500
501+ def test_gc_backups_ignores_bare_timestamp_dirs_from_other_tools (
502+ fake_root , dest_root , age_keys , tmp_path ):
503+ """--backup-dir 親にタイムスタンプ形式だが prefix 無しの無関係ディレクトリがあっても
504+ 旧フォーマット (後方互換) 以外は GC 対象にならない。新たに作られる backup は
505+ dbenv- prefix 付きになる"""
506+ _ , id_file = age_keys
507+ bundle_path = _export_bundle (fake_root , age_keys , tmp_path )
508+
509+ custom_backup_root = tmp_path / "shared-backups"
510+ custom_backup_root .mkdir ()
511+ # 他ツールが作ったタイムスタンプ風ディレクトリ (prefix 無し・microsecond 付き形式に
512+ # 一致しないパターン: 例えば "backup-20240101-120000" は regex に引っかからない)
513+ other_tool_dir = custom_backup_root / "backup-20240101-120000"
514+ other_tool_dir .mkdir ()
515+ (other_tool_dir / "data.db" ).write_text ("important" )
516+
517+ rc = import_bundle (dest_root , ImportOptions (
518+ source = str (bundle_path ), identities = [str (id_file )],
519+ backup_dir = str (custom_backup_root ), keep_last = 1 ))
520+ assert rc == 0
521+
522+ # 他ツールのディレクトリは無傷
523+ assert other_tool_dir .exists ()
524+ assert (other_tool_dir / "data.db" ).read_text () == "important"
525+
526+ # 新しい backup は dbenv- prefix 付き
527+ new_backups = [p for p in custom_backup_root .iterdir ()
528+ if p .is_dir () and p .name .startswith ("dbenv-" )]
529+ assert len (new_backups ) == 1
530+
531+
500532def test_import_passphrase_env_roundtrip (fake_root , dest_root , tmp_path , monkeypatch ):
501533 dest = tmp_path / "out.dbenv"
502534 monkeypatch .setenv ("DEVBASE_TEST_PASS" , "s3cr3t" )
0 commit comments