Ignore up to 4 non-word characters when stripping HEARTBEAT_OK token … (#15847)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: dc03ce5005
Co-authored-by: Spacefish <375633+Spacefish@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
This commit is contained in:
Spacefish
2026-02-14 01:36:04 +01:00
committed by GitHub
parent 6daa4911e7
commit f9379ecee2
3 changed files with 74 additions and 3 deletions

View File

@@ -107,6 +107,62 @@ describe("stripHeartbeatToken", () => {
didStrip: true,
});
});
it("strips trailing punctuation only when directly after the token", () => {
// Token with trailing dot/exclamation/dashes → should still strip
expect(stripHeartbeatToken(`${HEARTBEAT_TOKEN}.`, { mode: "heartbeat" })).toEqual({
shouldSkip: true,
text: "",
didStrip: true,
});
expect(stripHeartbeatToken(`${HEARTBEAT_TOKEN}!!!`, { mode: "heartbeat" })).toEqual({
shouldSkip: true,
text: "",
didStrip: true,
});
expect(stripHeartbeatToken(`${HEARTBEAT_TOKEN}---`, { mode: "heartbeat" })).toEqual({
shouldSkip: true,
text: "",
didStrip: true,
});
});
it("strips a sentence-ending token and keeps trailing punctuation", () => {
// Token appears at sentence end with trailing punctuation.
expect(
stripHeartbeatToken(`I should not respond ${HEARTBEAT_TOKEN}.`, {
mode: "message",
}),
).toEqual({
shouldSkip: false,
text: `I should not respond.`,
didStrip: true,
});
});
it("strips sentence-ending token with emphasis punctuation in heartbeat mode", () => {
expect(
stripHeartbeatToken(
`There is nothing todo, so i should respond with ${HEARTBEAT_TOKEN} !!!`,
{
mode: "heartbeat",
},
),
).toEqual({
shouldSkip: true,
text: "",
didStrip: true,
});
});
it("preserves trailing punctuation on text before the token", () => {
// Token at end, preceding text has its own punctuation — only the token is stripped
expect(stripHeartbeatToken(`All clear. ${HEARTBEAT_TOKEN}`, { mode: "message" })).toEqual({
shouldSkip: false,
text: "All clear.",
didStrip: true,
});
});
});
describe("isHeartbeatContentEffectivelyEmpty", () => {