fix(FN-2155): require explicit store rootDir in tests

- Add constructor guards in AgentStore and ReflectionStore that throw when rootDir is omitted under Vitest
- Keep default .fusion root resolution for non-test execution paths
- Prevent accidental test writes to unintended filesystem locations by forcing explicit paths
This commit is contained in:
Fusion
2026-04-19 10:47:23 -07:00
committed by gsxdsm
parent a794cc0237
commit 302367e5c4
2 changed files with 14 additions and 0 deletions

View File

@@ -134,6 +134,13 @@ export class AgentStore extends EventEmitter {
constructor(options: AgentStoreOptions = {}) {
super();
if (!options.rootDir && process.env.VITEST === "true") {
throw new Error(
"AgentStore requires an explicit rootDir during test execution. Pass an absolute path to avoid writing to unintended locations.",
);
}
this.rootDir = options.rootDir ?? resolve(".fusion");
this.agentsDir = join(this.rootDir, "agents");
this.taskStore = options.taskStore;

View File

@@ -63,6 +63,13 @@ export class ReflectionStore extends EventEmitter {
constructor(options: ReflectionStoreOptions = {}) {
super();
if (!options.rootDir && process.env.VITEST === "true") {
throw new Error(
"ReflectionStore requires an explicit rootDir during test execution. Pass an absolute path to avoid writing to unintended locations.",
);
}
this.rootDir = options.rootDir ?? resolve(".fusion");
this.agentsDir = join(this.rootDir, "agents");
}