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
10 changes: 5 additions & 5 deletions cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ export const uploadCommand = {
})

const cidStr = result.pieceCid.toString()
const copyResults = result.copies.map((copy: any) => ({
dataSetId: copy.dataSetId,
const copyResults = result.copies.map((copy) => ({
dataSetId: copy.dataSetId.toString(),
datasetScannerUrl: datasetScannerUrl(copy.dataSetId, chain),
url: copy.retrievalUrl,
pieceId: copy.pieceId,
providerId: copy.providerId,
pieceId: copy.pieceId.toString(),
providerId: copy.providerId.toString(),
isNewDataSet: copy.isNewDataSet,
providerRole: copy.role,
}))
const copyFailures = result.failedAttempts.map((failure: any) => ({
const copyFailures = result.failedAttempts.map((failure) => ({
providerId: failure.providerId.toString(),
role: failure.role,
error: formatFailedAttemptError(failure),
Expand Down
100 changes: 91 additions & 9 deletions cli/tests/synapse-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ afterEach(async () => {
describe('top-level upload commands', () => {
test('upload prepares storage, executes funding, uploads, and maps copy results', async () => {
const filePath = await tempFile('upload.txt', 'data')
const contexts = [{ id: 'ctx-primary' }]
const contexts = [{ id: 'ctx-primary' }, { id: 'ctx-secondary' }]
const execute = mock(async () => ({ hash: '0xprepare' }))

synapseStorage.createContexts.mockImplementation(async () => contexts)
Expand All @@ -125,8 +125,8 @@ describe('top-level upload commands', () => {
synapseStorage.upload.mockImplementation(async () => ({
pieceCid: cid('baga-upload'),
size: 4,
requestedCopies: 3,
complete: false,
requestedCopies: 2,
complete: true,
copies: [
{
dataSetId: 42n,
Expand All @@ -136,12 +136,20 @@ describe('top-level upload commands', () => {
isNewDataSet: true,
role: 'primary',
},
{
dataSetId: 43n,
retrievalUrl: 'https://backup.example/piece/baga-upload',
pieceId: 8n,
providerId: 79n,
isNewDataSet: false,
role: 'secondary',
},
],
failedAttempts: [
{
providerId: 78n,
role: 'secondary',
error: 'temporarily unavailable',
error: 'replaced after transient failure',
explicit: false,
},
],
Expand All @@ -150,7 +158,7 @@ describe('top-level upload commands', () => {
const result = await uploadCommand.run(
commandContext({
args: { path: filePath },
options: { copies: 3, withCDN: true },
options: { copies: 2, withCDN: true },
})
)

Expand All @@ -159,7 +167,7 @@ describe('top-level upload commands', () => {
{ client: fakeWalletClient, source: 'foc-cli' },
])
expect(synapseStorage.createContexts).toHaveBeenCalledWith({
copies: 3,
copies: 2,
withCDN: true,
})
expect(synapseStorage.prepare).toHaveBeenCalledWith({
Expand All @@ -171,13 +179,13 @@ describe('top-level upload commands', () => {
contexts,
withCDN: true,
})
expect(result.status).toBe('partially_uploaded')
expect(result.status).toBe('uploaded')
expect(result.result).toEqual({
pieceCid: 'baga-upload',
pieceScannerUrl: 'https://pdp.vxb.ai/calibration/piece/baga-upload',
size: 4,
requestedCopies: 3,
complete: false,
requestedCopies: 2,
complete: true,
copyResults: [
{
dataSetId: '42',
Expand All @@ -188,6 +196,80 @@ describe('top-level upload commands', () => {
isNewDataSet: true,
providerRole: 'primary',
},
{
dataSetId: '43',
datasetScannerUrl: 'https://pdp.vxb.ai/calibration/dataset/43',
url: 'https://backup.example/piece/baga-upload',
pieceId: '8',
providerId: '79',
isNewDataSet: false,
providerRole: 'secondary',
},
],
copyFailures: [
{
providerId: '78',
role: 'secondary',
error: 'replaced after transient failure',
explicit: false,
},
],
})
})

test('upload reports partial status when Synapse commits fewer copies than requested', async () => {
const filePath = await tempFile('partial.txt', 'data')
const contexts = [
{ id: 'ctx-primary' },
{ id: 'ctx-secondary-a' },
{ id: 'ctx-secondary-b' },
]

synapseStorage.createContexts.mockImplementation(async () => contexts)
synapseStorage.upload.mockImplementation(async () => ({
pieceCid: cid('baga-partial'),
size: 4,
requestedCopies: 3,
complete: false,
copies: [
{
dataSetId: 42n,
retrievalUrl: 'https://provider.example/piece/baga-partial',
pieceId: 7n,
providerId: 77n,
isNewDataSet: true,
role: 'primary',
},
],
failedAttempts: [
{
providerId: 78n,
role: 'secondary',
error: 'temporarily unavailable',
explicit: false,
},
],
}))

const result = await uploadCommand.run(
commandContext({
args: { path: filePath },
options: { copies: 3 },
})
)

expect(result.status).toBe('partially_uploaded')
expect(result.result).toMatchObject({
pieceCid: 'baga-partial',
requestedCopies: 3,
complete: false,
copyResults: [
{
dataSetId: '42',
pieceId: '7',
providerId: '77',
providerRole: 'primary',
},
],
copyFailures: [
{
Expand Down
Loading