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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user