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:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user