import { describe, expect, it } from 'vitest'; import { resolveOwnerCompletionSignal } from './paired-completion-signals.js'; import { containsReviewRequest, evaluateReviewSkipGuards, extractReviewSkipMarker, findToolUsageMutations, isReviewRequestMessage, type OwnerReviewSkipRequest, } from './review-skip.js'; describe('extractReviewSkipMarker', () => { it('strips a trailing marker line and returns the reason', () => { expect( extractReviewSkipMarker( 'TASK_DONE\n\n설명입니다.\n\n리뷰 불필요: 코드 변경 없는 설명\n', ), ).toEqual({ text: 'TASK_DONE\n\n설명입니다.', reason: '코드 변경 없는 설명', }); }); it('accepts bold and full-width colon variants', () => { expect( extractReviewSkipMarker('답변\n**리뷰 불필요**: 조회만 함').reason, ).toBe('조회만 함'); }); it('ignores a marker that is not the last line', () => { const text = '리뷰 불필요: 이건 본문 인용\n실제 마지막 줄'; expect(extractReviewSkipMarker(text)).toEqual({ text, reason: null }); }); it('does not strip when the marker is the whole answer', () => { const text = '리뷰 불필요: 이유'; expect(extractReviewSkipMarker(text)).toEqual({ text, reason: null }); }); it('returns the text untouched without a marker', () => { expect(extractReviewSkipMarker('TASK_DONE\n본문')).toEqual({ text: 'TASK_DONE\n본문', reason: null, }); }); }); describe('isReviewRequestMessage', () => { it.each([ '검토해줘', '검토해 줘', '검토 해줘', '리뷰해줘', '리뷰 해줘', '검토 부탁해', '검토 부탁드려요', '검토 좀 해줘', '이거 검토해줘', '방금 거 리뷰 좀', '검토해주세요.', '검토!', '<@123456> 검토해줘', 'review', 'please review', 'review it please', ])('treats %j as a review request', (text) => { expect(isReviewRequestMessage(text)).toBe(true); }); it.each([ '검토하지 마', '검토 안 해도 돼', '이 코드 고치고 검토해줘', '검토해줘\n그리고 배포도', '리뷰 불필요', '리뷰어 설정 바꿔줘', '로그인 기능 검토해서 개선안 만들어줘', 'review the login flow and fix the bug', '', ])('does not treat %j as a bare review request', (text) => { expect(isReviewRequestMessage(text)).toBe(false); }); }); describe('containsReviewRequest', () => { it.each([ '이 코드 고치고 검토해줘', '수정한 다음 리뷰 받아줘', '검토 부탁합니다', 'please review this change', ])('detects an explicit review request in %j', (text) => { expect(containsReviewRequest(text)).toBe(true); }); it.each(['리뷰 불필요', '검토하지 마', '이 채널 왜 답 안 해?', 'reviewer'])( 'does not flag %j', (text) => { expect(containsReviewRequest(text)).toBe(false); }, ); }); describe('findToolUsageMutations', () => { it('passes read-only tools and read-only shell commands', () => { expect( findToolUsageMutations({ tools: [ 'Read', 'Grep', 'Bash', 'mcp__ejclaw__read_db_evidence', 'mcp__ejclaw__send_message', ], bashCommands: ['git status', 'journalctl --user -u ejclaw -n 20'], }), ).toEqual([]); }); it.each([ ['Edit'], ['Write'], ['MultiEdit'], ['NotebookEdit'], ['Agent'], ['Task'], ['TeamCreate'], ['mcp__ejclaw__schedule_task'], ['mcp__ejclaw__update_task'], ['mcp__ejclaw__cancel_task'], ['mcp__ejclaw__pause_task'], ['mcp__ejclaw__resume_task'], ['mcp__ejclaw__watch_ci'], ['mcp__ejclaw__assign_room'], ['mcp__other__read_db_evidence'], ['SomeNewTool'], ])('flags the %s tool', (tool) => { expect(findToolUsageMutations({ tools: [tool], bashCommands: [] })).toEqual( [`tool ${tool}`], ); }); it('flags mutating shell commands', () => { expect( findToolUsageMutations({ tools: ['Bash', 'Bash'], bashCommands: ['ls', 'systemctl --user restart ejclaw'], }), ).toEqual(['bash: systemctl --user restart ejclaw']); }); it('fails closed when usage is missing or truncated', () => { expect(findToolUsageMutations(null)).toEqual(['tool usage not reported']); expect( findToolUsageMutations({ tools: [], bashCommands: [], truncated: true }), ).toEqual(['tool usage report truncated']); }); }); describe('evaluateReviewSkipGuards', () => { const request: OwnerReviewSkipRequest = { reason: '설명만 함', toolUsage: { tools: ['Read', 'Bash'], bashCommands: ['git log -3'] }, workspaceHeadAtStart: 'abc', }; const clean = { request, hasCodeChangesSinceBase: false, workingTreeClean: true, workspaceHeadNow: 'abc', explicitReviewRequested: false, } as const; it('passes when nothing changed', () => { expect(evaluateReviewSkipGuards(clean)).toEqual([]); }); it.each([ [{ hasCodeChangesSinceBase: true }], [{ hasCodeChangesSinceBase: null }], [{ workingTreeClean: false }], [{ workingTreeClean: null }], [{ workspaceHeadNow: 'def' }], [{ workspaceHeadNow: null }], [{ explicitReviewRequested: true }], [{ request: { ...request, workspaceHeadAtStart: null } }], [ { request: { ...request, toolUsage: { tools: ['Bash'], bashCommands: ['rm -rf x'] }, }, }, ], ])('fails when %j', (override) => { expect( evaluateReviewSkipGuards({ ...clean, ...override }).length, ).toBeGreaterThan(0); }); }); describe('resolveOwnerCompletionSignal review skip', () => { it('completes a TASK_DONE answer when the skip was approved', () => { expect( resolveOwnerCompletionSignal({ phase: 'normal', visibleVerdict: 'task_done', reviewSkipApproved: true, }), ).toEqual({ kind: 'complete', completionReason: 'review_skipped' }); }); it('still requests review without approval or for non-final verdicts', () => { expect( resolveOwnerCompletionSignal({ phase: 'normal', visibleVerdict: 'task_done', }).kind, ).toBe('request_reviewer'); expect( resolveOwnerCompletionSignal({ phase: 'normal', visibleVerdict: 'step_done', reviewSkipApproved: true, }).kind, ).toBe('request_reviewer'); }); });