fix(FN-000): skip qmd index mutations in test runs

Why: tests were leaking ~700 per-temp-dir collection registrations
into the user's global ~/.config/qmd/index.yml because searchWithQmd
and the agent-memory qmd path called execFile("qmd", ...) with the
real binary, bypassing shouldSkipBackgroundQmdRefresh() which only
guarded the schedule* wrappers.

Guard both direct-execFile paths under the same skip flag and fall
back to file-based agent memory search when skipping.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-17 13:54:28 -07:00
parent ef696f4564
commit 217ccdd4aa
3 changed files with 11 additions and 1 deletions

View File

@@ -12,7 +12,7 @@ import { existsSync } from "node:fs";
import { createHash } from "node:crypto";
import { join } from "node:path";
import type { AgentStore, AgentState, AgentCapability, TaskDocument, TaskDocumentCreateInput, TaskStore, RunMutationContext, MessageStore, Message } from "@fusion/core";
import { dailyMemoryPath, ensureOpenClawMemoryFiles, getMemoryBackendCapabilities, getProjectMemory, isEphemeralAgent, memoryLongTermPath, resolveMemoryBackend, scheduleQmdProjectMemoryRefresh, searchProjectMemory } from "@fusion/core";
import { dailyMemoryPath, ensureOpenClawMemoryFiles, getMemoryBackendCapabilities, getProjectMemory, isEphemeralAgent, memoryLongTermPath, resolveMemoryBackend, scheduleQmdProjectMemoryRefresh, searchProjectMemory, shouldSkipBackgroundQmdRefresh } from "@fusion/core";
import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
import { Type, type Static } from "@mariozechner/pi-ai";
import type { AgentReflectionService } from "./agent-reflection.js";
@@ -283,6 +283,9 @@ async function searchAgentMemoryFile(rootDir: string, agentMemory: AgentMemoryCo
}
async function refreshAgentMemoryQmdIndex(rootDir: string, agentMemory: AgentMemoryContext): Promise<void> {
if (shouldSkipBackgroundQmdRefresh()) {
return;
}
await syncAgentMemoryFile(rootDir, agentMemory);
const key = `${rootDir}:${agentMemory.agentId}`;
const now = Date.now();
@@ -330,6 +333,9 @@ async function searchAgentMemoryWithQmd(rootDir: string, agentMemory: AgentMemor
if (!agentMemory.memory?.trim()) {
return [];
}
if (shouldSkipBackgroundQmdRefresh()) {
return searchAgentMemoryFile(rootDir, agentMemory, query, limit);
}
try {
await refreshAgentMemoryQmdIndex(rootDir, agentMemory);
const { execFile } = await import("node:child_process");