mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-17 05:20:23 -07:00
chore: update test
This commit is contained in:
@@ -19,6 +19,12 @@ describe('formatArgsPattern', () => {
|
||||
expect(formatArgsPattern(pattern)).toBe('git diff*');
|
||||
});
|
||||
|
||||
it('should parse commandPrefix with escaped quotes (git show)', () => {
|
||||
// buildArgsPatterns uses escapeRegex() which escapes quotes to \"
|
||||
const pattern = new RegExp('\\"command\\":\\"git\\ show(?:[\\s"]|\\\\")');
|
||||
expect(formatArgsPattern(pattern)).toBe('git show*');
|
||||
});
|
||||
|
||||
it('should parse commandPrefix with special chars (npm run test:ci)', () => {
|
||||
// escapeRegex escapes the colon
|
||||
const pattern = new RegExp(
|
||||
@@ -37,6 +43,11 @@ describe('formatArgsPattern', () => {
|
||||
expect(formatArgsPattern(pattern)).toBe('npm run .*');
|
||||
});
|
||||
|
||||
it('should parse commandRegex with escaped quotes', () => {
|
||||
const pattern = new RegExp('\\"command\\":\\"npm run .*');
|
||||
expect(formatArgsPattern(pattern)).toBe('npm run .*');
|
||||
});
|
||||
|
||||
it('should parse file_path pattern', () => {
|
||||
const pattern = new RegExp('"file_path":".*\\/plans\\/.*"');
|
||||
expect(formatArgsPattern(pattern)).toBe('path: .*\\/plans\\/.*');
|
||||
|
||||
@@ -65,16 +65,23 @@ export function formatArgsPattern(
|
||||
|
||||
const source = argsPattern.source;
|
||||
|
||||
// 1. commandPrefix: "command":"<escaped-prefix>(?:[\s"]|\\")"
|
||||
// buildArgsPatterns uses escapeRegex() which escapes quotes to \", so the
|
||||
// regex source contains escaped quotes. We support both escaped (\") and
|
||||
// unescaped (") formats for robustness.
|
||||
const cmdPrefix = /^\\?"command\\?":\\?"(.+?)\(\?:\[\\s"]\|\\\\"?\)$/;
|
||||
|
||||
// 1. commandPrefix: \"command\":\"<escaped-prefix>(?:[\s"]|\\")"
|
||||
// The lookahead ensures the prefix is word-bounded in JSON.
|
||||
const prefixMatch = source.match(/^"command":"(.+?)\(\?:\[\\s"\]\|\\\\"?\)$/);
|
||||
const prefixMatch = source.match(cmdPrefix);
|
||||
if (prefixMatch) {
|
||||
return unescapeRegex(prefixMatch[1]) + '*';
|
||||
}
|
||||
|
||||
// 2. commandRegex: starts with "command":"
|
||||
if (source.startsWith('"command":"')) {
|
||||
const regex = source.slice('"command":"'.length);
|
||||
// 2. commandRegex: starts with "command":" or \"command\":\"
|
||||
const cmdRegexPrefix = /^\\?"command\\?":\\?"/;
|
||||
const cmdRegexMatch = source.match(cmdRegexPrefix);
|
||||
if (cmdRegexMatch) {
|
||||
const regex = source.slice(cmdRegexMatch[0].length);
|
||||
return regex;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user