fix: address PR #57 CodeRabbit feedback

- Acquire AniList post-watch in-flight lock before async gating to prevent duplicate writes
- Isolate manual watched mark result from AniList post-watch callback failures
- Report known-word cache clears as mutations during immediate append when state existed
- Add regression tests for each fix
This commit is contained in:
2026-05-03 22:15:18 -07:00
parent f2fb9fa1b9
commit 77f5a48f5d
8 changed files with 225 additions and 22 deletions
+32
View File
@@ -326,6 +326,38 @@ test('registerIpcHandlers runs AniList update after manual mark watched succeeds
assert.deepEqual(calls, ['mark', 'anilist']);
});
test('registerIpcHandlers isolates AniList update failures after manual mark watched succeeds', async () => {
const { registrar, handlers } = createFakeIpcRegistrar();
const calls: string[] = [];
const originalWarn = console.warn;
console.warn = () => undefined;
try {
registerIpcHandlers(
createRegisterIpcDeps({
immersionTracker: createFakeImmersionTracker({
markActiveVideoWatched: async () => {
calls.push('mark');
return true;
},
}),
runAnilistPostWatchUpdateOnManualMark: async () => {
calls.push('anilist');
throw new Error('post-watch failed');
},
}),
registrar,
);
const result = await handlers.handle.get(IPC_CHANNELS.command.markActiveVideoWatched)?.({});
assert.equal(result, true);
assert.deepEqual(calls, ['mark', 'anilist']);
} finally {
console.warn = originalWarn;
}
});
test('registerIpcHandlers skips AniList update when manual mark watched has no active session', async () => {
const { registrar, handlers } = createFakeIpcRegistrar();
const calls: string[] = [];
+8 -1
View File
@@ -390,7 +390,14 @@ export function registerIpcHandlers(deps: IpcServiceDeps, ipc: IpcMainRegistrar
ipc.handle(IPC_CHANNELS.command.markActiveVideoWatched, async () => {
const marked = (await deps.immersionTracker?.markActiveVideoWatched()) ?? false;
if (marked) {
await deps.runAnilistPostWatchUpdateOnManualMark?.();
try {
await deps.runAnilistPostWatchUpdateOnManualMark?.();
} catch (error) {
console.warn(
'Failed to run AniList post-watch update after manual watched mark:',
(error as Error).message,
);
}
}
return marked;
});