plugin-load-isolation.fixture.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { createRoot } from "react-dom/client";
  2. import type { IPluginManagementService } from "@zcode/services";
  3. import { createPluginManagementStore } from "@/store/pluginManagementStore.js";
  4. import { PluginStoreCard } from "@/settings/PluginStoreCard.js";
  5. import { buildStoreItems } from "@/settings/pluginStoreListing.js";
  6. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  7. import { TooltipProvider } from "@/components/ui/tooltip.js";
  8. import { Button } from "@/components/ui/button.js";
  9. import "@/styles.css";
  10. const params = new URLSearchParams(location.search);
  11. document.documentElement.className =
  12. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  13. let failure = params.get("failure");
  14. const calls = { list: 0, overview: 0 };
  15. const plugin = {
  16. id: "installed@fixture",
  17. name: "installed",
  18. marketplace: "fixture",
  19. enabled: true,
  20. source: "cache",
  21. rootPath: "/fixture/installed",
  22. skillRootCount: 1,
  23. commandRootCount: 0,
  24. mcpServerNames: [],
  25. };
  26. const service = {
  27. listPlugins: async () => {
  28. calls.list++;
  29. if (failure === "list" || failure === "both") throw new Error("fixture list unavailable");
  30. return { plugins: [plugin], diagnostics: [] };
  31. },
  32. getPluginsOverview: async () => {
  33. calls.overview++;
  34. if (failure === "overview" || failure === "both")
  35. throw new Error("fixture overview unavailable");
  36. return {
  37. marketplaces: [{ id: "fixture", name: "Fixture", source: {}, pluginCount: 2 }],
  38. availablePlugins: [{ id: "available@fixture", name: "available", marketplace: "fixture" }],
  39. installedPlugins: [
  40. {
  41. ...plugin,
  42. installPath: plugin.rootPath,
  43. installedAt: "2026-01-01T00:00:00Z",
  44. scope: "user",
  45. version: "1.0.0",
  46. },
  47. ],
  48. restorableBuiltins: [],
  49. diagnostics: [],
  50. };
  51. },
  52. } as unknown as IPluginManagementService;
  53. const store = createPluginManagementStore(service);
  54. const initialize = () =>
  55. store.getState().initialize({ workspacePath: "/fixture", pluginService: service });
  56. await initialize();
  57. function Fixture() {
  58. const state = store();
  59. const items = buildStoreItems(state);
  60. return (
  61. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  62. <TooltipProvider>
  63. <main className="min-h-screen space-y-4 bg-background p-4 text-ui-base text-foreground">
  64. <Button
  65. data-testid="recover"
  66. onClick={() => {
  67. failure = null;
  68. void initialize();
  69. }}
  70. >
  71. Retry
  72. </Button>
  73. {state.error && (
  74. <div role="alert" className="text-destructive">
  75. {state.error}
  76. </div>
  77. )}
  78. <output data-testid="state">
  79. {JSON.stringify({
  80. calls,
  81. plugins: state.plugins.length,
  82. marketplaces: state.marketplaces.length,
  83. available: state.availablePlugins.length,
  84. known: state.marketplaceAvailabilityKnown,
  85. orphaned: items.some((item) => item.orphaned),
  86. })}
  87. </output>
  88. <div className="grid gap-4 lg:grid-cols-2">
  89. {items.map((item) => (
  90. <PluginStoreCard
  91. key={item.id}
  92. item={item}
  93. actions={{
  94. ...state,
  95. onOpenDetail() {},
  96. onInstall() {},
  97. onUninstall() {},
  98. onUpdate() {},
  99. }}
  100. />
  101. ))}
  102. </div>
  103. </main>
  104. </TooltipProvider>
  105. </ZCodeIntlProvider>
  106. );
  107. }
  108. createRoot(document.getElementById("root")!).render(<Fixture />);