Adopt active Replicator ownership contracts

This commit is contained in:
vorotamoroz committed 2026-08-30 09:45:00 +00:00
1 parent db70b4c2b6
commit 7300db08d6
18 files changed
+984 -410

No files matched your search

@@ -232,19 +232,24 @@ export class ModuleResolvingMismatchedTweaks extends AbstractModule {
return CHOICES[retKey];
}
async _askResolvingMismatchedTweaks(): Promise<"OK" | "CHECKAGAIN" | "IGNORE"> {
if (!this.core.replicator.tweakSettingsMismatched) {
return "OK";
}
const tweaks = this.core.replicator.preferredTweakValue;
if (!tweaks) {
return "IGNORE";
}
const [conf, rebuildRequired] = await this.services.tweakValue.checkAndAskResolvingMismatched(tweaks);
async _askResolvingMismatchedTweaks(
preferredSource: TweakValues,
updatePreferredRemote?: (setting: ObsidianLiveSyncSettings) => Promise<boolean>
): Promise<"OK" | "CHECKAGAIN" | "IGNORE"> {
const [conf, rebuildRequired] =
await this.services.tweakValue.checkAndAskResolvingMismatched(preferredSource);
if (!conf) return "IGNORE";
const updateRemote = async () => {
if (updatePreferredRemote) return await updatePreferredRemote(this.settings);
const candidate = this.core.replicator;
if (typeof candidate.setPreferredRemoteTweakSettings !== "function") return false;
await candidate.setPreferredRemoteTweakSettings(this.settings);
return true;
};
if (conf === true) {
await this.core.replicator.setPreferredRemoteTweakSettings(this.settings);
if (!(await updateRemote())) return "IGNORE";
if (rebuildRequired) {
await this.core.rebuilder.$rebuildRemote();
}
@@ -261,7 +266,7 @@ export class ModuleResolvingMismatchedTweaks extends AbstractModule {
// chunk-generation managers now so hash and splitter changes take effect before retrying.
await this.localDatabase.managers.reinitialise();
}
await this.core.replicator.setPreferredRemoteTweakSettings(this.settings);
if (!(await updateRemote())) return "IGNORE";
if (rebuildRequired) {
await this.core.rebuilder.$fetchLocal();
}
@@ -272,13 +272,18 @@ describe("ModuleResolvingMismatchedTweaks", () => {
reinitialise.mockImplementation(async () => {
calls.push("reinitialise");
});
const updatePreferredRemote = vi.fn(async () => {
calls.push("set-preferred");
return true;
});
const result = await module._askResolvingMismatchedTweaks();
const result = await module._askResolvingMismatchedTweaks(preferred, updatePreferredRemote);
expect(result).toBe("CHECKAGAIN");
expect(core.settings).toBe(initialSettings);
expect(core.settings.hashAlg).toBe("xxhash32");
expect(calls).toEqual(["save", "reinitialise", "set-preferred"]);
expect(core.replicator.setPreferredRemoteTweakSettings).not.toHaveBeenCalled();
});
});