Merge pull request #79 from nrslib/takt/issue-25-1769915145
detectRuleIndex を最後のマッチに変更する
This commit is contained in:
commit
05bf51cfbb
@ -66,4 +66,13 @@ describe('detectRuleIndex', () => {
|
||||
expect(detectRuleIndex('[AI_REVIEW:1]', 'ai_review')).toBe(0);
|
||||
expect(detectRuleIndex('[SECURITY_FIX:2]', 'security_fix')).toBe(1);
|
||||
});
|
||||
|
||||
it('should detect last occurrence when multiple tags exist', () => {
|
||||
const content = 'Previous: [AI_REVIEW:1]\n\nActual result:\n[AI_REVIEW:2]';
|
||||
expect(detectRuleIndex(content, 'ai_review')).toBe(1);
|
||||
});
|
||||
|
||||
it('should detect last match with multiple occurrences', () => {
|
||||
expect(detectRuleIndex('[PLAN:1] then [PLAN:2] finally [PLAN:3]', 'plan')).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
@ -43,8 +43,9 @@ export interface ClaudeCallOptions {
|
||||
*/
|
||||
export function detectRuleIndex(content: string, stepName: string): number {
|
||||
const tag = stepName.toUpperCase();
|
||||
const regex = new RegExp(`\\[${tag}:(\\d+)\\]`, 'i');
|
||||
const match = content.match(regex);
|
||||
const regex = new RegExp(`\\[${tag}:(\\d+)\\]`, 'gi');
|
||||
const matches = [...content.matchAll(regex)];
|
||||
const match = matches.at(-1);
|
||||
if (match?.[1]) {
|
||||
const index = Number.parseInt(match[1], 10) - 1;
|
||||
return index >= 0 ? index : -1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user