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(desktop): validate scheduled provider harness routes

ylliuuu66d2666599ece3
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts
index 9e7dc8bce6..9b22a0e152 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts
@@ -8,7 +8,7 @@ const choice: ScheduledModelSelection = {
agentKind: 'codex', model: 'test-model', providerId: 'openai-shared', effort: 'high', fastMode: false,
};
function catalog(id: string): ProviderView[] {
- return [{ id, connected: true, agents: ['codex'], source: 'user', models: { codex: [{
+ return [{ id, connected: true, agents: ['codex'], routing: { codex: {} }, source: 'user', models: { codex: [{
id: 'test-model', efforts: ['low', 'high'], defaultEffort: 'low', supportsFastMode: false,
}] } }] as ProviderView[];
}
@@ -120,6 +120,24 @@ describe('automation restore uses the execution computer', () => {
expect(h.switchHarness).not.toHaveBeenCalled();
expect(h.guard).not.toHaveBeenCalled();
});
+ // #6759: the model can remain in the catalog after its Harness route is
+ // removed or disabled. Exercise the production resolver and persisted restore.
+ it.each(['agent-removed', 'route-missing', 'route-disabled'] as const)(
+ 'preserves the baseline when the remote Harness is unavailable: %s', async reason => {
+ const h = fixture();
+ const before = h.state();
+ const views = catalog('openai-shared');
+ if (reason === 'agent-removed') views[0].agents = [];
+ else if (reason === 'route-missing') views[0].routing = {};
+ else views[0].routing.codex!.disabled = true;
+ h.remote.mockResolvedValueOnce(views);
+ await expect(createScheduledModelScope(h.deps).restore('task')).rejects.toThrow('unavailable');
+ expect(h.state()).toEqual(before);
+ expect(h.applyModel).not.toHaveBeenCalled();
+ expect(h.switchHarness).not.toHaveBeenCalled();
+ expect(h.guard).not.toHaveBeenCalled();
+ },
+ );
it.each(['archived', 'deleted', 'missing'])('resolves the replacement locally for a %s target', async status => {
const h = fixture('share:test', status);
const before = h.state();
diff --git a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
index 2fb3859df1..1d17b6db79 100644
--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
@@ -1,5 +1,5 @@
import type { AgentKind, Effort } from '@cindy/maker-core';
-import { effectiveSourceIdForModel, findCatalogModel, isModelSelectableForNewRoute, type ProviderView } from '@cindy/model-providers';
+import { connectedProvidersForAgent, effectiveSourceIdForModel, findCatalogModel, isModelSelectableForNewRoute, type ProviderView } from '@cindy/model-providers';
import { resolveCompatibleSessionRuntimeEffort } from './sessionRuntimeControl';
import { parseScheduledModelBaseline, type ScheduledModelBaseline } from '../../shared/scheduledModelBaseline';
@@ -90,9 +90,10 @@ export function resolveScheduledModelSelection(
): ScheduledModelSelection {
const providerId = selection.providerId ??
effectiveSourceIdForModel(providers, null, selection.model, selection.agentKind);
- const provider = providers.find((candidate) => candidate.id === providerId);
+ const provider = connectedProvidersForAgent(providers, selection.agentKind)
+ .find((candidate) => candidate.id === providerId);
const model = findCatalogModel(provider, selection.model, selection.agentKind, { exact: true });
- if (!provider?.connected || provider.suspended === true || !model ||
+ if (!provider || !model ||
!isModelSelectableForNewRoute(model, { userProvider: provider.source === 'user' })) {
throw new Error(`Scheduled model "${selection.model}" is unavailable from provider "${providerId ?? 'default'}"`);
}