fix: suppress bulk conflict resolution notice spam

Bulk newest-revision conflict resolution created one notice per resolved file
and updated progress for nine out of every ten files.

Keep per-file bulk resolution success messages in the log without displaying
notices, update notice-level progress once every ten files, and cover both
behaviours with unit tests.
This commit is contained in:
Ouyang Xingyuan
2026-07-14 17:25:26 +08:00
committed by vorotamoroz
parent 943b2a3bd4
commit 3103dc4f52
2 changed files with 69 additions and 2 deletions
@@ -58,7 +58,7 @@ export class ModuleConflictResolver extends AbstractModule {
this._log(`Could not write the resolved content to the storage: ${path}`, LOG_LEVEL_NOTICE); this._log(`Could not write the resolved content to the storage: ${path}`, LOG_LEVEL_NOTICE);
return MISSING_OR_ERROR; return MISSING_OR_ERROR;
} }
const level = subTitle.indexOf("same") !== -1 ? LOG_LEVEL_INFO : LOG_LEVEL_NOTICE; const level = subTitle.indexOf("same") !== -1 || subTitle === "NEWEST" ? LOG_LEVEL_INFO : LOG_LEVEL_NOTICE;
this._log(`${path} has been merged automatically`, level); this._log(`${path} has been merged automatically`, level);
return AUTO_MERGED; return AUTO_MERGED;
} }
@@ -214,7 +214,8 @@ export class ModuleConflictResolver extends AbstractModule {
let i = 0; let i = 0;
for (const file of files) { for (const file of files) {
if (i++ % 10) i++;
if (i % 10 === 0)
this._log( this._log(
`Check and Processing ${i} / ${files.length}`, `Check and Processing ${i} / ${files.length}`,
LOG_LEVEL_NOTICE, LOG_LEVEL_NOTICE,
@@ -0,0 +1,66 @@
import { describe, expect, it, vi } from "vitest";
import { DEFAULT_SETTINGS, LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, type FilePathWithPrefix } from "@lib/common/types";
import { ModuleConflictResolver } from "./ModuleConflictResolver";
function createModule(files: FilePathWithPrefix[] = []) {
const resolveByNewest = vi.fn(async () => true);
const core = {
_services: {
API: {
addLog: vi.fn(),
addCommand: vi.fn(),
registerWindow: vi.fn(),
addRibbonIcon: vi.fn(),
registerProtocolHandler: vi.fn(),
},
setting: {
saveSettingData: vi.fn(async () => undefined),
},
conflict: {
resolveByNewest,
},
},
settings: DEFAULT_SETTINGS,
fileHandler: {
deleteRevisionFromDB: vi.fn(async () => true),
dbToStorage: vi.fn(async () => true),
},
databaseFileAccess: {
getConflictedRevs: vi.fn(async () => []),
},
storageAccess: {
getFileNames: vi.fn(async () => files),
},
} as any;
Object.defineProperty(core, "services", { get: () => core._services });
const module = new ModuleConflictResolver(core);
module._log = vi.fn();
return { module, resolveByNewest };
}
describe("ModuleConflictResolver bulk newest resolution", () => {
it("logs each successful newest resolution without displaying a notice", async () => {
const { module } = createModule();
const path = "example.md" as FilePathWithPrefix;
await (module as any)._resolveConflictByDeletingRev(path, "2-old", "NEWEST");
expect(module._log).toHaveBeenLastCalledWith(`${path} has been merged automatically`, LOG_LEVEL_INFO);
});
it("updates notice-level progress once every ten checked files", async () => {
const files = Array.from({ length: 11 }, (_, index) => `note-${index}.md` as FilePathWithPrefix);
const { module, resolveByNewest } = createModule(files);
await (module as any)._resolveAllConflictedFilesByNewerOnes();
expect(resolveByNewest).toHaveBeenCalledTimes(11);
expect(module._log).toHaveBeenCalledWith(
"Check and Processing 10 / 11",
LOG_LEVEL_NOTICE,
"resolveAllConflictedFilesByNewerOnes"
);
expect(module._log).toHaveBeenCalledTimes(3);
});
});