From ef836348b62ca4feb7ce62c594c063e21bcd966f Mon Sep 17 00:00:00 2001 From: Sina Iman Date: Tue, 20 Feb 2024 05:11:44 -0800 Subject: [PATCH] fix tests --- bootstrapCeramic.sh | 2 +- desci-server/src/services/nodeManager.ts | 4 +- nodes-lib/.env.example | 2 +- nodes-lib/package-lock.json | 14 ++-- nodes-lib/src/codex.ts | 97 ++++++++++++------------ nodes-lib/test/root.spec.ts | 2 +- 6 files changed, 60 insertions(+), 61 deletions(-) diff --git a/bootstrapCeramic.sh b/bootstrapCeramic.sh index 1e37365e2..8cbd077bd 100755 --- a/bootstrapCeramic.sh +++ b/bootstrapCeramic.sh @@ -15,7 +15,7 @@ CTX="[bootstrapCeramic.sh]" set -euo pipefail trap catch ERR catch() { - echo "$CTX script failed" + echo "$CTX script failed -- ensure CODEX_REPO_PATH and TOGGLE_CERAMIC are set in .env" exit 1 } diff --git a/desci-server/src/services/nodeManager.ts b/desci-server/src/services/nodeManager.ts index 76d0097e7..4a83f629f 100644 --- a/desci-server/src/services/nodeManager.ts +++ b/desci-server/src/services/nodeManager.ts @@ -9,7 +9,7 @@ import { uploadDataToEstuary } from '../services/estuary.js'; import { getIndexedResearchObjects } from '../theGraph.js'; import { generateDataReferences } from '../utils/dataRefTools.js'; import { cleanupManifestUrl } from '../utils/manifest.js'; -import { hexToCid, randomUUID64, asyncMap } from '../utils.js'; +import { hexToCid, randomUUID64, asyncMap, ensureUuidEndsWithDot } from '../utils.js'; import { addBufferToIpfs, downloadFilesAndMakeManifest, getSizeForCid, resolveIpfsData } from './ipfs.js'; @@ -56,7 +56,7 @@ export const createNodeDraftBlank = async ( export const setCeramicStream = async (uuid: string, ceramicStream: string) => { logger.debug({ fn: 'setCeramicStream', uuid, ceramicStream }, 'node::setCeramicStream'); - uuid = uuid.endsWith('.') ? uuid : uuid + '.'; + uuid = ensureUuidEndsWithDot(uuid); return await prisma.node.update({ data: { ceramicStream, diff --git a/nodes-lib/.env.example b/nodes-lib/.env.example index 959d8597d..86910b054 100644 --- a/nodes-lib/.env.example +++ b/nodes-lib/.env.example @@ -40,7 +40,7 @@ NODES_API_URL=http://localhost:5420 # NODES_API_URL=https://nodes-api-dev.desci.com #!!!!!!!!!! -# REQUIRED: Set your API key or auth token +# REQUIRED: Set your API key (login to nodes-web-v2 locally, generate API key from profile page) #!!!!!!!!!! NODES_API_KEY= diff --git a/nodes-lib/package-lock.json b/nodes-lib/package-lock.json index 0bc8a417f..1e91e47c8 100644 --- a/nodes-lib/package-lock.json +++ b/nodes-lib/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@desci-labs/desci-codex-lib": "^1.0.5", - "@desci-labs/desci-models": "^0.2.3-nodes-lib-preview", + "@desci-labs/desci-models": "^0.2.3-rc1", "axios": "^1.6.5", "dotenv": "^16.4.4", "ethers": "^5.7.2", @@ -454,9 +454,9 @@ } }, "node_modules/@desci-labs/desci-models": { - "version": "0.2.3-nodes-lib-preview", - "resolved": "https://registry.npmjs.org/@desci-labs/desci-models/-/desci-models-0.2.3-nodes-lib-preview.tgz", - "integrity": "sha512-o6dlSPOxnEtNmLBQY7sv5CnPlW0lG9Voz2YRUOjjUc2MiIfEH/vzvOEAVfDoabKZFfsesUPAlIbe9QdXbd82OQ==", + "version": "0.2.3-rc1", + "resolved": "https://registry.npmjs.org/@desci-labs/desci-models/-/desci-models-0.2.3-rc1.tgz", + "integrity": "sha512-FW74CkgfZTNhky0Q6Sk3lCoBZ+Yl5D4KVTTLBv/NG+e8qH9jyT6DVbiXvaThQWZQNulFXJg2UFZm73AVInu3wA==", "dependencies": { "jsonld": "^8.1.1", "schema-dts": "^1.1.2" @@ -5213,9 +5213,9 @@ } }, "@desci-labs/desci-models": { - "version": "0.2.3-nodes-lib-preview", - "resolved": "https://registry.npmjs.org/@desci-labs/desci-models/-/desci-models-0.2.3-nodes-lib-preview.tgz", - "integrity": "sha512-o6dlSPOxnEtNmLBQY7sv5CnPlW0lG9Voz2YRUOjjUc2MiIfEH/vzvOEAVfDoabKZFfsesUPAlIbe9QdXbd82OQ==", + "version": "0.2.3-rc1", + "resolved": "https://registry.npmjs.org/@desci-labs/desci-models/-/desci-models-0.2.3-rc1.tgz", + "integrity": "sha512-FW74CkgfZTNhky0Q6Sk3lCoBZ+Yl5D4KVTTLBv/NG+e8qH9jyT6DVbiXvaThQWZQNulFXJg2UFZm73AVInu3wA==", "requires": { "jsonld": "^8.1.1", "schema-dts": "^1.1.2" diff --git a/nodes-lib/src/codex.ts b/nodes-lib/src/codex.ts index d8ed874f3..02d3babfe 100644 --- a/nodes-lib/src/codex.ts +++ b/nodes-lib/src/codex.ts @@ -11,10 +11,7 @@ import { } from "@desci-labs/desci-codex-lib/dist/src/index.js"; import type { IndexedNodeVersion, PrepublishResponse } from "./api.js"; import { convert0xHexToCid } from "./util/converting.js"; -import { - PUBLISH_PKEY, - CERAMIC_NODE_URL, -} from "./config.js"; +import { PUBLISH_PKEY, CERAMIC_NODE_URL } from "./config.js"; /** * Publish an object modification to Codex. If it's the initial publish, it will be done @@ -29,7 +26,7 @@ import { */ export const codexPublish = async ( prepublishResult: PrepublishResponse, - dpidHistory: IndexedNodeVersion[], + dpidHistory: IndexedNodeVersion[] ): Promise => { console.log("[DEBUG]::CODEX starting publish..."); const ceramic = await authenticatedCeramicClient( @@ -39,7 +36,9 @@ export const codexPublish = async ( // If we know about a stream already, let's assume we backfilled it initially if (prepublishResult.ceramicStream) { - console.log(`[DEBUG]::CODEX publishing to known stream ${prepublishResult.ceramicStream}...`); + console.log( + `[DEBUG]::CODEX publishing to known stream ${prepublishResult.ceramicStream}...` + ); const ro = await updateResearchObject(compose, { id: prepublishResult.ceramicStream, title: prepublishResult.updatedManifest.title, @@ -49,12 +48,14 @@ export const codexPublish = async ( `[DEBUG]::CODEX successfully updated ${ro.streamID} with commit ${ro.commitID}` ); return { streamID: ro.streamID, commitID: ro.commitID }; - }; + } // Otherwise, create a new stream, potentially backfilling it with // earlier updates. if (dpidHistory.length === 0) { - console.log("[DEBUG]::CODEX publishing to new stream..."); + console.log( + "[DEBUG]::CODEX publishing to new stream... (if running locally make sure you run ./nodes/bootstrapCeramic.sh)" + ); const ro = await createResearchObject(compose, { title: prepublishResult.updatedManifest.title || "", manifest: prepublishResult.updatedManifestCid, @@ -66,12 +67,14 @@ export const codexPublish = async ( } else { console.log("[DEBUG]::CODEX backfilling new stream to mirror history..."); const streamID = await backfillNewStream(compose, dpidHistory); - console.log("[DEBUG]::CODEX backfill done, recursing to append latest event..."); + console.log( + "[DEBUG]::CODEX backfill done, recursing to append latest event..." + ); return await codexPublish( { ...prepublishResult, ceramicStream: streamID }, - dpidHistory, + dpidHistory ); - }; + } }; /** @@ -82,55 +85,51 @@ export const codexPublish = async ( * @returns ID of the new stream */ const backfillNewStream = async ( - compose: ComposeClient, - versions: IndexedNodeVersion[] + compose: ComposeClient, + versions: IndexedNodeVersion[] ): Promise => { - console.log( - `[DEBUG]::CODEX starting backfill migration for versions:\n${JSON.stringify( - versions, - undefined, - 2 - )}` - ); - const backfillSequential = async ( - prevPromise: Promise, - nextVersion: IndexedNodeVersion, - ix: number - ): Promise => { - const { streamID, commitID } = await prevPromise; - streamID && - console.log( - `[DEBUG]::CODEX backfilled version ${ix} into ${streamID} with commit ${commitID}` - ); + console.log( + `[DEBUG]::CODEX starting backfill migration for versions:\n${JSON.stringify( + versions, + undefined, + 2 + )}` + ); + const backfillSequential = async ( + prevPromise: Promise, + nextVersion: IndexedNodeVersion, + ix: number + ): Promise => { + const { streamID, commitID } = await prevPromise; + streamID && + console.log( + `[DEBUG]::CODEX backfilled version ${ix} into ${streamID} with commit ${commitID}` + ); - const title = "[BACKFILLED]"; // version.title is the title of the event, e.g. "Published" - const manifest = convert0xHexToCid(nextVersion.cid); - const op = - streamID === "" - ? createResearchObject(compose, { title, manifest }) - : updateResearchObject(compose, { id: streamID, title, manifest }); - return op; - }; + const title = "[BACKFILLED]"; // version.title is the title of the event, e.g. "Published" + const manifest = convert0xHexToCid(nextVersion.cid); + const op = + streamID === "" + ? createResearchObject(compose, { title, manifest }) + : updateResearchObject(compose, { id: streamID, title, manifest }); + return op; + }; - const { streamID } = await versions.reduce( - backfillSequential, - Promise.resolve({ streamID: "", commitID: "" }) - ); - return streamID; + const { streamID } = await versions.reduce( + backfillSequential, + Promise.resolve({ streamID: "", commitID: "" }) + ); + return streamID; }; -export const getPublishedFromCodex = async ( - id: string -) => { +export const getPublishedFromCodex = async (id: string) => { const ceramic = newCeramicClient(CERAMIC_NODE_URL); const compose = newComposeClient({ ceramic }); return await queryResearchObject(compose, id); }; -export const getCodexHistory = async ( - streamID: string -) => { +export const getCodexHistory = async (streamID: string) => { const ceramic = newCeramicClient(CERAMIC_NODE_URL); return await resolveHistory(ceramic, streamID); }; diff --git a/nodes-lib/test/root.spec.ts b/nodes-lib/test/root.spec.ts index 19d7831ae..e425e4ec0 100644 --- a/nodes-lib/test/root.spec.ts +++ b/nodes-lib/test/root.spec.ts @@ -128,7 +128,7 @@ describe("nodes-lib", () => { expect(updatedManifest.authors).toEqual([newContributors[0]]) }); - describe.only("cover image", async () => { + describe("cover image", async () => { test("can be set", async () => { const coverCid = "bafkreidivzimqfqtoqxkrpge6bjyhlvxqs3rhe73owtmdulaxr5do5in7u"; const { document: { manifest: updatedManifest } } = await updateCoverImage(uuid, coverCid);