Skip to content

Commit 2541bf7

Browse files
committed
test(auto-reply): tighten silent-token boundaries
1 parent 8edb939 commit 2541bf7

2 files changed

Lines changed: 27 additions & 42 deletions

File tree

‎src/auto-reply/tokens.test.ts‎

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -110,36 +110,29 @@ describe("isSilentReplyText", () => {
110110
expect(isSilentReplyText("Please NO_REPLY to this")).toBe(false);
111111
});
112112

113-
it("returns true for token with stray leading punctuation (#98166)", () => {
114-
expect(isSilentReplyText(".NO_REPLY")).toBe(true);
115-
expect(isSilentReplyText("*NO_REPLY")).toBe(true);
116-
expect(isSilentReplyText("...NO_REPLY")).toBe(true);
117-
});
118-
119-
it("returns true for token with stray trailing punctuation (#98166)", () => {
120-
expect(isSilentReplyText("NO_REPLY.")).toBe(true);
121-
expect(isSilentReplyText("NO_REPLY*")).toBe(true);
122-
expect(isSilentReplyText("NO_REPLY...")).toBe(true);
123-
});
124-
125-
it("returns true for token with punctuation on both sides (#98166)", () => {
126-
expect(isSilentReplyText("*NO_REPLY*")).toBe(true);
127-
expect(isSilentReplyText("\"NO_REPLY\"")).toBe(true);
128-
expect(isSilentReplyText(".NO_REPLY.")).toBe(true);
129-
});
130-
131-
it("still returns false for substantive text with stray punctuation before token", () => {
132-
// "the sentinel is NO_REPLY, fyi" should remain false
133-
expect(isSilentReplyText("the sentinel is NO_REPLY, fyi")).toBe(false);
134-
});
135-
136-
it("returns true for punctuation with surrounding whitespace (#98166)", () => {
137-
expect(isSilentReplyText(" .NO_REPLY")).toBe(true);
138-
expect(isSilentReplyText(".NO_REPLY ")).toBe(true);
139-
expect(isSilentReplyText(" .NO_REPLY ")).toBe(true);
140-
expect(isSilentReplyText(" NO_REPLY. ")).toBe(true);
141-
expect(isSilentReplyText(" *NO_REPLY* ")).toBe(true);
142-
});
113+
it.each([
114+
".NO_REPLY",
115+
"*NO_REPLY",
116+
"...NO_REPLY",
117+
"NO_REPLY.",
118+
"NO_REPLY*",
119+
"NO_REPLY...",
120+
"*NO_REPLY*",
121+
'"NO_REPLY"',
122+
".NO_REPLY.",
123+
" .NO_REPLY ",
124+
" NO_REPLY. ",
125+
" *NO_REPLY* ",
126+
])("returns true for punctuation-wrapped token-only text: %j (#98166)", (text) => {
127+
expect(isSilentReplyText(text)).toBe(true);
128+
});
129+
130+
it.each(["the sentinel is NO_REPLY, fyi", "💬NO_REPLY", "NO_REPLY👍"])(
131+
"keeps substantive punctuation or symbols: %j",
132+
(text) => {
133+
expect(isSilentReplyText(text)).toBe(false);
134+
},
135+
);
143136

144137
it("preserves exact custom-token matches with punctuation-edged tokens", () => {
145138
// Custom tokens whose first/last character is punctuation must still match

‎src/auto-reply/tokens.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ function getSilentTrailingRegex(token: string): RegExp {
4242
return regex;
4343
}
4444

45-
/**
46-
* Strip leading and trailing punctuation characters.
47-
* Unicode-aware: uses \p{P} for all punctuation categories.
48-
* This prevents stray punctuation (e.g. ".NO_REPLY", "*NO_REPLY*") from
49-
* causing token-only silent-reply detection to fail, while preserving
50-
* substantive content like emoji or symbols before the token.
51-
*/
52-
function stripEdgePunct(text: string): string {
45+
function stripEdgePunctuation(text: string): string {
5346
return text.replace(/^\p{P}+|\p{P}+$/gu, "");
5447
}
5548

@@ -63,12 +56,11 @@ export function isSilentReplyText(
6356
}
6457
// Match only token-only replies, including repeated tokens separated by whitespace.
6558
// This prevents substantive replies ending with NO_REPLY from being suppressed (#19537).
66-
// Try exact match first to preserve custom-token punctuation semantics, then fall back
67-
// to edge-punctuation-stripped match so ".NO_REPLY" and "*NO_REPLY*" are caught (#98166).
68-
// Trim whitespace before stripping edge punct so " .NO_REPLY " is also caught.
59+
// Models sometimes wrap the token in punctuation. Preserve exact custom-token matching,
60+
// but keep symbols such as emoji substantive so they are still delivered.
6961
return (
7062
getSilentExactRegex(token).test(text) ||
71-
getSilentExactRegex(token).test(stripEdgePunct(text.trim()))
63+
getSilentExactRegex(token).test(stripEdgePunctuation(text.trim()))
7264
);
7365
}
7466

0 commit comments

Comments
 (0)