Skip to content

Commit 52fb8e7

Browse files
committed
test: Add regression test for multi-line git commit messages in auto-approve
- Add test case demonstrating current behavior where multi-line commit messages fail auto-approval due to newline splitting before quote handling - Simplified reproduction of real-world scenario with git add && git commit -m - Documents expected behavior for future fix
1 parent 8187a8e commit 52fb8e7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

webview-ui/src/utils/__tests__/command-validation.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,32 @@ describe("Unified Command Decision Functions", () => {
10831083
expect(getCommandDecision("dangerous", allowed, denied)).toBe("ask_user")
10841084
expect(getCommandDecision("npm install && dangerous", allowed, denied)).toBe("ask_user")
10851085
})
1086+
// Real-world regression: multi-line git commit message in quotes should not be treated as separate commands
1087+
// Current behavior splits on newlines before quote handling, which causes follow-up lines to be considered commands.
1088+
// This test reproduces the failure mode for visibility. A future fix could change parseCommand to preserve
1089+
// newlines inside quotes for specific cases (e.g., git commit -m).
1090+
describe("real-world: multi-line git commit message", () => {
1091+
it("auto-approves when commit message is single-line", () => {
1092+
const allowed = ["cd", "git add", "git commit"]
1093+
const command =
1094+
'cd /repo && git add src/a.ts src/b.ts && git commit -m "feat: title - one line message"'
1095+
1096+
expect(getCommandDecision(command, allowed, [])).toBe("auto_approve")
1097+
})
1098+
1099+
it("asks user when commit message is multi-line due to newline splitting (bug reproduction)", () => {
1100+
const allowed = ["cd", "git add", "git commit"]
1101+
// Simplified reproduction of the user's example: a multi-line quoted commit message
1102+
const command = `cd /repo && git add src/a.ts src/b.ts && git commit -m "feat: title
1103+
1104+
- point a
1105+
- point b"`
1106+
1107+
// Because parseCommand splits on actual newlines first, the lines after the first are treated as separate
1108+
// commands (e.g., "- point a"), which are not in the allowlist, so the overall decision becomes "ask_user".
1109+
expect(getCommandDecision(command, allowed, [])).toBe("ask_user")
1110+
})
1111+
})
10861112
})
10871113

10881114
describe("CommandValidator Integration Tests", () => {

0 commit comments

Comments
 (0)