From 94ba537310f7f26f96e7ad19ceab465ec0d1f297 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 22 Feb 2026 02:18:08 +1100 Subject: [PATCH] Decouple formatting test from `@Andy` (#329) * Fix trigger pattern tests to use config name Tests hardcoded "Andy" but the pattern is built from `ASSISTANT_NAME` which comes from `.env`. --- Generated with the help of Claude Code, https://claude.ai/code Co-Authored-By: Claude Code Opus 4.6 * Restore usage comment in trim test --- Generated with the help of Claude Code, https://claude.ai/code Co-Authored-By: Claude Code Opus 4.6 --------- Co-authored-by: Claude Code Opus 4.6 --- src/formatting.test.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) 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); });