From daaa6e7802fbe53afa02308e392e6c9c437932df Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Wed, 16 Aug 2023 16:27:39 -0700 Subject: [PATCH 1/3] fix: re-enable upload-api tests mocha's globbing behavior is... quirky. tests currently broken, working to fix. --- packages/upload-api/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/upload-api/package.json b/packages/upload-api/package.json index c19fa9217..6036ecc7f 100644 --- a/packages/upload-api/package.json +++ b/packages/upload-api/package.json @@ -103,7 +103,7 @@ "build": "tsc --build", "check": "tsc --build", "lint": "tsc --build", - "test": "mocha --bail --timeout 10s -n no-warnings -n experimental-vm-modules -n experimental-fetch test/**/*.spec.js", + "test": "mocha --bail --timeout 10s -n no-warnings -n experimental-vm-modules -n experimental-fetch 'test/**/*.spec.js'", "test-watch": "pnpm build && mocha --bail --timeout 10s --watch --parallel -n no-warnings -n experimental-vm-modules -n experimental-fetch --watch-files src,test" }, "dependencies": { From ed4c775297d6e4ff3b6c796fee9d8af1177dc616 Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Thu, 17 Aug 2023 12:12:08 -0700 Subject: [PATCH 2/3] fix: update tests I still can't really figure out why, but "equal" CIDs suddenly stopped comparing equally with `deepEqual` - we were already converting them to strings in at least one place, so do that in the remaining spots. --- packages/upload-api/test/access-authorize.js | 12 ++------ packages/upload-api/test/store.js | 12 ++++---- packages/upload-api/test/upload.js | 30 +++++++++----------- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/packages/upload-api/test/access-authorize.js b/packages/upload-api/test/access-authorize.js index 6eab52e70..6092d118f 100644 --- a/packages/upload-api/test/access-authorize.js +++ b/packages/upload-api/test/access-authorize.js @@ -257,15 +257,9 @@ export const test = { ? delegations : delegations.reverse() - assert.deepEqual(attestation.capabilities, [ - { - can: 'ucan/attest', - with: service.did(), - nb: { - proof: authorization.cid, - }, - }, - ]) + assert.equal(attestation.capabilities[0].can, 'ucan/attest') + assert.equal(attestation.capabilities[0].with, service.did()) + assert.equal(attestation.capabilities[0].nb.proof.toString(), authorization.cid.toString()) assert.equal(authorization.issuer.did(), account.did()) assert.deepEqual(authorization.capabilities, [ diff --git a/packages/upload-api/test/store.js b/packages/upload-api/test/store.js index 2c2b65d5e..abfcad735 100644 --- a/packages/upload-api/test/store.js +++ b/packages/upload-api/test/store.js @@ -43,7 +43,7 @@ export const test = { assert.equal(storeAdd.out.ok.status, 'upload') assert.equal(storeAdd.out.ok.with, spaceDid) - assert.deepEqual(storeAdd.out.ok.link, link) + assert.deepEqual(storeAdd.out.ok.link.toString(), link.toString()) assert.equal(storeAdd.out.ok.headers?.['content-length'], String(size)) assert.deepEqual( @@ -84,13 +84,13 @@ export const test = { assert.deepEqual( { space: item.space, - link: item.link, + link: item.link.toString(), size: item.size, issuer: item.issuer, }, { space: spaceDid, - link, + link: link.toString(), size: data.byteLength, issuer: alice.did(), } @@ -243,7 +243,7 @@ export const test = { assert.equal(storeAdd.out.ok.status, 'done') assert.equal(storeAdd.out.ok.with, spaceDid) - assert.deepEqual(storeAdd.out.ok.link, link) + assert.deepEqual(storeAdd.out.ok.link.toString(), link.toString()) assert.equal(storeAdd.out.ok.url == null, true) const item = await context.testStoreTable.get(spaceDid, link) @@ -254,13 +254,13 @@ export const test = { assert.deepEqual( { space: item.space, - link: item.link, + link: item.link.toString(), size: item.size, issuer: item.issuer, }, { space: spaceDid, - link, + link: link.toString(), size: data.byteLength, issuer: alice.did(), } diff --git a/packages/upload-api/test/upload.js b/packages/upload-api/test/upload.js index d8885a848..87c0597cc 100644 --- a/packages/upload-api/test/upload.js +++ b/packages/upload-api/test/upload.js @@ -47,14 +47,15 @@ export const test = { throw new Error('invocation failed', { cause: uploadAdd }) } - assert.deepEqual(uploadAdd.out.ok, { root, shards }) + assert.equal(uploadAdd.out.ok.root.toString(), root.toString()) + assert.deepEqual(uploadAdd.out.ok.shards.map(String).sort(), shards.map(String).sort()) const { results } = await context.uploadTable.list(spaceDid) assert.deepEqual(results.length, 1) const [item] = results - assert.deepEqual(item.root, root) - assert.deepEqual(item.shards, shards) + assert.deepEqual(item.root.toString(), root.toString()) + assert.deepEqual(item.shards?.map(String).sort(), shards.map(String).sort()) const msAgo = Date.now() - new Date(item.insertedAt).getTime() assert.equal(msAgo < 60_000, true) @@ -91,8 +92,8 @@ export const test = { } assert.deepEqual( - uploadAdd.out.ok, - { root, shards: [] }, + uploadAdd.out.ok.shards, + [], 'Should have an empty shards array' ) @@ -148,18 +149,13 @@ export const test = { throw new Error('invocation failed', { cause: uploadAdd2 }) } - assert.deepEqual(uploadAdd2.out.ok.shards, shards) + assert.deepEqual(uploadAdd2.out.ok.shards.map(String).sort(), shards.map(String).sort()) const { results } = await context.uploadTable.list(spaceDid) assert.equal(results.length, 1) const [upload] = results - assert.deepEqual( - { - root: upload.root, - shards: upload.shards?.map(String).sort(), - }, - { root, shards: shards.map(String).sort() } - ) + assert.equal(upload.root.toString(), root.toString()) + assert.deepEqual(upload.shards?.map(String).sort(), shards.map(String).sort()) }, 'upload/add merges shards to an existing item with shards': async ( @@ -223,11 +219,11 @@ export const test = { const [upload] = results assert.deepEqual( { - root: upload.root, + root: upload.root.toString(), shards: upload.shards?.map(String).sort(), }, { - root, + root: root.toString(), shards: cars.map((car) => car.cid.toString()).sort(), } ) @@ -579,8 +575,8 @@ export const test = { (x) => x.root.toString() === root.toString() ) - assert.deepEqual(item?.root, root) - assert.deepEqual(item?.shards, [car.cid]) + assert.deepEqual(item?.root.toString(), root.toString()) + assert.deepEqual(item?.shards.map(String), [car.cid.toString()]) assert.deepEqual(item?.updatedAt, item?.insertedAt) } }, From 2604887b374ab6e56951e63271bd71283e845dee Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Thu, 17 Aug 2023 12:25:40 -0700 Subject: [PATCH 3/3] fix: sooth the linter's tired eyes --- packages/upload-api/test/access-authorize.js | 6 +++++- packages/upload-api/test/upload.js | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/upload-api/test/access-authorize.js b/packages/upload-api/test/access-authorize.js index 6092d118f..9351aa75c 100644 --- a/packages/upload-api/test/access-authorize.js +++ b/packages/upload-api/test/access-authorize.js @@ -257,9 +257,13 @@ export const test = { ? delegations : delegations.reverse() + assert.equal(attestation.capabilities[0].can, 'ucan/attest') assert.equal(attestation.capabilities[0].with, service.did()) - assert.equal(attestation.capabilities[0].nb.proof.toString(), authorization.cid.toString()) + assert.equal( + /** @type {import('@ucanto/interface').Capability} */(attestation.capabilities[0]).nb.proof.toString(), + authorization.cid.toString() + ) assert.equal(authorization.issuer.did(), account.did()) assert.deepEqual(authorization.capabilities, [ diff --git a/packages/upload-api/test/upload.js b/packages/upload-api/test/upload.js index 87c0597cc..389e1b2e6 100644 --- a/packages/upload-api/test/upload.js +++ b/packages/upload-api/test/upload.js @@ -48,7 +48,7 @@ export const test = { } assert.equal(uploadAdd.out.ok.root.toString(), root.toString()) - assert.deepEqual(uploadAdd.out.ok.shards.map(String).sort(), shards.map(String).sort()) + assert.deepEqual(uploadAdd.out.ok.shards?.map(String).sort(), shards.map(String).sort()) const { results } = await context.uploadTable.list(spaceDid) assert.deepEqual(results.length, 1) @@ -149,7 +149,7 @@ export const test = { throw new Error('invocation failed', { cause: uploadAdd2 }) } - assert.deepEqual(uploadAdd2.out.ok.shards.map(String).sort(), shards.map(String).sort()) + assert.deepEqual(uploadAdd2.out.ok.shards?.map(String).sort(), shards.map(String).sort()) const { results } = await context.uploadTable.list(spaceDid) assert.equal(results.length, 1) @@ -576,7 +576,7 @@ export const test = { ) assert.deepEqual(item?.root.toString(), root.toString()) - assert.deepEqual(item?.shards.map(String), [car.cid.toString()]) + assert.deepEqual(item?.shards?.map(String), [car.cid.toString()]) assert.deepEqual(item?.updatedAt, item?.insertedAt) } },