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(cindy-make): prevent legacy version and share bypasses

MagicLizi63c0e488c649
diff --git a/apps/desktop/src/main/cindy-make/__tests__/versionStartup.test.ts b/apps/desktop/src/main/cindy-make/__tests__/versionStartup.test.ts
index dd13535dc7..61abe6cb15 100644
--- a/apps/desktop/src/main/cindy-make/__tests__/versionStartup.test.ts
+++ b/apps/desktop/src/main/cindy-make/__tests__/versionStartup.test.ts
@@ -18,6 +18,7 @@ const h = vi.hoisted(() => ({
appPath: '',
name: 'Cindy',
packaged: false,
+ makeEnabled: true,
spawn: vi.fn(),
pty: vi.fn(),
exit: vi.fn(),
@@ -65,6 +66,11 @@ vi.mock('../../logger.js', () => ({
}));
vi.mock('../../i18n.js', () => ({ t: (key: string) => key }));
vi.mock('../../../shared/brandRegion.js', () => ({ CURRENT_CINDY_REGION: 'global' }));
+vi.mock('@cindy/maker-shared/cindy-make-feature', () => ({
+ get CINDY_MAKE_ENABLED() {
+ return h.makeEnabled;
+ },
+}));
const originalExec = process.execPath;
const originalResourcesPath = Object.getOwnPropertyDescriptor(process, 'resourcesPath');
@@ -83,6 +89,7 @@ beforeEach(async ({ task }) => {
Object.defineProperty(process, 'resourcesPath', { value: h.appPath, configurable: true });
h.name = 'Cindy';
h.packaged = false;
+ h.makeEnabled = true;
h.ready = false;
await mkdir(h.profile);
await mkdir(path.join(h.appPath, 'drizzle'), { recursive: true });
@@ -446,6 +453,37 @@ describe('one original version type for Dev and installed Cindy', () => {
// path that keeps this process running lets Electron become ready first (the 2026-09-20 Dev
// startup failure with a recorded original.json).
describe('startup dispatch stays ahead of Electron ready', () => {
+ it.each([false, true])('ignores a compatible retained personal selection while Make is disabled (packaged=%s)', async packaged => {
+ h.packaged = packaged;
+ h.makeEnabled = false;
+ original.migrationHash = store.migrationIdentity(path.join(h.appPath, 'drizzle'));
+ saveOriginal();
+ const personal = await savePersonalVersion();
+ await store.selectVersion(h.profile, personal.id);
+ const ready = armReadyOnNextTurn();
+ expect(await startup.dispatchCindyVersionStartup()).toBe(false);
+ expect(ready).not.toHaveBeenCalled();
+ expect(startup.getCurrentCindyVersionId()).toBe('original');
+ expect(h.spawn).not.toHaveBeenCalled();
+ expect(h.exit).not.toHaveBeenCalled();
+ expect(store.selectedVersion(h.profile)).toBe(personal.id);
+ startup.finishCindyVersionStartup();
+ await waitForIo(() => expect(store.selectedVersion(h.profile)).toBe('original'));
+ expect(fs.existsSync(personal.executable)).toBe(true);
+ expect(fs.existsSync(path.join(store.versionDirectory(h.profile, personal.id), 'resources', 'app.asar'))).toBe(true);
+ });
+ it('resets a retained selection even when its original record is missing', async () => {
+ h.makeEnabled = false;
+ const personal = await savePersonalVersion();
+ await store.selectVersion(h.profile, personal.id);
+ const ready = armReadyOnNextTurn();
+ expect(await startup.dispatchCindyVersionStartup()).toBe(false);
+ expect(ready).not.toHaveBeenCalled();
+ expect(h.spawn).not.toHaveBeenCalled();
+ startup.finishCindyVersionStartup();
+ await waitForIo(() => expect(store.selectedVersion(h.profile)).toBe('original'));
+ expect(fs.existsSync(personal.executable)).toBe(true);
+ });
it.each([false, true])(
'rejects an outdated selection using the running original before its registry refresh (packaged=%s)',
async (packaged) => {
diff --git a/apps/desktop/src/main/cindy-make/versionStartup.ts b/apps/desktop/src/main/cindy-make/versionStartup.ts
index 782d26d78e..b24f37453f 100644
--- a/apps/desktop/src/main/cindy-make/versionStartup.ts
+++ b/apps/desktop/src/main/cindy-make/versionStartup.ts
@@ -4,6 +4,7 @@ import fs from 'node:fs';
import { spawn } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { resolveClientEndpointsStrict } from '@cindy/maker-shared/client-endpoints';
+import { CINDY_MAKE_ENABLED } from '@cindy/maker-shared/cindy-make-feature';
import { CURRENT_CINDY_REGION } from '../../shared/brandRegion.js';
import { createLogger } from '../logger.js';
import { t } from '../i18n.js';
@@ -695,6 +696,8 @@ export async function dispatchCindyVersionStartup(): Promise<boolean> {
return true;
}
const profile = app.getPath('userData');
+ const restoreOriginal = !CINDY_MAKE_ENABLED || process.argv.includes(RESTORE_ORIGINAL_FLAG);
+ if (restoreOriginal && fs.existsSync(versionsRoot(profile))) deferredSelection = 'original';
if (fs.existsSync(versionsRoot(profile))) {
if (!request) {
const pending = readVersionJson<{ id: string; pid: number }>(
@@ -721,7 +724,6 @@ export async function dispatchCindyVersionStartup(): Promise<boolean> {
}
setCindyVersionLockScope('profile');
}
- const restoreOriginal = process.argv.includes(RESTORE_ORIGINAL_FLAG);
if (currentId !== 'original') {
const original = readOriginalVersion(profile);
if (!original) throw versionError('unavailable');
diff --git a/apps/desktop/src/renderer/features/device-link/SharedTaskDialog.tsx b/apps/desktop/src/renderer/features/device-link/SharedTaskDialog.tsx
index e9a501b0a9..fca9b3650e 100644
--- a/apps/desktop/src/renderer/features/device-link/SharedTaskDialog.tsx
+++ b/apps/desktop/src/renderer/features/device-link/SharedTaskDialog.tsx
@@ -250,10 +250,13 @@ export function SharedTaskDialog({ open, onOpenChange, session, returnFocus, ini
try {
const result = await window.electronAPI.sharedTask.account({ action: 'join', invitation: invitation.trim(), displayName: sharedTaskAccountName(user?.name) }) as { sharedTaskId: string };
if (!current()) return;
- setInvitation(''); setSuccess({ sharedTaskId: result.sharedTaskId, title: '' });
- invalidateLists(); void loadList('joined');
const joinedDetail = await window.electronAPI.sharedTask.account({ action: 'get', sharedTaskId: result.sharedTaskId }) as SharedTaskDetail;
- if (current()) setSuccess({ sharedTaskId: result.sharedTaskId, title: joinedDetail.title });
+ if (!current()) return;
+ const visible = await filterVisibleSharedTasks([joinedDetail], current);
+ if (!current()) return;
+ if (!visible.length) { toast.error(t('sharedTask.invitationUnavailable')); return; }
+ setInvitation(''); setSuccess({ sharedTaskId: result.sharedTaskId, title: joinedDetail.title });
+ invalidateLists(); void loadList('joined');
if (enter && current()) await enterTask(result.sharedTaskId, current);
} catch (error) { if (current()) toast.error(t(sharedTaskErrorKey(error, 'join'))); }
});
diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx b/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx
index fc58ac3e84..6050ca43fe 100644
--- a/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx
+++ b/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx
@@ -63,6 +63,59 @@ it.each(['cindy-make', 'cindy-make-merge'])('filters %s from owned and joined ac
expect(screen.queryByText(joinedTask.title)).toBeNull();
expect(state.invoke).toHaveBeenCalledWith('other-pc', 'local-db:sessions:get', [owned[1].sessionId]);
expect(state.invoke).toHaveBeenCalledWith(sharedTaskHostPeer(joinedTask.sharedTaskId, joinedTask.hostDeviceId), 'local-db:sessions:get', [joinedTask.sessionId]);
+ expect(state.account).toHaveBeenCalledWith({ action: 'leave', sharedTaskId: joinedTask.sharedTaskId });
+ expect(state.account).not.toHaveBeenCalledWith(expect.objectContaining({ action: 'close' }));
+});
+
+it.each([
+ ['cindy-make', false], ['cindy-make-merge', false],
+ ['cindy-make', true], ['cindy-make-merge', true],
+] as const)('undoes a legacy %s invitation before showing success or entering (link=%s)', async (source, automatic) => {
+ ownedItems = []; joinedItems = [];
+ state.rawSessions.mockReturnValue([]);
+ state.invoke.mockResolvedValue({ id: joinedTask.sessionId, source });
+ const close = vi.fn();
+ const invitation = 'https://relay.example.test/shared-task/join#' + 'A'.repeat(43);
+ render(<MemoryRouter><JoinSharedTaskDialog open initialInvitation={automatic ? invitation : undefined} onOpenChange={close} /></MemoryRouter>);
+ if (!automatic) {
+ fireEvent.change(screen.getByLabelText('sharedTask.invitation'), { target: { value: invitation } });
+ click('join');
+ }
+ await waitFor(() => expect(state.account).toHaveBeenCalledWith({ action: 'leave', sharedTaskId: joinedTask.sharedTaskId }));
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('sharedTask.invitationUnavailable'));
+ const peer = sharedTaskHostPeer(joinedTask.sharedTaskId, joinedTask.hostDeviceId);
+ expect(state.invoke).toHaveBeenCalledExactlyOnceWith(peer, 'local-db:sessions:get', [joinedTask.sessionId]);
+ expect(state.closeLink).toHaveBeenCalledWith(peer);
+ expect(state.reset).toHaveBeenCalledWith(peer);
+ expect(state.removeDevice).toHaveBeenCalledWith(peer);
+ expect(state.setSessions).not.toHaveBeenCalled();
+ expect(close).not.toHaveBeenCalled();
+ expect(screen.queryByText('sharedTask.joinedTitle:' + joinedTask.title)).toBeNull();
+ expect((screen.getByLabelText('sharedTask.invitation') as HTMLTextAreaElement).value).toBe(invitation);
+});
+
+it('does not show join success until ordinary source metadata arrives', async () => {
+ ownedItems = []; joinedItems = []; state.rawSessions.mockReturnValue([]);
+ let finish!: (session: unknown) => void;
+ state.invoke.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
+ open(); fill();
+ await waitFor(() => expect(finish).toBeTypeOf('function'));
+ expect(screen.queryByText('sharedTask.joinedTitle:' + joinedTask.title)).toBeNull();
+ await act(async () => finish({ id: joinedTask.sessionId, source: 'desktop' }));
+ await screen.findByText('sharedTask.joinedTitle:' + joinedTask.title);
+ expect(state.account).not.toHaveBeenCalledWith(expect.objectContaining({ action: 'leave' }));
+});
+
+it('does not revoke a new account when hidden join metadata arrives late', async () => {
+ ownedItems = []; joinedItems = []; state.rawSessions.mockReturnValue([]);
+ let finish!: (session: unknown) => void;
+ state.invoke.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
+ open(); fill();
+ await waitFor(() => expect(finish).toBeTypeOf('function'));
+ await act(async () => { setDataOwnerGeneration('other'); finish({ id: joinedTask.sessionId, source: 'cindy-make' }); });
+ expect(state.account).not.toHaveBeenCalledWith(expect.objectContaining({ action: 'leave' }));
+ expect(state.closeLink).not.toHaveBeenCalled();
+ expect(state.setSessions).not.toHaveBeenCalled();
});
it('does not expose unconfirmed offline shares in account management and retries on focus', async () => {
ownedItems = [owned[1]]; joinedItems = [];
diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/useSharedTaskTasks.test.tsx b/apps/desktop/src/renderer/features/device-link/__tests__/useSharedTaskTasks.test.tsx
new file mode 100644
index 0000000000..5ef4c2e066
--- /dev/null
+++ b/apps/desktop/src/renderer/features/device-link/__tests__/useSharedTaskTasks.test.tsx
@@ -0,0 +1,129 @@
+// @vitest-environment jsdom
+import { act, createElement } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import { sharedTaskHostPeer } from '@cindy/device-link';
+import { setDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';
+import { useSharedTaskTasks } from '../useSharedTaskTasks';
+
+const state = vi.hoisted(() => ({
+ account: vi.fn(), openLink: vi.fn(), closeLink: vi.fn(), invoke: vi.fn(),
+ subscribe: vi.fn(), unsubscribe: vi.fn(), setSessions: vi.fn(), removeDevice: vi.fn(),
+ disconnected: vi.fn(), bind: vi.fn(), reset: vi.fn(),
+ rawSessions: vi.fn(),
+}));
+vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => ({ isAuthenticated: true, dataOwnerId: 'guest', dataOwnerRecoveryEpoch: 0 }) }));
+vi.mock('@/lib/sessionsStore', () => ({ sessionsStore: { findById: vi.fn() } }));
+vi.mock('@/lib/sessionService', () => ({ get: vi.fn() }));
+vi.mock('../remoteProjectsStore', () => ({ remoteProjectsStore: {
+ getAllDeviceIds: () => [], getDeviceSessions: state.rawSessions, setDeviceSessions: state.setSessions,
+ removeDevice: state.removeDevice, markDeviceDisconnected: state.disconnected,
+} }));
+vi.mock('@/lib/remoteDataOwnerPushFence', () => ({ bindSharedTaskPushOwner: state.bind, resetRemoteDataOwnerPushFence: state.reset }));
+
+const task = { sharedTaskId: 'share', sessionId: 'task', ownerAccountId: 'host', hostDeviceId: 'desktop', title: 'Shared task', revision: 1 };
+const peer = sharedTaskHostPeer(task.sharedTaskId, task.hostDeviceId);
+let root: Root;
+function Probe() { useSharedTaskTasks(); return null; }
+async function render() { await act(async () => root.render(createElement(Probe))); }
+beforeEach(() => {
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
+ vi.useFakeTimers(); vi.resetAllMocks(); setDataOwnerGeneration('guest');
+ state.account.mockImplementation(async command => command.action === 'list' ? [task] : {});
+ state.openLink.mockResolvedValue(undefined); state.closeLink.mockResolvedValue(undefined);
+ state.subscribe.mockResolvedValue(undefined); state.unsubscribe.mockResolvedValue(undefined);
+ state.rawSessions.mockReturnValue([]);
+ Object.assign(window, { electronAPI: { sharedTask: { account: state.account }, deviceLink: {
+ openLink: state.openLink, closeLink: state.closeLink, invoke: state.invoke,
+ subscribe: state.subscribe, unsubscribe: state.unsubscribe,
+ } } });
+ root = createRoot(document.createElement('div'));
+});
+afterEach(async () => { await act(async () => root.unmount()); vi.useRealTimers(); });
+
+it.each(['cindy-make', 'cindy-make-merge'])('leaves a restored %s membership before publishing its session', async source => {
+ state.invoke.mockResolvedValue({ id: task.sessionId, source });
+ await render();
+ expect(state.account).toHaveBeenCalledWith({ action: 'leave', sharedTaskId: task.sharedTaskId });
+ expect(state.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.removeDevice).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.reset).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.setSessions).not.toHaveBeenCalled();
+});
+
+it('keeps ordinary shared task restoration unchanged', async () => {
+ const session = { id: task.sessionId, source: 'desktop' };
+ state.invoke.mockResolvedValue(session);
+ await render();
+ expect(state.setSessions).toHaveBeenCalledExactlyOnceWith(peer, task.title, [session]);
+ expect(state.account).not.toHaveBeenCalledWith(expect.objectContaining({ action: 'leave' }));
+ expect(state.closeLink).not.toHaveBeenCalled();
+});
+
+it('leaves a known hidden membership without waiting for its offline host', async () => {
+ state.rawSessions.mockReturnValue([{ id: task.sessionId, source: 'cindy-make' }]);
+ state.invoke.mockRejectedValue(new Error('offline'));
+ await render();
+ expect(state.account).toHaveBeenCalledWith({ action: 'leave', sharedTaskId: task.sharedTaskId });
+ expect(state.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.openLink).not.toHaveBeenCalled();
+ expect(state.invoke).not.toHaveBeenCalled();
+});
+
+it('does not revoke a membership using mismatched task metadata', async () => {
+ state.invoke.mockResolvedValue({ id: 'another-task', source: 'cindy-make' });
+ await render();
+ expect(state.account).not.toHaveBeenCalledWith(expect.objectContaining({ action: 'leave' }));
+ expect(state.setSessions).not.toHaveBeenCalled();
+ expect(state.disconnected).toHaveBeenCalledWith(peer);
+});
+
+it('keeps another shared task on the same host connected while leaving Make', async () => {
+ const ordinary = { ...task, sharedTaskId: 'ordinary-share', sessionId: 'ordinary-task' };
+ state.account.mockImplementation(async command => command.action === 'list' ? [task, ordinary] : {});
+ state.invoke.mockImplementation(async (_peer, _channel, [sessionId]) => ({ id: sessionId, source: sessionId === task.sessionId ? 'cindy-make' : 'desktop' }));
+ await render();
+ expect(state.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.removeDevice).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.setSessions).toHaveBeenCalledExactlyOnceWith(sharedTaskHostPeer(ordinary.sharedTaskId, ordinary.hostDeviceId), ordinary.title, [{ id: ordinary.sessionId, source: 'desktop' }]);
+ expect(state.account.mock.calls.filter(([command]) => command.action === 'leave')).toEqual([[{ action: 'leave', sharedTaskId: task.sharedTaskId }]]);
+});
+
+it('retries a failed disabled membership leave on the next authority poll', async () => {
+ const account = state.account.getMockImplementation()!;
+ let failed = false;
+ state.account.mockImplementation(async command => {
+ if (command.action === 'leave' && !failed) { failed = true; throw new Error('offline'); }
+ return account(command);
+ });
+ state.invoke.mockResolvedValue({ id: task.sessionId, source: 'cindy-make' });
+ await render();
+ expect(state.closeLink).not.toHaveBeenCalled();
+ expect(state.setSessions).not.toHaveBeenCalled();
+ await act(async () => vi.advanceTimersByTimeAsync(5_000));
+ expect(state.account.mock.calls.filter(([command]) => command.action === 'leave')).toHaveLength(2);
+ expect(state.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.setSessions).not.toHaveBeenCalled();
+});
+
+it('does not revoke a membership using an old account metadata response', async () => {
+ let finish!: (session: unknown) => void;
+ state.invoke.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
+ await render();
+ await act(async () => { setDataOwnerGeneration('other'); finish({ id: task.sessionId, source: 'cindy-make' }); });
+ expect(state.account).not.toHaveBeenCalledWith(expect.objectContaining({ action: 'leave' }));
+ expect(state.closeLink).not.toHaveBeenCalled();
+ expect(state.setSessions).not.toHaveBeenCalled();
+});
+
+it('does not clean up a new account after a late disabled membership leave response', async () => {
+ const account = state.account.getMockImplementation()!;
+ let finish!: (value: unknown) => void;
+ state.account.mockImplementation(command => command.action === 'leave' ? new Promise(resolve => { finish = resolve; }) : account(command));
+ state.invoke.mockResolvedValue({ id: task.sessionId, source: 'cindy-make' });
+ await render();
+ await act(async () => { setDataOwnerGeneration('other'); finish({}); });
+ expect(state.closeLink).not.toHaveBeenCalled();
+ expect(state.removeDevice).not.toHaveBeenCalled();
+ expect(state.setSessions).not.toHaveBeenCalled();
+});
diff --git a/apps/desktop/src/renderer/features/device-link/sharedTaskVisibility.ts b/apps/desktop/src/renderer/features/device-link/sharedTaskVisibility.ts
index e907f3f0b8..ccb2333562 100644
--- a/apps/desktop/src/renderer/features/device-link/sharedTaskVisibility.ts
+++ b/apps/desktop/src/renderer/features/device-link/sharedTaskVisibility.ts
@@ -4,8 +4,19 @@ import { getDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';
import type { Session } from '@/lib/ccAgent.types';
import * as sessionService from '@/lib/sessionService';
import { sessionsStore } from '@/lib/sessionsStore';
+import { resetRemoteDataOwnerPushFence } from '@/lib/remoteDataOwnerPushFence';
import { remoteProjectsStore } from './remoteProjectsStore';
+export async function leaveHiddenSharedTask(task: SharedTaskListItem, isCurrent: () => boolean) {
+ if (!isCurrent()) return;
+ await window.electronAPI.sharedTask.account({ action: 'leave', sharedTaskId: task.sharedTaskId });
+ if (!isCurrent()) return;
+ const peer = sharedTaskHostPeer(task.sharedTaskId, task.hostDeviceId);
+ resetRemoteDataOwnerPushFence(peer);
+ void window.electronAPI.deviceLink.closeLink(peer).catch(() => undefined);
+ remoteProjectsStore.removeDevice(peer);
+}
+
export function filterVisibleSharedTasks<Task extends SharedTaskListItem & { local?: boolean }>(
tasks: readonly Task[],
isCurrent: () => boolean,
@@ -15,6 +26,8 @@ export function filterVisibleSharedTasks<Task extends SharedTaskListItem & { loc
? task.hostDeviceId : sharedTaskHostPeer(task.sharedTaskId, task.hostDeviceId);
return filterCindyMakeSharedTasks(tasks, {
isCurrent,
+ onHiddenTask: task => task.ownerAccountId === owner.dataOwnerId
+ ? Promise.resolve() : leaveHiddenSharedTask(task, isCurrent),
knownSession: task => task.local
? sessionsStore.findById(task.sessionId)
: remoteProjectsStore.getDeviceSessions(deviceId(task)).find(session => session.id === task.sessionId),
diff --git a/apps/desktop/src/renderer/features/device-link/useSharedTaskTasks.ts b/apps/desktop/src/renderer/features/device-link/useSharedTaskTasks.ts
index 6d8cfcb725..fc7bdbf490 100644
--- a/apps/desktop/src/renderer/features/device-link/useSharedTaskTasks.ts
+++ b/apps/desktop/src/renderer/features/device-link/useSharedTaskTasks.ts
@@ -1,10 +1,12 @@
import { useEffect } from 'react';
import { sharedTaskHostPeer, parseSharedTaskPeer, type SharedTaskListItem } from '@cindy/device-link';
+import { CINDY_MAKE_ENABLED, isCindyMakeSource } from '@cindy/maker-shared/cindy-make-feature';
import { useAuth } from '@/contexts/AuthContext';
import { getDataOwnerGeneration, isDataOwnerGenerationCurrent } from '@/contexts/dataOwnerGeneration';
import type { Session } from '@/lib/ccAgent.types';
import { remoteProjectsStore } from './remoteProjectsStore';
import { bindSharedTaskPushOwner, resetRemoteDataOwnerPushFence } from '@/lib/remoteDataOwnerPushFence';
+import { leaveHiddenSharedTask } from './sharedTaskVisibility';
/** SharedTask peers have their own authority list, independent of the user's device directory. */
export function useSharedTaskTasks(): void {
@@ -34,8 +36,14 @@ export function useSharedTaskTasks(): void {
for (const sharedTask of sharedTasks) {
if (!currentOwner()) return;
const peer = sharedTaskHostPeer(sharedTask.sharedTaskId, sharedTask.hostDeviceId);
- bindSharedTaskPushOwner(peer, sharedTask.ownerAccountId);
try {
+ const known = remoteProjectsStore.getDeviceSessions(peer).find(session => session.id === sharedTask.sessionId);
+ if (!CINDY_MAKE_ENABLED && isCindyMakeSource(known?.source)) {
+ await leaveHiddenSharedTask(sharedTask, currentOwner);
+ linked.delete(peer);
+ continue;
+ }
+ bindSharedTaskPushOwner(peer, sharedTask.ownerAccountId);
if (!linked.has(peer)) {
await window.electronAPI.deviceLink.openLink(peer);
if (!currentOwner()) return;
@@ -46,6 +54,11 @@ export function useSharedTaskTasks(): void {
const session = await window.electronAPI.deviceLink.invoke(peer, 'local-db:sessions:get', [sharedTask.sessionId]) as Session;
if (!currentOwner()) return;
if (session?.id !== sharedTask.sessionId) throw new Error('SharedTask task mismatch');
+ if (!CINDY_MAKE_ENABLED && isCindyMakeSource(session.source)) {
+ await leaveHiddenSharedTask(sharedTask, currentOwner);
+ linked.delete(peer);
+ continue;
+ }
remoteProjectsStore.setDeviceSessions(peer, sharedTask.title, [session]);
} catch {
if (!currentOwner()) return;
diff --git a/apps/mobile/app/shared-session.tsx b/apps/mobile/app/shared-session.tsx
index 0da4b72ce3..45e3ab5291 100644
--- a/apps/mobile/app/shared-session.tsx
+++ b/apps/mobile/app/shared-session.tsx
@@ -84,7 +84,7 @@ export default function SharedSessionScreen() {
const current = () => visible() && mounted.current && captured === epoch.current && isMobileAuthOwnerCurrent(owner);
if (!isAuthenticated || link.sharedTaskAvailable !== true || ended) return;
if (!guestId && (management || tab === 'owned')) {
- const value = await filterVisibleSharedTasks(await api.list(), owner.accountId, link, current);
+ const value = await filterVisibleSharedTasks(await api.list(), owner.accountId, link, current, api.leave);
if (!current()) return;
const mine = value.filter((task) => task.ownerAccountId === owner.accountId);
setOwned(mine);
@@ -116,7 +116,7 @@ export default function SharedSessionScreen() {
if (guestId && value.detail?.status === 'closed') endAccess();
else setState(value);
if (hostContext) {
- const all = await api.list().then(items => filterVisibleSharedTasks(items, owner.accountId, link, current)).catch(() => null);
+ const all = await api.list().then(items => filterVisibleSharedTasks(items, owner.accountId, link, current, api.leave)).catch(() => null);
if (current() && all) setOwned(all.filter((task) => task.ownerAccountId === owner.accountId));
}
} catch (error) {
@@ -124,7 +124,7 @@ export default function SharedSessionScreen() {
else throw error;
}
} else {
- const value = await filterVisibleSharedTasks(await api.list(), owner.accountId, link, current);
+ const value = await filterVisibleSharedTasks(await api.list(), owner.accountId, link, current, api.leave);
if (current()) {
setOwned(value.filter((task) => task.ownerAccountId === owner.accountId));
}
@@ -231,6 +231,11 @@ export default function SharedSessionScreen() {
if (!parsed.ok) { setNotice(t(parsed.reason === 'different-server' ? 'sharedTask.invitationDifferentServer' : 'sharedTask.invalid')); return; }
const joined = await api.join(parsed.invitation, sharedTaskAccountName(user?.name));
if (!current()) return;
+ const detail = await api.get(joined.sharedTaskId);
+ if (!current()) return;
+ const visible = await filterVisibleSharedTasks([detail], getMobileAuthOwner().accountId, link, current, api.leave);
+ if (!current()) return;
+ if (!visible.length) { setNotice(t('sharedTask.invitationUnavailable')); return; }
Keyboard.dismiss(); setInvitation(''); setJoinedId(joined.sharedTaskId);
setManualOpen(false);
if (enter) await openTask(joined.sharedTaskId, current);
diff --git a/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx b/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx
index 280d627dbc..5695a223cd 100644
--- a/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx
+++ b/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx
@@ -99,7 +99,9 @@ beforeEach(() => {
afterEach(async () => { await act(async () => root.unmount()); clearSharedTaskInvitationIntent(); vi.useRealTimers(); });
it.each(['cindy-make', 'cindy-make-merge'])('hides cold %s shares from both account management lists', async source => {
h.params = { mode: 'manage' };
- h.api.list.mockResolvedValue([owned('Legacy owned'), { ...owned('Legacy joined'), ownerAccountId: 'other' }]);
+ let shares = [owned('Legacy owned'), { ...owned('Legacy joined'), ownerAccountId: 'other' }];
+ h.api.list.mockImplementation(async () => shares);
+ h.api.leave.mockImplementation(async sharedTaskId => { shares = shares.filter(task => task.sharedTaskId !== sharedTaskId); });
h.store.getSessions.mockReturnValue([]);
h.link.invoke.mockImplementation(async (_peer, _channel, [sessionId]) => ({ id: sessionId, source }));
await render();
@@ -110,6 +112,8 @@ it.each(['cindy-make', 'cindy-make-merge'])('hides cold %s shares from both acco
expect(element.textContent).toContain('sharedTask.joinedEmptyTitle');
expect(h.link.invoke).toHaveBeenCalledWith('host', 'local-db:sessions:get', ['task']);
expect(h.link.invoke).toHaveBeenCalledWith(sharedTaskHostPeer('Legacy-joined', 'host'), 'local-db:sessions:get', ['task']);
+ expect(h.api.leave).toHaveBeenCalledExactlyOnceWith('Legacy-joined');
+ expect(h.api.close).not.toHaveBeenCalled();
});
it('does not show unknown offline shares and restores a confirmed ordinary share on the next poll', async () => {
h.params = { mode: 'manage' }; h.api.list.mockResolvedValue([owned('Recovered normal task')]);
@@ -123,6 +127,50 @@ it('does not show unknown offline shares and restores a confirmed ordinary share
});
const invitationLink = 'https://relay.example.test/shared-task/join#' + 'A'.repeat(43);
const invitationIntent = 'cindy://shared-session?invitation=' + 'A'.repeat(43) + '&server=https%3A%2F%2Frelay.example.test';
+it.each([
+ ['cindy-make', false], ['cindy-make-merge', false],
+ ['cindy-make', true], ['cindy-make-merge', true],
+] as const)('undoes a legacy %s invitation before publishing success or navigating (link=%s)', async (source, automatic) => {
+ h.store.getSessions.mockReturnValue([]);
+ h.link.invoke.mockResolvedValue({ id: 'task', source });
+ if (automatic) receiveSharedTaskInvitationIntent(invitationIntent);
+ await render();
+ if (!automatic) { await fill('sharedTask.invitation', invitationLink); await click('sharedTask.join'); }
+ const peer = sharedTaskHostPeer('shared', 'desktop');
+ expect(h.api.leave).toHaveBeenCalledExactlyOnceWith('shared');
+ expect(h.revoked).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(h.link.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(h.store.removeDevice).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(h.api.close).not.toHaveBeenCalled();
+ expect(h.store.setDeviceSessions).not.toHaveBeenCalled();
+ expect(h.router.replace).not.toHaveBeenCalled();
+ expect(element.textContent).toContain('sharedTask.invitationUnavailable');
+ expect(element.textContent).not.toContain('Design review');
+ expect(element.querySelector('[aria-label="sharedTask.invitation"]')).not.toBeNull();
+});
+it('does not revoke membership after an account change while confirming an invitation', async () => {
+ h.store.getSessions.mockReturnValue([]);
+ let finish!: (session: unknown) => void;
+ h.link.invoke.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
+ await render(); await fill('sharedTask.invitation', invitationLink); await click('sharedTask.join');
+ expect(finish).toBeTypeOf('function');
+ setMobileAuthOwner('other'); h.generation++;
+ await render(); await act(async () => finish({ id: 'task', source: 'cindy-make' }));
+ expect(h.api.leave).not.toHaveBeenCalled();
+ expect(h.link.closeLink).not.toHaveBeenCalled();
+ expect(h.router.replace).not.toHaveBeenCalled();
+});
+it('retries failed Make membership rollback without exposing the task', async () => {
+ h.store.getSessions.mockReturnValue([]); h.link.invoke.mockResolvedValue({ id: 'task', source: 'cindy-make' });
+ h.api.leave.mockRejectedValueOnce(new Error('offline'));
+ await render(); await fill('sharedTask.invitation', invitationLink); await click('sharedTask.join');
+ expect(element.textContent).toContain('sharedTask.retry');
+ expect(element.textContent).not.toContain('Design review');
+ expect(h.router.replace).not.toHaveBeenCalled();
+ await click('sharedTask.join');
+ expect(h.api.leave).toHaveBeenCalledTimes(2);
+ expect(element.textContent).toContain('sharedTask.invitationUnavailable');
+});
it('copies a shareable invitation message with a link accepted by automatic and manual admission', async () => {
h.params = { sessionId: 'task', deviceId: 'desktop' };
h.link.invoke.mockImplementation(async (_device, _channel, [command]) => command.action === 'invite' ? { invitation: 'A'.repeat(43) } : { available: true, detail });
diff --git a/apps/mobile/src/__tests__/useSharedTasks.test.tsx b/apps/mobile/src/__tests__/useSharedTasks.test.tsx
index a4d15ff6a5..3f2222eb8e 100644
--- a/apps/mobile/src/__tests__/useSharedTasks.test.tsx
+++ b/apps/mobile/src/__tests__/useSharedTasks.test.tsx
@@ -11,13 +11,15 @@ const state = vi.hoisted(() => ({
auth: { isAuthenticated: true, accountGeneration: 1 },
link: { status: 'online', sharedTaskAvailable: false as boolean | undefined,
openLink: vi.fn(), closeLink: vi.fn(), invoke: vi.fn() },
- api: { list: vi.fn<() => Promise<SharedTaskListItem[]>>(async () => []) },
+ api: { list: vi.fn<() => Promise<SharedTaskListItem[]>>(async () => []), leave: vi.fn() },
+ revoked: vi.fn(),
store: { getSessions: vi.fn<() => RemoteSession[]>(() => []), removeDevice: vi.fn(), setDeviceSessions: vi.fn() },
}));
vi.mock('@/auth/AuthContext', () => ({ useAuth: () => state.auth }));
vi.mock('@/device-link/DeviceLinkContext', () => ({ useDeviceLink: () => state.link }));
vi.mock('@/device-link/useSharedTaskApi', () => ({ useSharedTaskApi: () => state.api }));
vi.mock('@/session/remoteSessionStore', () => ({ remoteSessionStore: state.store }));
+vi.mock('@/device-link/accessRevoked', () => ({ markDeviceAccessRevoked: state.revoked }));
let root: Root;
let ownedTasks: readonly SharedTaskListItem[];
function Probe() { ownedTasks = useSharedTasks(); return null; }
@@ -60,6 +62,58 @@ it('keeps guest admission separate while listing shares owned by the same accoun
expect(ownedTasks).toEqual([confirmedOwned]);
expect(state.link.openLink).toHaveBeenCalledExactlyOnceWith(sharedTaskHostPeer('joined', 'desktop'));
expect(state.store.setDeviceSessions).toHaveBeenCalledExactlyOnceWith(sharedTaskHostPeer('joined', 'desktop'), guest.title, [{ id: 'guest-task' }]);
+ expect(state.api.leave).not.toHaveBeenCalled();
+});
+it.each(['cindy-make', 'cindy-make-merge'])('revokes a restored %s membership without publishing its session', async source => {
+ state.link.sharedTaskAvailable = true;
+ const guest = { ...owned, sharedTaskId: 'joined', sessionId: 'guest-task', ownerAccountId: 'other' };
+ state.api.list.mockResolvedValue([guest]);
+ state.link.invoke.mockResolvedValue({ id: 'guest-task', source });
+ await render();
+ const peer = sharedTaskHostPeer('joined', 'desktop');
+ expect(state.api.leave).toHaveBeenCalledExactlyOnceWith('joined');
+ expect(state.revoked).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.link.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.store.removeDevice).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.store.setDeviceSessions).not.toHaveBeenCalled();
+});
+it('retries membership cleanup on the next restore poll after a leave failure', async () => {
+ state.link.sharedTaskAvailable = true;
+ const guest = { ...owned, sharedTaskId: 'joined', sessionId: 'guest-task', ownerAccountId: 'other' };
+ state.api.list.mockResolvedValue([guest]); state.link.invoke.mockResolvedValue({ id: 'guest-task', source: 'cindy-make' });
+ state.api.leave.mockRejectedValueOnce(new Error('offline'));
+ await render();
+ expect(state.api.leave).toHaveBeenCalledTimes(1);
+ expect(state.store.setDeviceSessions).not.toHaveBeenCalled();
+ await act(async () => vi.advanceTimersByTimeAsync(5_000));
+ expect(state.api.leave).toHaveBeenCalledTimes(2);
+ expect(state.link.closeLink).toHaveBeenCalledWith(sharedTaskHostPeer('joined', 'desktop'));
+});
+it('leaves a cached hidden guest membership without contacting the offline host', async () => {
+ state.link.sharedTaskAvailable = true;
+ const guest = { ...owned, sharedTaskId: 'joined', sessionId: 'guest-task', ownerAccountId: 'other' };
+ const peer = sharedTaskHostPeer('joined', 'desktop');
+ state.api.list.mockResolvedValue([guest]);
+ state.store.getSessions.mockReturnValue([{ id: 'guest-task', deviceLinkDeviceId: peer, source: 'cindy-make' } as RemoteSession]);
+ state.link.invoke.mockRejectedValue(new Error('offline'));
+ await render();
+ expect(state.api.leave).toHaveBeenCalledExactlyOnceWith('joined');
+ expect(state.link.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.link.openLink).not.toHaveBeenCalled();
+ expect(state.link.invoke).not.toHaveBeenCalled();
+});
+it('keeps an ordinary shared peer on the same host unaffected by Make withdrawal', async () => {
+ state.link.sharedTaskAvailable = true;
+ const hidden = { ...owned, sharedTaskId: 'hidden-share', sessionId: 'hidden-task', ownerAccountId: 'other' };
+ const ordinary = { ...hidden, sharedTaskId: 'ordinary-share', sessionId: 'ordinary-task' };
+ state.api.list.mockResolvedValue([hidden, ordinary]);
+ state.link.invoke.mockImplementation(async (_peer, _channel, [sessionId]) => ({ id: sessionId, source: sessionId === hidden.sessionId ? 'cindy-make' : 'desktop' }));
+ await render();
+ const peer = sharedTaskHostPeer(hidden.sharedTaskId, hidden.hostDeviceId);
+ expect(state.api.leave).toHaveBeenCalledExactlyOnceWith(hidden.sharedTaskId);
+ expect(state.link.closeLink).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.store.removeDevice).toHaveBeenCalledExactlyOnceWith(peer);
+ expect(state.store.setDeviceSessions).toHaveBeenCalledExactlyOnceWith(sharedTaskHostPeer(ordinary.sharedTaskId, ordinary.hostDeviceId), ordinary.title, [{ id: ordinary.sessionId, source: 'desktop' }]);
});
it('hides the previous account shares and ignores its late list response', async () => {
state.link.sharedTaskAvailable = true; state.api.list.mockResolvedValue([owned]);
diff --git a/apps/mobile/src/device-link/sharedTaskVisibility.ts b/apps/mobile/src/device-link/sharedTaskVisibility.ts
index fd6b654ca5..a12a85b103 100644
--- a/apps/mobile/src/device-link/sharedTaskVisibility.ts
+++ b/apps/mobile/src/device-link/sharedTaskVisibility.ts
@@ -2,18 +2,37 @@ import { sharedTaskHostPeer, type SharedTaskListItem } from '@cindy/device-link'
import { filterCindyMakeSharedTasks } from '@cindy/maker-shared/cindy-make-feature';
import { remoteSessionStore } from '@/session/remoteSessionStore';
import type { RemoteSession } from '@/session/types';
+import { markDeviceAccessRevoked } from './accessRevoked';
import type { useDeviceLink } from './DeviceLinkContext';
+export async function leaveHiddenSharedTask(
+ task: SharedTaskListItem,
+ closeLink: ReturnType<typeof useDeviceLink>['closeLink'],
+ leave: (sharedTaskId: string) => Promise<unknown>,
+ isCurrent: () => boolean,
+) {
+ if (!isCurrent()) return;
+ await leave(task.sharedTaskId);
+ if (!isCurrent()) return;
+ const peer = sharedTaskHostPeer(task.sharedTaskId, task.hostDeviceId);
+ markDeviceAccessRevoked(peer);
+ closeLink(peer);
+ remoteSessionStore.removeDevice(peer);
+}
+
export function filterVisibleSharedTasks(
tasks: readonly SharedTaskListItem[],
ownerAccountId: string | null,
- link: Pick<ReturnType<typeof useDeviceLink>, 'openLink' | 'invoke'>,
+ link: Pick<ReturnType<typeof useDeviceLink>, 'openLink' | 'invoke' | 'closeLink'>,
isCurrent: () => boolean,
+ leave: (sharedTaskId: string) => Promise<unknown>,
) {
const deviceId = (task: SharedTaskListItem) => task.ownerAccountId === ownerAccountId
? task.hostDeviceId : sharedTaskHostPeer(task.sharedTaskId, task.hostDeviceId);
return filterCindyMakeSharedTasks(tasks, {
isCurrent,
+ onHiddenTask: task => task.ownerAccountId === ownerAccountId
+ ? Promise.resolve() : leaveHiddenSharedTask(task, link.closeLink, leave, isCurrent),
knownSession: task => remoteSessionStore.getSessions().find(session =>
session.id === task.sessionId && session.deviceLinkDeviceId === deviceId(task)),
readSession: async task => {
diff --git a/apps/mobile/src/device-link/useSharedTasks.ts b/apps/mobile/src/device-link/useSharedTasks.ts
index 58187463ec..ffe13632a5 100644
--- a/apps/mobile/src/device-link/useSharedTasks.ts
+++ b/apps/mobile/src/device-link/useSharedTasks.ts
@@ -1,12 +1,13 @@
import { useEffect, useState } from 'react';
import { isSharedTaskPeer, sharedTaskHostPeer, type SharedTaskListItem } from '@cindy/device-link';
+import { CINDY_MAKE_ENABLED, isCindyMakeSource } from '@cindy/maker-shared/cindy-make-feature';
import { useAuth } from '@/auth/AuthContext';
import { getMobileAuthOwner, isMobileAuthOwnerCurrent } from '@/auth/authOwnerGeneration';
import { remoteSessionStore } from '@/session/remoteSessionStore';
import type { RemoteSession } from '@/session/types';
import { useDeviceLink } from './DeviceLinkContext';
import { useSharedTaskApi } from './useSharedTaskApi';
-import { filterVisibleSharedTasks } from './sharedTaskVisibility';
+import { filterVisibleSharedTasks, leaveHiddenSharedTask } from './sharedTaskVisibility';
/** Shared tasks have their own account authority list, separate from paired devices. */
export function useSharedTasks(): readonly SharedTaskListItem[] {
@@ -27,7 +28,7 @@ export function useSharedTasks(): readonly SharedTaskListItem[] {
const all = await api.list();
if (!current()) return;
const visibleOwned = await filterVisibleSharedTasks(
- all.filter(task => task.ownerAccountId === owner.accountId), owner.accountId, { openLink, invoke }, current,
+ all.filter(task => task.ownerAccountId === owner.accountId), owner.accountId, { openLink, closeLink, invoke }, current, api.leave,
);
if (!current()) return;
setOwned({ owner, tasks: visibleOwned });
@@ -44,11 +45,21 @@ export function useSharedTasks(): readonly SharedTaskListItem[] {
if (!current()) return;
const peer = sharedTaskHostPeer(task.sharedTaskId, task.hostDeviceId);
try {
+ const known = remoteSessionStore.getSessions().find(session => session.id === task.sessionId && session.deviceLinkDeviceId === peer);
+ if (!CINDY_MAKE_ENABLED && isCindyMakeSource(known?.source)) {
+ await leaveHiddenSharedTask(task, closeLink, api.leave, current);
+ continue;
+ }
await openLink(peer);
if (!current()) return;
const session = await invoke<RemoteSession>(peer, 'local-db:sessions:get', [task.sessionId]);
if (!current()) return;
- if (session.id === task.sessionId) remoteSessionStore.setDeviceSessions(peer, task.title, [session]);
+ if (session.id !== task.sessionId) continue;
+ if (!CINDY_MAKE_ENABLED && isCindyMakeSource(session.source)) {
+ await leaveHiddenSharedTask(task, closeLink, api.leave, current);
+ continue;
+ }
+ remoteSessionStore.setDeviceSessions(peer, task.title, [session]);
} catch { /* Keep offline history; only the authority list removes membership. */ }
}
} catch { /* A transient authority failure is not evidence of departure. */ }
diff --git a/docs/cindy-make-upstream.md b/docs/cindy-make-upstream.md
index 145cbdafaf..cb289fe91d 100644
--- a/docs/cindy-make-upstream.md
+++ b/docs/cindy-make-upstream.md
@@ -6,6 +6,12 @@
制作任务或相关搜索结果;旧链接不能打开制作界面,已有制作与上游合并任务不能继续执行。
主进程同时拒绝源码准备、生成、测试、版本切换和相关命令。已有源码、任务历史与个人版文件保留。
+官方客户端启动时忽略已保存的个人版选择,继续启动原版,并在取得现有实例锁后将选择持久化为
+`original`;不因个人版仍与当前协议或数据库兼容而自动交接到旧个人版。复用原有启动恢复流程,
+不提前等待异步注册表写入,不删除个人版文件。实现与回归见
+[versionStartup](../apps/desktop/src/main/cindy-make/versionStartup.ts) 与
+[versionStartup.test](../apps/desktop/src/main/cindy-make/__tests__/versionStartup.test.ts)。
+
共享开关见 [cindyMakeFeature](../packages/maker-shared/src/cindyMakeFeature.ts),
执行边界见 [featureGate](../apps/desktop/src/main/cindy-make/featureGate.ts) 与
[回归测试](../apps/desktop/src/main/maker-ipc/__tests__/cindyMakeFeatureGate.test.ts)。
diff --git a/docs/product-rules/shared-task-mode.md b/docs/product-rules/shared-task-mode.md
index b7994021c2..659f5c6f64 100644
--- a/docs/product-rules/shared-task-mode.md
+++ b/docs/product-rules/shared-task-mode.md
@@ -53,6 +53,7 @@
- 移除或退出立即撤权;原邀请不可重入,房主生成新邀请后才能再次加入。
- 停止共享、归档、房主登出使旧邀请和成员关系失效。重新共享产生新的共享 ID。
- Cindy Make 停用时,房主 Desktop 按本机原始任务来源关闭已有的制作任务共享(含 `cindy-make-merge`),不恢复访客访问、不允许重新开启。复用原有关闭账本与服务端关闭接口,离线先撤销本机授权,联网后重试关闭并从房主、访客目录移除,旧邀请随共享关闭失效;普通任务共享不受影响,任务历史与工作目录保留。新版控制端的账号共享目录也先按原始元数据确认任务来源;房主离线、旧版或读取失败而无法确认时,不展示标题、管理入口或合成首页行,确认普通来源后恢复显示。来源确认复用现有授权和元数据读取,不为目录发现申请整机远控或扩大访客权限。实现与回归见 `sharedTaskHost.ts`、`sharedTaskHost.test.ts` 和 `sharedTaskRuntime.test.ts`。
+- 访客通过旧邀请加入后,先通过已授权的单任务通道确认原始来源,再展示加入成功或进入任务;确认是已停用的制作任务时立即退出该共享,撤销成员资格并释放加入名额,关闭单任务连接并清理其镜像,不仅从界面隐藏。管理目录与冷启动恢复同样清理已确认的历史制作任务成员关系;退出失败时不展示任务、在后续刷新或加入重试中继续退出。来源未知或账号已切换时不猜测来源、不撤销普通任务权限,普通任务共享与同账号远控不受影响。
- 归档后恢复为活动任务,可以显式重新开启共享;须先完成旧共享关闭,旧代次的请求仍然失效。
- 房主设备的 relay 连接确认离线后有 60 秒重连宽限,期间重连保留共享、邀请与成员关系;持续离线超过宽限后由下一轮服务端扫描关闭(正常情况下确认离线后 60–90 秒)。关闭后重新上线不会恢复旧共享,需显式重新开启并发送新邀请。主动关闭与登出的显式关闭请求不等待宽限。已由新连接接管的旧连接退出不算离线;TTL 内短暂网络抖动不承诺立即判定。
- 服务端是成员关系权威;主机保存恢复与关闭记录。迟到响应、旧快照、缓存和重连不能恢复已撤销访问。
diff --git a/packages/maker-shared/src/__tests__/cindyMakeSharedTasks.test.ts b/packages/maker-shared/src/__tests__/cindyMakeSharedTasks.test.ts
index f29c808a35..09f90debc3 100644
--- a/packages/maker-shared/src/__tests__/cindyMakeSharedTasks.test.ts
+++ b/packages/maker-shared/src/__tests__/cindyMakeSharedTasks.test.ts
@@ -6,12 +6,14 @@ const options = () => ({
knownSession: vi.fn<() => { id: string; source?: string | null } | undefined>(() => undefined),
readSession: vi.fn<() => Promise<{ id: string; source?: string } | null>>(async () => null),
isCurrent: vi.fn(() => true),
+ onHiddenTask: vi.fn(async () => {}),
});
it.each(['cindy-make', 'cindy-make-merge'])('hides a legacy share confirmed as %s by the old host', async source => {
const reader = options();
reader.readSession.mockResolvedValue({ id: task.sessionId, source });
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
+ expect(reader.onHiddenTask).toHaveBeenCalledExactlyOnceWith(task);
});
it.each(['cindy-make', 'cindy-make-merge'])('uses the unfiltered cached %s source even with an offline host', async source => {
@@ -19,6 +21,7 @@ it.each(['cindy-make', 'cindy-make-merge'])('uses the unfiltered cached %s sourc
reader.knownSession.mockReturnValue({ id: task.sessionId, source });
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
expect(reader.readSession).not.toHaveBeenCalled();
+ expect(reader.onHiddenTask).toHaveBeenCalledExactlyOnceWith(task);
});
it.each(['offline', 'missing', 'wrong-task'])('keeps an unconfirmed %s share hidden and retries on recovery', async reason => {
@@ -26,8 +29,10 @@ it.each(['offline', 'missing', 'wrong-task'])('keeps an unconfirmed %s share hid
if (reason === 'offline') reader.readSession.mockRejectedValueOnce(new Error('offline'));
if (reason === 'wrong-task') reader.readSession.mockResolvedValueOnce({ id: 'other-task', source: 'desktop' });
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
+ expect(reader.onHiddenTask).not.toHaveBeenCalled();
reader.readSession.mockResolvedValue({ id: task.sessionId, source: 'desktop' });
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([{ ...task, source: 'desktop' }]);
+ expect(reader.onHiddenTask).not.toHaveBeenCalled();
});
it('confirms a matching legacy ordinary task whose successful metadata omits source', async () => {
@@ -36,6 +41,7 @@ it('confirms a matching legacy ordinary task whose successful metadata omits sou
reader.readSession.mockResolvedValue({ id: task.sessionId });
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([{ ...task, source: null }]);
expect(reader.readSession).toHaveBeenCalledExactlyOnceWith(task);
+ expect(reader.onHiddenTask).not.toHaveBeenCalled();
});
it('does not publish an old account response or start new reads after invalidation', async () => {
@@ -47,6 +53,7 @@ it('does not publish an old account response or start new reads after invalidati
reader.readSession.mockClear();
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
expect(reader.readSession).not.toHaveBeenCalled();
+ expect(reader.onHiddenTask).not.toHaveBeenCalled();
});
it('does not let a delayed read override newly arrived hidden source metadata', async () => {
@@ -56,4 +63,25 @@ it('does not let a delayed read override newly arrived hidden source metadata',
return { id: task.sessionId, source: 'desktop' };
});
expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
+ expect(reader.onHiddenTask).toHaveBeenCalledExactlyOnceWith(task);
+});
+
+it.each(['cached', 'remote'])('reports failed hidden membership cleanup and retries it (%s)', async origin => {
+ const reader = options();
+ if (origin === 'cached') reader.knownSession.mockReturnValue({ id: task.sessionId, source: 'cindy-make' });
+ else reader.readSession.mockResolvedValue({ id: task.sessionId, source: 'cindy-make' });
+ reader.onHiddenTask.mockRejectedValueOnce(new Error('leave failed'));
+ await expect(filterCindyMakeSharedTasks([task], reader)).rejects.toThrow('leave failed');
+ expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
+ expect(reader.onHiddenTask).toHaveBeenCalledTimes(2);
+});
+
+it('does not revoke a membership identified after an account change', async () => {
+ const reader = options();
+ reader.readSession.mockImplementation(async () => {
+ reader.isCurrent.mockReturnValue(false);
+ return { id: task.sessionId, source: 'cindy-make' };
+ });
+ expect(await filterCindyMakeSharedTasks([task], reader)).toEqual([]);
+ expect(reader.onHiddenTask).not.toHaveBeenCalled();
});
diff --git a/packages/maker-shared/src/cindyMakeFeature.ts b/packages/maker-shared/src/cindyMakeFeature.ts
index 05983a3e02..f23273166d 100644
--- a/packages/maker-shared/src/cindyMakeFeature.ts
+++ b/packages/maker-shared/src/cindyMakeFeature.ts
@@ -22,25 +22,31 @@ export async function filterCindyMakeSharedTasks<Task extends { sessionId: strin
knownSession(task: Task): SharedTaskSessionSource | null | undefined;
readSession(task: Task): Promise<SharedTaskSessionSource | null | undefined>;
isCurrent(): boolean;
+ onHiddenTask?(task: Task): Promise<void>;
},
): Promise<SourceConfirmedSharedTask<Task>[]> {
+ const hide = async (task: Task) => {
+ if (options.isCurrent()) await options.onHiddenTask?.(task);
+ return null;
+ };
const confirmed = await Promise.all(tasks.map(async (task): Promise<{ task: Task; source: string | null } | null> => {
if (!options.isCurrent()) return null;
const known = options.knownSession(task);
if (CINDY_MAKE_ENABLED) return { task, source: known?.source ?? null };
if (known?.id === task.sessionId && known.source !== undefined) {
- return isCindyMakeSource(known.source) ? null : { task, source: known.source };
+ return isCindyMakeSource(known.source) ? hide(task) : { task, source: known.source };
}
+ let session: SharedTaskSessionSource | null | undefined;
try {
- const session = await options.readSession(task);
- if (!options.isCurrent() || session?.id !== task.sessionId) return null;
- const latest = options.knownSession(task);
- const source = latest?.id === task.sessionId && latest.source !== undefined
- ? latest.source : session.source ?? null;
- return isCindyMakeSource(source) ? null : { task, source };
+ session = await options.readSession(task);
} catch {
return null;
}
+ if (!options.isCurrent() || session?.id !== task.sessionId) return null;
+ const latest = options.knownSession(task);
+ const source = latest?.id === task.sessionId && latest.source !== undefined
+ ? latest.source : session.source ?? null;
+ return isCindyMakeSource(source) ? hide(task) : { task, source };
}));
return options.isCurrent() ? confirmed.flatMap(result => result ? [{ ...result.task, source: result.source }] : []) : [];
}