Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(contacts): stabilize conflict membership fingerprint

Chris3ab38fa64dc7
diff --git a/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts b/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts
index fbfaac449d..edf4f393a3 100644
--- a/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts
+++ b/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts
@@ -348,6 +348,69 @@ describe("contacts device sync", () => {
expect(b.stats().pending).toBe(1);
});
+ it("确认后同一身份删除重建不撤销确认", () => {
+ const a = createStore();
+ const b = createStore();
+ a.activateDeviceSync();
+ b.activateDeviceSync();
+ const aContact = a.createContact({
+ kind: "person",
+ displayName: "甲",
+ identities: [{ platform: "email", value: "[email protected]" }],
+ });
+ b.createContact({
+ kind: "person",
+ displayName: "乙",
+ identities: [{ platform: "email", value: "[email protected]" }],
+ });
+ exchange(a, b);
+ a.updateContact(aContact.id, { status: "confirmed" });
+ const state = stateOf(a);
+ const recreated = structuredClone(state);
+ const identity = recreated.identities.find(
+ (record) => record.value.value.contactId === aContact.id,
+ )!;
+ identity.id = `${identity.id}-recreated`;
+
+ const projection = materializeContactsSyncState(recreated);
+ expect(
+ projection.contacts.find((contact) => contact.id === aContact.id)!.status,
+ ).toBe("confirmed");
+ });
+
+ it("清理同 owner 重复 identity 不撤销确认", () => {
+ const a = createStore();
+ const b = createStore();
+ a.activateDeviceSync();
+ b.activateDeviceSync();
+ const aContact = a.createContact({
+ kind: "person",
+ displayName: "甲",
+ identities: [{ platform: "email", value: "[email protected]" }],
+ });
+ b.createContact({
+ kind: "person",
+ displayName: "乙",
+ identities: [{ platform: "email", value: "[email protected]" }],
+ });
+ exchange(a, b);
+ a.updateContact(aContact.id, { status: "confirmed" });
+ const state = stateOf(a);
+ const duplicate = structuredClone(state);
+ const identity = duplicate.identities.find(
+ (record) => record.value.value.contactId === aContact.id,
+ )!;
+ duplicate.identities.push({
+ ...identity,
+ id: `${identity.id}-duplicate`,
+ });
+
+ const projection = materializeContactsSyncState(duplicate);
+ expect(
+ projection.contacts.find((contact) => contact.id === aContact.id)!.status,
+ ).toBe("confirmed");
+ });
+
it("旧客户端丢失确认凭据后不靠 Lamport 大小吞掉新冲突", () => {
const a = createStore();
const b = createStore();
diff --git a/packages/maker-core/src/contacts/sync/conflicts.ts b/packages/maker-core/src/contacts/sync/conflicts.ts
index e6ef2e38c7..9c1ed25cc7 100644
--- a/packages/maker-core/src/contacts/sync/conflicts.ts
+++ b/packages/maker-core/src/contacts/sync/conflicts.ts
@@ -42,17 +42,11 @@ export function collectContactsIdentityConflicts(
records.map((record) => record.value.value.contactId),
);
if (owners.size <= 1) continue;
- const sortedRecords = [...records].sort((left, right) =>
- compareContactsSyncText(left.id, right.id),
- );
- const first = sortedRecords[0]!.value.value;
+ const first = records[0]!.value.value;
const membershipHash = createHash("sha256")
.update(
JSON.stringify(
- sortedRecords.map((record) => [
- record.id,
- record.value.value.contactId,
- ]),
+ [...owners].sort(compareContactsSyncText),
),
)
.digest("hex");