🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(acceptance): refine author review and delivery rejection (#19851)
AmAzing-e0d4b61bbbec
diff --git a/.agents/acceptance/probe-mock-patterns.md b/.agents/acceptance/probe-mock-patterns.mdindex 6268007dd99..f8af8543c54 100644--- a/.agents/acceptance/probe-mock-patterns.md+++ b/.agents/acceptance/probe-mock-patterns.md@@ -2640,7 +2640,9 @@ had to take down.response at the CDP Fetch layer and leave the product's own guard logic intact:```js-await send('Fetch.enable', { patterns: [{ urlPattern: '*listDevices*', requestStage: 'Response' }] });+await send('Fetch.enable', {+ patterns: [{ urlPattern: '*listDevices*', requestStage: 'Response' }],+});// in Fetch.requestPaused: getResponseBody → text.replace(/"online":true/g, '"online":false') → fulfillRequest```@@ -2649,7 +2651,7 @@ fulfilled body is truncated. The interception dies with the CDP connection, so alater HMR re-fetch brings the device back online and the banner disappears —keep one script alive for the whole capture rather than attaching per step.-The run-status tray needs a *real* operation, not a DOM stub:+The run-status tray needs a _real_ operation, not a DOM stub:```jsconst { useChatStore } = await import('http://localhost:<vitePort>/src/store/chat/index.ts');@@ -2675,7 +2677,7 @@ the code as the variable.Vite server, letting HMR settle between measurements — same route, same data,same viewport, same injected state. In a shared working tree take the "after"copy with `cp` first and restore from it (never `git stash`, see-[[feedback_no_git_stash_shared_worktrees]] in the user memory); recover the+\[\[feedback\_no\_git\_stash\_shared\_worktrees]] in the user memory); recover the"before" with `git show HEAD:<path>`. When the tree sits on an unrelated branch,write the PR branch's exact file content in for the capture and record thesha256 of both sides in the evidence.diff --git a/apps/server/src/routers/lambda/__tests__/acceptance.reject.test.ts b/apps/server/src/routers/lambda/__tests__/acceptance.reject.test.tsnew file mode 100644index 00000000000..b4b69b13573--- /dev/null+++ b/apps/server/src/routers/lambda/__tests__/acceptance.reject.test.ts@@ -0,0 +1,85 @@+// @vitest-environment node+import { randomUUID } from 'node:crypto';++import type { LobeChatDatabase } from '@lobechat/database';+import { acceptances, verifyRuns } from '@lobechat/database/schemas';+import { getTestDB } from '@lobechat/database/test-utils';+import { eq } from 'drizzle-orm';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { acceptanceRouter } from '../acceptance';+import { cleanupTestUser, createTestContext, createTestUser } from './integration/setup';++let serverDB: LobeChatDatabase;+vi.mock('@/database/core/db-adaptor', () => ({ getServerDB: () => serverDB }));+vi.mock('@/server/workflows/expertiseRejection', () => ({+ ExpertiseRejectionWorkflow: { trigger: vi.fn() },+}));++describe('acceptanceRouter reject', () => {+ let userId: string;+ let strangerId: string;+ let acceptanceId: string;+ let runId: string;++ beforeEach(async () => {+ serverDB = await getTestDB();+ userId = await createTestUser(serverDB);+ strangerId = await createTestUser(serverDB);+ const [acceptance] = await serverDB+ .insert(acceptances)+ .values({+ status: 'delivered',+ subjectId: randomUUID(),+ subjectType: 'standalone',+ userId,+ })+ .returning();+ acceptanceId = acceptance.id;+ const [run] = await serverDB+ .insert(verifyRuns)+ .values({+ acceptanceId,+ roundIndex: 1,+ status: 'passed',+ userId,+ })+ .returning();+ runId = run.id;+ });++ afterEach(async () => {+ await cleanupTestUser(serverDB, strangerId);+ await cleanupTestUser(serverDB, userId);+ });++ it.each([undefined, '', ' ', ' Add dark mode evidence '])(+ 'returns the delivery and records the optional reason (%j)',+ async (comment) => {+ const caller = acceptanceRouter.createCaller(createTestContext(userId));+ const result = await caller.reject({ comment, id: acceptanceId });+ expect(result.status).toBe('rejected');+ const [run] = await serverDB.select().from(verifyRuns).where(eq(verifyRuns.id, runId));+ expect(run.userDecision).toBe('reject');+ expect(run.decisionDetail?.comment).toBe(comment?.trim() || undefined);+ expect(run.decisionDetail?.decidedBy).toBe(userId);+ },+ );++ it('still rejects reasons over the length limit', async () => {+ const caller = acceptanceRouter.createCaller(createTestContext(userId));+ await expect(+ caller.reject({ comment: 'x'.repeat(2001), id: acceptanceId }),+ ).rejects.toMatchObject({ code: 'BAD_REQUEST' });+ });++ it('does not let another user return a private delivery without a reason', async () => {+ const caller = acceptanceRouter.createCaller(createTestContext(strangerId));+ await expect(caller.reject({ id: acceptanceId })).rejects.toMatchObject({ code: 'NOT_FOUND' });+ const [acceptance] = await serverDB+ .select()+ .from(acceptances)+ .where(eq(acceptances.id, acceptanceId));+ expect(acceptance.status).toBe('delivered');+ });+});diff --git a/apps/server/src/routers/lambda/acceptance.ts b/apps/server/src/routers/lambda/acceptance.tsindex 72fa3756830..b0670233f98 100644--- a/apps/server/src/routers/lambda/acceptance.ts+++ b/apps/server/src/routers/lambda/acceptance.ts@@ -1211,17 +1211,17 @@ export const acceptanceRouter = router({}),/**- * The user rejects the delivery. The comment is a re-tasking input: it is+ * The user rejects the delivery. An optional comment is a re-tasking input: it is* recorded on the current round's decision and seeds the next repair/verify* round (spawned by the runtime for agent rounds, or by the next* `lh verify ingest-report` for harness rounds).*/reject: acceptanceWriteProcedure- .input(z.object({ comment: z.string().min(1).max(2000), id: z.string() }))+ .input(z.object({ comment: z.string().trim().max(2000).optional(), id: z.string() })).mutation(async ({ ctx, input }) => {const { acceptance, service } = await resolveAcceptanceForWrite(ctx, input.id);- return service.reject(acceptance.id, input.comment);+ return service.reject(acceptance.id, input.comment || undefined);}),/**diff --git a/apps/server/src/services/verify/acceptanceService.ts b/apps/server/src/services/verify/acceptanceService.tsindex ff91824a9ae..5cdcd67ab22 100644--- a/apps/server/src/services/verify/acceptanceService.ts+++ b/apps/server/src/services/verify/acceptanceService.ts@@ -924,7 +924,7 @@ export class AcceptanceService {};/**- * The user rejects the delivery. The comment is the re-tasking input: it is+ * The user rejects the delivery. An optional comment is a re-tasking input: it is* recorded on the round's decision detail, where the next repair/verify round* picks it up. (Spawning the repair run itself is the runtime's job — for* agent-bound rounds via the repair pipeline, for ingested rounds via the@@ -934,7 +934,7 @@ export class AcceptanceService {* coordinator on the following tick, which reads the rejected round's* decision detail through the prompt builder.*/- reject = async (acceptanceId: string, comment: string): Promise<AcceptanceItem> => {+ reject = async (acceptanceId: string, comment?: string): Promise<AcceptanceItem> => {await this.requireDecidableAcceptance(acceptanceId);const settled = await this.stampDecision(acceptanceId, 'reject', comment);diff --git a/locales/en-US/verify.json b/locales/en-US/verify.jsonindex e97976f8dd1..0dd2efec066 100644--- a/locales/en-US/verify.json+++ b/locales/en-US/verify.json@@ -29,7 +29,7 @@"acceptance.bar.progress": "Confirmed {{done}} / {{total}} checks — {{rest}} awaiting your review","acceptance.bar.progressDone": "All {{total}} checks confirmed — ready to accept","acceptance.bar.progressZero": "{{total}} checks awaiting your review",- "acceptance.bar.rejectComment": "Reject with comment",+ "acceptance.bar.rejectComment": "Reject delivery","acceptance.bar.rerun": "Fix","acceptance.bar.rerunDrafted": "Drafted into your composer — review and send it.","acceptance.bar.rerunSent": "Sent to the origin conversation — the repair round is starting.",@@ -223,8 +223,8 @@"acceptance.proposal.regionUnnamed": "Marked region","acceptance.proposal.request": "Ask AI to review the pending checks","acceptance.proposal.title": "AI review · may not be met",- "acceptance.reject.description": "Your reason becomes input for the next repair round; this is not a passive comment.",- "acceptance.reject.placeholder": "Describe what must change before this delivery can be accepted.",+ "acceptance.reject.description": "Return this delivery for another repair round. You can optionally add a reason to guide the repairs.",+ "acceptance.reject.placeholder": "Reason (optional), e.g. add screenshot evidence for dark mode…","acceptance.reportDrawer.close": "Close the round report","acceptance.requirementEmpty": "No acceptance goal recorded for this subject yet.","acceptance.requirementEmptyEditable": "No acceptance goal yet — click to add one.",@@ -263,11 +263,12 @@"acceptance.review.reject": "Reject with comment","acceptance.review.rejectDescription": "Reject \"{{title}}\" — your feedback is what the next verification round acts on.","acceptance.review.rejectPlaceholder": "What is wrong, and what do you expect instead…",+ "acceptance.review.rejectWithRegions": "Reject with region comments","acceptance.review.rejectedHint": "You rejected this check — the next round reads your feedback.","acceptance.review.removeAttachment": "Remove attachment","acceptance.review.removeRegion": "Remove this region","acceptance.review.revertToAccept": "Undo send-back · mark accepted",- "acceptance.review.revertToReject": "Change to reject with comment",+ "acceptance.review.revertToReject": "Change to reject with region comments","acceptance.review.submitFailed": "Could not submit. Your draft is saved; please try again.","acceptance.review.supplement": "Additional notes (optional)","acceptance.review.supplementButton": "Notes",diff --git a/locales/zh-CN/verify.json b/locales/zh-CN/verify.jsonindex e8b270bedd9..9c22fbd139c 100644--- a/locales/zh-CN/verify.json+++ b/locales/zh-CN/verify.json@@ -29,7 +29,7 @@"acceptance.bar.progress": "已完成 {{done}} / {{total}} 项验证项,剩余 {{rest}} 项等待你的验收","acceptance.bar.progressDone": "{{total}} 项验证项已全部确认,可以接受交付","acceptance.bar.progressZero": "共 {{total}} 项等待你的验收",- "acceptance.bar.rejectComment": "评论并打回",+ "acceptance.bar.rejectComment": "打回交付","acceptance.bar.rerun": "打回重跑","acceptance.bar.rerunDrafted": "已填入对话框,检查后发送。","acceptance.bar.rerunSent": "已发送到源会话,修复轮次启动中。",@@ -223,8 +223,8 @@"acceptance.proposal.regionUnnamed": "标注区域","acceptance.proposal.request": "让 AI 复核待验收项","acceptance.proposal.title": "AI 复核 · 疑似未达成",- "acceptance.reject.description": "打回不是留言:你的意见将作为输入,发起新一轮修复,完成后回到「待验收」。",- "acceptance.reject.placeholder": "说明打回原因,例如:深色模式需补截图证据……",+ "acceptance.reject.description": "打回后将发起新一轮修复,完成后回到「待验收」。可补充打回原因,为修复提供参考。",+ "acceptance.reject.placeholder": "打回原因(可选),例如:深色模式需补截图证据……","acceptance.reportDrawer.close": "关闭该轮报告","acceptance.requirementEmpty": "尚未记录该对象的验收目标。","acceptance.requirementEmptyEditable": "尚未记录验收目标,点击填写。",@@ -263,11 +263,12 @@"acceptance.review.reject": "拒绝并评论","acceptance.review.rejectDescription": "拒绝「{{title}}」——你的反馈将成为下一轮验证的处理输入。","acceptance.review.rejectPlaceholder": "哪里不对、你期望的是什么…",+ "acceptance.review.rejectWithRegions": "拒绝并圈选评论","acceptance.review.rejectedHint": "你已拒绝该项——下一轮将读取你的反馈。","acceptance.review.removeAttachment": "移除附件","acceptance.review.removeRegion": "删除该圈选","acceptance.review.revertToAccept": "撤销打回 · 改为验收通过",- "acceptance.review.revertToReject": "改为拒绝并评论",+ "acceptance.review.revertToReject": "改为拒绝并圈选评论","acceptance.review.submitFailed": "提交失败,草稿已保留,请重试。","acceptance.review.supplement": "补充说明(可选)","acceptance.review.supplementButton": "补充说明",diff --git a/packages/locales/src/default/verify.ts b/packages/locales/src/default/verify.tsindex 98d91d6296c..ca804d982a9 100644--- a/packages/locales/src/default/verify.ts+++ b/packages/locales/src/default/verify.ts@@ -140,7 +140,7 @@ export default {'Confirmed {{done}} / {{total}} checks — {{rest}} awaiting your review','acceptance.bar.progressDone': 'All {{total}} checks confirmed — ready to accept','acceptance.bar.progressZero': '{{total}} checks awaiting your review',- 'acceptance.bar.rejectComment': 'Reject with comment',+ 'acceptance.bar.rejectComment': 'Reject delivery','acceptance.bar.rerun': 'Fix','acceptance.bar.rerunDrafted': 'Drafted into your composer — review and send it.','acceptance.bar.rerunSent': 'Sent to the origin conversation — the repair round is starting.',@@ -341,9 +341,8 @@ export default {'acceptance.origin.backToRuns': 'Back to runs','acceptance.origin.openTopic': 'Open topic','acceptance.reject.description':- 'Your reason becomes input for the next repair round; this is not a passive comment.',- 'acceptance.reject.placeholder':- 'Describe what must change before this delivery can be accepted.',+ 'Return this delivery for another repair round. You can optionally add a reason to guide the repairs.',+ 'acceptance.reject.placeholder': 'Reason (optional), e.g. add screenshot evidence for dark mode…','acceptance.reportDrawer.close': 'Close the round report','acceptance.review.accept': 'Accept','acceptance.review.acceptAll': 'Accept all',@@ -385,13 +384,14 @@ export default {'acceptance.review.regionCommentsEmpty':'Drag on the image to circle a region — its comment lands here.','acceptance.review.reject': 'Reject with comment',+ 'acceptance.review.rejectWithRegions': 'Reject with region comments','acceptance.review.rejectDescription':'Reject "{{title}}" — your feedback is what the next verification round acts on.','acceptance.review.rejectPlaceholder': 'What is wrong, and what do you expect instead…','acceptance.review.rejectedHint': 'You rejected this check — the next round reads your feedback.','acceptance.review.removeRegion': 'Remove this region','acceptance.review.revertToAccept': 'Undo send-back · mark accepted',- 'acceptance.review.revertToReject': 'Change to reject with comment',+ 'acceptance.review.revertToReject': 'Change to reject with region comments','acceptance.review.supplement': 'Additional notes (optional)','acceptance.review.supplementButton': 'Notes','acceptance.review.supplementButtonDraft': 'Notes · draft saved',diff --git a/src/features/Acceptance/Viewer/Checks/CheckRow.tsx b/src/features/Acceptance/Viewer/Checks/CheckRow.tsxindex 34b708c15bf..dc863766aac 100644--- a/src/features/Acceptance/Viewer/Checks/CheckRow.tsx+++ b/src/features/Acceptance/Viewer/Checks/CheckRow.tsx@@ -46,6 +46,7 @@ import type { CheckProposal } from '../Review/proposal';import { classifyProposalEdit } from '../Review/proposal';import ProposalCard from '../Review/ProposalCard';import { useAcceptanceBundle } from '../useAcceptanceBundle';+import { canCommentOnAcceptanceEvidence } from '../visibility';import {AcceptedNote,collectEvidenceById,@@ -226,7 +227,9 @@ export const AcceptanceCheckRow = memo<{// eslint-disable-next-line react-hooks/exhaustive-deps}, [proposalOverlays, checkThreads, comments.canComment, canResolveThread, authorColor]);const canCommentEvidence =- comments.canComment && Boolean(check.result) && hasAnnotatableEvidence(check);+ canCommentOnAcceptanceEvidence(bundle, comments.canComment) &&+ Boolean(check.result) &&+ hasAnnotatableEvidence(check);const openEvidenceComment = () =>openEvidenceCommentModal({evidence: check.evidence,@@ -471,7 +474,7 @@ export const AcceptanceCheckRow = memo<{disabled={reviewPending}icon={MessageSquareX}size={'small'}- title={t('acceptance.review.reject')}+ title={t('acceptance.review.rejectWithRegions')}onClick={(event) => {event.stopPropagation();openReject();@@ -908,7 +911,7 @@ export const AcceptanceCheckRow = memo<{openReject();}}>- {t('acceptance.review.reject')}+ {t('acceptance.review.rejectWithRegions')}</Button><Buttondisabled={reviewPending && !accepting}diff --git a/src/features/Acceptance/Viewer/Review/DecisionBar.test.ts b/src/features/Acceptance/Viewer/Review/DecisionBar.test.tsindex c2207108a94..778bf732fcf 100644--- a/src/features/Acceptance/Viewer/Review/DecisionBar.test.ts+++ b/src/features/Acceptance/Viewer/Review/DecisionBar.test.ts@@ -1,11 +1,18 @@-import { cleanup, fireEvent, render, screen } from '@testing-library/react';+import { ModalHost } from '@lobehub/ui/base-ui';+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import type * as I18next from 'i18next';import { createElement } from 'react';import { afterEach, describe, expect, it, vi } from 'vitest';import verify from '../../../../../packages/locales/src/default/verify';import DecisionBar from './DecisionBar';+import { openRejectModal } from './modals';vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock('i18next', async (importOriginal) => ({+ ...(await importOriginal<typeof I18next>()),+ t: (key: string) => key,+}));afterEach(cleanup);describe('DecisionBar copy', () => {@@ -64,3 +71,29 @@ it('keeps the repair prompt available after an aggregate rejection', () => {expect(screen.getByRole('button', { name: 'acceptance.bar.copyReview' })).toBeTruthy();expect(screen.queryByRole('button', { name: 'acceptance.bar.rerun' })).toBeNull();});++it.each(['', ' ', ' Please add dark mode evidence '])(+ 'allows returning a delivery with an optional reason (%j)',+ async (reason) => {+ const onConfirm = vi.fn().mockResolvedValue(true);+ render(createElement(ModalHost));+ render(+ createElement(DecisionBar, {+ ...props,+ feedbackCount: 0,+ needsFixCount: 0,+ onRejectComment: () => openRejectModal({ onConfirm }),+ }),+ );++ fireEvent.click(screen.getByRole('button', { name: 'acceptance.bar.rejectComment' }));+ const input = await screen.findByRole('textbox');+ fireEvent.change(input, { target: { value: reason } });+ const submit = screen.getByRole('button', { name: 'acceptance.actions.confirmReject' });+ expect(submit).not.toBeDisabled();+ fireEvent.click(submit);++ await waitFor(() => expect(onConfirm).toHaveBeenCalledWith(reason.trim()));+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());+ },+);diff --git a/src/features/Acceptance/Viewer/Review/modals.tsx b/src/features/Acceptance/Viewer/Review/modals.tsxindex 51db2cf2b39..65a5c01f09c 100644--- a/src/features/Acceptance/Viewer/Review/modals.tsx+++ b/src/features/Acceptance/Viewer/Review/modals.tsx@@ -103,7 +103,7 @@ export const openAcceptModal = (options: AcceptContentProps): ModalInstance =>});interface RejectContentProps {- /** Perform the reject with the reason; resolve true to close. */+ /** Perform the reject with an optional reason; resolve true to close. */onConfirm: (comment: string) => Promise<boolean>;}@@ -115,7 +115,6 @@ const RejectContent = memo<RejectContentProps>(({ onConfirm }) => {const handleConfirm = async () => {const trimmed = comment.trim();- if (!trimmed) return;setLoading(true);try {if (await onConfirm(trimmed)) close();@@ -139,12 +138,7 @@ const RejectContent = memo<RejectContentProps>(({ onConfirm }) => {<Button disabled={loading} onClick={close}>{translate('acceptance.actions.cancel')}</Button>- <Button- disabled={!comment.trim()}- loading={loading}- type={'primary'}- onClick={handleConfirm}- >+ <Button loading={loading} type={'primary'} onClick={handleConfirm}>{translate('acceptance.actions.confirmReject')}</Button></Flexbox>@@ -154,7 +148,7 @@ const RejectContent = memo<RejectContentProps>(({ onConfirm }) => {RejectContent.displayName = 'AcceptanceRejectContent';-/** Reject dialog — the reason is required: it is the next round's input, not a note. */+/** Reject dialog — an optional reason adds context for the next repair round. */export const openRejectModal = (options: RejectContentProps): ModalInstance =>createModal({content: <RejectContent {...options} />,diff --git a/src/features/Acceptance/Viewer/visibility.test.ts b/src/features/Acceptance/Viewer/visibility.test.tsindex c9a49899964..1d98ca04ab5 100644--- a/src/features/Acceptance/Viewer/visibility.test.ts+++ b/src/features/Acceptance/Viewer/visibility.test.ts@@ -1,11 +1,27 @@import { describe, expect, it } from 'vitest';import {+ canCommentOnAcceptanceEvidence,canReviewAcceptance,canViewAcceptanceHistory,resolveAcceptanceHistoryNavigation,} from './visibility';+describe('canCommentOnAcceptanceEvidence', () => {+ it('hides standalone region comments from the acceptance author', () => {+ expect(canCommentOnAcceptanceEvidence({ isOwner: true }, true)).toBe(false);+ });++ it('keeps region comments available to another viewer with comment access', () => {+ expect(canCommentOnAcceptanceEvidence({ isOwner: false }, true)).toBe(true);+ });++ it('withholds region comments without comment access or a loaded identity', () => {+ expect(canCommentOnAcceptanceEvidence({ isOwner: false }, false)).toBe(false);+ expect(canCommentOnAcceptanceEvidence(undefined, true)).toBe(false);+ });+});+describe('canViewAcceptanceHistory', () => {it('keeps run history available to the acceptance owner', () => {expect(canViewAcceptanceHistory(true)).toBe(true);diff --git a/src/features/Acceptance/Viewer/visibility.ts b/src/features/Acceptance/Viewer/visibility.tsindex 327116a18bd..24217960e76 100644--- a/src/features/Acceptance/Viewer/visibility.ts+++ b/src/features/Acceptance/Viewer/visibility.ts@@ -20,3 +20,9 @@ export const resolveAcceptanceHistoryNavigation = (*/export const canReviewAcceptance = (bundle?: { canReview?: boolean; isOwner?: boolean } | null) =>Boolean(bundle?.canReview);++/** Authors give region feedback through the check's rejection action. */+export const canCommentOnAcceptanceEvidence = (+ bundle: { isOwner: boolean } | null | undefined,+ canComment: boolean,+) => canComment && bundle?.isOwner === false;diff --git a/src/services/verify.ts b/src/services/verify.tsindex 8919cd58f14..49e822b98f5 100644--- a/src/services/verify.ts+++ b/src/services/verify.ts@@ -237,7 +237,7 @@ export class VerifyService {acceptDelivery = (id: string, comment?: string) =>lambdaClient.acceptance.accept.mutate({ comment, id });- rejectDelivery = (id: string, comment: string) =>+ rejectDelivery = (id: string, comment?: string) =>lambdaClient.acceptance.reject.mutate({ comment, id });/**