fix(library): skip book sync on olid search miss (identity-swap guard)

This commit is contained in:
afiqzudinhadi 2026-08-03 15:51:15 +08:00
parent 1c90ae9abc
commit 0c8f897e46
2 changed files with 17 additions and 3 deletions

View file

@ -215,6 +215,13 @@ describe('bookSpec.sync — open library enrich', () => {
expect(result).toBeNull();
});
test('olid search miss (results present, none match stored olid) -> null, no identity swap, logged', async () => {
const deps = makeDeps({ http: async () => ({ docs: [{ key: '/works/OL999999W', title: '1984', author_name: ['Someone Else'] }] }) });
const result = await bookSpec.sync(ctxFor({ olid: 'OL1168083W', title: '1984' }), deps);
expect(result).toBeNull();
expect(deps.logCalls.some(m => m.includes('OL1168083W'))).toBe(true);
});
test('successful enrich -> canonical fm + flipped always false', async () => {
const deps = makeDeps({ http: async () => olFixture });
const fm = { olid: 'OL1168083W', title: '1984', read_status: 'Read', rating: '5', rating_stars: '⭐️⭐️⭐️⭐️⭐️' };