From 58c69ee8bd3f310088493948a35aacd2a1fb7c98 Mon Sep 17 00:00:00 2001 From: divanoli Date: Thu, 5 Feb 2026 11:07:31 +0300 Subject: [PATCH] test(telegram): add comprehensive edge case coverage for file ref wrapping Add 16 edge case tests covering: - File refs inside bold/italic tags - Fenced code blocks (no double-wrap) - Domain-like paths preserved as links (example.com/README.md) - GitHub URLs with file paths - wrapFileRefs: false behavior - All TLD extensions (.ai, .io, .tv, .fm) - Non-TLD extensions not wrapped (.png, .css, .js) - File ref position (start, end, multiple in sequence) - Nested paths without domain segments - Version-like paths (v1.0/README.md wraps, example.com/v1.0/README.md links) - Hyphens and underscores in filenames - Uppercase extensions --- src/telegram/format.wrap-md.test.ts | 95 +++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/telegram/format.wrap-md.test.ts b/src/telegram/format.wrap-md.test.ts index 917fb78898b..db83d753aba 100644 --- a/src/telegram/format.wrap-md.test.ts +++ b/src/telegram/format.wrap-md.test.ts @@ -156,3 +156,98 @@ describe("markdownToTelegramChunks - file reference wrapping", () => { expect(chunks[0].html).toContain("backup.sh"); }); }); + +describe("edge cases", () => { + it("wraps file ref inside bold tags", () => { + const result = markdownToTelegramHtml("**README.md**"); + expect(result).toBe("README.md"); + }); + + it("wraps file ref inside italic tags", () => { + const result = markdownToTelegramHtml("*script.py*"); + expect(result).toBe("script.py"); + }); + + it("does not wrap inside fenced code blocks", () => { + const result = markdownToTelegramHtml("```\nREADME.md\n```"); + expect(result).toBe("
README.md\n
"); + expect(result).not.toContain(""); + }); + + it("preserves domain-like paths as anchor tags", () => { + const result = markdownToTelegramHtml("example.com/README.md"); + expect(result).toContain(''); + expect(result).not.toContain(""); + }); + + it("preserves github URLs with file paths", () => { + const result = markdownToTelegramHtml("https://github.com/foo/README.md"); + expect(result).toContain(''); + }); + + it("handles wrapFileRefs: false (plain text output)", () => { + const result = markdownToTelegramHtml("README.md", { wrapFileRefs: false }); + // buildTelegramLink returns null, so no tag; wrapFileRefs: false skips + expect(result).toBe("README.md"); + }); + + it("wraps all TLD extensions (.ai, .io, .tv, .fm)", () => { + const result = markdownToTelegramHtml("logo.ai and app.io and video.tv and audio.fm"); + expect(result).toContain("logo.ai"); + expect(result).toContain("app.io"); + expect(result).toContain("video.tv"); + expect(result).toContain("audio.fm"); + }); + + it("does not wrap non-TLD extensions", () => { + const result = markdownToTelegramHtml("image.png and style.css and script.js"); + expect(result).not.toContain("image.png"); + expect(result).not.toContain("style.css"); + expect(result).not.toContain("script.js"); + }); + + it("handles file ref at start of message", () => { + const result = markdownToTelegramHtml("README.md is important"); + expect(result).toBe("README.md is important"); + }); + + it("handles file ref at end of message", () => { + const result = markdownToTelegramHtml("Check the README.md"); + expect(result).toBe("Check the README.md"); + }); + + it("handles multiple file refs in sequence", () => { + const result = markdownToTelegramHtml("README.md CHANGELOG.md LICENSE.md"); + expect(result).toContain("README.md"); + expect(result).toContain("CHANGELOG.md"); + expect(result).toContain("LICENSE.md"); + }); + + it("handles nested path without domain-like segments", () => { + const result = markdownToTelegramHtml("src/utils/helpers/format.go"); + expect(result).toContain("src/utils/helpers/format.go"); + }); + + it("wraps path with version-like segment (not a domain)", () => { + // v1.0/README.md is not linkified by markdown-it (no TLD), so it's wrapped + const result = markdownToTelegramHtml("v1.0/README.md"); + expect(result).toContain("v1.0/README.md"); + }); + + it("preserves domain path with version segment", () => { + // example.com/v1.0/README.md IS linkified (has domain), preserved as link + const result = markdownToTelegramHtml("example.com/v1.0/README.md"); + expect(result).toContain(''); + }); + + it("handles file ref with hyphen and underscore in name", () => { + const result = markdownToTelegramHtml("my-file_name.md"); + expect(result).toContain("my-file_name.md"); + }); + + it("handles uppercase extensions", () => { + const result = markdownToTelegramHtml("README.MD and SCRIPT.PY"); + expect(result).toContain("README.MD"); + expect(result).toContain("SCRIPT.PY"); + }); +});