diff --git a/src/formatting.test.ts b/src/formatting.test.ts index 0ca1185..647905d 100644 --- a/src/formatting.test.ts +++ b/src/formatting.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; -import { TRIGGER_PATTERN } from './config.js'; +import { ASSISTANT_NAME, TRIGGER_PATTERN } from './config.js'; import { escapeXml, formatMessages, @@ -102,34 +102,38 @@ describe('formatMessages', () => { // --- TRIGGER_PATTERN --- describe('TRIGGER_PATTERN', () => { - it('matches @Andy at start of message', () => { - expect(TRIGGER_PATTERN.test('@Andy hello')).toBe(true); + const name = ASSISTANT_NAME; + const lower = name.toLowerCase(); + const upper = name.toUpperCase(); + + it('matches @name at start of message', () => { + expect(TRIGGER_PATTERN.test(`@${name} hello`)).toBe(true); }); it('matches case-insensitively', () => { - expect(TRIGGER_PATTERN.test('@andy hello')).toBe(true); - expect(TRIGGER_PATTERN.test('@ANDY hello')).toBe(true); + expect(TRIGGER_PATTERN.test(`@${lower} hello`)).toBe(true); + expect(TRIGGER_PATTERN.test(`@${upper} hello`)).toBe(true); }); it('does not match when not at start of message', () => { - expect(TRIGGER_PATTERN.test('hello @Andy')).toBe(false); + expect(TRIGGER_PATTERN.test(`hello @${name}`)).toBe(false); }); - it('does not match partial name like @Andrew (word boundary)', () => { - expect(TRIGGER_PATTERN.test('@Andrew hello')).toBe(false); + it('does not match partial name like @NameExtra (word boundary)', () => { + expect(TRIGGER_PATTERN.test(`@${name}extra hello`)).toBe(false); }); it('matches with word boundary before apostrophe', () => { - expect(TRIGGER_PATTERN.test("@Andy's thing")).toBe(true); + expect(TRIGGER_PATTERN.test(`@${name}'s thing`)).toBe(true); }); - it('matches @Andy alone (end of string is a word boundary)', () => { - expect(TRIGGER_PATTERN.test('@Andy')).toBe(true); + it('matches @name alone (end of string is a word boundary)', () => { + expect(TRIGGER_PATTERN.test(`@${name}`)).toBe(true); }); it('matches with leading whitespace after trim', () => { // The actual usage trims before testing: TRIGGER_PATTERN.test(m.content.trim()) - expect(TRIGGER_PATTERN.test('@Andy hey'.trim())).toBe(true); + expect(TRIGGER_PATTERN.test(`@${name} hey`.trim())).toBe(true); }); }); @@ -219,7 +223,7 @@ describe('trigger gating (requiresTrigger interaction)', () => { }); it('non-main group with requiresTrigger=true processes when trigger present', () => { - const msgs = [makeMsg({ content: '@Andy do something' })]; + const msgs = [makeMsg({ content: `@${ASSISTANT_NAME} do something` })]; expect(shouldProcess(false, true, msgs)).toBe(true); });