plugin-application.test.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { describe, expect, it, vi } from 'vitest';
  2. import { McodePluginApplication } from '../../src/plugin/application.js';
  3. const plugin = (name: string, marketplace: 'official' | 'local', installed: boolean) => ({
  4. pluginId: `${name}@${marketplace}`,
  5. name,
  6. displayName: name,
  7. marketplace,
  8. installed,
  9. enabled: installed,
  10. capabilities: { appCount: 0, mcpServerCount: 0, skillCount: 1 },
  11. });
  12. describe('McodePluginApplication', () => {
  13. it('partitions installed and available Plugins across the real Runtime sources', async () => {
  14. const port = {
  15. listInstalledPlugins: vi.fn(async () => [plugin('legacy', 'official', true)]),
  16. listMarketplacePlugins: vi
  17. .fn()
  18. .mockResolvedValueOnce([plugin('docs', 'official', false)])
  19. .mockResolvedValueOnce([plugin('notes', 'local', false)]),
  20. };
  21. const application = new McodePluginApplication(port as never);
  22. await expect(application.catalog({ includeAvailable: true })).resolves.toEqual({
  23. installed: [plugin('legacy', 'official', true)],
  24. available: [plugin('docs', 'official', false), plugin('notes', 'local', false)],
  25. });
  26. expect(port.listMarketplacePlugins).toHaveBeenNthCalledWith(1, {
  27. marketplace: 'official',
  28. });
  29. expect(port.listMarketplacePlugins).toHaveBeenNthCalledWith(2, {
  30. marketplace: 'local',
  31. });
  32. expect(port.listInstalledPlugins).toHaveBeenCalledWith({ marketplace: undefined });
  33. });
  34. it('applies mutations through the Runtime owner and returns the committed state', async () => {
  35. const selected = plugin('docs', 'official', false);
  36. const port = {
  37. mutatePlugin: vi
  38. .fn()
  39. .mockResolvedValueOnce({ installed: true, enabled: true })
  40. .mockResolvedValueOnce({ installed: true, enabled: false })
  41. .mockResolvedValueOnce({ installed: false, enabled: false }),
  42. refreshPlugins: vi.fn(async () => undefined),
  43. };
  44. const application = new McodePluginApplication(port as never);
  45. const installed = await application.install(selected);
  46. await expect(application.setEnabled(installed, false)).resolves.toMatchObject({
  47. installed: true,
  48. enabled: false,
  49. });
  50. await expect(application.remove(installed)).resolves.toMatchObject({
  51. installed: false,
  52. enabled: false,
  53. });
  54. await expect(application.refresh()).resolves.toBeUndefined();
  55. expect(port.mutatePlugin).toHaveBeenNthCalledWith(1, {
  56. action: 'install',
  57. plugin: { name: 'docs', marketplace: 'official' },
  58. });
  59. expect(port.mutatePlugin).toHaveBeenNthCalledWith(2, {
  60. action: 'disable',
  61. plugin: { name: 'docs', marketplace: 'official' },
  62. });
  63. expect(port.mutatePlugin).toHaveBeenNthCalledWith(3, {
  64. action: 'remove',
  65. plugin: { name: 'docs', marketplace: 'official' },
  66. });
  67. expect(port.refreshPlugins).toHaveBeenCalledOnce();
  68. });
  69. });