Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 保存分享用户备注前刷新成员名单
DavidShen1d84018391b5
diff --git a/apps/desktop/src/main/device-link/__tests__/providerShareManagement.test.ts b/apps/desktop/src/main/device-link/__tests__/providerShareManagement.test.tsindex 63e1be0acf..ceee60c1e6 100644--- a/apps/desktop/src/main/device-link/__tests__/providerShareManagement.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/providerShareManagement.test.ts@@ -79,6 +79,19 @@ const mutations: ProviderShareManagementCommand[] = [{ action: 'set-member', memberId: 'm1', status: 'remove' },];+function saveMemberNote(entry: 'local' | 'same-account'): Promise<unknown> {+ const command = { action: 'set-member-note', memberId: 'm1', note: 'Alice' } as const;+ if (entry === 'same-account') return executeProviderShareManagementCommand(command);+ const handle = vi.spyOn(ipcMain, 'handle');+ try {+ registerProviderShareIpc();+ const handler = handle.mock.calls.find(([channel]) => channel === 'provider-share:command')![1];+ return handler({} as Electron.IpcMainInvokeEvent, command);+ } finally {+ handle.mockRestore();+ }+}+beforeEach(() => {vi.resetAllMocks();state.owner = 'owner-a';@@ -179,12 +192,32 @@ describe('member note management', () => {it.each([null, 123, 'x'.repeat(81)])('rejects an invalid note %j', (note) => {expect(() => parseProviderShareCommand({ action: 'set-member-note', memberId: 'm1', note })).toThrow('INVALID_PARAMS');});- it('saves an existing member note without changing sharing authorization', async () => {- await expect(executeProviderShareManagementCommand({ action: 'set-member-note', memberId: 'm1', note: 'Alice' }))+ it.each(['local', 'same-account'] as const)('saves an existing member note without changing sharing authorization (%s)', async (entry) => {+ await expect(saveMemberNote(entry)).resolves.toEqual({ ok: true });expect(memberNotes.set).toHaveBeenCalledWith('m1', 'Alice', expect.any(Function));+ expect(host.refresh).toHaveBeenCalledExactlyOnceWith('management');expect(api.setMember).not.toHaveBeenCalled();});+ /* PR #6445 discussion_r4312429158:本机真实 IPC 之前绕过管理入口的刷新。+ * 现有缺口:只测远程入口与已缺席成员,未测缓存仍有、刷新后退出的成员。+ * 最小输入:m1 在刷新后消失;或刷新期间切账号。结果必须拒绝保存,不写备注。+ * tier: unit;复用本文件内存 fixture 与生产 IPC / 管理入口,不新增网络或等待。+ * 单文件实测:50 项通过,1.58 秒。+ */+ it.each(['local', 'same-account'] as const)('refuses a note when the cached member has left before saving (%s)', async (entry) => {+ host.refresh.mockImplementationOnce(async () => { host.snapshot.mockReturnValue([]); });+ await expect(saveMemberNote(entry)).rejects.toThrow('NOT_FOUND');+ expect(memberNotes.set).not.toHaveBeenCalled();+ });+ it.each(['pending', 'switched'] as const)('refuses a local note when the account changes during refresh (%s)', async (boundary) => {+ host.refresh.mockImplementationOnce(async () => {+ if (boundary === 'pending') state.boundaryPending = true;+ else state.owner = 'owner-b';+ });+ await expect(saveMemberNote('local')).rejects.toThrow('PRECONDITION_FAILED');+ expect(memberNotes.set).not.toHaveBeenCalled();+ });it('refuses notes for absent members and a pending account transition', async () => {await expect(executeProviderShareManagementCommand({ action: 'set-member-note', memberId: 'absent', note: 'Alice' })).rejects.toThrow('NOT_FOUND');diff --git a/apps/desktop/src/main/device-link/providerShareRuntime.ts b/apps/desktop/src/main/device-link/providerShareRuntime.tsindex e3768b2438..308e7c9471 100644--- a/apps/desktop/src/main/device-link/providerShareRuntime.ts+++ b/apps/desktop/src/main/device-link/providerShareRuntime.ts@@ -730,6 +730,10 @@ async function execute(command: ProviderShareCommand, assertCurrent: () => voidcase 'set-member-note': {const assertOwner = captureProviderManagementScope();requireRunning();+ // 本机 IPC 与同账号管理共用刷新,避免用旧名单给已退出的成员保存备注。+ await refreshProviderShareHost('management');+ assertCurrent();+ assertOwner();const member = getProviderShareHostSnapshot().some((share) => share.members.some((item) => item.memberId === command.memberId));if (!member) throwIpcError('NOT_FOUND', 'This shared provider member is no longer available');await providerShareMemberNotes.set(command.memberId, command.note, () => { assertCurrent(); assertOwner(); });@@ -780,12 +784,12 @@ async function execute(command: ProviderShareCommand, assertCurrent: () => void*/export async function executeProviderShareManagementCommand(command: ProviderShareManagementCommand): Promise<unknown> {const assertCurrent = captureProviderManagementScope();- if (command.action === 'approve' || command.action === 'reject' || command.action === 'set-member' || command.action === 'set-member-note') {+ if (command.action === 'approve' || command.action === 'reject' || command.action === 'set-member') {requireRunning();await refreshProviderShareHost('management');assertCurrent();const shares = getProviderShareHostSnapshot();- const found = command.action === 'set-member' || command.action === 'set-member-note'+ const found = command.action === 'set-member'? shares.some((share) => share.members.some((member) => member.memberId === command.memberId)): shares.some((share) => share.requests.some((request) => request.requestId === command.requestId));if (!found) throwIpcError('NOT_FOUND', 'The share request or member is no longer on this computer');diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.mdindex 328e395de6..ce8745d8d9 100644--- a/docs/product-rules/provider-sharing.md+++ b/docs/product-rules/provider-sharing.md@@ -302,6 +302,7 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):有备注时按人列表与使用方筛选优先显示备注,列表另保留原用户名,关闭、删除等操作也用备注称呼;没有备注时沿用原昵称。备注只属于分享者的这个成员关系,保存在供应商所在电脑、按账号隔离,同账号其他电脑经现有管理通道读写;不修改对方的昵称,不交给分享服务、受邀者或其他账号,也不改变分享权限。旧电脑不支持保存时明确提示更新,不退到控制端保存。+ 本机与同账号跨电脑保存均先刷新成员名单,刷新后成员已不在名单中或账号已切换时拒绝保存。- **用量**(2026-10-11 起移到页面上方的「用量」块;2026-10-17 起与设置 → 用量同一套,见[供应商组](provider-groups.md) §7):标题同一行右侧筛选使用方、组内电脑、时间范围与日期,默认是所有人的合计;概览、按人(第一行是自己即当前登录账号,之后是分享的人,只显示昵称与头像,§6)、近 30 天每日 token、活跃热力图、按电脑(有组时)、按模型(含估算金额)。时间范围与设置页相同: