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(plugin): 分享覆盖前明确确认替换及数据影响

liugaowei706acf8cdd98
diff --git a/apps/desktop/scripts/fixtures/local-plugin-sharing/fixture.tsx b/apps/desktop/scripts/fixtures/local-plugin-sharing/fixture.tsx
index b9ee06c12d..96b28bb353 100644
--- a/apps/desktop/scripts/fixtures/local-plugin-sharing/fixture.tsx
+++ b/apps/desktop/scripts/fixtures/local-plugin-sharing/fixture.tsx
@@ -46,8 +46,14 @@ mountPage({
if (request.actionId === 'management:snapshot') return { effects: [], result: { version: 1, ghosts: [],
market: { items: [], customSourceNames: [], unavailableCustomSourceNames: [] }, ...(ctx.case === 'remote-unsupported' ? {} : { localShares: true }) } };
return { effects: [], result: { operationId: request.input.operationId, phase: 'confirmation', consent: {
- requestId: 'fixture-consent', initiator: 'user', origin: 'local-file', facts: { kind: 'install', name: snapshot.name, version: snapshot.version,
- permissions: [{ key: 'network:host:api.example.test', kind: 'network', labelKey: 'networkHost', labelArgs: { host: 'api.example.test' } }] },
+ requestId: 'fixture-consent', initiator: 'user', origin: 'local-file',
+ ...(ctx.case === 'remote-replace' ? { purpose: 'share-replace' as const,
+ target: { namespace: null, sourceChanged: false, otherCopies: 0 } } : {}),
+ facts: ctx.case === 'remote-replace'
+ ? { kind: 'update', ghostId: snapshot.ghostId, name: snapshot.name, version: snapshot.version, previousVersion: snapshot.version,
+ added: [], removed: [], unchangedCount: 1, builtinOauthClientChanged: false }
+ : { kind: 'install', name: snapshot.name, version: snapshot.version,
+ permissions: [{ key: 'network:host:api.example.test', kind: 'network', labelKey: 'networkHost', labelArgs: { host: 'api.example.test' } }] },
} } };
} },
pluginMarket: {
diff --git a/apps/desktop/scripts/fixtures/local-plugin-sharing/ui-page.mjs b/apps/desktop/scripts/fixtures/local-plugin-sharing/ui-page.mjs
index 02b14aa40d..ec581ece80 100644
--- a/apps/desktop/scripts/fixtures/local-plugin-sharing/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/local-plugin-sharing/ui-page.mjs
@@ -30,8 +30,10 @@ export default {
changed: { about: 'Changed content requires reopening to check and confirm the new package', viewport: { width: 360, height: 740 } },
recipient: { about: 'Exact shared version, explicit installation and real permission confirmation' },
'recipient-narrow': { about: 'Exact shared package at narrow width', viewport: { width: 360, height: 740 } },
+ 'recipient-replace': { about: 'Explicit same-ID replacement and existing account/data notice', viewport: { width: 320, height: 740 } },
'remote-select': { about: 'Choose another computer and confirm that computer’s permissions', viewport: { width: 900, height: 850 } },
'remote-narrow': { about: 'Remote package and permission confirmation at minimum width', viewport: { width: 320, height: 740 } },
+ 'remote-replace': { about: 'Same replacement action and data notice on the selected computer', viewport: { width: 320, height: 740 } },
'remote-offline': { about: 'Keep the offline target selected and disable installation', viewport: { width: 320, height: 740 } },
'remote-unsupported': { about: 'Explain the required target update without local fallback', viewport: { width: 320, height: 740 } },
login: { about: 'No package read until login', viewport: { width: 360, height: 740 } },
@@ -80,6 +82,10 @@ export default {
await ui.capture('target-device');
await button.click();
await page.getByRole('alertdialog').waitFor();
+ if (ui.case === 'remote-replace') {
+ await page.getByRole('button', { name: await ui.t('sharing.localReplaceButton'), exact: true }).waitFor();
+ await page.getByText(await ui.t('sharing.localReplaceRetainsState'), { exact: true }).waitFor();
+ }
await ui.capture('target-permissions');
return;
}
@@ -89,11 +95,19 @@ export default {
await page.getByRole('button', { name: await ui.t('sharing.localInstallButton', { version: '1.0.0' }) }).click();
await ui.emit('consent', {
requestId: 'local-share-fixture', initiator: 'user', origin: 'local-file',
+ ...(ui.case === 'recipient-replace' ? { purpose: 'share-replace' } : {}),
target: { namespace: null, sourceChanged: false, otherCopies: 0 },
- facts: { kind: 'install', ghostId: 'local-share-example', name: '我的本地插件', version: '1.0.0',
- permissions: [{ key: 'network:host:api.example.test', kind: 'network', labelKey: 'networkHost', labelArgs: { host: 'api.example.test' } }] },
+ facts: ui.case === 'recipient-replace'
+ ? { kind: 'update', ghostId: 'local-share-example', name: '我的本地插件', version: '1.0.0', previousVersion: '1.0.0',
+ added: [], removed: [], unchangedCount: 1, builtinOauthClientChanged: false }
+ : { kind: 'install', ghostId: 'local-share-example', name: '我的本地插件', version: '1.0.0',
+ permissions: [{ key: 'network:host:api.example.test', kind: 'network', labelKey: 'networkHost', labelArgs: { host: 'api.example.test' } }] },
});
await page.getByRole('alertdialog').waitFor();
+ if (ui.case === 'recipient-replace') {
+ await page.getByRole('button', { name: await ui.t('sharing.localReplaceButton'), exact: true }).waitFor();
+ await page.getByText(await ui.t('sharing.localReplaceRetainsState'), { exact: true }).waitFor();
+ }
await ui.capture('permissions');
return;
}
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostLocalInstallIdentity.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostLocalInstallIdentity.test.ts
index d07ac759e2..5b361b0498 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostLocalInstallIdentity.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostLocalInstallIdentity.test.ts
@@ -11,6 +11,7 @@ import { ghostInstallApprovalToken } from '../../../shared/ghost.js';
import { createGhostProductionCallbacks } from './ghostProductionCallbacksFixture.js';
import { GhostManager } from '../GhostManager.js';
import { effectiveInstallOrigin } from '../ghostInstallReceipt.js';
+import { classifyGhostLocalUpdateSource } from '../ghostLocalUpdateSource.js';
import { runGhostSnapshotWorkerRequest } from '../ghostSnapshotWorkerProcess.js';
import { writeTestCindyPackage } from './cindyPackageFixture.js';
@@ -121,17 +122,21 @@ const sharedPackageCallbacks = createGhostProductionCallbacks<{
installLocalPluginSharePackage: (file: string, options: Record<string, unknown>) => Promise<InstalledGhost>;
}>({ functions: ['installLocalPluginSharePackage'] });
-it.each(['new', 'update', 'cancel', 'different-bytes', 'owner-changed'] as const)('shared local package consent: %s', async mode => {
+// Same-ID unsigned shares previously skipped consent when permissions were unchanged.
+// Exercise the production entry and source classifier, including a declined replacement.
+it.each(['new', 'update', 'cancel', 'cancel-update', 'different-bytes', 'owner-changed'] as const)('shared local package consent: %s', async mode => {
const manifest: InstalledGhost['manifest'] = { schemaVersion: 3, minCindyVersion: '99.0.0', id: 'helper', name: 'Helper', version: '1.0.0', kind: 'chip', entry: 'main.js' };
const root: InstalledGhost = { manifest, namespace: null, instanceKey: '_root__helper', dir: '/plugins/_root/helper', enabled: true,
approval: { state: 'approved', revision: '11111111-1111-4111-8111-111111111111' } };
const digest = 'a'.repeat(64);
let current = true;
- const prompt = vi.fn<(request: Omit<GhostInstallConsentRequest, 'requestId'>) => Promise<boolean>>(async () => mode !== 'cancel');
+ const replacing = mode === 'update' || mode === 'cancel-update';
+ const trust = { level: 'unverified' as const, publisherSigned: false, publisherVerified: false, reviewed: false };
+ const prompt = vi.fn<(request: Omit<GhostInstallConsentRequest, 'requestId'>) => Promise<boolean>>(async () => !mode.startsWith('cancel'));
const install = vi.fn<(...args: unknown[]) => Promise<InstalledGhost>>(async () => root),
update = vi.fn<(...args: unknown[]) => Promise<InstalledGhost>>(async () => root), release = vi.fn();
const entry = sharedPackageCallbacks({
- getGhostManager: () => ({ list: () => mode === 'update' ? [root] : [],
+ getGhostManager: () => ({ list: () => replacing ? [root] : [],
inspect: async () => { if (mode === 'owner-changed') current = false;
return { manifest, canonicalManifest: manifest, packageSha256: mode === 'different-bytes' ? 'b'.repeat(64) : digest }; } }),
captureGhostMutationOwner: () => 'owner', beginGhostMutation: () => release,
@@ -139,13 +144,17 @@ it.each(['new', 'update', 'cancel', 'different-bytes', 'owner-changed'] as const
throwInstallError: () => { throw new Error('invalid package'); },
throwIpcError: (code: string) => { throw new Error(code); },
findInstalledGhostForDeliveryTarget, ghostInstallApprovalToken, installedGhostStoragePart,
- readLocalGhostUpdateSource: () => ({ sourceChanged: true, authorizationOverrides: {} }),
+ readLocalGhostUpdateSource: () => ({ ...classifyGhostLocalUpdateSource({
+ existingSourceChanged: false,
+ previousApprovedReceipt: { id: manifest.id, namespace: null, packageSha256: 'b'.repeat(64), trust },
+ inspectedPackage: { ghostId: manifest.id, namespace: null, packageSha256: digest, trust },
+ }), authorizationOverrides: {} }),
obtainGhostInstallConsent, withGhostInstallLock: async (_id: string, run: () => unknown) => run(),
installAndDock: install, updateLocalGhostPackageLocked: update,
}).installLocalPluginSharePackage;
const result = entry('/tmp/shared.cindy', { ghostId: 'helper', version: '1.0.0', sha256: digest, prompt,
assertCurrent() { if (!current) throw new Error('OWNER_CHANGED'); } });
- if (mode === 'cancel' || mode === 'different-bytes' || mode === 'owner-changed') {
+ if (mode.startsWith('cancel') || mode === 'different-bytes' || mode === 'owner-changed') {
await expect(result).rejects.toThrow();
expect(install).not.toHaveBeenCalled(); expect(update).not.toHaveBeenCalled();
if (mode === 'owner-changed') expect(prompt).not.toHaveBeenCalled();
@@ -155,11 +164,17 @@ it.each(['new', 'update', 'cancel', 'different-bytes', 'owner-changed'] as const
if (mode === 'update') {
expect(install).not.toHaveBeenCalled();
expect(update.mock.calls[0]?.[5]).toBe('_root__helper');
- expect(prompt.mock.calls[0]?.[0]).toMatchObject({ target: { namespace: null, sourceChanged: true } });
+ expect(update.mock.calls[0]?.[6]).toMatchObject({ mode: 'confirmed', forced: true });
+ expect(update.mock.calls[0]?.[9]).toBe(false);
} else {
expect(install.mock.calls[0]?.[2]).toMatchObject({ namespace: null, enable: true, registrySource: 'manual', expectedPackageSha256: digest });
}
}
+ if (replacing) {
+ expect(prompt).toHaveBeenCalledOnce();
+ expect(prompt.mock.calls[0]?.[0]).toMatchObject({ purpose: 'share-replace',
+ facts: { kind: 'update', added: [] }, target: { namespace: null, sourceChanged: false } });
+ }
});
// Same production entry with real archive inspection, placement and receipt.
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index f24891180d..29112d195a 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -8056,8 +8056,9 @@ export async function installLocalPluginSharePackage(file: string, options: {
const updateSource = existing ? readLocalGhostUpdateSource(manager, existing, inspected) : undefined;
rejectUnauthorizedTokenBroker(inspected.canonicalManifest, updateSource?.authorizationOverrides);
const approval = existing ? ghostInstallApprovalToken(existing.approval) : undefined;
- const consent = await obtainGhostInstallConsent({ mode: 'prompt', prompt: options.prompt, initiator: 'user', origin: 'local-file',
- force: updateSource?.sourceChanged,
+ const consent = await obtainGhostInstallConsent({ mode: 'prompt',
+ prompt: request => options.prompt(existing ? { ...request, purpose: 'share-replace' } : request),
+ initiator: 'user', origin: 'local-file', force: Boolean(existing),
target: ghostInstallTargetContext(manager.list(), inspected.manifest.id, null, existing, updateSource?.sourceChanged === true) },
existing, inspected.manifest, inspected.packageSha256);
options.assertCurrent();
diff --git a/apps/desktop/src/renderer/cindy-brain/GhostInstallConsentHost.tsx b/apps/desktop/src/renderer/cindy-brain/GhostInstallConsentHost.tsx
index f83d353c83..63cdc767f9 100644
--- a/apps/desktop/src/renderer/cindy-brain/GhostInstallConsentHost.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/GhostInstallConsentHost.tsx
@@ -2,8 +2,8 @@
* 插件安装/更新确认框(docs/dev-rules/plugin-security-and-authoring.md §3.1)。
*
* Main 在用户从插件页、拖入或双击 `.cindy` 发起安装后,检查完真实包、在任何安装锁之外
- * 把确认请求投给发起安装的这个窗口;首次安装展示全部权限,更新只在权限变多时出现并
- * 高亮变化。无论确认、取消还是被 Main 收起(超时、账号切换),答案都会回给 Main。
+ * 把确认请求投给发起安装的这个窗口;首次安装展示全部权限,更新高亮权限变化,分享覆盖
+ * 另需明确确认替换。无论确认、取消还是被 Main 收起(超时、账号切换),答案都会回给 Main。
* 落位前 Main 还会在锁内用同一份包复核,确认框本身不是授权事实。
*/
import { useEffect, type ReactNode } from 'react';
@@ -101,7 +101,9 @@ function ConsentSection({ title, children }: { title: string; children: ReactNod
);
}
-export function GhostInstallConsentContent({ facts, capabilityOnly = false }: { facts: GhostInstallConsentFacts; capabilityOnly?: boolean }) {
+export function GhostInstallConsentContent({ facts, capabilityOnly = false, replacement = false, sourceChanged = false }: {
+ facts: GhostInstallConsentFacts; capabilityOnly?: boolean; replacement?: boolean; sourceChanged?: boolean;
+}) {
const { t } = useTranslation();
if (facts.kind === 'install') {
return (
@@ -128,8 +130,11 @@ export function GhostInstallConsentContent({ facts, capabilityOnly = false }: {
return (
<div>
<p className="text-13 leading-5 text-[var(--confirm-desc)]">
- {capabilityOnly ? null : t('settings.ghosts.installConsent.updateDescription')}
+ {capabilityOnly ? null : t(replacement ? 'sharing.localReplaceNotice' : 'settings.ghosts.installConsent.updateDescription')}
</p>
+ {replacement ? <p className="mt-2 text-13 leading-5 text-[var(--confirm-desc)]">
+ {t(sourceChanged ? 'settings.ghosts.installConsent.sourceChanged' : 'sharing.localReplaceRetainsState')}
+ </p> : null}
{facts.builtinOauthClientChanged ? (
<p className="mt-2 text-13 leading-5 text-[var(--confirm-desc)]">
{t('settings.ghosts.installConsent.oauthClientChanged')}
@@ -202,11 +207,13 @@ export function GhostInstallConsentHost() {
if (ownerStamp !== undefined && !isDataOwnerPushStampCurrent(ownerStamp)) return;
const { facts } = request;
const capabilityOnly = request.purpose === 'task-capability';
+ const replacement = request.purpose === 'share-replace' && facts.kind === 'update';
const source = ghostInstallConsentSourceLabel(t, request);
confirmed = await confirm(
{
title:
- capabilityOnly ? facts.name : facts.kind === 'install'
+ capabilityOnly ? facts.name : replacement
+ ? t('sharing.localReplaceTitle', { name: facts.name }) : facts.kind === 'install'
? t('settings.ghosts.installConsent.installTitle', { name: facts.name })
: t('settings.ghosts.installConsent.updateTitle', { name: facts.name }),
description:
@@ -223,16 +230,18 @@ export function GhostInstallConsentHost() {
content: <>
{request.target && <div className="mb-3 space-y-2 text-13 leading-5 text-[var(--confirm-desc)]">
<p>{t('settings.ghosts.installConsent.targetIdentity', { name: request.target.namespace || t('settings.ghosts.installConsent.personalTarget') })}</p>
- {request.target.sourceChanged && <p>{t('settings.ghosts.installConsent.sourceChanged')}</p>}
+ {request.target.sourceChanged && !replacement && <p>{t('settings.ghosts.installConsent.sourceChanged')}</p>}
{request.target.otherCopies > 0 && <p>{t('settings.ghosts.installConsent.otherCopies', { count: request.target.otherCopies })}</p>}
</div>}
- <GhostInstallConsentContent facts={facts} capabilityOnly={capabilityOnly} />
+ <GhostInstallConsentContent facts={facts} capabilityOnly={capabilityOnly}
+ replacement={replacement} sourceChanged={request.target?.sourceChanged} />
</>,
maxWidth: 460,
contentSelectable: true,
describeContent: true,
confirmText:
- capabilityOnly ? t('settings.ghosts.connections.confirmAllow') : facts.kind === 'install'
+ capabilityOnly ? t('settings.ghosts.connections.confirmAllow') : replacement
+ ? t('sharing.localReplaceButton') : facts.kind === 'install'
? t('settings.ghosts.installConsent.confirmInstall')
: t('settings.ghosts.installConsent.confirmUpdate'),
cancelText: t('settings.ghosts.installConsent.cancel'),
diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/GhostInstallConsentHost.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/GhostInstallConsentHost.test.tsx
index 1c2f26d709..c8e2120f61 100644
--- a/apps/desktop/src/renderer/cindy-brain/__tests__/GhostInstallConsentHost.test.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/GhostInstallConsentHost.test.tsx
@@ -106,6 +106,26 @@ describe('GhostInstallConsentHost', () => {
await waitFor(()=>expect(resolveInstallConsent).toHaveBeenCalledWith('tasks',true));
});
+ // Shared same-ID packages need a distinct replacement action and accurate
+ // state impact even with no added permissions (unit: real Host, fake Main).
+ it.each([false, true])('explains shared replacement without changing source rules (sourceChanged=%s)', async sourceChanged => {
+ render(<GhostInstallConsentHost />);
+ await act(async () => push?.({
+ requestId: 'share-replace', purpose: 'share-replace', initiator: 'user', origin: 'local-file',
+ target: { namespace: null, sourceChanged, otherCopies: 0 },
+ facts: { kind: 'update', ghostId: 'weather-chip', name: 'Weather', version: '1.0.0',
+ previousVersion: '1.0.0', added: [], removed: [], unchangedCount: 1, builtinOauthClientChanged: false },
+ }));
+ const options = mocks.confirm.mock.calls[0][0];
+ expect(options.title).toBe('sharing.localReplaceTitle:{"name":"Weather"}');
+ expect(options.confirmText).toBe('sharing.localReplaceButton');
+ render(<>{options.content}</>);
+ expect(screen.getByText('sharing.localReplaceNotice')).toBeTruthy();
+ expect(screen.queryByText('sharing.localReplaceRetainsState') !== null).toBe(!sourceChanged);
+ expect(screen.queryByText('settings.ghosts.installConsent.sourceChanged') !== null).toBe(sourceChanged);
+ await waitFor(() => expect(resolveInstallConsent).toHaveBeenCalledWith('share-replace', true));
+ });
+
it('answers cancel when Main dismisses the pending dialog', async () => {
let seenSignal: AbortSignal | undefined;
mocks.confirm.mockImplementation(
diff --git a/apps/desktop/src/renderer/features/plugin/LocalPluginShareView.tsx b/apps/desktop/src/renderer/features/plugin/LocalPluginShareView.tsx
index e93283e3ad..ab09b5bdbc 100644
--- a/apps/desktop/src/renderer/features/plugin/LocalPluginShareView.tsx
+++ b/apps/desktop/src/renderer/features/plugin/LocalPluginShareView.tsx
@@ -153,13 +153,15 @@ function RemoteShareInstall({ snapshot, device, online, onBusy, onError, onInsta
const abort = new AbortController(); dialog.current = abort;
try {
const consent = next.consent;
+ const replacement = consent.purpose === 'share-replace' && consent.facts.kind === 'update';
const confirmed = await confirm({
title: t('settings.ghosts.remote.confirmOn', { device: device.name, name: consent.facts.name }),
description: `${device.name} · ${consent.facts.kind === 'install'
? t('settings.ghosts.installConsent.installMeta', { version: consent.facts.version, source: ghostInstallConsentSourceLabel(t, consent) })
: t('settings.ghosts.installConsent.updateMeta', { from: consent.facts.previousVersion, to: consent.facts.version, source: ghostInstallConsentSourceLabel(t, consent) })}`,
- content: <GhostInstallConsentContent facts={consent.facts} />,
- confirmText: t(consent.facts.kind === 'install' ? 'settings.ghosts.installConsent.confirmInstall' : 'settings.ghosts.installConsent.confirmUpdate'),
+ content: <GhostInstallConsentContent facts={consent.facts} replacement={replacement} sourceChanged={consent.target?.sourceChanged} />,
+ confirmText: t(replacement ? 'sharing.localReplaceButton' : consent.facts.kind === 'install'
+ ? 'settings.ghosts.installConsent.confirmInstall' : 'settings.ghosts.installConsent.confirmUpdate'),
cancelText: t('settings.ghosts.installConsent.cancel'), maxWidth: 460, contentSelectable: true,
}, abort.signal);
if (writable() && !abort.signal.aborted && operation.current === next.operationId)
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/LocalPluginShareView.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/LocalPluginShareView.test.tsx
index 21a213ce18..7d768d1a45 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/LocalPluginShareView.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/LocalPluginShareView.test.tsx
@@ -90,16 +90,22 @@ it.each([false, true])('installs on this computer without requiring a device cho
expect(io.invoke).not.toHaveBeenCalled();
});
-function remoteHost(supported = true) {
+function remoteHost(supported = true, replacing = false) {
+ let outcome: 'succeeded' | 'cancelled' = 'succeeded';
io.invoke.mockImplementation(async (_device, channel, [request]) => {
if (String(channel).includes('manifest')) return { collections: [{ id: 'plugins', actions: [{ id: 'management:snapshot' }] }] };
if (request.actionId === 'management:snapshot') return { effects: [], result: { version: 1, ghosts: [],
market: { items: [], customSourceNames: [], unavailableCustomSourceNames: [] }, ...(supported ? { localShares: true } : {}) } };
const operationId = request.input.operationId;
if (request.actionId === 'management:begin') return { effects: [], result: { operationId, phase: 'confirmation', consent: {
- requestId: 'consent-request', initiator: 'user', origin: 'local-file', facts: { kind: 'install', name: snapshot.name, version: snapshot.version, permissions: [] },
+ requestId: 'consent-request', initiator: 'user', origin: 'local-file',
+ ...(replacing ? { purpose: 'share-replace', target: { namespace: null, sourceChanged: false, otherCopies: 0 } } : {}),
+ facts: replacing ? { kind: 'update', name: snapshot.name, version: snapshot.version, previousVersion: snapshot.version,
+ added: [], removed: [], unchangedCount: 1, builtinOauthClientChanged: false }
+ : { kind: 'install', name: snapshot.name, version: snapshot.version, permissions: [] },
} } };
- return { effects: [], result: { operationId, phase: 'succeeded' } };
+ if (request.actionId === 'management:answer') outcome = request.input.confirmed ? 'succeeded' : 'cancelled';
+ return { effects: [], result: { operationId, phase: outcome } };
});
}
it('installs on the chosen device with its consent receipt and never invokes local installation', async () => {
@@ -119,6 +125,31 @@ it('installs on the chosen device with its consent receipt and never invokes loc
expect(io.confirm).toHaveBeenCalledOnce();
});
+// A remote replacement with unchanged permissions must show state inheritance
+// and send the explicit choice to the selected Host, including cancellation.
+it.each([false, true])('confirms replacement on the selected computer (allow=%s)', async allow => {
+ remoteHost(true, true); io.confirm.mockResolvedValue(allow);
+ const installed = vi.fn(); render(view(installed, control()));
+ const button = await screen.findByRole<HTMLButtonElement>('button', { name: 'sharing.localInstallButton' });
+ await waitFor(() => expect(button.disabled).toBe(false));
+ vi.useFakeTimers();
+ try {
+ await act(async () => { fireEvent.click(button); });
+ await act(async () => { await vi.advanceTimersByTimeAsync(650); });
+ } finally { vi.useRealTimers(); }
+ expect(button.disabled).toBe(false);
+ const options = io.confirm.mock.calls[0][0];
+ expect(options.confirmText).toBe('sharing.localReplaceButton');
+ render(<>{options.content}</>);
+ expect(screen.getByText('sharing.localReplaceNotice')).toBeTruthy();
+ expect(screen.getByText('sharing.localReplaceRetainsState')).toBeTruthy();
+ const answer = io.invoke.mock.calls.find(([, , [r]]) => r.actionId === 'management:answer');
+ expect(answer?.[0]).toBe(target.deviceId);
+ expect(answer?.[2][0].input).toMatchObject({ requestId: 'consent-request', confirmed: allow });
+ expect(installed).toHaveBeenCalledTimes(allow ? 1 : 0);
+ expect(io.install).not.toHaveBeenCalled();
+});
+
// The fixed snapshot may carry a valid 512 KiB icon, while device-link actions
// allow only 64 KiB. Exercise the real request parser at the fake IPC boundary;
// the earlier remote test only used icon=null and could not expose the failure.
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 0222399890..f97bf2772d 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -17895,6 +17895,10 @@
"localInstallTarget": "Install on",
"localTargetUnsupported": "Update Cindy on “{{device}}” to install shared local plugins.",
"localInstallButton": "Install v{{version}}",
+ "localReplaceTitle": "Replace “{{name}}”",
+ "localReplaceButton": "Replace",
+ "localReplaceNotice": "This shared package will replace the installed plugin. Only replace it if you trust this package.",
+ "localReplaceRetainsState": "The new code will continue using the existing accounts and data. A matching plugin ID does not prove it came from the same author.",
"localInstalling": "Installing plugin…",
"localVersionNotice": "This link keeps the version saved when it was shared. Review the plugin’s permissions before installation.",
"localSignIn": "Sign In to View",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index e5ea0adffa..bbf8e40bfe 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -17835,6 +17835,10 @@
"localInstallTarget": "インストール先",
"localTargetUnsupported": "共有されたローカルプラグインをインストールするには、「{{device}}」の Cindy を更新してください。",
"localInstallButton": "v{{version}} をインストール",
+ "localReplaceTitle": "「{{name}}」を置き換え",
+ "localReplaceButton": "置き換え",
+ "localReplaceNotice": "この共有パッケージでインストール済みのプラグインを置き換えます。信頼できるパッケージの場合のみ置き換えてください。",
+ "localReplaceRetainsState": "新しいコードは既存のアカウントとデータを引き続き使用します。プラグイン ID が同じでも、同じ作者とは限りません。",
"localInstalling": "プラグインをインストール中…",
"localVersionNotice": "このリンクには共有時のバージョンが保存されています。インストール前にプラグインの権限を確認できます。",
"localSignIn": "ログインして確認",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 5b2f49bb84..74117a6c00 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -17835,6 +17835,10 @@
"localInstallTarget": "설치할 기기",
"localTargetUnsupported": "공유된 로컬 플러그인을 설치하려면 “{{device}}”의 Cindy를 업데이트하세요。",
"localInstallButton": "v{{version}} 설치",
+ "localReplaceTitle": "‘{{name}}’ 교체",
+ "localReplaceButton": "교체",
+ "localReplaceNotice": "이 공유 패키지로 설치된 플러그인을 교체합니다. 신뢰할 수 있는 패키지인 경우에만 교체하세요.",
+ "localReplaceRetainsState": "새 코드는 기존 계정과 데이터를 계속 사용합니다. 플러그인 ID가 같아도 같은 제작자의 패키지라는 보장은 없습니다.",
"localInstalling": "플러그인 설치 중…",
"localVersionNotice": "이 링크에는 공유 당시의 버전이 저장되어 있습니다. 설치 전에 플러그인 권한을 확인할 수 있습니다.",
"localSignIn": "로그인하여 보기",
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 b5c6c25c9c..1455d02782 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -17835,6 +17835,10 @@
"localInstallTarget": "安装到哪台设备",
"localTargetUnsupported": "请更新「{{device}}」上的 Cindy 后,再安装分享的本地插件。",
"localInstallButton": "安装 v{{version}}",
+ "localReplaceTitle": "替换「{{name}}」",
+ "localReplaceButton": "替换",
+ "localReplaceNotice": "将使用本次分享包替换已安装的插件。请仅在信任此包时替换。",
+ "localReplaceRetainsState": "替换后的代码会继续使用原账号和数据。插件标识相同,不代表作者相同。",
"localInstalling": "正在安装插件…",
"localVersionNotice": "此链接保留分享时的版本。安装前会显示插件权限,由你确认。",
"localSignIn": "登录并查看",
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 4781baa0b1..f5d4cb6ef5 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -17835,6 +17835,10 @@
"localInstallTarget": "安裝到哪台裝置",
"localTargetUnsupported": "請更新「{{device}}」上的 Cindy 後,再安裝分享的本機插件。",
"localInstallButton": "安裝 v{{version}}",
+ "localReplaceTitle": "取代「{{name}}」",
+ "localReplaceButton": "取代",
+ "localReplaceNotice": "將使用本次分享包取代已安裝的插件。請僅在信任此包時取代。",
+ "localReplaceRetainsState": "取代後的程式碼會繼續使用原帳號和資料。插件識別碼相同,不代表作者相同。",
"localInstalling": "正在安裝插件…",
"localVersionNotice": "此連結保留分享時的版本。安裝前會顯示插件權限,由你確認。",
"localSignIn": "登入並查看",
diff --git a/apps/desktop/src/shared/ghostInstallConsent.ts b/apps/desktop/src/shared/ghostInstallConsent.ts
index a93eca211f..4c0ef520d8 100644
--- a/apps/desktop/src/shared/ghostInstallConsent.ts
+++ b/apps/desktop/src/shared/ghostInstallConsent.ts
@@ -58,8 +58,8 @@ export type GhostInstallConsentFacts =
/** Main 投给确认界面的一次确认请求。 */
export interface GhostInstallConsentRequest {
- /** Host-only first-use capability confirmation; does not install/update a package. */
- purpose?: 'task-capability';
+ /** Host-selected presentation; task-capability does not install/update a package. */
+ purpose?: 'task-capability' | 'share-replace';
requestId: string;
initiator: GhostInstallConsentInitiator;
origin: GhostInstallConsentOrigin;
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 9601d26b59..e94bde2047 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -3658,6 +3658,9 @@ Main 先用原一致性读取入口核对已批准的本地实例,绑定版本
服务地址或用户身份。下载只取固定服务签发的该快照票据,核对大小、SHA、ghostId 和版本后,
复用本地包的真实权限确认、root/manual 安装/更新锁及 durable receipt。换源必须沿原确认,
不写市场更新订阅,不改写 namespace、签名或 `minCindyVersion` 策略;取消不报告安装完成。
+分享包覆盖已安装的同 ID 插件时,即使权限未增加也必须明确点击“替换”;本机与远程目标
+共用原确认回执(`purpose=share-replace`)。普通本地来源更新的说明明确告知会继续使用旧账号和数据,
+相同 ID 不证明作者相同;已触发原换源判据时仍展示原隔离说明,不改变状态继承规则。
临时包使用独立目录,失败、释放面板、窗口关闭及退出清理;切换账号使在途结果失效。
需先部署支持独立快照与增量表的 Plugin Server,再部署本地模块的 Share Server,最后发布客户端。