Skip to content

Commit 770be54

Browse files
committed
test: add unit tests for responseMatcher in generateCommitMessage
1 parent 6b31dbe commit 770be54

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { expect } from "chai";
2+
import { stringToRegExp } from "../utils/string";
3+
import { defaultConfigData } from "./default";
4+
5+
describe("Config: generateCommitMessage.responseMatcher", () => {
6+
// Test parameters
7+
const responseMatcher = defaultConfigData.chat.generateCommitMessage.responseMatcher;
8+
const regExp = stringToRegExp(responseMatcher);
9+
10+
// Helper function for reusing test logic
11+
function testResponseMatch(testCase: string, input: string, expectedMatch: string) {
12+
it(testCase, () => {
13+
const match = regExp.exec(input);
14+
expect(match).to.not.be.null;
15+
if (match) {
16+
expect(match[1]).to.equal(expectedMatch);
17+
}
18+
});
19+
}
20+
21+
// Core functionality: Extract commit message from simple response
22+
testResponseMatch(
23+
"test for extracting conventional commit message from simple response",
24+
"Based on the diff, I would suggest the following commit message:\n\nfeat(core): add new feature\n",
25+
"feat(core): add new feature"
26+
);
27+
28+
// Core functionality: Handle commit messages in code blocks
29+
testResponseMatch(
30+
"test for handling responses with code blocks",
31+
`Based on the diff, here's an appropriate commit message:
32+
33+
\`\`\`
34+
fix(auth): resolve user authentication timeout issue
35+
\`\`\`
36+
37+
This commit message follows the conventional format with a 'fix' type and 'auth' scope.`,
38+
"fix(auth): resolve user authentication timeout issue"
39+
);
40+
41+
// Bug fix: Handle commit messages with double quotes
42+
testResponseMatch(
43+
"test for handling responses with double quotes",
44+
`Based on the provided diff, I recommend using the following commit message:
45+
46+
"docs(readme): update installation instructions"
47+
48+
This commit message follows the conventional format and accurately describes the changes made to the documentation.`,
49+
"docs(readme): update installation instructions"
50+
);
51+
52+
// Bug fix: Handle commit messages with single quotes and backticks
53+
testResponseMatch(
54+
"test for handling responses with single quotes and backticks",
55+
`Here are some commit message options:
56+
'chore(build): update dependencies'
57+
\`test(components): add unit tests for login form\``,
58+
"chore(build): update dependencies"
59+
);
60+
61+
// Bug fix: Handle responses with markdown images
62+
testResponseMatch(
63+
"test for handling responses with markdown images",
64+
`Here's a diagram showing the changes you made:
65+
![Diagram](https://example.com/diagram.png)
66+
67+
Based on the diff, I suggest the following commit message:
68+
69+
feat(ui): improve button design and layout
70+
71+
[Diagram]: https://example.com/diagram-ref.png`,
72+
"feat(ui): improve button design and layout"
73+
);
74+
});

clients/tabby-agent/src/config/default.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const defaultConfigData: ConfigData = {
103103
maxDiffLength: 3600,
104104
promptTemplate: generateCommitMessagePrompt,
105105
responseMatcher:
106-
/(?<=(["'`]+)?\s*)(feat|fix|docs|refactor|style|test|build|ci|chore)(\(\S+\))?:.+(?=\s*\1)/gis.toString(),
106+
/^(?:(?!!\[|^\[.*\]:\s*http).*?)(?:["'`]?)?((?:feat|fix|docs|refactor|style|test|build|ci|chore)(?:\(\S+\))?:.+?)(?:["'`])?(?:\n|$)/mis.toString(),
107107
},
108108
generateBranchName: {
109109
maxDiffLength: 3600,

0 commit comments

Comments
 (0)