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
23 changes: 19 additions & 4 deletions cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import type { FailedAttempt } from '@filoz/synapse-sdk'
import { Synapse } from '@filoz/synapse-sdk'
import { z } from 'incur'
import { privateKeyClient } from '../client.ts'
Expand Down Expand Up @@ -32,6 +33,8 @@ export const uploadCommand = {
pieceCid: z.string(),
pieceScannerUrl: z.string(),
size: z.number(),
requestedCopies: z.number(),
complete: z.boolean(),
copyResults: z.array(
z.object({
dataSetId: z.string(),
Expand Down Expand Up @@ -122,18 +125,20 @@ export const uploadCommand = {
providerRole: copy.role,
}))
const copyFailures = result.failedAttempts.map((failure: any) => ({
providerId: failure.providerId,
providerId: failure.providerId.toString(),
role: failure.role,
error: failure instanceof Error ? failure.message : String(failure),
explicit: failure.explicit,
error: formatFailedAttemptError(failure),
explicit: Boolean(failure.explicit),
}))

return out.done({
status: 'uploaded',
status: result.complete ? 'uploaded' : 'partially_uploaded',
result: {
pieceCid: cidStr,
pieceScannerUrl: pieceScannerUrl(cidStr, chain),
size: result.size,
requestedCopies: result.requestedCopies,
complete: result.complete,
copyResults,
copyFailures,
},
Expand All @@ -144,3 +149,13 @@ export const uploadCommand = {
}
},
}

function formatFailedAttemptError(failure: FailedAttempt | Error | unknown) {
if (failure instanceof Error) return failure.message
if (failure && typeof failure === 'object' && 'error' in failure) {
const error = failure.error
if (error instanceof Error) return error.message
if (error !== undefined && error !== null) return String(error)
}
return String(failure)
}
6 changes: 5 additions & 1 deletion cli/src/commands/wallet/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const summaryCommand = {
availableFunds: z.string(),
timeRemaining: z.string(),
totalLockup: z.string(),
rateBasedLockup: z.string(),
monthlyAccountRate: z.string(),
monthlyStorageRate: z.string(),
funds: z.string(),
Expand All @@ -39,9 +40,12 @@ export const summaryCommand = {
availableFunds: formatBalance({ value: summary.availableFunds }),
timeRemaining,
totalLockup: formatBalance({ value: summary.totalLockup }),
monthlyAccountRate: formatBalance({
rateBasedLockup: formatBalance({
value: summary.totalRateBasedLockup,
}),
monthlyAccountRate: formatBalance({
value: summary.lockupRatePerMonth,
}),
monthlyStorageRate: formatBalance({
value: summary.lockupRatePerMonth,
}),
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/command-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const synapseStorage = {
upload: mock(async () => ({
pieceCid: cid('baga-upload'),
size: 4,
requestedCopies: 0,
complete: true,
Comment on lines +63 to +64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep reset upload mock in sync

Because resetCommandMocks() is called at module load and before each test, the new successful-upload defaults here are overwritten by the reset implementation below, which still returns no requestedCopies or complete. Any test that relies on the shared upload mock after reset will now exercise undefined for those fields and report partially_uploaded, so update the reset mock to include the same fields.

Useful? React with 👍 / 👎.

copies: [],
failedAttempts: [],
})),
Expand Down
12 changes: 7 additions & 5 deletions cli/tests/synapse-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ describe('top-level upload commands', () => {
synapseStorage.upload.mockImplementation(async () => ({
pieceCid: cid('baga-upload'),
size: 4,
requestedCopies: 3,
complete: false,
copies: [
{
dataSetId: 42n,
Expand All @@ -141,9 +143,6 @@ describe('top-level upload commands', () => {
role: 'secondary',
error: 'temporarily unavailable',
explicit: false,
toString() {
return this.error
},
},
],
}))
Expand Down Expand Up @@ -172,11 +171,13 @@ describe('top-level upload commands', () => {
contexts,
withCDN: true,
})
expect(result.status).toBe('uploaded')
expect(result.status).toBe('partially_uploaded')
expect(result.result).toEqual({
pieceCid: 'baga-upload',
pieceScannerUrl: 'https://pdp.vxb.ai/calibration/piece/baga-upload',
size: 4,
requestedCopies: 3,
complete: false,
copyResults: [
{
dataSetId: '42',
Expand Down Expand Up @@ -426,7 +427,8 @@ describe('wallet commands', () => {
availableFunds: 'formatted:1',
timeRemaining: '1h 0d 0w 0m 0y',
totalLockup: 'formatted:2',
monthlyAccountRate: 'formatted:3',
rateBasedLockup: 'formatted:3',
monthlyAccountRate: 'formatted:4',
monthlyStorageRate: 'formatted:4',
funds: 'formatted:5',
})
Expand Down
Loading