Skip to content

Commit 00db703

Browse files
committed
Test(workflows): read a restored link's text past Windows' backslashes
Three assertions in workflow-apply.test.ts compared the text of a symlink a run had put back with `../sources/Real.md`, and failed on the Windows runner with `..\sources\Real.md`: Windows stores a symlink's target with backslashes whatever text created it, so `readlink` there never returns the forward slashes the test wrote. The run itself is right, it wrote the recorded text as is. A `linkText` helper reads the target with forward slashes on every platform and the three assertions use it. Found by the 2.55.0 release PR's Windows job; no app code changes.
1 parent b251ff0 commit 00db703

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎apps/desktop/src/main/workflow-apply.test.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ async function isSymlink(abs: string): Promise<boolean> {
167167
return (await lstat(abs)).isSymbolicLink()
168168
}
169169

170+
/**
171+
* A link's text with forward slashes, whatever the platform stored. Windows
172+
* keeps a symlink's target with backslashes even when it was created from
173+
* `../sources/Real.md`, so a test that compares the text a run put back has
174+
* to read past that spelling; the run itself wrote the recorded text as is.
175+
*/
176+
async function linkText(abs: string): Promise<string> {
177+
return (await readlink(abs)).split(path.sep).join('/')
178+
}
179+
170180
/**
171181
* Whether two paths differing only in case are one file here. macOS and Windows
172182
* say yes, which is the whole reason the journal folds its keys; on Linux those
@@ -1800,7 +1810,7 @@ describe('symlinked notes', () => {
18001810
const receipt = await apply(root, [{ kind: 'archive', path: 'inbox/Rel.md' }])
18011811
await undoWorkflowRun(root, receipt.runId)
18021812

1803-
expect(await readlink(path.join(root, 'inbox', 'Rel.md'))).toBe('../sources/Real.md')
1813+
expect(await linkText(path.join(root, 'inbox', 'Rel.md'))).toBe('../sources/Real.md')
18041814
expect(await readOrNull(root, 'sources/Real.md')).toBe('real\n')
18051815
expect(await pathExists(path.join(root, 'archive', 'Rel.md'))).toBe(false)
18061816
})
@@ -1819,7 +1829,7 @@ describe('symlinked notes', () => {
18191829
const undo = await undoWorkflowRun(root, receipt.runId)
18201830

18211831
expect(undo.driftedPaths).toEqual([])
1822-
expect(await readlink(path.join(root, 'inbox', 'Rel.md'))).toBe('../sources/Real.md')
1832+
expect(await linkText(path.join(root, 'inbox', 'Rel.md'))).toBe('../sources/Real.md')
18231833
expect(await readOrNull(root, 'inbox/Rel.md')).toBe('real\n')
18241834
expect(await readOrNull(root, 'sources/Real.md')).toBe('real\n')
18251835
expect(await pathExists(path.join(root, 'inbox', 'Topics', 'Rel.md'))).toBe(false)
@@ -1836,7 +1846,7 @@ describe('symlinked notes', () => {
18361846
expect(await readOrNull(root, 'inbox/Topics/Rel.md')).toBe('real\n')
18371847
await undoWorkflowRun(root, receipt.runId)
18381848

1839-
expect(await readlink(path.join(root, 'inbox', 'Rel.md'))).toBe('./../sources/Real.md')
1849+
expect(await linkText(path.join(root, 'inbox', 'Rel.md'))).toBe('./../sources/Real.md')
18401850
expect(await readOrNull(root, 'inbox/Rel.md')).toBe('real\n')
18411851
})
18421852

0 commit comments

Comments
 (0)