Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(desktop): consolidate scheduled route coverage and catalog fixtures
ylliuuu6650e587256557
diff --git a/apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.ts b/apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.tsindex 194486098a..edb5857779 100644--- a/apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.ts@@ -8,7 +8,7 @@ const h = vi.hoisted(() => ({vi.mock('@cindy/model-providers', async (importOriginal) => ({findCatalogModel: (await importOriginal<typeof import('@cindy/model-providers')>()).findCatalogModel,- connectedProvidersForAgent: vi.fn(() => []),+ connectedProvidersForAgent: (await importOriginal<typeof import('@cindy/model-providers')>()).connectedProvidersForAgent,effectiveSourceIdForModel: h.effectiveSourceIdForModel,getModel: vi.fn(() => null),isExclusiveXaiModelId: (model: string | null | undefined) =>@@ -64,6 +64,7 @@ describe('resolveDefaultScheduleRoute', () => {name: 'Anthropic',connected: true,source: 'bundled',+ agents: ['claude-code'], routing: { 'claude-code': {} },models: { 'claude-code': [dynamicModel] },},];@@ -139,8 +140,8 @@ describe('scheduled selection uses the live source copy', () => {it('reads the current catalog without claiming credentials and preserves the requested route', async () => {const selection = { agentKind: 'pi' as const, model: 'same-model', providerId: 'selected', effort: 'ultra' as const, fastMode: true };h.listProviders.mockResolvedValue([- { id: 'other', connected: true, models: { pi: [{ id: 'same-model', efforts: ['ultra'], defaultEffort: 'ultra', supportsFastMode: true }] } },- { id: 'selected', connected: true, models: { pi: [{ id: 'same-model', efforts: ['medium'], defaultEffort: 'medium', supportsFastMode: false }] } },+ { id: 'other', connected: true, agents: ['pi'], routing: { pi: {} }, models: { pi: [{ id: 'same-model', efforts: ['ultra'], defaultEffort: 'ultra', supportsFastMode: true }] } },+ { id: 'selected', connected: true, agents: ['pi'], routing: { pi: {} }, models: { pi: [{ id: 'same-model', efforts: ['medium'], defaultEffort: 'medium', supportsFastMode: false }] } },]);await expect(resolveScheduledModelSelectionLive(selection)).resolves.toEqual({ ...selection, effort: 'medium', fastMode: false });expect(h.listProviders).toHaveBeenLastCalledWith({ allowSideEffects: false, catalog: h.catalog });diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.tsdeleted file mode 100644index 9b22a0e152..0000000000--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts+++ /dev/null@@ -1,174 +0,0 @@-import { describe, expect, it, vi } from 'vitest';-import type { ProviderView } from '@cindy/model-providers';-import { applyScheduledModelSelection, createScheduledModelScope, createScheduledModelSelectionResolver, resolveScheduledModelSelection, type ScheduledModelSelection } from '../scheduledModelSelection';--// #6745: invoke the same production resolver wired into register.ts with the-// real persisted-scope lifecycle; only catalog, storage and engine I/O are fakes.-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'], routing: { codex: {} }, source: 'user', models: { codex: [{- id: 'test-model', efforts: ['low', 'high'], defaultEffort: 'low', supportsFastMode: false,- }] } }] as ProviderView[];-}-function fixture(device: string | null = 'share:test', status = 'active') {- let current = { ...choice, agentDeviceId: device };- let baseline: string | null = JSON.stringify({ ...choice, scopeId: 'old-run' });- const local = catalog('openai');- const remote = vi.fn(async () => catalog('openai-shared'));- const guard = vi.fn(async (_agent: string, _model: string, providerId: string | null) => {- if (!local.some(p => p.id === providerId)) throw new Error('provider unavailable on this computer');- return undefined;- });- const switchHarness = vi.fn(async () => ({ engineReady: true }));- const applyModel = vi.fn(async (route: ScheduledModelSelection) => {- current = { ...current, ...route };- });- const apply = async (_id: string, selection: ScheduledModelSelection) => applyScheduledModelSelection(selection, {- getTarget: async () => status === 'missing' ? null : ({ ...current, status }),- isBusy: () => false,- resolveSelection: createScheduledModelSelectionResolver({- readRemoteProviders: remote,- resolveLocalSelection: async route => {- await guard(route.agentKind, route.model, route.providerId);- return resolveScheduledModelSelection(route, local);- },- }),- switchHarness, applyModel,- });- const deps = {- read: async () => ({ profile: current, baseline }),- write: async (_id: string, value: unknown) => { baseline = value ? JSON.stringify(value) : null; },- isBusy: () => false, createId: () => 'new-run',- apply: async (id: string, profile: ScheduledModelSelection) => { await apply(id, profile); },- };- return { deps, apply, remote, guard, switchHarness, applyModel, scope: createScheduledModelScope(deps),- state: () => ({ current, baseline }), save: (value: unknown) => { baseline = JSON.stringify(value); } };-}--describe('automation restore uses the execution computer', () => {- it.each(['share:test', 'other-device'])('restores a legacy baseline on %s after restart', async device => {- const h = fixture(device);- await createScheduledModelScope(h.deps).restore('task');- expect(h.remote).toHaveBeenCalledWith(device, 'codex', 'test-model', 'openai-shared');- expect(h.guard).not.toHaveBeenCalled();- expect(h.applyModel).toHaveBeenCalledOnce();- expect(h.state().baseline).toBeNull();- expect(h.state().current).toMatchObject(choice);- });- it('validates an automation choice on the same remote execution computer', async () => {- const h = fixture();- await h.apply('task', choice);- expect(h.remote).toHaveBeenCalledWith('share:test', 'codex', 'test-model', 'openai-shared');- expect(h.guard).not.toHaveBeenCalled();- expect(h.switchHarness).not.toHaveBeenCalled();- expect(h.state().current.agentDeviceId).toBe('share:test');- });- it('keeps ordinary local-provider validation for a local task', async () => {- const h = fixture(null);- h.save({ ...choice, providerId: 'openai', scopeId: 'old-run' });- await h.scope.restore('task');- expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', 'openai');- expect(h.remote).not.toHaveBeenCalled();- expect(h.state().current.providerId).toBe('openai');- expect(h.state().baseline).toBeNull();- });- it('does not substitute a local provider when the remote catalog no longer contains the source', async () => {- const h = fixture();- h.remote.mockResolvedValueOnce(catalog('another-source'));- await expect(h.scope.restore('task')).rejects.toThrow('unavailable');- expect(h.applyModel).not.toHaveBeenCalled();- expect(h.guard).not.toHaveBeenCalled();- expect(h.state().baseline).not.toBeNull();- });- it('preserves the standard admission exception for a custom user-owned model group', async () => {- const h = fixture();- const views = catalog('openai-shared');- const model = 'gpt-4o-audio-preview';- views[0].models.codex![0].id = model;- views[0].models.codex![0].group = 'custom:openai-shared';- h.save({ ...choice, model, scopeId: 'old-run' });- h.remote.mockResolvedValueOnce(views);- await h.scope.restore('task');- expect(h.state().baseline).toBeNull();- expect(h.state().current).toMatchObject({ ...choice, model });- });- it.each([{ status: 'retired' }, { availability: 'requires_payment' }, { mode: 'image' }])(- 'rejects a remote catalog entry outside new-route admission: %j', async flags => {- const h = fixture();- const before = h.state();- const views = catalog('openai-shared');- Object.assign(views[0].models.codex![0], flags);- h.remote.mockResolvedValueOnce(views);- await expect(h.scope.restore('task')).rejects.toThrow('unavailable');- expect(h.state()).toEqual(before);- expect(h.applyModel).not.toHaveBeenCalled();- expect(h.switchHarness).not.toHaveBeenCalled();- },- );- it.each(['provider', 'model'] as const)('preserves the baseline when the remote %s is disabled after restart', async disabled => {- const h = fixture();- const before = h.state();- const views = catalog('openai-shared');- if (disabled === 'provider') views[0].suspended = true;- else views[0].models.codex![0].disabled = true;- h.remote.mockResolvedValueOnce(views);- await expect(h.scope.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();- });- // #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();- h.remote.mockRejectedValue(new Error('REMOTE_AGENT_SHARE_PAUSED'));- const localChoice = { ...choice, providerId: 'openai' };- await expect(h.apply('task', localChoice)).resolves.toEqual(localChoice);- expect(h.remote).not.toHaveBeenCalled();- expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', 'openai');- expect(h.applyModel).not.toHaveBeenCalled();- expect(h.switchHarness).not.toHaveBeenCalled();- expect(h.state()).toEqual(before);- });- it.each(['archived', 'deleted'])('rejects a remote-only source for the local replacement of a %s target', async status => {- const h = fixture('share:test', status);- await expect(h.apply('task', choice)).rejects.toThrow('provider unavailable');- expect(h.remote).not.toHaveBeenCalled();- expect(h.applyModel).not.toHaveBeenCalled();- expect(h.switchHarness).not.toHaveBeenCalled();- });- it('retains the scope and task when the sharing host rejects access', async () => {- const h = fixture();- h.remote.mockRejectedValueOnce(new Error('REMOTE_AGENT_SHARE_PAUSED'));- await expect(h.scope.restore('task')).rejects.toThrow('REMOTE_AGENT_SHARE_PAUSED');- expect(h.state().baseline).not.toBeNull();- expect(h.applyModel).not.toHaveBeenCalled();- expect(h.guard).not.toHaveBeenCalled();- });- it('rejects a missing local provider without guessing a remote source', async () => {- const h = fixture(null);- await expect(h.scope.restore('task')).rejects.toThrow('provider unavailable');- expect(h.remote).not.toHaveBeenCalled();- expect(h.state().baseline).not.toBeNull();- });-});diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.tsindex cc0da87806..61c9d1c58d 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from 'vitest';import type { CatalogModel, ProviderView } from '@cindy/model-providers';-import { applyScheduledModelSelection, assertScheduledHarnessSupported, createScheduledModelScope, resolveScheduledModelSelection, ScheduledModelSelectionBusyError, type ScheduledModelSelection } from '../scheduledModelSelection';+import { applyScheduledModelSelection, assertScheduledHarnessSupported, createScheduledModelScope, createScheduledModelSelectionResolver, resolveScheduledModelSelection, ScheduledModelSelectionBusyError, type ScheduledModelSelection } from '../scheduledModelSelection';const selection: ScheduledModelSelection = {agentKind: 'pi', model: 'test-model', providerId: 'custom', effort: null, fastMode: false,@@ -250,3 +250,174 @@ describe('bound target Harness capability', () => {expect(() => assertScheduledHarnessSupported(null, 'pi')).not.toThrow();});});++// #6745: invoke the same production resolver wired into register.ts with the+// real persisted-scope lifecycle; only catalog, storage and engine I/O are fakes.+const remoteChoice: ScheduledModelSelection = {+ agentKind: 'codex', model: 'test-model', providerId: 'openai-shared', effort: 'high', fastMode: false,+};+function remoteCatalog(id: string): ProviderView[] {+ return [{ id, connected: true, agents: ['codex'], routing: { codex: {} }, source: 'user', models: { codex: [{+ id: 'test-model', efforts: ['low', 'high'], defaultEffort: 'low', supportsFastMode: false,+ }] } }] as ProviderView[];+}+function remoteFixture(device: string | null = 'share:test', status = 'active') {+ let current = { ...remoteChoice, agentDeviceId: device };+ let baseline: string | null = JSON.stringify({ ...remoteChoice, scopeId: 'old-run' });+ const local = remoteCatalog('openai');+ const remote = vi.fn(async () => remoteCatalog('openai-shared'));+ const guard = vi.fn(async (_agent: string, _model: string, providerId: string | null) => {+ if (!local.some(p => p.id === providerId)) throw new Error('provider unavailable on this computer');+ return undefined;+ });+ const switchHarness = vi.fn(async () => ({ engineReady: true }));+ const applyModel = vi.fn(async (route: ScheduledModelSelection) => {+ current = { ...current, ...route };+ });+ const apply = async (_id: string, selection: ScheduledModelSelection) => applyScheduledModelSelection(selection, {+ getTarget: async () => status === 'missing' ? null : ({ ...current, status }),+ isBusy: () => false,+ resolveSelection: createScheduledModelSelectionResolver({+ readRemoteProviders: remote,+ resolveLocalSelection: async route => {+ await guard(route.agentKind, route.model, route.providerId);+ return resolveScheduledModelSelection(route, local);+ },+ }),+ switchHarness, applyModel,+ });+ const deps = {+ read: async () => ({ profile: current, baseline }),+ write: async (_id: string, value: unknown) => { baseline = value ? JSON.stringify(value) : null; },+ isBusy: () => false, createId: () => 'new-run',+ apply: async (id: string, profile: ScheduledModelSelection) => { await apply(id, profile); },+ };+ return { deps, apply, remote, guard, switchHarness, applyModel, scope: createScheduledModelScope(deps),+ state: () => ({ current, baseline }), save: (value: unknown) => { baseline = JSON.stringify(value); } };+}++describe('automation restore uses the execution computer', () => {+ it.each(['share:test', 'other-device'])('restores a legacy baseline on %s after restart', async device => {+ const h = remoteFixture(device);+ await createScheduledModelScope(h.deps).restore('task');+ expect(h.remote).toHaveBeenCalledWith(device, 'codex', 'test-model', 'openai-shared');+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.applyModel).toHaveBeenCalledOnce();+ expect(h.state().baseline).toBeNull();+ expect(h.state().current).toMatchObject(remoteChoice);+ });+ it('validates an automation choice on the same remote execution computer', async () => {+ const h = remoteFixture();+ await h.apply('task', remoteChoice);+ expect(h.remote).toHaveBeenCalledWith('share:test', 'codex', 'test-model', 'openai-shared');+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ expect(h.state().current.agentDeviceId).toBe('share:test');+ });+ it('keeps ordinary local-provider validation for a local task', async () => {+ const h = remoteFixture(null);+ h.save({ ...remoteChoice, providerId: 'openai', scopeId: 'old-run' });+ await h.scope.restore('task');+ expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', 'openai');+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.state().current.providerId).toBe('openai');+ expect(h.state().baseline).toBeNull();+ });+ it('does not substitute a local provider when the remote catalog no longer contains the source', async () => {+ const h = remoteFixture();+ h.remote.mockResolvedValueOnce(remoteCatalog('another-source'));+ await expect(h.scope.restore('task')).rejects.toThrow('unavailable');+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.state().baseline).not.toBeNull();+ });+ it('preserves the standard admission exception for a custom user-owned model group', async () => {+ const h = remoteFixture();+ const views = remoteCatalog('openai-shared');+ const model = 'gpt-4o-audio-preview';+ views[0].models.codex![0].id = model;+ views[0].models.codex![0].group = 'custom:openai-shared';+ h.save({ ...remoteChoice, model, scopeId: 'old-run' });+ h.remote.mockResolvedValueOnce(views);+ await h.scope.restore('task');+ expect(h.state().baseline).toBeNull();+ expect(h.state().current).toMatchObject({ ...remoteChoice, model });+ });+ it.each([{ status: 'retired' }, { availability: 'requires_payment' }, { mode: 'image' }])(+ 'rejects a remote catalog entry outside new-route admission: %j', async flags => {+ const h = remoteFixture();+ const before = h.state();+ const views = remoteCatalog('openai-shared');+ Object.assign(views[0].models.codex![0], flags);+ h.remote.mockResolvedValueOnce(views);+ await expect(h.scope.restore('task')).rejects.toThrow('unavailable');+ expect(h.state()).toEqual(before);+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ },+ );+ it.each(['provider', 'model'] as const)('preserves the baseline when the remote %s is disabled after restart', async disabled => {+ const h = remoteFixture();+ const before = h.state();+ const views = remoteCatalog('openai-shared');+ if (disabled === 'provider') views[0].suspended = true;+ else views[0].models.codex![0].disabled = true;+ h.remote.mockResolvedValueOnce(views);+ await expect(h.scope.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();+ });+ // #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 = remoteFixture();+ const before = h.state();+ const views = remoteCatalog('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 = remoteFixture('share:test', status);+ const before = h.state();+ h.remote.mockRejectedValue(new Error('REMOTE_AGENT_SHARE_PAUSED'));+ const localChoice = { ...remoteChoice, providerId: 'openai' };+ await expect(h.apply('task', localChoice)).resolves.toEqual(localChoice);+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', 'openai');+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ expect(h.state()).toEqual(before);+ });+ it.each(['archived', 'deleted'])('rejects a remote-only source for the local replacement of a %s target', async status => {+ const h = remoteFixture('share:test', status);+ await expect(h.apply('task', remoteChoice)).rejects.toThrow('provider unavailable');+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ });+ it('retains the scope and task when the sharing host rejects access', async () => {+ const h = remoteFixture();+ h.remote.mockRejectedValueOnce(new Error('REMOTE_AGENT_SHARE_PAUSED'));+ await expect(h.scope.restore('task')).rejects.toThrow('REMOTE_AGENT_SHARE_PAUSED');+ expect(h.state().baseline).not.toBeNull();+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ });+ it('rejects a missing local provider without guessing a remote source', async () => {+ const h = remoteFixture(null);+ await expect(h.scope.restore('task')).rejects.toThrow('provider unavailable');+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.state().baseline).not.toBeNull();+ });+});diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.tsindex 38980cc8cb..d28f29872f 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts@@ -430,11 +430,11 @@ describe('MakerScheduleRunner model selection', () => {Object.assign(h.session, { agentKind: 'pi', model: 'shared-model' });const selectedEfforts = effort === 'none' ? [] : ['medium', 'high'];const providers = [{- id: 'selected', name: 'Selected', connected: true, agents: ['pi'],+ id: 'selected', name: 'Selected', connected: true, agents: ['pi'], routing: { pi: {} },models: { pi: [{ id: 'shared-model', name: 'Shared', efforts: selectedEfforts,defaultEffort: effort === 'none' ? null : 'high', supportsFastMode: false }] },}, {- id: 'other', name: 'Other', connected: true, agents: ['pi'],+ id: 'other', name: 'Other', connected: true, agents: ['pi'], routing: { pi: {} },models: { pi: [{ id: 'shared-model', name: 'Shared', efforts: ['ultra'], defaultEffort: 'ultra', supportsFastMode: true }] },}] as unknown as ProviderView[];const resolveModelSelection = vi.fn(async (choice) => resolveScheduledModelSelection(choice, providers));