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(plugins): guard preferences at runtime mutation boundary

Chrisf3de86f04044
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskSnapshot.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskSnapshot.test.ts
index f3b6e38ea0..6f7fe6805c 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskSnapshot.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskSnapshot.test.ts
@@ -37,11 +37,48 @@ it.each([
const assertCurrent=vi.fn();
await apply('task',{agentKind:target,providerId:'chosen',model:'chosen-model',effort:'medium',fastMode:false},assertCurrent);
expect(assertCurrent).toHaveBeenCalledOnce();
- expect(set).toHaveBeenCalledWith({targetSessionId:'task',expectedGeneration:7,patch:{
+ expect(set).toHaveBeenCalledWith({targetSessionId:'task',expectedGeneration:7,beforeMutation:assertCurrent,patch:{
...(harness ? {harness} : {}),providerId:'chosen',model:'chosen-model',effort:'medium',fastMode:false,
}});
});
+it.each(['codex', 'cc'])('rechecks preferences after runtime admission waits for %s', async agentKind => {
+ const start = source.indexOf(' setModel: async (taskId, route, assertUnchanged) =>');
+ const property = source.slice(start, source.indexOf(' assertTeamPlanUnstarted:', start)).trim().replace(/,$/, '');
+ let selectedModel = 'selected';
+ let release!: () => void;
+ let entered!: () => void;
+ const waiting = new Promise<void>(resolve => { entered = resolve; });
+ const admission = new Promise<void>(resolve => { release = resolve; });
+ const write = vi.fn();
+ const apply = compile(`return ({${property}}).setModel;`, { PluginTaskError, sessionControlService: {
+ getSessionRuntime: async () => ({ ok: true, runtime: {
+ runtimeGeneration: 7, effectiveProfile: { agentKind: 'codex' },
+ } }),
+ setSessionRuntime: async ({ beforeMutation, patch }: {
+ beforeMutation?: () => Promise<void>; patch: { model: string };
+ }) => {
+ entered();
+ await admission;
+ await beforeMutation?.();
+ write(patch.model);
+ return { ok: true, status: 'applied' };
+ },
+ } });
+ const assertCurrent = async () => {
+ if (selectedModel !== 'selected') throw new PluginTaskError('STALE_REVISION', 'preferences changed');
+ };
+ const result = apply('task', {
+ agentKind, model: 'selected', providerId: 'provider', effort: 'medium', fastMode: false,
+ }, assertCurrent);
+ const rejected = expect(result).rejects.toMatchObject({ code: 'STALE_REVISION' });
+ await waiting;
+ selectedModel = 'new-selection';
+ release();
+ await rejected;
+ expect(write).not.toHaveBeenCalled();
+});
+
it.each(['auto', 'acceptEdits'])('exposes independent Plan Mode alongside stored %s permission', async permissionMode => {
const start = source.indexOf(' readSession: async taskId =>');
const property = source.slice(start, source.indexOf(' dispatch:', start)).trim().replace(/,$/, '');
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 0b6ad7ee8b..aed0cab785 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -12303,6 +12303,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
|| (pendingAgent !== undefined && pendingAgent !== targetAgent);
const result = await sessionControlService.setSessionRuntime({ targetSessionId: taskId,
expectedGeneration: current.runtime.runtimeGeneration,
+ beforeMutation: assertUnchanged,
patch: { ...(selectHarness ? { harness: targetAgent } : {}),
model: route.model, providerId: route.providerId, effort: (route.effort || null) as Effort | null,
fastMode: route.fastMode } });