feat(FN-4041): harden empty rawResponse handling in memory-insights

Hardened empty `rawResponse` handling in the memory insights module by adding defensive checks to prevent errors when the response is empty, accompanied by tests to cover those edge cases (FN-4041 Step 1).

Fusion-Task-Id: FN-4041
This commit is contained in:
Fusion
2026-05-11 17:34:20 -07:00
committed by gsxdsm
parent b92ea7121a
commit 55bcf045eb
4 changed files with 85 additions and 5 deletions

View File

@@ -838,6 +838,19 @@ describe("memory-insights run processing", () => {
expect(result.summary).toContain("AI timeout");
});
it("should treat undefined successful response as no output", async () => {
const result = await processInsightExtractionRun(tempDir, {
rawResponse: undefined,
stepSuccess: true,
runAt: new Date().toISOString(),
});
expect(result.insights).toHaveLength(0);
expect(result.summary).toBe("Step did not produce output");
expect(result.newInsightCount).toBe(0);
expect(result.duplicateCount).toBe(0);
});
it("should preserve existing insights on failure", async () => {
// Create existing insights
const existingInsights = `# Memory Insights

View File

@@ -230,7 +230,7 @@ interface MemoryAuditState {
/** Input for processing an insight extraction run. */
export interface ProcessRunInput {
/** Raw AI response text from the insight extraction step. */
rawResponse: string;
rawResponse?: string;
/** Whether the AI step itself succeeded. */
stepSuccess: boolean;
/** Timestamp of the run. */
@@ -1118,7 +1118,7 @@ export async function processInsightExtractionRun(
let parseError: string | undefined;
// Try to parse the AI response
if (stepSuccess && rawResponse.trim()) {
if (stepSuccess && rawResponse?.trim()) {
try {
parsedResult = parseInsightExtractionResponse(rawResponse);
} catch (err) {