feat(FN-3722): route plugin store to configured global directory
Merges centralized plugin installation (FN-3722): TaskStore plugin store is now routed to a configured global directory with legacy migration hardening, and CLI plugin commands are aligned accordingly, backed by comprehensive integration and regression tests. Also includes a dashboard fix to return Fusion-Task-Id: FN-3722
This commit is contained in:
@@ -55,6 +55,7 @@ const mocks = vi.hoisted(() => {
|
||||
const missionStore = {
|
||||
listMissions: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
const pluginStore = pluginStoreCtor();
|
||||
|
||||
return {
|
||||
init: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -63,6 +64,7 @@ const mocks = vi.hoisted(() => {
|
||||
getFusionDir: vi.fn().mockReturnValue("/repo/.fusion"),
|
||||
getRootDir: vi.fn().mockReturnValue("/repo"),
|
||||
getMissionStore: vi.fn().mockReturnValue(missionStore),
|
||||
getPluginStore: vi.fn().mockReturnValue(pluginStore),
|
||||
getSettings: vi.fn().mockResolvedValue({
|
||||
maxConcurrent: 2,
|
||||
recycleWorktrees: false,
|
||||
|
||||
@@ -75,6 +75,17 @@ function makeMockStore() {
|
||||
listMilestones: vi.fn().mockReturnValue([]),
|
||||
listFeatures: vi.fn().mockReturnValue([]),
|
||||
};
|
||||
const mockPluginStore = {
|
||||
init: vi.fn().mockResolvedValue(undefined),
|
||||
listPlugins: vi.fn().mockResolvedValue([]),
|
||||
getPlugin: vi.fn(),
|
||||
registerPlugin: vi.fn(),
|
||||
enablePlugin: vi.fn(),
|
||||
disablePlugin: vi.fn(),
|
||||
updatePluginSettings: vi.fn(),
|
||||
unregisterPlugin: vi.fn(),
|
||||
updatePluginState: vi.fn(),
|
||||
};
|
||||
return {
|
||||
init: vi.fn().mockResolvedValue(undefined),
|
||||
watch: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -101,6 +112,7 @@ function makeMockStore() {
|
||||
})),
|
||||
getActiveMergingTask: vi.fn().mockReturnValue(undefined),
|
||||
getMissionStore: vi.fn().mockReturnValue(mockMissionStore),
|
||||
getPluginStore: vi.fn().mockReturnValue(mockPluginStore),
|
||||
close: vi.fn(),
|
||||
on: vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
emitter.on(event, handler);
|
||||
|
||||
@@ -68,6 +68,7 @@ vi.mock("@fusion/core", () => ({
|
||||
PluginStore: mocks.PluginStore,
|
||||
PluginLoader: mocks.PluginLoader,
|
||||
validatePluginManifest: vi.fn().mockReturnValue({ valid: true, errors: [] }),
|
||||
resolveGlobalDir: vi.fn().mockReturnValue("/tmp/fusion-global"),
|
||||
}));
|
||||
|
||||
vi.mock("../../project-context.js", () => ({
|
||||
@@ -132,6 +133,100 @@ describe("plugin commands", () => {
|
||||
await expect(resolvePluginEntryFile(pluginDir)).resolves.toBe(resolve(pluginDir, "dist/index.js"));
|
||||
});
|
||||
|
||||
it("uses resolved TaskStore plugin store when available", async () => {
|
||||
const contextStore = {
|
||||
getPluginStore: vi.fn().mockReturnValue({
|
||||
init: vi.fn().mockResolvedValue(undefined),
|
||||
registerPlugin: vi.fn().mockResolvedValue({ id: "paperclip-runtime", enabled: true }),
|
||||
listPlugins: vi.fn().mockResolvedValue([]),
|
||||
getPlugin: vi.fn(),
|
||||
updatePluginSettings: vi.fn().mockResolvedValue(undefined),
|
||||
}),
|
||||
};
|
||||
vi.mocked(resolveProject).mockResolvedValue({
|
||||
projectPath: "/tmp/fn-project",
|
||||
store: contextStore,
|
||||
} as never);
|
||||
|
||||
const pluginDir = await createTempPluginFixture([
|
||||
{
|
||||
path: "manifest.json",
|
||||
content: JSON.stringify({ id: "paperclip-runtime", name: "Paperclip Runtime", version: "1.0.0" }),
|
||||
},
|
||||
{
|
||||
path: "package.json",
|
||||
content: JSON.stringify({ exports: { ".": { import: "./dist/index.js" } } }),
|
||||
},
|
||||
{
|
||||
path: "dist/index.js",
|
||||
content:
|
||||
"export default { manifest: { id: 'paperclip-runtime', name: 'Paperclip Runtime', version: '1.0.0' }, async onLoad() {}, async onUnload() {} };",
|
||||
},
|
||||
]);
|
||||
tempDirs.push(pluginDir);
|
||||
|
||||
await expect(runPluginInstall(pluginDir)).resolves.toBeUndefined();
|
||||
|
||||
expect(contextStore.getPluginStore).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.PluginStore).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("writes runPluginInstall metadata to central tables only", async () => {
|
||||
const actualCore = await vi.importActual<typeof import("@fusion/core")>("@fusion/core");
|
||||
const projectDir = await mkdtemp(join(tmpdir(), "fn-plugin-project-"));
|
||||
const centralDir = await mkdtemp(join(tmpdir(), "fn-plugin-central-"));
|
||||
tempDirs.push(projectDir, centralDir);
|
||||
|
||||
const realStore = new actualCore.PluginStore(projectDir, { centralGlobalDir: centralDir });
|
||||
await realStore.init();
|
||||
|
||||
vi.mocked(resolveProject).mockResolvedValue({
|
||||
projectPath: projectDir,
|
||||
store: { getPluginStore: () => realStore },
|
||||
} as never);
|
||||
|
||||
const pluginDir = await createTempPluginFixture([
|
||||
{
|
||||
path: "manifest.json",
|
||||
content: JSON.stringify({ id: "paperclip-runtime", name: "Paperclip Runtime", version: "1.0.0" }),
|
||||
},
|
||||
{
|
||||
path: "package.json",
|
||||
content: JSON.stringify({ exports: { ".": { import: "./dist/index.js" } } }),
|
||||
},
|
||||
{
|
||||
path: "dist/index.js",
|
||||
content:
|
||||
"export default { manifest: { id: 'paperclip-runtime', name: 'Paperclip Runtime', version: '1.0.0' }, async onLoad() {}, async onUnload() {} };",
|
||||
},
|
||||
]);
|
||||
tempDirs.push(pluginDir);
|
||||
|
||||
await expect(runPluginInstall(pluginDir)).resolves.toBeUndefined();
|
||||
|
||||
const centralDb = new actualCore.CentralDatabase(centralDir);
|
||||
centralDb.init();
|
||||
const installCount = centralDb
|
||||
.prepare("SELECT COUNT(*) as count FROM plugin_installs WHERE id = ?")
|
||||
.get("paperclip-runtime") as { count: number };
|
||||
const stateCount = centralDb
|
||||
.prepare("SELECT COUNT(*) as count FROM project_plugin_states WHERE pluginId = ? AND projectPath = ?")
|
||||
.get("paperclip-runtime", projectDir) as { count: number };
|
||||
|
||||
const localDb = new actualCore.Database(join(projectDir, ".fusion"));
|
||||
localDb.init();
|
||||
const legacyCount = localDb
|
||||
.prepare("SELECT COUNT(*) as count FROM plugins WHERE id = ?")
|
||||
.get("paperclip-runtime") as { count: number };
|
||||
|
||||
expect(installCount.count).toBe(1);
|
||||
expect(stateCount.count).toBe(1);
|
||||
expect(legacyCount.count).toBe(0);
|
||||
|
||||
centralDb.close();
|
||||
localDb.close();
|
||||
});
|
||||
|
||||
it("includes getRootDir on the plugin loader taskStore mock (FN-2687)", async () => {
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
||||
throw new Error(`exit:${code}`);
|
||||
|
||||
@@ -75,6 +75,7 @@ const mocks = vi.hoisted(() => {
|
||||
const missionStore = {
|
||||
listMissions: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
const pluginStore = pluginStoreCtor();
|
||||
|
||||
return {
|
||||
init: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -86,6 +87,7 @@ const mocks = vi.hoisted(() => {
|
||||
getSettings: vi.fn().mockResolvedValue({}),
|
||||
})),
|
||||
getMissionStore: vi.fn().mockReturnValue(missionStore),
|
||||
getPluginStore: vi.fn().mockReturnValue(pluginStore),
|
||||
getSettings: vi.fn().mockResolvedValue({
|
||||
maxConcurrent: 2,
|
||||
recycleWorktrees: false,
|
||||
@@ -907,13 +909,14 @@ describe("runServe — Plugin wiring", () => {
|
||||
process.exit = originalExit;
|
||||
});
|
||||
|
||||
it("creates PluginStore and PluginLoader instances", async () => {
|
||||
it("gets PluginStore from TaskStore and creates PluginLoader", async () => {
|
||||
const { PluginStore, PluginLoader } = await import("@fusion/core");
|
||||
|
||||
await runServe(4040, {});
|
||||
|
||||
expect(PluginStore).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.taskStores[0].getPluginStore).toHaveBeenCalledTimes(1);
|
||||
expect(PluginLoader).toHaveBeenCalledTimes(1);
|
||||
expect(PluginStore).toHaveBeenCalled();
|
||||
|
||||
await triggerSignal("SIGINT");
|
||||
});
|
||||
@@ -933,12 +936,12 @@ describe("runServe — Plugin wiring", () => {
|
||||
await triggerSignal("SIGINT");
|
||||
});
|
||||
|
||||
it("initializes PluginStore with the task store's project root", async () => {
|
||||
const { PluginStore } = await import("@fusion/core");
|
||||
|
||||
it("initializes the TaskStore-provided PluginStore", async () => {
|
||||
await runServe(4040, {});
|
||||
|
||||
expect(PluginStore).toHaveBeenCalledWith("/repo");
|
||||
expect(mocks.taskStores[0].getPluginStore).toHaveBeenCalledTimes(1);
|
||||
const taskStorePluginStore = mocks.taskStores[0].getPluginStore.mock.results[0]?.value as { init: ReturnType<typeof vi.fn> };
|
||||
expect(taskStorePluginStore?.init).toHaveBeenCalledTimes(1);
|
||||
|
||||
await triggerSignal("SIGINT");
|
||||
});
|
||||
|
||||
@@ -12,7 +12,6 @@ import type { AddressInfo } from "node:net";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
CentralCore,
|
||||
PluginStore,
|
||||
PluginLoader,
|
||||
getTaskMergeBlocker,
|
||||
INSIGHT_EXTRACTION_SCHEDULE_NAME,
|
||||
@@ -367,12 +366,7 @@ export async function runDaemon(opts: DaemonOptions = {}) {
|
||||
}
|
||||
|
||||
// ── PluginStore: plugin installation management ─────────────────────
|
||||
// Some mocked stores used in tests may not implement getRootDir(); fall
|
||||
// back to the resolved runtime cwd in that case.
|
||||
const storeRootDir = typeof (store as { getRootDir?: () => string }).getRootDir === "function"
|
||||
? (store as { getRootDir: () => string }).getRootDir()
|
||||
: cwd;
|
||||
const pluginStore = new PluginStore(storeRootDir);
|
||||
const pluginStore = store.getPluginStore();
|
||||
await pluginStore.init();
|
||||
|
||||
// ── PluginLoader: plugin lifecycle management ───────────────────────
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AddressInfo } from "node:net";
|
||||
import { dirname, join, resolve as pathResolve } from "node:path";
|
||||
import { join, resolve as pathResolve } from "node:path";
|
||||
import { execFile as execFileCb } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { stat, readdir, readFile as fsReadFile } from "node:fs/promises";
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
AutomationStore,
|
||||
CentralCore,
|
||||
AgentStore,
|
||||
PluginStore,
|
||||
PluginLoader,
|
||||
getTaskMergeBlocker,
|
||||
getEnabledPiExtensionPaths,
|
||||
@@ -1067,11 +1066,7 @@ export async function runDashboard(port: number, opts: { paused?: boolean; dev?:
|
||||
// Enables the PluginManager UI to list, install, enable, disable, and
|
||||
// configure plugins via the /api/plugins REST endpoints.
|
||||
//
|
||||
const pluginStoreRootDir =
|
||||
typeof (store as { getRootDir?: () => string }).getRootDir === "function"
|
||||
? store.getRootDir()
|
||||
: dirname(store.getFusionDir());
|
||||
const pluginStore = new PluginStore(pluginStoreRootDir);
|
||||
const pluginStore = store.getPluginStore();
|
||||
await pluginStore.init();
|
||||
|
||||
// ── PluginLoader: plugin lifecycle management ───────────────────────
|
||||
|
||||
@@ -13,7 +13,7 @@ import { existsSync } from "node:fs";
|
||||
import { dirname, extname, join, resolve } from "node:path";
|
||||
import { readFile, stat } from "node:fs/promises";
|
||||
import * as readline from "node:readline";
|
||||
import { PluginStore, PluginLoader, validatePluginManifest } from "@fusion/core";
|
||||
import { PluginStore, PluginLoader, validatePluginManifest, resolveGlobalDir } from "@fusion/core";
|
||||
import { resolveProject } from "../project-context.js";
|
||||
|
||||
export interface BuiltinPluginCatalogEntry {
|
||||
@@ -92,11 +92,23 @@ async function getProjectPath(projectName?: string): Promise<string> {
|
||||
/**
|
||||
* Create a PluginStore for the given project.
|
||||
*/
|
||||
async function createPluginStore(projectName?: string): Promise<PluginStore> {
|
||||
const projectPath = await getProjectPath(projectName);
|
||||
const pluginStore = new PluginStore(projectPath);
|
||||
await pluginStore.init();
|
||||
return pluginStore;
|
||||
async function createPluginStore(
|
||||
projectName?: string,
|
||||
options?: { centralGlobalDir?: string },
|
||||
): Promise<PluginStore> {
|
||||
try {
|
||||
const context = await resolveProject(projectName, process.cwd(), options?.centralGlobalDir);
|
||||
const pluginStore = context.store.getPluginStore();
|
||||
await pluginStore.init();
|
||||
return pluginStore;
|
||||
} catch {
|
||||
const projectPath = await getProjectPath(projectName);
|
||||
const pluginStore = new PluginStore(projectPath, {
|
||||
centralGlobalDir: options?.centralGlobalDir ?? resolveGlobalDir(),
|
||||
});
|
||||
await pluginStore.init();
|
||||
return pluginStore;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
*/
|
||||
|
||||
import type { AddressInfo } from "node:net";
|
||||
import { dirname, join } from "node:path";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
CentralCore,
|
||||
PluginStore,
|
||||
PluginLoader,
|
||||
getTaskMergeBlocker,
|
||||
INSIGHT_EXTRACTION_SCHEDULE_NAME,
|
||||
@@ -425,11 +424,7 @@ export async function runServe(
|
||||
// internally for task-execution plugin hooks. These instances here serve the
|
||||
// HTTP plugin-management API routes and are intentionally separate.
|
||||
//
|
||||
const pluginStoreRootDir =
|
||||
typeof (store as { getRootDir?: () => string }).getRootDir === "function"
|
||||
? store.getRootDir()
|
||||
: dirname(store.getFusionDir());
|
||||
const pluginStore = new PluginStore(pluginStoreRootDir);
|
||||
const pluginStore = store.getPluginStore();
|
||||
await pluginStore.init();
|
||||
|
||||
// ── PluginLoader: plugin lifecycle management ───────────────────────
|
||||
|
||||
Reference in New Issue
Block a user