fix(FN-2141): route reflection stores through getFusionDir
- Initialize AgentStore and ReflectionStore with taskStore.getFusionDir() in reflection APIs - Prevent reflection endpoints from touching root-level fusion.db and agents artifacts - Add regression coverage to ensure root project files are not created by reflection requests
This commit is contained in:
@@ -15332,6 +15332,7 @@ describe("Agent Reflection routes", () => {
|
||||
|
||||
function buildApp() {
|
||||
const store = createMockStore({
|
||||
getRootDir: vi.fn().mockReturnValue(tempDir),
|
||||
getFusionDir: vi.fn().mockReturnValue(fusionDir),
|
||||
} as any);
|
||||
const app = express();
|
||||
@@ -15438,6 +15439,31 @@ describe("Agent Reflection routes", () => {
|
||||
expect([404, 500]).toContain(res.status);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not create fusion.db or agents directory in project root for reflection endpoints", async () => {
|
||||
const app = buildApp();
|
||||
|
||||
const rootDbPath = join(tempDir, "fusion.db");
|
||||
const rootDbWalPath = join(tempDir, "fusion.db-wal");
|
||||
const rootDbShmPath = join(tempDir, "fusion.db-shm");
|
||||
const rootAgentsDir = join(tempDir, "agents");
|
||||
|
||||
expect(existsSync(rootDbPath)).toBe(false);
|
||||
expect(existsSync(rootDbWalPath)).toBe(false);
|
||||
expect(existsSync(rootDbShmPath)).toBe(false);
|
||||
expect(existsSync(rootAgentsDir)).toBe(false);
|
||||
|
||||
const postRes = await REQUEST(app, "POST", `/api/agents/${agentId}/reflections`);
|
||||
expect([500, 503]).toContain(postRes.status);
|
||||
|
||||
const contextRes = await GET(app, `/api/agents/${agentId}/reflection-context`);
|
||||
expect([500, 503]).toContain(contextRes.status);
|
||||
|
||||
expect(existsSync(rootDbPath)).toBe(false);
|
||||
expect(existsSync(rootDbWalPath)).toBe(false);
|
||||
expect(existsSync(rootDbShmPath)).toBe(false);
|
||||
expect(existsSync(rootAgentsDir)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// ── AI Refine Text Route with Scoped Settings ────────────────────────────────
|
||||
|
||||
@@ -13609,8 +13609,8 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
|
||||
const { store: taskStore } = await getProjectContext(req);
|
||||
const { AgentStore, ReflectionStore } = await import("@fusion/core");
|
||||
const { AgentReflectionService } = await import("@fusion/engine");
|
||||
const agentStore = new AgentStore({ rootDir: taskStore.getRootDir() });
|
||||
const reflectionStore = new ReflectionStore({ rootDir: taskStore.getRootDir() });
|
||||
const agentStore = new AgentStore({ rootDir: taskStore.getFusionDir() });
|
||||
const reflectionStore = new ReflectionStore({ rootDir: taskStore.getFusionDir() });
|
||||
await agentStore.init();
|
||||
await reflectionStore.init();
|
||||
|
||||
@@ -13696,8 +13696,8 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
|
||||
try {
|
||||
const { store: taskStore } = await getProjectContext(req);
|
||||
const { AgentStore, ReflectionStore } = await import("@fusion/core");
|
||||
const agentStore = new AgentStore({ rootDir: taskStore.getRootDir() });
|
||||
const reflectionStore = new ReflectionStore({ rootDir: taskStore.getRootDir() });
|
||||
const agentStore = new AgentStore({ rootDir: taskStore.getFusionDir() });
|
||||
const reflectionStore = new ReflectionStore({ rootDir: taskStore.getFusionDir() });
|
||||
await agentStore.init();
|
||||
await reflectionStore.init();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user