fix(#105): corrige le contexte plugin pour hello-plugin
Ajoute logger, subscriptions et commandes scindées au contexte plugin activé. Les plugins full-trust s'attendent à ce shape public.
This commit is contained in:
@ -13,6 +13,7 @@ import { useState } from "react";
|
||||
import type { PluginAdmin, PluginLifecycleState, PluginReview } from "@/domain";
|
||||
import { Button, Panel } from "@/shared";
|
||||
import { PluginConfirmDialog as ConfirmDialog } from "./PluginConfirmDialog";
|
||||
import { usePluginRuntime } from "./PluginRuntimeProvider";
|
||||
import { usePlugins } from "./usePlugins";
|
||||
|
||||
const STATE_LABEL: Record<PluginLifecycleState, string> = {
|
||||
@ -36,6 +37,7 @@ interface InstallFlow {
|
||||
|
||||
export function PluginsPanel() {
|
||||
const vm = usePlugins();
|
||||
const pluginRuntime = usePluginRuntime();
|
||||
const [pendingAction, setPendingAction] = useState<PendingAction | null>(null);
|
||||
const [installFlow, setInstallFlow] = useState<InstallFlow | null>(null);
|
||||
const [installFlowError, setInstallFlowError] = useState<string | null>(null);
|
||||
@ -108,6 +110,24 @@ export function PluginsPanel() {
|
||||
</p>
|
||||
)}
|
||||
|
||||
{pluginRuntime.failures.length > 0 && (
|
||||
<Panel className="border-warning/40">
|
||||
<div className="flex flex-col gap-1">
|
||||
<p role="alert" className="text-sm font-medium text-warning">
|
||||
Certains plugins installés n'ont pas pu être chargés.
|
||||
</p>
|
||||
<ul className="flex flex-col gap-0.5">
|
||||
{pluginRuntime.failures.map((failure) => (
|
||||
<li key={`${failure.pluginId}:${failure.reason}`} className="text-xs text-muted">
|
||||
<span className="font-medium text-content">{failure.pluginId}</span> :{" "}
|
||||
{failure.reason}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</Panel>
|
||||
)}
|
||||
|
||||
{vm.plugins.length === 0 ? (
|
||||
<Panel>
|
||||
<p className="text-sm text-muted">Aucun plugin installé.</p>
|
||||
|
||||
@ -9,9 +9,19 @@ import { render, screen, waitFor, fireEvent, within } from "@testing-library/rea
|
||||
import { MockPluginGateway, MockSystemGateway } from "@/adapters/mock";
|
||||
import type { Gateways } from "@/ports";
|
||||
import { DIProvider } from "@/app/di";
|
||||
import { PluginRuntimeRegistry } from "@/plugins/runtime";
|
||||
import { PluginsPanel } from "./PluginsPanel";
|
||||
import { PluginRuntimeProvider, type PluginRuntimeContextValue } from "./PluginRuntimeProvider";
|
||||
|
||||
function renderPanel(plugin?: MockPluginGateway, system?: MockSystemGateway) {
|
||||
function renderPanel(
|
||||
plugin?: MockPluginGateway,
|
||||
system?: MockSystemGateway,
|
||||
runtimeValue: PluginRuntimeContextValue = {
|
||||
registry: new PluginRuntimeRegistry(),
|
||||
failures: [],
|
||||
loading: false,
|
||||
},
|
||||
) {
|
||||
const p = plugin ?? new MockPluginGateway();
|
||||
const s = system ?? new MockSystemGateway();
|
||||
const gateways = { plugin: p, system: s } as unknown as Gateways;
|
||||
@ -20,7 +30,9 @@ function renderPanel(plugin?: MockPluginGateway, system?: MockSystemGateway) {
|
||||
system: s,
|
||||
...render(
|
||||
<DIProvider gateways={gateways}>
|
||||
<PluginsPanel />
|
||||
<PluginRuntimeProvider value={runtimeValue}>
|
||||
<PluginsPanel />
|
||||
</PluginRuntimeProvider>
|
||||
</DIProvider>,
|
||||
),
|
||||
};
|
||||
@ -32,6 +44,19 @@ describe("PluginsPanel", () => {
|
||||
expect(await screen.findByText("Aucun plugin installé.")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("keeps the Plugins panel rendered when a runtime bundle fails to load", async () => {
|
||||
renderPanel(undefined, undefined, {
|
||||
registry: new PluginRuntimeRegistry(),
|
||||
failures: [{ pluginId: "com.example.hello-plugin", reason: "Cannot use import statement outside a module" }],
|
||||
loading: false,
|
||||
});
|
||||
|
||||
expect(await screen.findByText("Aucun plugin installé.")).toBeTruthy();
|
||||
expect(screen.getByText("Certains plugins installés n'ont pas pu être chargés.")).toBeTruthy();
|
||||
expect(screen.getByText("com.example.hello-plugin")).toBeTruthy();
|
||||
expect(screen.getByText(/Cannot use import statement outside a module/)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("installs from an archive via the review dialog, mentioning full-trust", async () => {
|
||||
renderPanel();
|
||||
await screen.findByText("Aucun plugin installé.");
|
||||
|
||||
Reference in New Issue
Block a user