Skip to content

Commit 79a4839

Browse files
committed
test: Add skipped tests documenting Issue #1109 link preservation bug
Instant Task Convert destroys markdown links and wikilinks when converting checklist items to TaskNotes. The sanitizeForFilename function removes brackets [] which breaks link syntax like [text](url) and [[note]]. Tests document: - How markdown link URLs are mangled (brackets/slashes stripped) - How wikilink syntax is destroyed (double brackets stripped) - How wikilinks with aliases lose their path structure Skipped tests outline expected behavior after fix: - Extract link display text for title, preserve full links in body - Handle both markdown links and wikilinks
1 parent c670e37 commit 79a4839

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/**
2+
* InstantTaskConvertService Issue #1109 Tests
3+
*
4+
* Bug: Instant Task Convert breaks links
5+
*
6+
* When converting a checklist item containing markdown links or wikilinks
7+
* to a TaskNote, the links are destroyed due to filename sanitization
8+
* removing brackets and special characters.
9+
*
10+
* Example from issue:
11+
* Before: `- [ ] Alfred: Make quick way to change display resolution ([Resolution Changer](https://alfred.app/workflows/firefingers21/resolution-changer/))`
12+
* After: `- [[Alfred Make quick way to change display resolution (Resolution Changer(httpsalfred.appworkflowsfirefingers21resolution-changer))-3]]`
13+
*
14+
* Root cause:
15+
* TaskService.sanitizeTitleForFilename (line 63-96) and filenameGenerator.sanitizeForFilename
16+
* both use this regex: .replace(/[<>:"/\\|?*#[\]]/g, "")
17+
* This strips [], which destroys markdown link syntax [text](url) and wikilinks [[note]].
18+
* The sanitized title is stored in frontmatter, so the link information is completely lost.
19+
*
20+
* Expected behavior:
21+
* 1. Links should be preserved in the task body
22+
* 2. Link display text should be kept in the title (without the URL)
23+
*/
24+
25+
import { sanitizeForFilename } from '../../../src/utils/filenameGenerator';
26+
27+
/**
28+
* Tests documenting Issue #1109: Instant Task Convert breaks links
29+
*
30+
* These tests verify that the sanitization functions strip link syntax,
31+
* demonstrating the bug. The skipped tests document the expected behavior
32+
* once the bug is fixed.
33+
*/
34+
describe('InstantTaskConvertService - Issue #1109: Link Preservation', () => {
35+
/**
36+
* These tests directly test sanitizeForFilename to demonstrate
37+
* how it destroys link syntax - this is the root cause of the bug.
38+
*/
39+
describe('sanitizeForFilename destroys links (documenting the bug)', () => {
40+
it('strips markdown link brackets, destroying the link syntax', () => {
41+
// The exact example from the issue
42+
const input =
43+
'Alfred: Make quick way to change display resolution ([Resolution Changer](https://alfred.app/workflows/firefingers21/resolution-changer/))';
44+
45+
const result = sanitizeForFilename(input);
46+
47+
// Brackets are stripped, URL is mangled
48+
expect(result).not.toContain('[');
49+
expect(result).not.toContain(']');
50+
// URL slashes are removed because / is stripped
51+
expect(result).not.toContain('https://');
52+
53+
// What we actually get (documenting the broken output)
54+
expect(result).toContain('Resolution Changer');
55+
expect(result).toContain('httpsalfred.appworkflowsfirefingers21resolution-changer');
56+
});
57+
58+
it('strips wikilink double brackets', () => {
59+
const input = 'Review [[Meeting Notes 2024-01-15]]';
60+
61+
const result = sanitizeForFilename(input);
62+
63+
// Double brackets are stripped
64+
expect(result).not.toContain('[[');
65+
expect(result).not.toContain(']]');
66+
67+
// The note name is preserved but no longer a valid link
68+
expect(result).toBe('Review Meeting Notes 2024-01-15');
69+
});
70+
71+
it('strips wikilink with alias', () => {
72+
const input = 'Follow up on [[projects/Q1 Planning|Q1 Planning]]';
73+
74+
const result = sanitizeForFilename(input);
75+
76+
// Brackets, pipe, and slashes are all stripped
77+
expect(result).not.toContain('[[');
78+
expect(result).not.toContain(']]');
79+
expect(result).not.toContain('|');
80+
81+
// Path is mangled - slashes removed, link structure destroyed
82+
// The result is: "Follow up on projectsQ1 PlanningQ1 Planning"
83+
expect(result).toContain('projectsQ1 Planning');
84+
});
85+
86+
it('mangles URLs in markdown links', () => {
87+
const input = 'Check [docs](https://example.com/path?query=1)';
88+
89+
const result = sanitizeForFilename(input);
90+
91+
// URL is completely mangled
92+
expect(result).not.toContain('https://');
93+
expect(result).not.toContain('?'); // Query string symbol stripped
94+
});
95+
96+
it('handles multiple links by destroying all of them', () => {
97+
const input = 'See [[Note A]] and [Link](https://example.com)';
98+
99+
const result = sanitizeForFilename(input);
100+
101+
// All link syntax destroyed
102+
expect(result).not.toContain('[[');
103+
expect(result).not.toContain('[');
104+
expect(result).not.toContain('https://');
105+
});
106+
});
107+
108+
/**
109+
* These tests document what the expected behavior SHOULD be after the fix.
110+
* They are skipped until the fix is implemented.
111+
*/
112+
describe('Expected behavior after fix (skipped until implemented)', () => {
113+
it.skip('should extract markdown link display text for title, preserve URL in body', () => {
114+
// When fixed, we should have a function that:
115+
// 1. Extracts markdown links from the title
116+
// 2. Replaces [text](url) with just "text" in the title
117+
// 3. Preserves the full [text](url) in the task body/details
118+
119+
const input =
120+
'Alfred: Make quick way to change display resolution ([Resolution Changer](https://alfred.app/workflows/firefingers21/resolution-changer/))';
121+
122+
// Expected title (with link display text preserved, URL removed)
123+
const expectedTitle =
124+
'Alfred: Make quick way to change display resolution (Resolution Changer)';
125+
126+
// Expected body/details (should contain the full link)
127+
const expectedLinkInBody =
128+
'[Resolution Changer](https://alfred.app/workflows/firefingers21/resolution-changer/)';
129+
130+
// TODO: Implement extractLinksFromTitle function that returns { cleanTitle, links }
131+
});
132+
133+
it.skip('should preserve wikilinks in task body', () => {
134+
const input = 'Review [[Meeting Notes 2024-01-15]]';
135+
136+
// For wikilinks, the expected behavior could be:
137+
// Title: "Review Meeting Notes 2024-01-15" (display text only)
138+
// Body: Contains the wikilink [[Meeting Notes 2024-01-15]]
139+
140+
// TODO: Implement wikilink extraction
141+
});
142+
143+
it.skip('should handle multiple mixed link types', () => {
144+
const input = 'See [[Project Notes]] and [external docs](https://docs.example.com)';
145+
146+
// Expected title: "See Project Notes and external docs"
147+
// Expected body: Should contain both links
148+
149+
// TODO: Implement mixed link extraction
150+
});
151+
});
152+
});

0 commit comments

Comments
 (0)