Files
makelore/tests/unit/host-api-dispatcher.test.ts
brother7 5a275b93a7 feat: remove legacy OpenCode runtime
Cut product flows over to Coding/Pi and retain only the migration-owned v1 boundary. Promote supported native optional packages because electron-builder omitted pnpm transitive optional closure from the packaged ASAR.
2026-08-24 12:17:43 +08:00

33 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { dispatchHostApiRequest } from '@electron/api/host-api-dispatcher';
import { shouldUseLoopbackHostApi } from '@electron/api/host-api-transport';
describe('Host API transport selection', () => {
it('keeps long-lived and binary responses on loopback HTTP', () => {
expect(shouldUseLoopbackHostApi('/api/events')).toBe(true);
expect(shouldUseLoopbackHostApi('/api/events?token=session')).toBe(true);
expect(shouldUseLoopbackHostApi('/api/coding/events')).toBe(true);
expect(shouldUseLoopbackHostApi('/api/ai-proxy/v1/chat/completions', 'POST')).toBe(true);
expect(shouldUseLoopbackHostApi('/api/image-workspace/workspaces/w1/conversations/c1/events')).toBe(true);
expect(shouldUseLoopbackHostApi('/api/image-workspace/workspaces/w1/assets/a1/content?download=1')).toBe(true);
});
it('dispatches JSON and control requests in Main', () => {
expect(shouldUseLoopbackHostApi('/api/app/runtime-info')).toBe(false);
expect(shouldUseLoopbackHostApi('/api/works/projects/release-jobs', 'POST')).toBe(false);
expect(shouldUseLoopbackHostApi('/api/coding/projects')).toBe(false);
});
it('reuses the existing route contract without opening a socket', async () => {
const data = await dispatchHostApiRequest({
codingProducts: { runtime: { getDiagnostics: () => ({ revision: 3 }) } },
codingProjectStore: {},
eventBus: {},
mainWindow: null,
} as never, { path: '/api/app/runtime-info' });
expect(data).toMatchObject({ status: 200, ok: true });
expect(data.json).toMatchObject({ runtime: 'pi', diagnostics: { revision: 3 } });
});
});