fix(filelib): 恢复撞名不再死锁,自动改名「(已恢复)」(ADR-0033)

- restore 前查活跃兄弟:撞名则恢复为「原名(已恢复[/ N])」(截断计入
  128 长度预算),同事务落审计并记 renamedFrom;API 返回最终名
- BinView toast 提示改名;测试补撞名/二次恢复用例
This commit is contained in:
ymy
2026-07-31 13:52:23 +08:00
parent f99c8ea4d8
commit 9e38d1e011
5 changed files with 107 additions and 12 deletions
+26
View File
@@ -91,6 +91,32 @@ describe("binService · 恢复", () => {
});
expect(audits).toHaveLength(1);
});
it("ADR-0033:与活跃兄弟撞名时恢复为「(已恢复)」,不死锁;审计记 renamedFrom", async () => {
const root = await createNode(treeDeps(), ADMIN, { parentId: null, kind: "FOLDER", name: "物理" });
const child = await createNode(treeDeps(), ADMIN, { parentId: root.id, kind: "FOLDER", name: "必修一" });
await softDeleteNode(treeDeps(), ADMIN, child.id);
// 删除后同名新建 → 活跃兄弟占了名字
await createNode(treeDeps(), ADMIN, { parentId: root.id, kind: "FOLDER", name: "必修一" });
const result = await restoreBinEntry(binDeps(), ADMIN, child.id);
expect(result.renamedFrom).toBe("必修一");
expect(result.name).toBe("必修一(已恢复)");
const visible = await listChildren(treeDeps(), ADMIN, root.id);
expect(visible.map((c) => c.name).sort()).toEqual(["必修一", "必修一(已恢复)"]);
// 再删再恢复:名字已是去重后的「(已恢复)」,不再冲突 → 保持,不二次改名
await softDeleteNode(treeDeps(), ADMIN, child.id);
const second = await restoreBinEntry(binDeps(), ADMIN, child.id);
expect(second.name).toBe("必修一(已恢复)");
expect(second.renamedFrom).toBeUndefined();
const audits = await prisma.auditEntry.findMany({
where: { action: FILE_LIB_AUDIT_ACTIONS.folderRestore },
});
expect(audits).toHaveLength(2);
});
});
describe("binService · 彻底删除", () => {