Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): keep review authorization errors out of the media-transfer label

billythegod5a6d3fd7ec2c
diff --git a/apps/desktop/src/main/__tests__/deviceLinkIpc.test.ts b/apps/desktop/src/main/__tests__/deviceLinkIpc.test.ts
index 36b7d143bb..6deb42d9be 100644
--- a/apps/desktop/src/main/__tests__/deviceLinkIpc.test.ts
+++ b/apps/desktop/src/main/__tests__/deviceLinkIpc.test.ts
@@ -112,6 +112,8 @@ import {
import { DeviceLinkError, PLUGIN_OAUTH_CHANNEL, PLUGIN_SECRET_LOCAL_CHANNEL } from '@cindy/device-link';
import { invokeWithClosedLinkRecovery } from '../device-link/linkRecovery';
import { ServerApiError } from '../serverApiClient';
+import { createIpcError } from '../../shared/ipc-errors';
+import { ReviewArtifactAuthorizationError } from '../reviewer/reviewArtifactAuthorization';
import {
__testing as settingsTesting,
normalizeCachedDeviceName,
@@ -941,6 +943,37 @@ describe('device-link controller handlers', () => {
});
});
+ it('invoke:Review 授权/校验拒绝保留原错误码,不再误标为媒体传输失败', async () => {
+ // 回归:maker:review:start 与附件上传共用 rewriteOutboundMedia, 其 PERMISSION_DENIED
+ // (凭证/密钥附件拒绝)、INVALID_PARAMS(整批请求校验)与用户取消授权对话框
+ // (ReviewArtifactAuthorizationError)曾被 catch 一律折叠成
+ // DEVICE_LINK_MEDIA_TRANSFER_FAILED —— 消费端会把"有意拒绝"当可重试传输故障。
+ const invoke = vi.fn().mockResolvedValue({ ok: true, result: null });
+ for (const rejection of [
+ createIpcError('PERMISSION_DENIED', 'Review refused a credential or key attachment'),
+ createIpcError('INVALID_PARAMS', 'review attachments must be an array'),
+ Object.assign(new ReviewArtifactAuthorizationError('Review of external artifacts was cancelled')),
+ ]) {
+ const deps = makeDeps({
+ invoke,
+ rewriteOutboundMedia: vi.fn().mockRejectedValue(rejection),
+ });
+ await expect(handleInvoke(deps, 'dev-2', 'maker:review:start', [{ sourceSessionId: 's' }]))
+ .rejects.toThrowError(rejection instanceof ReviewArtifactAuthorizationError
+ ? /\[PERMISSION_DENIED\] Review of external artifacts was cancelled/
+ : new RegExp(`\\[${rejection.code}\\]`));
+ expect(invoke).not.toHaveBeenCalled();
+ }
+ // 真传输失败(普通 Error)仍折叠为 MEDIA_TRANSFER_FAILED。
+ const deps = makeDeps({
+ invoke,
+ rewriteOutboundMedia: vi.fn().mockRejectedValue(new Error('OSS PUT 失败 (403)')),
+ });
+ await expect(handleInvoke(deps, 'dev-2', 'maker:review:start', [{ sourceSessionId: 's' }]))
+ .rejects.toThrowError(/\[DEVICE_LINK_MEDIA_TRANSFER_FAILED\]/);
+ expect(invoke).not.toHaveBeenCalled();
+ });
+
it('invoke:出方向附件改写失败 → DEVICE_LINK_MEDIA_TRANSFER_FAILED,不发 invoke(整条不发)', async () => {
const invoke = vi.fn().mockResolvedValue({ ok: true, result: null });
const deps = makeDeps({
diff --git a/apps/desktop/src/main/device-link/ipc.ts b/apps/desktop/src/main/device-link/ipc.ts
index 75b6602a6f..081bad933d 100644
--- a/apps/desktop/src/main/device-link/ipc.ts
+++ b/apps/desktop/src/main/device-link/ipc.ts
@@ -26,6 +26,7 @@ import { serverApiFetch, ServerApiError } from '../serverApiClient';
import { requireString, throwIpcError } from '../utils/ipcValidate';
import { assertTrustedAppRendererEvent } from '../security/trustedAppRenderer';
import { isIpcError, type IpcErrorCode } from '../../shared/ipc-errors';
+import { ReviewArtifactAuthorizationError } from '../reviewer/reviewArtifactAuthorization.js';
import { decodeRemoteHistory } from '../../shared/remoteHistoryCache';
import {
DEVICE_LINK_INVOKE,
@@ -694,6 +695,17 @@ export async function handleInvoke(
if (isIpcError(err) && err.code === 'DEVICE_LINK_CHANNEL_NOT_ALLOWED') {
throw err;
}
+ // Review 走同一条出方向改写管线, 但它的授权/校验拒绝不是媒体传输失败:
+ // PERMISSION_DENIED(凭证/密钥附件拒绝、授权不可用)、INVALID_PARAMS(整批
+ // 请求校验)与用户取消外部成果授权对话框, 保留原错误码/原语义, 消费端才
+ // 不会把"有意拒绝"当成可重试的传输故障。上传/压缩等真传输路径只抛普通
+ // Error, 不受影响。
+ if (isIpcError(err) && (err.code === 'PERMISSION_DENIED' || err.code === 'INVALID_PARAMS')) {
+ throw err;
+ }
+ if (err instanceof ReviewArtifactAuthorizationError) {
+ throwIpcError('PERMISSION_DENIED', err.message);
+ }
throwIpcError(
'DEVICE_LINK_MEDIA_TRANSFER_FAILED',
err instanceof Error ? err.message : String(err),