Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/add/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export async function runAdd(options: AddOptions): Promise<AddResult> {
const proceed = await warnAboutCDNPricingLimitations()
if (!proceed) {
cancel('Add cancelled')
process.exitCode = 1
throw new Error('CDN pricing limitations warning cancelled')
}
}
Expand All @@ -101,7 +100,7 @@ export async function runAdd(options: AddOptions): Promise<AddResult> {
if (!pathValidation.exists || !pathValidation.stats) {
spinner.stop(`${pc.red('✗')} ${pathValidation.error}`)
cancel('Add cancelled')
process.exit(1)
throw new Error(pathValidation.error)
}

const pathStat = pathValidation.stats
Expand Down Expand Up @@ -247,6 +246,6 @@ export async function runAdd(options: AddOptions): Promise<AddResult> {
}

cancel('Add failed')
process.exit(1)
throw error
}
}
3 changes: 1 addition & 2 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export const addCommand = new Command('add')
}

await runAdd(addOptions)
} catch (error) {
console.error('Add failed:', error instanceof Error ? error.message : error)
} catch {
process.exit(1)
}
})
Expand Down
24 changes: 9 additions & 15 deletions src/test/unit/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,51 +233,45 @@ describe('Add Command', () => {
})

it('should reject when file does not exist', async () => {
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called')
})
const mockExit = vi.spyOn(process, 'exit')

await expect(
runAdd({
filePath: '/non/existent/file.txt',
privateKey: 'test-key',
})
).rejects.toThrow('process.exit called')
).rejects.toThrow('Path not found')

expect(mockExit).toHaveBeenCalledWith(1)
expect(mockExit).not.toHaveBeenCalled()
mockExit.mockRestore()
})

it('should reject when private key is missing', async () => {
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called')
})
const mockExit = vi.spyOn(process, 'exit')

await expect(
runAdd({
filePath: testFile,
// No private key
})
).rejects.toThrow('process.exit called')
).rejects.toThrow()

expect(mockExit).toHaveBeenCalledWith(1)
expect(mockExit).not.toHaveBeenCalled()
mockExit.mockRestore()
})

it('should reject --bare flag with directories', async () => {
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called')
})
const mockExit = vi.spyOn(process, 'exit')

await expect(
runAdd({
filePath: testDir, // Directory
privateKey: 'test-key',
bare: true, // --bare flag should not work with directories
})
).rejects.toThrow('process.exit called')
).rejects.toThrow('--bare flag is not supported for directories')

expect(mockExit).toHaveBeenCalledWith(1)
expect(mockExit).not.toHaveBeenCalled()
mockExit.mockRestore()
})
})
Expand Down