Skip to content

Commit 8c71c30

Browse files
authored
fix: resolve test failures in releases-github and process-lock (#112)
- 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
1 parent 3127769 commit 8c71c30

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/process-lock.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ class ProcessLockManager {
280280
}
281281

282282
// Ensure parent directory exists.
283-
const lastSlash = lockPath.lastIndexOf('/')
283+
const lastSlash = Math.max(
284+
lockPath.lastIndexOf('/'),
285+
lockPath.lastIndexOf('\\'),
286+
)
284287
if (lastSlash > 0) {
285288
mkdirSync(lockPath.slice(0, lastSlash), { recursive: true })
286289
}
@@ -328,7 +331,10 @@ class ProcessLockManager {
328331

329332
// Handle parent path issues - not retryable.
330333
if (code === 'ENOTDIR') {
331-
const lastSlashIndex = lockPath.lastIndexOf('/')
334+
const lastSlashIndex = Math.max(
335+
lockPath.lastIndexOf('/'),
336+
lockPath.lastIndexOf('\\'),
337+
)
332338
const parentDir =
333339
lastSlashIndex === -1 ? '.' : lockPath.slice(0, lastSlashIndex)
334340
throw new Error(
@@ -344,7 +350,10 @@ class ProcessLockManager {
344350
}
345351

346352
if (code === 'ENOENT') {
347-
const lastSlashIndex = lockPath.lastIndexOf('/')
353+
const lastSlashIndex = Math.max(
354+
lockPath.lastIndexOf('/'),
355+
lockPath.lastIndexOf('\\'),
356+
)
348357
const parentDir =
349358
lastSlashIndex === -1 ? '.' : lockPath.slice(0, lastSlashIndex)
350359
throw new Error(

src/releases/github.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,11 @@ export async function getReleaseAssetUrl(
509509
}
510510

511511
// Find the matching asset.
512-
const asset = release.assets.find(a => isMatch(a.name))
512+
const assets = release.assets
513+
if (!Array.isArray(assets)) {
514+
throw new Error(`Release ${tag} has no assets`)
515+
}
516+
const asset = assets.find(a => isMatch(a.name))
513517

514518
if (!asset) {
515519
const patternDesc =

test/unit/releases-github.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ describe('releases/github', () => {
670670
})
671671

672672
it('should throw error when pattern does not match any asset', async () => {
673-
vi.mocked(httpRequest).mockResolvedValueOnce(
673+
vi.mocked(httpRequest).mockResolvedValue(
674674
createMockHttpResponse(
675675
Buffer.from(JSON.stringify(mockRelease)),
676676
true,

0 commit comments

Comments
 (0)