From 2ad3cc47ac712b0af4e1015d61c014fea45ea4a6 Mon Sep 17 00:00:00 2001 From: jdalton Date: Thu, 26 Mar 2026 12:17:39 -0400 Subject: [PATCH] fix: resolve test failures in releases-github and process-lock - Guard against missing assets array in GitHub release API response - Fix test mock to cover retry attempts in getReleaseAssetUrl - Fix Windows path separator handling in process-lock directory creation --- src/process-lock.ts | 15 ++++++++++++--- src/releases/github.ts | 6 +++++- test/unit/releases-github.test.mts | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/process-lock.ts b/src/process-lock.ts index 836ad68..e77c4e8 100644 --- a/src/process-lock.ts +++ b/src/process-lock.ts @@ -280,7 +280,10 @@ class ProcessLockManager { } // Ensure parent directory exists. - const lastSlash = lockPath.lastIndexOf('/') + const lastSlash = Math.max( + lockPath.lastIndexOf('/'), + lockPath.lastIndexOf('\\'), + ) if (lastSlash > 0) { mkdirSync(lockPath.slice(0, lastSlash), { recursive: true }) } @@ -328,7 +331,10 @@ class ProcessLockManager { // Handle parent path issues - not retryable. if (code === 'ENOTDIR') { - const lastSlashIndex = lockPath.lastIndexOf('/') + const lastSlashIndex = Math.max( + lockPath.lastIndexOf('/'), + lockPath.lastIndexOf('\\'), + ) const parentDir = lastSlashIndex === -1 ? '.' : lockPath.slice(0, lastSlashIndex) throw new Error( @@ -344,7 +350,10 @@ class ProcessLockManager { } if (code === 'ENOENT') { - const lastSlashIndex = lockPath.lastIndexOf('/') + const lastSlashIndex = Math.max( + lockPath.lastIndexOf('/'), + lockPath.lastIndexOf('\\'), + ) const parentDir = lastSlashIndex === -1 ? '.' : lockPath.slice(0, lastSlashIndex) throw new Error( diff --git a/src/releases/github.ts b/src/releases/github.ts index 19672e6..6f9d27e 100644 --- a/src/releases/github.ts +++ b/src/releases/github.ts @@ -509,7 +509,11 @@ export async function getReleaseAssetUrl( } // Find the matching asset. - const asset = release.assets.find(a => isMatch(a.name)) + const assets = release.assets + if (!Array.isArray(assets)) { + throw new Error(`Release ${tag} has no assets`) + } + const asset = assets.find(a => isMatch(a.name)) if (!asset) { const patternDesc = diff --git a/test/unit/releases-github.test.mts b/test/unit/releases-github.test.mts index 127fff2..5099b89 100644 --- a/test/unit/releases-github.test.mts +++ b/test/unit/releases-github.test.mts @@ -670,7 +670,7 @@ describe('releases/github', () => { }) it('should throw error when pattern does not match any asset', async () => { - vi.mocked(httpRequest).mockResolvedValueOnce( + vi.mocked(httpRequest).mockResolvedValue( createMockHttpResponse( Buffer.from(JSON.stringify(mockRelease)), true,