Files
inkling/tests/unit/inboxApi-revisions.test.ts
th-kim0823 352457189e feat(notes): 원문 편집/이력 복원 시 AI 재처리
dogfood: 사용자가 노트 본문 수정해도 기존 AI 제목/요약이 그대로 남는 문제.
NoteRepository.markAiPendingForReprocess 추가 — done/failed/pending 노트를
pending 으로 reset + pending_jobs 재투입. disabled 는 사용자가 명시적으로
비활성화한 상태라 존중하여 no-op.

inboxApi 의 update-raw-text / restore-revision 핸들러가 raw 갱신 후 위
헬퍼 + worker.enqueue + pushNoteUpdated 호출. NoteCard.saveRaw 는 optimistic
으로 aiStatus='pending' 즉시 반영 → UI 가 "Inkling이 정리하는 중…" 즉시
표시, 백엔드 push 로 자동 sync. updateAiResult 의 user-edit 가드가 사용자가
직접 편집한 title/summary 는 새 AI 결과로 덮어쓰지 않으므로 안전.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 13:11:38 +09:00

101 lines
3.6 KiB
TypeScript

import { describe, it, expect, beforeEach, vi } from 'vitest';
vi.mock('electron', () => ({
default: {
ipcMain: { handle: vi.fn(), on: vi.fn() }
}
}));
import electron from 'electron';
import { registerInboxApi } from '../../src/main/ipc/inboxApi.js';
import type { InboxIpcDeps } from '../../src/main/ipc/inboxApi.js';
function getHandler(channel: string): (...args: unknown[]) => unknown {
const handle = (electron.ipcMain as unknown as { handle: ReturnType<typeof vi.fn> }).handle;
const call = handle.mock.calls.find((c) => c[0] === channel);
if (!call) throw new Error(`channel ${channel} not registered`);
return call[1] as (...args: unknown[]) => unknown;
}
function makeDeps(overrides: Partial<InboxIpcDeps> = {}): InboxIpcDeps {
const repo = {
updateRawText: vi.fn(),
listRevisions: vi.fn(() => []),
restoreRevision: vi.fn(),
markAiPendingForReprocess: vi.fn(() => ({ ok: false })),
findById: vi.fn(),
list: vi.fn(),
listByStatus: vi.fn(),
countByStatus: vi.fn(() => 0),
countByAiStatus: vi.fn(() => 0),
countTrashed: vi.fn(() => 0),
countFailed: vi.fn(() => 0),
listTrashed: vi.fn(() => []),
setStatus: vi.fn(),
requeueDisabled: vi.fn(() => 0),
getAllPendingJobs: vi.fn(() => []),
getPendingCount: vi.fn(() => 0),
countToday: vi.fn(() => 0)
} as unknown as InboxIpcDeps['repo'];
return {
repo,
continuity: { get: vi.fn() } as unknown as InboxIpcDeps['continuity'],
capture: {} as InboxIpcDeps['capture'],
health: {} as InboxIpcDeps['health'],
intent: {} as InboxIpcDeps['intent'],
getInboxWindow: () => null,
settings: {} as InboxIpcDeps['settings'],
providerHolder: {} as InboxIpcDeps['providerHolder'],
paths: { profileDir: '/tmp' },
...overrides
};
}
describe('inboxApi revisions IPC', () => {
beforeEach(() => {
(electron.ipcMain as unknown as { handle: ReturnType<typeof vi.fn> }).handle.mockClear();
});
it('inbox:update-raw-text — repo.updateRawText 호출 + ok:true', async () => {
const deps = makeDeps();
registerInboxApi(deps);
const h = getHandler('inbox:update-raw-text');
const r = await h({}, 'note-1', 'new text');
expect(deps.repo.updateRawText).toHaveBeenCalledWith('note-1', 'new text');
expect(r).toEqual({ ok: true });
});
it('inbox:update-raw-text — 빈 문자열 reject', async () => {
const deps = makeDeps();
registerInboxApi(deps);
const h = getHandler('inbox:update-raw-text');
const r = await h({}, 'note-1', ' ');
expect(deps.repo.updateRawText).not.toHaveBeenCalled();
expect(r).toEqual({ ok: false, reason: 'empty' });
});
it('inbox:list-revisions — repo.listRevisions 결과 반환', async () => {
const deps = makeDeps();
(deps.repo.listRevisions as ReturnType<typeof vi.fn>).mockReturnValue([
{ revId: 1, noteId: 'a', rawText: 'v1', editedAt: 't1', editedBy: 'capture' }
]);
registerInboxApi(deps);
const h = getHandler('inbox:list-revisions');
const r = await h({}, 'a');
expect(r).toEqual([
{ revId: 1, noteId: 'a', rawText: 'v1', editedAt: 't1', editedBy: 'capture' }
]);
});
it('inbox:restore-revision — repo throw 시 ok:false', async () => {
const deps = makeDeps();
(deps.repo.restoreRevision as ReturnType<typeof vi.fn>).mockImplementation(() => {
throw new Error('revision 99 not found for note a');
});
registerInboxApi(deps);
const h = getHandler('inbox:restore-revision');
const r = await h({}, 'a', 99);
expect(r).toEqual({ ok: false, reason: 'revision 99 not found for note a' });
});
});