@@ -1150,10 +1150,11 @@ async function testReconcileDirectoriesPreservesRemoteDir() {
11501150
11511151 const stats = await plugin . reconcileDirectories ( remoteDirs ) ;
11521152
1153- assert . equal ( stats . deletedRemote , 0 , "directory reconcile should not delete remote dirs" ) ;
1154- assert . equal ( stats . createdLocal , 1 , "remote-only dir should be recreated locally" ) ;
1155- assert . equal ( deleteCalls . length , 0 , "remote-only dir should not be deleted" ) ;
1156- assert . ok ( app . vault . folders . has ( "RemovedFolder" ) , "RemovedFolder should be restored locally" ) ;
1153+ // Was synced before + remote only → user deleted locally → delete from remote
1154+ assert . equal ( stats . createdLocal , 0 , "previously-synced remote-only dir should NOT be recreated locally" ) ;
1155+ assert . ok ( stats . deletedRemote > 0 , "previously-synced remote-only dir should be deleted from remote" ) ;
1156+ assert . ok ( deleteCalls . length > 0 , "should issue DELETE for previously-synced remote-only dir" ) ;
1157+ assert . ok ( ! app . vault . folders . has ( "RemovedFolder" ) , "RemovedFolder should NOT be restored locally" ) ;
11571158}
11581159
11591160async function testReconcileDirectoriesCreatesLocalDir ( ) {
@@ -1401,6 +1402,27 @@ async function testCopyDedupChinesePath() {
14011402 assert . ok ( plugin . syncIndex . has ( pathB ) , "pathB should remain in syncIndex" ) ;
14021403}
14031404
1405+ async function testReconcileDirectoriesDeletesRemoteDirWhenLocalDeleted ( ) {
1406+ const deleteCalls = [ ] ;
1407+ const { plugin, app } = createHarness ( async ( options ) => {
1408+ const { url, method } = options ;
1409+ if ( method === "DELETE" ) { deleteCalls . push ( url ) ; return { status : 204 , headers : { } , arrayBuffer : new ArrayBuffer ( 0 ) } ; }
1410+ return { status : 200 , headers : { } , arrayBuffer : new ArrayBuffer ( 0 ) } ;
1411+ } ) ;
1412+ // Simulate: directory was previously synced, user deleted it locally, but it still exists remotely
1413+ plugin . syncedDirectories = new Set ( [ "DeletedLocally" ] ) ;
1414+ const rootFolder = plugin . normalizeFolder ( plugin . settings . vaultSyncRemoteFolder ) ;
1415+ const remoteDirs = new Set ( [ rootFolder , rootFolder + "DeletedLocally/" ] ) ;
1416+ // Note: NOT creating "DeletedLocally" locally — simulating user deleted it
1417+
1418+ const stats = await plugin . reconcileDirectories ( remoteDirs ) ;
1419+
1420+ assert . equal ( stats . createdLocal , 0 , "previously-synced remote-only dir should NOT be recreated locally" ) ;
1421+ assert . ok ( stats . deletedRemote > 0 , "previously-synced remote-only dir should be deleted from remote" ) ;
1422+ assert . ok ( deleteCalls . length > 0 , "should issue DELETE for the directory" ) ;
1423+ assert . ok ( ! app . vault . folders . has ( "DeletedLocally" ) , "DeletedLocally should NOT be restored locally" ) ;
1424+ }
1425+
14041426async function testReconcileDirectoriesKeepsNonEmptyLocalDir ( ) {
14051427 const { plugin, app } = createHarness ( async ( ) => ( { status : 200 , headers : { } , arrayBuffer : new ArrayBuffer ( 0 ) } ) ) ;
14061428 await app . vault . createFolder ( "HasFiles" ) ;
@@ -1435,6 +1457,7 @@ async function run() {
14351457 [ "目录同步:保留本地缺失的远端目录" , testReconcileDirectoriesPreservesRemoteDir ] ,
14361458 [ "目录同步:远端新目录在本地创建" , testReconcileDirectoriesCreatesLocalDir ] ,
14371459 [ "目录同步:非空本地目录不会被删除" , testReconcileDirectoriesKeepsNonEmptyLocalDir ] ,
1460+ [ "目录同步:本地删除空目录后同步应删除远端而非重建" , testReconcileDirectoriesDeletesRemoteDirWhenLocalDeleted ] ,
14381461 [ "非ASCII路径:Emoji 目录名同步" , testEmojiDirNameSync ] ,
14391462 [ "非ASCII路径:中文目录名同步" , testChineseDirNameSync ] ,
14401463 [ "去重:中文路径内容感知去重" , testCopyDedupChinesePath ] ,
0 commit comments