Skip to content

Commit 1ee35b2

Browse files
authored
Merge pull request #19 from FIL-Builders/codex/synapse-v1-review-fixes
[codex] fix Synapse v1 follow-up review findings
2 parents a21b11e + ae22f5b commit 1ee35b2

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

cli/src/commands/upload.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFile } from 'node:fs/promises'
22
import path from 'node:path'
3+
import type { FailedAttempt } from '@filoz/synapse-sdk'
34
import { Synapse } from '@filoz/synapse-sdk'
45
import { z } from 'incur'
56
import { privateKeyClient } from '../client.ts'
@@ -32,6 +33,8 @@ export const uploadCommand = {
3233
pieceCid: z.string(),
3334
pieceScannerUrl: z.string(),
3435
size: z.number(),
36+
requestedCopies: z.number(),
37+
complete: z.boolean(),
3538
copyResults: z.array(
3639
z.object({
3740
dataSetId: z.string(),
@@ -122,18 +125,20 @@ export const uploadCommand = {
122125
providerRole: copy.role,
123126
}))
124127
const copyFailures = result.failedAttempts.map((failure: any) => ({
125-
providerId: failure.providerId,
128+
providerId: failure.providerId.toString(),
126129
role: failure.role,
127-
error: failure instanceof Error ? failure.message : String(failure),
128-
explicit: failure.explicit,
130+
error: formatFailedAttemptError(failure),
131+
explicit: Boolean(failure.explicit),
129132
}))
130133

131134
return out.done({
132-
status: 'uploaded',
135+
status: result.complete ? 'uploaded' : 'partially_uploaded',
133136
result: {
134137
pieceCid: cidStr,
135138
pieceScannerUrl: pieceScannerUrl(cidStr, chain),
136139
size: result.size,
140+
requestedCopies: result.requestedCopies,
141+
complete: result.complete,
137142
copyResults,
138143
copyFailures,
139144
},
@@ -144,3 +149,13 @@ export const uploadCommand = {
144149
}
145150
},
146151
}
152+
153+
function formatFailedAttemptError(failure: FailedAttempt | Error | unknown) {
154+
if (failure instanceof Error) return failure.message
155+
if (failure && typeof failure === 'object' && 'error' in failure) {
156+
const error = failure.error
157+
if (error instanceof Error) return error.message
158+
if (error !== undefined && error !== null) return String(error)
159+
}
160+
return String(failure)
161+
}

cli/src/commands/wallet/summary.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const summaryCommand = {
1919
availableFunds: z.string(),
2020
timeRemaining: z.string(),
2121
totalLockup: z.string(),
22+
rateBasedLockup: z.string(),
2223
monthlyAccountRate: z.string(),
2324
monthlyStorageRate: z.string(),
2425
funds: z.string(),
@@ -39,9 +40,12 @@ export const summaryCommand = {
3940
availableFunds: formatBalance({ value: summary.availableFunds }),
4041
timeRemaining,
4142
totalLockup: formatBalance({ value: summary.totalLockup }),
42-
monthlyAccountRate: formatBalance({
43+
rateBasedLockup: formatBalance({
4344
value: summary.totalRateBasedLockup,
4445
}),
46+
monthlyAccountRate: formatBalance({
47+
value: summary.lockupRatePerMonth,
48+
}),
4549
monthlyStorageRate: formatBalance({
4650
value: summary.lockupRatePerMonth,
4751
}),

cli/tests/command-mocks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export const synapseStorage = {
6060
upload: mock(async () => ({
6161
pieceCid: cid('baga-upload'),
6262
size: 4,
63+
requestedCopies: 0,
64+
complete: true,
6365
copies: [],
6466
failedAttempts: [],
6567
})),

cli/tests/synapse-commands.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ describe('top-level upload commands', () => {
125125
synapseStorage.upload.mockImplementation(async () => ({
126126
pieceCid: cid('baga-upload'),
127127
size: 4,
128+
requestedCopies: 3,
129+
complete: false,
128130
copies: [
129131
{
130132
dataSetId: 42n,
@@ -141,9 +143,6 @@ describe('top-level upload commands', () => {
141143
role: 'secondary',
142144
error: 'temporarily unavailable',
143145
explicit: false,
144-
toString() {
145-
return this.error
146-
},
147146
},
148147
],
149148
}))
@@ -172,11 +171,13 @@ describe('top-level upload commands', () => {
172171
contexts,
173172
withCDN: true,
174173
})
175-
expect(result.status).toBe('uploaded')
174+
expect(result.status).toBe('partially_uploaded')
176175
expect(result.result).toEqual({
177176
pieceCid: 'baga-upload',
178177
pieceScannerUrl: 'https://pdp.vxb.ai/calibration/piece/baga-upload',
179178
size: 4,
179+
requestedCopies: 3,
180+
complete: false,
180181
copyResults: [
181182
{
182183
dataSetId: '42',
@@ -426,7 +427,8 @@ describe('wallet commands', () => {
426427
availableFunds: 'formatted:1',
427428
timeRemaining: '1h 0d 0w 0m 0y',
428429
totalLockup: 'formatted:2',
429-
monthlyAccountRate: 'formatted:3',
430+
rateBasedLockup: 'formatted:3',
431+
monthlyAccountRate: 'formatted:4',
430432
monthlyStorageRate: 'formatted:4',
431433
funds: 'formatted:5',
432434
})

0 commit comments

Comments
 (0)