Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hubsmoke committed Feb 20, 2024
1 parent ca80eea commit ef83634
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion bootstrapCeramic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions desci-server/src/services/nodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion nodes-lib/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=

Expand Down
14 changes: 7 additions & 7 deletions nodes-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 48 additions & 49 deletions nodes-lib/src/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +26,7 @@ import {
*/
export const codexPublish = async (
prepublishResult: PrepublishResponse,
dpidHistory: IndexedNodeVersion[],
dpidHistory: IndexedNodeVersion[]
): Promise<NodeIDs> => {
console.log("[DEBUG]::CODEX starting publish...");
const ceramic = await authenticatedCeramicClient(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
);
};
}
};

/**
Expand All @@ -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<string> => {
console.log(
`[DEBUG]::CODEX starting backfill migration for versions:\n${JSON.stringify(
versions,
undefined,
2
)}`
);
const backfillSequential = async (
prevPromise: Promise<NodeIDs>,
nextVersion: IndexedNodeVersion,
ix: number
): Promise<NodeIDs> => {
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<NodeIDs>,
nextVersion: IndexedNodeVersion,
ix: number
): Promise<NodeIDs> => {
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);
};
2 changes: 1 addition & 1 deletion nodes-lib/test/root.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ef83634

Please sign in to comment.