Files
kandev/apps/web/src/settings-routes.plugin.test.ts
T
Kandev Agent c53f699714 feat: add plugin system with grpc runtime and native ui plugins
- go plugin backends ship as release tarballs (per-platform binaries, checksums) that
  kandev installs from url/upload or filesystem sideload+sync, then spawns and
  supervises via hashicorp/go-plugin (unix socket / loopback tcp+automtls)
- strict typed grpc contract (kandev.plugin.v1): DeliverEvent/InvokeTool/HandleWebhook
  plus a capability-gated host service (state, secrets, emit); author sdk in
  pkg/pluginsdk; packaging cli in cmd/plugin-pack
- native frontend bundles: window.registerKandevPlugin + registry/host loader with
  dynamic routes, nav items, slots and ws handlers; plugins settings page with
  install dialog, sync button and enable/disable/uninstall
- gated behind the plugins feature flag (prod off, dev/e2e on); covered by unit and
  integration tests plus playwright e2e against a real packaged fixture plugin

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 17:55:45 +01:00

52 lines
1.9 KiB
TypeScript

import { isValidElement, type ReactElement } from "react";
import { afterEach, describe, expect, it } from "vitest";
import { pluginRegistry } from "@/lib/plugins/registry";
import { renderSettingsRoute } from "./settings-routes";
const PLUGIN_ID = "plugin-a";
const PLUGIN_SETTINGS_PATH = "/settings/plugins/plugin-a/config";
function cleanupPlugins(...pluginIds: string[]) {
pluginIds.forEach((id) => pluginRegistry.unregisterPlugin(id));
}
describe("renderSettingsRoute — plugin fallthrough", () => {
afterEach(() => cleanupPlugins(PLUGIN_ID));
it("falls back to the unported-route placeholder when no plugin owns the path", () => {
const route = renderSettingsRoute(PLUGIN_SETTINGS_PATH);
expect(isValidElement(route)).toBe(true);
// The fallback renders the raw pathname as text — assert via string search
// on the rendered props rather than a brittle component-type check.
expect((route as ReactElement<{ pathname?: string }>).props.pathname).toBe(
PLUGIN_SETTINGS_PATH,
);
});
it("renders the plugin-registered settings route once a plugin registers it", () => {
function PluginSettingsPage() {
return null;
}
pluginRegistry
.forPlugin(PLUGIN_ID)
.registerSettingsRoute(PLUGIN_SETTINGS_PATH, PluginSettingsPage);
const route = renderSettingsRoute(PLUGIN_SETTINGS_PATH);
expect(isValidElement(route)).toBe(true);
expect((route as ReactElement).type).toBe(PluginSettingsPage);
});
it("does not consult the registry for a path outside /settings/plugins/", () => {
function ShouldNotMatch() {
return null;
}
pluginRegistry.forPlugin(PLUGIN_ID).registerSettingsRoute("/settings/general", ShouldNotMatch);
const route = renderSettingsRoute("/settings/general");
// "/settings/general" is a real static route (GeneralSettings), not the plugin's.
expect((route as ReactElement).type).not.toBe(ShouldNotMatch);
});
});