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(shared-task): 明确提示房主无需加入自己的共享任务 (#5246)

DavidShenXD69fd194714d0
diff --git a/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts b/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts
index 662009d97c..a2eb098434 100644
--- a/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts
@@ -50,6 +50,15 @@ describe('sharedTask Main HTTP adapter', () => {
});
await expect(sharedTaskApi.create('session', 'Task')).rejects.toThrow('[' + code + '] Shared task limit reached');
});
+ it('preserves the self-join code through redaction and Electron serialization', async () => {
+ http.mockImplementation(async (_path, options) => {
+ expect(options.allowedRedactedErrorCodes).toContain('SHARED_TASK_SELF_JOIN');
+ throw Object.assign(new Error('private invitation details'), { code: 'SHARED_TASK_SELF_JOIN' });
+ });
+ await expect(sharedTaskApi.join('x'.repeat(43), 'Owner')).rejects.toThrow(
+ '[SHARED_TASK_SELF_JOIN] Shared task request rejected',
+ );
+ });
it('closes across a pending logout with fixed old credentials and no auth side effects', async () => {
state.boundary = true;
const close = captureSharedTaskBoundaryClose('owner', 'global')!;
diff --git a/apps/desktop/src/main/device-link/sharedTaskApi.ts b/apps/desktop/src/main/device-link/sharedTaskApi.ts
index 95a0a41c90..0aa7785e9f 100644
--- a/apps/desktop/src/main/device-link/sharedTaskApi.ts
+++ b/apps/desktop/src/main/device-link/sharedTaskApi.ts
@@ -29,7 +29,7 @@ const accountApi = createSharedTaskApi({
logLabel: '/api/device-link/shared-tasks',
redactErrorDetails: true,
allowedRedactedErrorCodes: ['NOT_FOUND', 'CONFLICT', 'PERMISSION_DENIED', 'INVALID_PARAMS', 'RATE_LIMITED',
- 'SHARED_TASK_HOST_LIMIT', 'SHARED_TASK_JOIN_LIMIT', 'SHARED_TASK_GUEST_LIMIT'],
+ 'SHARED_TASK_HOST_LIMIT', 'SHARED_TASK_JOIN_LIMIT', 'SHARED_TASK_GUEST_LIMIT', 'SHARED_TASK_SELF_JOIN'],
});
} catch (error) {
const code = error && typeof error === 'object' ? (error as { code?: unknown }).code : undefined;
@@ -38,7 +38,7 @@ const accountApi = createSharedTaskApi({
}
// Error properties do not survive Electron serialization. Preserve only
// actionable codes, never the server response or invitation details.
- if (code === 'NOT_FOUND' || code === 'PERMISSION_DENIED' || code === 'INVALID_PARAMS') {
+ if (code === 'NOT_FOUND' || code === 'PERMISSION_DENIED' || code === 'INVALID_PARAMS' || code === 'SHARED_TASK_SELF_JOIN') {
throwIpcError(code, 'Shared task request rejected');
}
if (code === 'NETWORK_ERROR') throwIpcError('DEVICE_LINK_NOT_CONNECTED', 'Shared task service unreachable');
diff --git a/apps/desktop/src/main/maker-host/__tests__/claudeLegacyConfigMigration.test.ts b/apps/desktop/src/main/maker-host/__tests__/claudeLegacyConfigMigration.test.ts
index 0173fbafaa..8ba6b3aa7f 100644
--- a/apps/desktop/src/main/maker-host/__tests__/claudeLegacyConfigMigration.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/claudeLegacyConfigMigration.test.ts
@@ -269,15 +269,36 @@ describe('ensureLegacyClaudeConfigMigrated', () => {
});
it('waits only once: after the first timeout later calls return immediately', async () => {
- await seedDevInstance();
+ const { legacyDir } = await seedDevInstance();
process.env.XDT_USER_DATA_DIR = h.userDataDir;
- // 补拷卡在目录遍历上,模拟超大旧目录。
- vi.spyOn(fs, 'readdir').mockImplementation(() => new Promise<Dirent[]>(() => undefined) as never);
-
- await ensureLegacyClaudeConfigMigrated(5);
- const started = Date.now();
- await ensureLegacyClaudeConfigMigrated(10_000);
- expect(Date.now() - started).toBeLessThan(1_000);
+ let releaseTraversal!: () => void;
+ const traversal = new Promise<Dirent[]>((resolve) => {
+ releaseTraversal = () => resolve([]);
+ });
+ const readdir = vi.spyOn(fs, 'readdir').mockImplementation(() => traversal as never);
+ vi.useFakeTimers();
+ const firstWait = ensureLegacyClaudeConfigMigrated(5);
+ // 在首次超时前挂一个等待者,用于最后收完同一次后台迁移。
+ const migrationFinished = ensureLegacyClaudeConfigMigrated(10_000);
+ try {
+ // 同步推进时钟,固定复现文件系统尚未到 readdir 就已超时的 CI 时序。
+ expect(readdir).not.toHaveBeenCalled();
+ vi.advanceTimersByTime(5);
+ await firstWait;
+ await ensureLegacyClaudeConfigMigrated(10_000);
+ // 后续调用没有新增等待定时器,仅保留上面的迁移收尾等待者。
+ expect(vi.getTimerCount()).toBe(1);
+ } finally {
+ releaseTraversal();
+ try {
+ // 恢复 mock / 删除临时目录前,必须让后台文件系统操作结束。
+ await migrationFinished;
+ await firstWait;
+ } finally {
+ vi.useRealTimers();
+ }
+ }
+ await expect(fs.stat(path.join(legacyDir, MARKER))).resolves.toBeTruthy();
});
it('never throws when the userData path is unavailable, and does not retry in the same run', async () => {
diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts b/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts
index 0aa481eac9..e7a62c4efb 100644
--- a/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts
+++ b/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts
@@ -2,6 +2,12 @@ import { describe, expect, it } from 'vitest';
import { sharedTaskErrorKey } from '../sharedTaskCompatibility';
describe('shared-task compatibility errors', () => {
+ it('explains self-join after the Electron boundary without treating other conflicts as self-join', () => {
+ expect(sharedTaskErrorKey(Object.assign(new Error('rejected'), { code: 'SHARED_TASK_SELF_JOIN' }), 'join')).toBe('sharedTask.selfJoin');
+ expect(sharedTaskErrorKey(new Error("Error invoking remote method 'shared-task:account': Error: [SHARED_TASK_SELF_JOIN] rejected"), 'join')).toBe('sharedTask.selfJoin');
+ expect(sharedTaskErrorKey(Object.assign(new Error('Use existing same-account device control'), { code: 'CONFLICT' }), 'join')).toBe('sharedTask.retry');
+ expect(sharedTaskErrorKey(new Error('[CONFLICT] Too many member devices'), 'join')).toBe('sharedTask.retry');
+ });
it.each([['SHARED_TASK_HOST_LIMIT', 'sharedTask.hostLimit'], ['SHARED_TASK_JOIN_LIMIT', 'sharedTask.joinLimit'],
['SHARED_TASK_GUEST_LIMIT', 'sharedTask.guestLimit']])('explains %s without suggesting retry', (code, key) => {
expect(sharedTaskErrorKey(Object.assign(new Error('limit'), { code }))).toBe(key);
diff --git a/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts b/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts
index 78dd385e75..b7cabbe86f 100644
--- a/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts
+++ b/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts
@@ -3,6 +3,7 @@ import { extractIpcError } from '@/utils/ipcError';
/** Only explicit capability failures imply an upgrade; offline is retryable. */
export function sharedTaskErrorKey(error: unknown, context: 'join' | 'operation' = 'operation') {
const code = extractIpcError(error)?.code;
+ if (code === 'SHARED_TASK_SELF_JOIN') return 'sharedTask.selfJoin';
if (context === 'join' && code === 'INVALID_PARAMS') return 'sharedTask.invalid';
if (context === 'join' && code === 'REGION_MISMATCH') return 'sharedTask.invitationDifferentServer';
if (code === 'NOT_FOUND') return context === 'join' ? 'sharedTask.invitationUnavailable' : 'sharedTask.unavailable';
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index c510ef463d..98482b25f8 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -63,6 +63,7 @@
"estimateFailed": "Could not count files. Check the source computer’s connection and version, then close and try again."
},
"sharedTask": {
+ "selfJoin": "You started this shared task, so you don’t need to join. Open it from “Shared by Me”.",
"manageSharing": "Manage Sharing",
"manageMembers": "Manage Members…",
"cancelSharing": "Stop Sharing",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 42fa380b27..47ecdf919f 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -63,6 +63,7 @@
"estimateFailed": "集計できませんでした。コピー元の接続とバージョンを確認し、閉じて再試行してください。"
},
"sharedTask": {
+ "selfJoin": "これは自分が開始した共有タスクのため、参加する必要はありません。「自分が共有中」から開いてください。",
"manageSharing": "共有管理",
"manageMembers": "メンバーを管理…",
"cancelSharing": "共有を停止",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index c369bf59da..702d244b78 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -63,6 +63,7 @@
"estimateFailed": "파일을 집계하지 못했습니다. 원본 컴퓨터의 연결과 버전을 확인한 후 닫고 다시 시도하세요."
},
"sharedTask": {
+ "selfJoin": "내가 시작한 공유 작업이므로 참여할 필요가 없습니다. “내가 공유한 항목”에서 여세요.",
"manageSharing": "공유 관리",
"manageMembers": "멤버 관리…",
"cancelSharing": "공유 중지",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 38afce7616..0bd25d4398 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -63,6 +63,7 @@
"estimateFailed": "无法统计文件。请检查任务所在电脑的连接和版本,然后关闭重试。"
},
"sharedTask": {
+ "selfJoin": "这是你发起的共享任务,无需加入。请从“我发起的”打开",
"manageSharing": "共享管理",
"manageMembers": "管理成员…",
"cancelSharing": "取消共享",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 8595356f78..4638f52e06 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -63,6 +63,7 @@
"estimateFailed": "無法統計檔案。請檢查任務所在電腦的連線和版本,然後關閉重試。"
},
"sharedTask": {
+ "selfJoin": "這是你發起的共享任務,無需加入。請從「我發起的」開啟",
"manageSharing": "共享管理",
"manageMembers": "管理成員…",
"cancelSharing": "取消共享",
diff --git a/apps/desktop/src/shared/ipc-errors.ts b/apps/desktop/src/shared/ipc-errors.ts
index 0a7ebd8cd3..c8861b9f65 100644
--- a/apps/desktop/src/shared/ipc-errors.ts
+++ b/apps/desktop/src/shared/ipc-errors.ts
@@ -96,6 +96,7 @@ export type IpcErrorCode =
| 'SHARED_TASK_HOST_LIMIT'
| 'SHARED_TASK_JOIN_LIMIT'
| 'SHARED_TASK_GUEST_LIMIT'
+ | 'SHARED_TASK_SELF_JOIN'
| 'APP_SHORTCUTS_WRITE_FAILED'
| 'NO_ACTIVE_TURN'
| 'SESSION_RUNNING'
@@ -373,6 +374,7 @@ const IPC_ERROR_CODES: ReadonlySet<IpcErrorCode> = new Set<IpcErrorCode>([
'SHARED_TASK_HOST_LIMIT',
'SHARED_TASK_JOIN_LIMIT',
'SHARED_TASK_GUEST_LIMIT',
+ 'SHARED_TASK_SELF_JOIN',
'APP_SHORTCUTS_WRITE_FAILED',
'NO_ACTIVE_TURN',
'SESSION_RUNNING',
diff --git a/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts b/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts
index 6b42334c7a..494215bbf8 100644
--- a/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts
+++ b/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts
@@ -5,6 +5,22 @@ import { sharedTaskErrorKey } from '../device-link/sharedTaskCompatibility';
describe('shared-task compatibility errors', () => {
afterEach(() => vi.unstubAllGlobals());
+ it.each([
+ ['SHARED_TASK_SELF_JOIN', 'sharedTask.selfJoin'],
+ ['CONFLICT', 'sharedTask.retry'],
+ ])('maps HTTP 409 %s by code without guessing from its message', async (code, key) => {
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({
+ error: { code, message: 'Use existing same-account device control' },
+ }), { status: 409, headers: { 'content-type': 'application/json' } })));
+ const error = await apiFetchRaw('/api/device-link/shared-tasks/join', {
+ baseUrl: 'https://relay.example.invalid', method: 'POST',
+ body: { invitation: 'a'.repeat(43), displayName: 'Owner' },
+ }).catch((error: unknown) => error);
+ expect(error).toMatchObject({ code, status: 409 });
+ expect(sharedTaskErrorKey(error, 'join')).toBe(key);
+ expect(sharedTaskErrorKey(Object.assign(new Error(`[${code}] rejected`), { code: 'IPC_ERROR' }), 'join')).toBe(key);
+ });
+
it('explains native network failures from the shared-task HTTP request', async () => {
vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new TypeError('Network request failed')));
const error = await apiFetchRaw('/api/device-link/shared-tasks/join', {
diff --git a/apps/mobile/src/device-link/sharedTaskCompatibility.ts b/apps/mobile/src/device-link/sharedTaskCompatibility.ts
index a04ce225ba..defbe60630 100644
--- a/apps/mobile/src/device-link/sharedTaskCompatibility.ts
+++ b/apps/mobile/src/device-link/sharedTaskCompatibility.ts
@@ -5,6 +5,7 @@ export function sharedTaskErrorKey(error: unknown, context: 'join' | 'operation'
const message = error instanceof Error ? error.message : '';
code = /^(?:Error invoking remote method '[^']+': Error: )?\[([A-Z0-9_]+)\]/.exec(message)?.[1];
}
+ if (code === 'SHARED_TASK_SELF_JOIN') return 'sharedTask.selfJoin';
if (code === 'NOT_FOUND') return context === 'join' ? 'sharedTask.invitationUnavailable' : 'sharedTask.unavailable';
if (code === 'PERMISSION_DENIED') return context === 'join' ? 'sharedTask.invitationRenew' : 'sharedTask.permissionDenied';
if (code === 'ACCESS_REVOKED' || code === 'DEVICE_LINK_ACCESS_REVOKED') return 'sharedTask.unavailable';
diff --git a/apps/mobile/src/i18n/locales/en/sharedTask.json b/apps/mobile/src/i18n/locales/en/sharedTask.json
index 9d75023da0..f8b7d8646c 100644
--- a/apps/mobile/src/i18n/locales/en/sharedTask.json
+++ b/apps/mobile/src/i18n/locales/en/sharedTask.json
@@ -1,4 +1,5 @@
{
+ "selfJoin": "You started this shared task, so you don’t need to join. Open it from “Shared by Me”.",
"waitingHost": "Waiting for the host to respond. You can continue sending messages.",
"join": "Join Shared Task",
"joinHint": "Paste an invitation link to open the shared task.",
diff --git a/apps/mobile/src/i18n/locales/ja/sharedTask.json b/apps/mobile/src/i18n/locales/ja/sharedTask.json
index 21b3644145..61200dc685 100644
--- a/apps/mobile/src/i18n/locales/ja/sharedTask.json
+++ b/apps/mobile/src/i18n/locales/ja/sharedTask.json
@@ -1,4 +1,5 @@
{
+ "selfJoin": "これは自分が開始した共有タスクのため、参加する必要はありません。「自分が共有中」から開いてください。",
"waitingHost": "ホストの対応を待っています。引き続きメッセージを送信できます。",
"join": "共有セッションに参加",
"joinHint": "招待リンクを貼り付けて、共有タスクを開きます。",
diff --git a/apps/mobile/src/i18n/locales/ko/sharedTask.json b/apps/mobile/src/i18n/locales/ko/sharedTask.json
index 4018310246..8fb1b761f2 100644
--- a/apps/mobile/src/i18n/locales/ko/sharedTask.json
+++ b/apps/mobile/src/i18n/locales/ko/sharedTask.json
@@ -1,4 +1,5 @@
{
+ "selfJoin": "내가 시작한 공유 작업이므로 참여할 필요가 없습니다. “내가 공유한 항목”에서 여세요.",
"waitingHost": "호스트의 응답을 기다리고 있습니다. 메시지는 계속 보낼 수 있습니다.",
"join": "공유 세션 참여",
"joinHint": "초대 링크를 붙여넣어 공유 작업을 여세요.",
diff --git a/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json b/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json
index af1c9dce09..f0590f4481 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json
@@ -1,4 +1,5 @@
{
+ "selfJoin": "这是你发起的共享任务,无需加入。请从“我发起的”打开",
"waitingHost": "等待房主处理,你可以继续发送消息。",
"join": "加入共享任务",
"joinHint": "粘贴邀请链接,进入同一个共享任务。",
diff --git a/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json b/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json
index 57ae607e49..94e7aecd51 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json
@@ -1,4 +1,5 @@
{
+ "selfJoin": "這是你發起的共享任務,無需加入。請從「我發起的」開啟",
"waitingHost": "等待房主處理,你可以繼續傳送訊息。",
"join": "加入共享任務",
"joinHint": "貼上邀請連結,進入同一個共享任務。",
diff --git a/docs/product-rules/shared-task-mode.md b/docs/product-rules/shared-task-mode.md
index ce8641e17f..90c39a4789 100644
--- a/docs/product-rules/shared-task-mode.md
+++ b/docs/product-rules/shared-task-mode.md
@@ -48,6 +48,7 @@
- 邀请可转发,持有邀请的登录用户即可加入;每个任务最多 2 位访客(加房主共 3 人),按账号计数。服务端在事务内强制校验,超额分别提示开启、加入或访客人数已满。
- 已存在的超额共享及成员关系不自动关闭或踢出;只拒绝新增开启/加入,退出、移除、关闭或房主离线关闭后释放对应名额。访客临时断线不释放加入名额。
- 同一账号重复加入幂等,多个设备不重复占用名额。邀请令牌只存摘要,不进入日志。
+- 房主使用自己的邀请不走访客加入流程,不创建访客或占用加入名额;服务端返回 HTTP 409 / `SHARED_TASK_SELF_JOIN`,两端提示“这是你发起的共享任务,无需加入。请从‘我发起的’打开”。同账号访问继续使用既有设备互联。旧服务端的通用 `CONFLICT` 仍显示兜底提示,不根据错误消息猜测是否为房主;旧客户端收到新错误码也沿用兜底提示。准确提示需服务端与客户端均升级,接口与成功响应结构不变。
- 移除或退出立即撤权;原邀请不可重入,房主生成新邀请后才能再次加入。
- 停止共享、归档、房主登出使旧邀请和成员关系失效。重新共享产生新的共享 ID。
- 归档后恢复为活动任务,可以显式重新开启共享;须先完成旧共享关闭,旧代次的请求仍然失效。