Skip to content

Commit 12c90eb

Browse files
committed
fix(scm): 🐛 reject empty generated commit messages
1 parent 0871a1c commit 12c90eb

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/services/commit-message/CommitMessageGenerator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ FINAL REMINDER: Your message MUST be COMPLETELY DIFFERENT from the previous mess
236236
const cleaned = response.trim()
237237
const withoutCodeBlocks = cleaned.replace(/^```[a-zA-Z0-9_-]*\r?\n/, "").replace(/\r?\n```$/, "")
238238
const withoutQuotes = withoutCodeBlocks.replace(/^["'`]|["'`]$/g, "")
239-
return withoutQuotes.trim()
239+
const normalized = withoutQuotes.trim()
240+
241+
if (!normalized) {
242+
throw new Error("AI returned an empty commit message")
243+
}
244+
245+
return normalized
240246
}
241247
}

src/services/commit-message/__tests__/CommitMessageGenerator.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,19 @@ Keep unstaged commit context focused on worktree changes.
200200
201201
Keep unstaged commit context focused on worktree changes.`)
202202
})
203+
204+
it("fails when AI output is empty after cleanup", async () => {
205+
completePrompt.mockResolvedValue("```\n \n```")
206+
const generator = createGenerator()
207+
208+
await expect(
209+
generator.generateMessage({
210+
workspacePath: "/repo",
211+
selectedFiles: ["src/file.ts"],
212+
gitContext: "Modified (staged): src/file.ts",
213+
}),
214+
).rejects.toThrow("AI returned an empty commit message")
215+
216+
expect(captureGenerated).not.toHaveBeenCalled()
217+
})
203218
})

0 commit comments

Comments
 (0)