feat: plugins v1.7

This commit is contained in:
2026-04-29 15:24:56 +02:00
parent eabbc08896
commit d261bac0ed
45 changed files with 5621 additions and 867 deletions

View File

@@ -129,6 +129,45 @@ describe('PluginStoreService', () => {
expect(service.installedPlugins()).toEqual([]);
});
it('caches plugin bundle entrypoints locally before registering installed plugins', async () => {
const manifest = createManifest({ entrypoint: './dist/main.js' });
const plugin = createStoreEntry({
bundleUrl: 'https://plugins.example.test/better/bundle.js',
version: '1.0.0'
});
const electronApi = {
ensureDir: vi.fn(async () => true),
getAppDataPath: vi.fn(async () => '/tmp/metoyou-user-data'),
writeFile: vi.fn(async () => true)
};
fetchMock
.mockResolvedValueOnce(jsonResponse(manifest))
.mockResolvedValueOnce(textResponse('export function activate() {}'));
const service = createService(registerLocalManifest, unregister, electronApi);
await service.installPlugin(plugin);
expect(electronApi.ensureDir).toHaveBeenCalledWith('/tmp/metoyou-user-data/plugin-bundles/example.better-channels/1.0.0');
expect(electronApi.writeFile).toHaveBeenCalledWith(
'/tmp/metoyou-user-data/plugin-bundles/example.better-channels/1.0.0/main.js',
expect.any(String)
);
expect(registerLocalManifest).toHaveBeenCalledWith(
expect.objectContaining({
bundle: {
entrypoint: './main.js',
url: plugin.bundleUrl
},
entrypoint: './main.js',
id: manifest.id
}),
'file:///tmp/metoyou-user-data/plugin-bundles/example.better-channels/1.0.0/toju-plugin.json'
);
});
it('loads plugin readmes as markdown text', async () => {
const plugin = createStoreEntry({ readmeUrl: 'https://plugins.example.test/better/README.md' });
@@ -149,7 +188,12 @@ describe('PluginStoreService', () => {
function createService(
registerLocalManifest: ReturnType<typeof vi.fn>,
unregister: ReturnType<typeof vi.fn>,
electronApi: { readFile: (filePath: string) => Promise<string> } | null = null
electronApi: {
ensureDir?: (dirPath: string) => Promise<boolean>;
getAppDataPath?: () => Promise<string>;
readFile?: (filePath: string) => Promise<string>;
writeFile?: (filePath: string, data: string) => Promise<boolean>;
} | null = null
): PluginStoreService {
const injector = Injector.create({
providers: [
@@ -165,6 +209,7 @@ function createService(
useValue: {
activatePersistedPlugins: vi.fn(async () => {}),
deactivatePlugin: vi.fn(async () => {}),
isPluginActive: vi.fn(() => false),
registerLocalManifest
}
},