Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1ea9074
first pass at getting multiple agents working with ad4m-test
jdeepee Mar 8, 2023
3c38d7c
remove old dead functions
jdeepee Mar 8, 2023
2e19c48
push current set of changes for ad4m-test (still a bit broken)
jdeepee Mar 9, 2023
fe93b4c
Added new helper functions to help with agent syncing
fayeed Mar 14, 2023
01aa9a2
link test updated with the new helper
fayeed Mar 14, 2023
da354ae
Added a max retry to agent sync function
fayeed Mar 15, 2023
607b757
Merge branch 'dev' into multiple-agents-ad4m-test-link-langs
jdeepee Mar 28, 2023
3220a90
first pass at link language sync using callbacks in ad4m-test
jdeepee Mar 28, 2023
7cde92f
Merge branch 'dev' into multiple-agents-ad4m-test-link-langs
jdeepee Mar 30, 2023
5a1b4a0
Merge branch 'dev' into multiple-agents-ad4m-test-link-langs
jdeepee Mar 30, 2023
f6ba88f
have executor and test runner use local bootstrap languages
jdeepee Mar 30, 2023
a78b4a6
local-language added
fayeed Mar 31, 2023
922e27a
local neighbourhood language added
fayeed Mar 31, 2023
3cefd0e
note ipfs language added
fayeed Mar 31, 2023
01e2d16
get-language script updated
fayeed Mar 31, 2023
53733a9
removed post install command updated
fayeed Mar 31, 2023
2d10e86
.npmignore updated
fayeed Mar 31, 2023
bf5b6cf
remove node-sass
jdeepee Mar 31, 2023
68254ab
dont error missing tests on new languages
jdeepee Mar 31, 2023
c61ad92
have executor use the new local languages
jdeepee Mar 31, 2023
20fd696
copy languages in test-runner after build
jdeepee Mar 31, 2023
6bd6452
remove icon rollup on ipfs lang
jdeepee Mar 31, 2023
b7a6320
use local ad4m for new languages
jdeepee Mar 31, 2023
22743f8
add new language to build-languages script
jdeepee Mar 31, 2023
bbc4277
add missing local-language build
jdeepee Mar 31, 2023
ea96670
update ipfs-core-types
jdeepee Mar 31, 2023
76833ae
use consistent typescript versions & get build working correctly
jdeepee Mar 31, 2023
d9f654c
remove get-languages from post build since it turbo is not running ta…
jdeepee Mar 31, 2023
bc012bf
update rollup config for local language
fayeed Apr 3, 2023
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
4,676 changes: 4,676 additions & 0 deletions test-runner/example/languages/link-lang.js

Large diffs are not rendered by default.

4,609 changes: 0 additions & 4,609 deletions test-runner/example/languages/social-context.js

This file was deleted.

78 changes: 49 additions & 29 deletions test-runner/example/link.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { spawnLinkAgent } = require('@perspect3vism/ad4m-test/helpers')
const { spawnLinkAgent, sleep } = require('@perspect3vism/ad4m-test/helpers')

describe("Link", () => {
it("Create Link", async () => {
Expand All @@ -16,49 +16,69 @@ describe("Link", () => {
expect(all1[0].data.source).toBe(link.data.source)
expect(all1[0].data.predicate).toBe(link.data.predicate)
expect(all1[0].data.target).toBe(link.data.target)

const agent2 = await spawnLinkAgent();

await sleep(4000);

const all2 = await agent2.queryLinks({});
expect(all2.length).toBe(1)
// expect(all2[0].data.source).toBe(link.data.source)
// expect(all2[0].data.predicate).toBe(link.data.predicate)
// expect(all2[0].data.target).toBe(link.data.target)

// const link2 = await agent.addLink({source:"root2", predicate: "soic://test", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})

// await sleep(2000);

// const all3 = await agent.queryLinks({});
// expect(all3.length).toBe(2)

// const all4 = await agent2.queryLinks({});
// expect(all4.length).toBe(2)
});

it("Remove Link", async () => {
const agent = await spawnLinkAgent();
// it("Remove Link", async () => {
// const agent = await spawnLinkAgent();

const all = await agent.queryLinks({});
// const all = await agent.queryLinks({});

expect(all.length).toBe(0)
const link = await agent.addLink({source:"root", predicate: "soic://test", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})
// expect(all.length).toBe(0)
// const link = await agent.addLink({source:"root", predicate: "soic://test", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})

const all1 = await agent.queryLinks({});
// const all1 = await agent.queryLinks({});

expect(all1.length).toBe(1)
// expect(all1.length).toBe(1)

const removedlink = await agent.removeLink(link)
// const removedlink = await agent.removeLink(link)

const all2 = await agent.queryLinks({});
// const all2 = await agent.queryLinks({});

expect(all2.length).toBe(0)
});
// expect(all2.length).toBe(0)
// });

it("Update Link", async () => {
const agent = await spawnLinkAgent();
// it("Update Link", async () => {
// const agent = await spawnLinkAgent();

const all = await agent.queryLinks({});
// const all = await agent.queryLinks({});

expect(all.length).toBe(0)
const link = await agent.addLink({source:"root", predicate: "soic://test", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})
// expect(all.length).toBe(0)
// const link = await agent.addLink({source:"root", predicate: "soic://test", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})

const all1 = await agent.queryLinks({});
// const all1 = await agent.queryLinks({});

expect(all1.length).toBe(1)
expect(all1[0].data.source).toBe(link.data.source)
expect(all1[0].data.predicate).toBe(link.data.predicate)
expect(all1[0].data.target).toBe(link.data.target)
// expect(all1.length).toBe(1)
// expect(all1[0].data.source).toBe(link.data.source)
// expect(all1[0].data.predicate).toBe(link.data.predicate)
// expect(all1[0].data.target).toBe(link.data.target)

const newLink = await agent.updateLink(link, {source:"root", predicate: "soic://test1", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})
// const newLink = await agent.updateLink(link, {source:"root", predicate: "soic://test1", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})

const all2 = await agent.queryLinks({});
// const all2 = await agent.queryLinks({});

expect(all2.length).toBe(1)
expect(all2[0].data.source).toBe(newLink.data.source)
expect(all2[0].data.predicate).toBe(newLink.data.predicate)
expect(all2[0].data.target).toBe(newLink.data.target)
});
// expect(all2.length).toBe(1)
// expect(all2[0].data.source).toBe(newLink.data.source)
// expect(all2[0].data.predicate).toBe(newLink.data.predicate)
// expect(all2[0].data.target).toBe(newLink.data.target)
// });
})
2 changes: 1 addition & 1 deletion test-runner/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test-expression": "ad4m-test --test ./expression.test.js --bundle languages/note-ipfs.js --meta '{\"name\":\"note-ipfs\",\"description\":\"Language for storing data on IPFS\",\"sourceCodeLink\":\"https://github.com/perspect3vism/lang-note-ipfs\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'",
"test-link": "ad4m-test --test ./link.test.js --bundle \"languages/social-context.js\" --meta '{\"name\":\"social-context\",\"description\":\"Shortform expression for flux application\",\"sourceCodeLink\":\"https://github.com/juntofoundation/ad4m-languages\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'"
"test-link": "ad4m-test --test ./link.test.js --bundle \"languages/link-lang.js\" --meta '{\"name\":\"perspective-diff-sync\",\"description\":\"Holochain based language for sharing Perspectives\",\"sourceCodeLink\":\"https://github.com/perspect3vism/perspective-diff-sync\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'"
},
"dependencies": {
"@perspect3vism/ad4m-test": "../"
Expand Down
2 changes: 1 addition & 1 deletion test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:util": "browserify build/client.js --standalone Bundle -p esmify > public/client.js",
"test": "yarn run test-expression",
"test-expression": "node build/cli.js --test ./example/expression.test.js --bundle \"example/languages/note-ipfs.js\" --meta '{\"name\":\"note-ipfs\",\"description\":\"IPFS based language for storing data\",\"sourceCodeLink\":\"https://github.com/perspect3vism/note-ipfs\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'",
"test-link": "node build/cli.js --languageType linkLanguage --test ./example/link.test.js --bundle \"example/languages/social-context.js\" --meta '{\"name\":\"social-context\",\"description\":\"Shortform expression for flux application\",\"sourceCodeLink\":\"https://github.com/juntofoundation/ad4m-languages\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'",
"test-link": "node build/cli.js --test ./example/link.test.js --bundle \"example/languages/link-lang.js\" --meta '{\"name\":\"perspective-diff-sync\",\"description\":\"Holochain based language for sharing Perspectives\",\"sourceCodeLink\":\"https://github.com/perspect3vism/perspective-diff-sync\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'",
"test-ui": "node build/cli.js --ui --bundle \"example/languages/note-ipfs.js\" --meta '{\"name\":\"note-ipfs\",\"description\":\"Shortform expression for flux application\",\"sourceCodeLink\":\"https://github.com/juntofoundation/ad4m-languages\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'",
"ad4m-test": "./build/cli.js",
"postinstall": "node ./scripts/get-builtin-test-langs.js"
Expand Down
9 changes: 3 additions & 6 deletions test-runner/scripts/get-builtin-test-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ const languages = {
bundle: "https://github.com/perspect3vism/agent-language/releases/download/0.2.0/bundle.js",
},
languages: {
targetDnaName: "languages",
bundle: "https://github.com/perspect3vism/local-language-persistence/releases/download/0.0.1/bundle.js",
bundle: "https://github.com/perspect3vism/local-language-persistence/releases/download/0.0.5/bundle.js",
},
"neighbourhood-store": {
targetDnaName: "neighbourhood-store",
//dna: "https://github.com/perspect3vism/neighbourhood-language/releases/download/0.0.2/neighbourhood-store.dna",
bundle: "https://github.com/perspect3vism/local-neighbourhood-persistence/releases/download/0.0.1/bundle.js",
bundle: "https://github.com/perspect3vism/local-neighbourhood-persistence/releases/download/0.0.2/bundle.js",
},
"perspective-diff-sync": {
bundle: "https://github.com/perspect3vism/perspective-diff-sync/releases/download/v0.2.2-test/bundle.js",
bundle: "https://github.com/perspect3vism/perspective-diff-sync/releases/download/v0.3.3/bundle.js",
},
"note-ipfs": {
bundle: "https://github.com/perspect3vism/lang-note-ipfs/releases/download/0.0.4/bundle.js",
Expand Down
69 changes: 35 additions & 34 deletions test-runner/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ async function installLanguage(child: any, binaryPath: string, bundle: string, m
const createdNeighbourhood = await ad4mClient.neighbourhood.publishFromPerspective(perspective, templateLanguage.address, JSON.parse('{"links":[]}'));
logger.info(`Neighbourhood created: `, createdNeighbourhood)

global.neighnourhood = createdNeighbourhood;
global.neighbourhood = createdNeighbourhood;

neighbourhood = createdNeighbourhood;
} else {
const joinedPerspectve = await ad4mClient.neighbourhood.joinFromUrl(global.neighnourhood);
logger.info(`Neighbouhood joined: `, joinedPerspectve)
const joinedPerspectve = await ad4mClient.neighbourhood.joinFromUrl(global.neighbourhood);
logger.info(`Neighbourhood joined: `, joinedPerspectve)

global.perspective = joinedPerspectve.uuid;

perspective = joinedPerspectve.uuid;

global.neighnourhood = global.neighnourhood;
global.neighbourhood = global.neighbourhood;

neighbourhood = global.neighnourhood;
neighbourhood = global.neighbourhood;
}
}

Expand All @@ -85,15 +85,7 @@ async function installLanguage(child: any, binaryPath: string, bundle: string, m
return {
languageAddress,
perspective,
neighbourhood,
clear: () => {
kill(child.pid!, async () => {
await findAndKillProcess('holochain')
await findAndKillProcess('lair-keystore')
deleteAllAd4mData(relativePath);
resolve(null);
})
}
neighbourhood
}
}
} catch (err) {
Expand All @@ -103,6 +95,12 @@ async function installLanguage(child: any, binaryPath: string, bundle: string, m

}

interface StartServerResponse {
languageAddress?: string;
perspective?: string;
neighbourhood: string;
clear: () => void;
}

export function startServer(relativePath: string, bundle: string, meta: string, languageType: string, port: number, defaultLangPath?: string, callback?: any): Promise<any> {
return new Promise(async (resolve, reject) => {
Expand All @@ -115,26 +113,13 @@ export function startServer(relativePath: string, bundle: string, meta: string,
binaryPath = path.join(ad4mDataDirectory(`.ad4m-test`), 'binary', `ad4m`);
}

await findAndKillProcess('holochain')
//await findAndKillProcess('holochain')
const seedFile = path.join(__dirname, '../bootstrapSeed.json')
const agentSeedFile = path.join(__dirname, `../${relativePath}-bootstrapSeed.json`);


const tempSeedFile = JSON.parse(fs.readFileSync(seedFile).toString())

if (!fs.pathExistsSync(`${tempSeedFile.languageLanguageSettings.storagePath}-${relativePath}`)) {
fs.removeSync(`${tempSeedFile.languageLanguageSettings.storagePath}-${relativePath}`)
fs.mkdirSync(`${tempSeedFile.languageLanguageSettings.storagePath}-${relativePath}`)
}
if (!fs.pathExistsSync(`${tempSeedFile.neighbourhoodLanguageSettings.storagePath}-${relativePath}`)) {
fs.removeSync(`${tempSeedFile.neighbourhoodLanguageSettings.storagePath}-${relativePath}`)
fs.mkdirSync(`${tempSeedFile.neighbourhoodLanguageSettings.storagePath}-${relativePath}`)
}

fs.copySync(tempSeedFile.languageLanguageSettings.storagePath, `${tempSeedFile.languageLanguageSettings.storagePath}-${relativePath}`, { overwrite: true })

tempSeedFile.languageLanguageSettings.storagePath = `${tempSeedFile.languageLanguageSettings.storagePath}-${relativePath}`
tempSeedFile.neighbourhoodLanguageSettings.storagePath = `${tempSeedFile.neighbourhoodLanguageSettings.storagePath}-${relativePath}`
fs.writeFileSync(agentSeedFile, JSON.stringify(tempSeedFile));

execSync(`${binaryPath} init --dataPath ${relativePath} --networkBootstrapSeed ${agentSeedFile} --overrideConfig`, { encoding: 'utf-8' });
Expand All @@ -144,14 +129,16 @@ export function startServer(relativePath: string, bundle: string, meta: string,
let child: ChildProcessWithoutNullStreams;

const ipfsPort = await getPort({port: 14000});
const holochainAppPort = await getPort({port: 15000});
const holochainAdminPort = await getPort({port: 16000});

if (defaultLangPath) {
child = spawn(`${binaryPath}`, ['serve', '--reqCredential', global.ad4mToken, '--dataPath', relativePath, '--port', port.toString(), '--ipfsPort', ipfsPort.toString(),'--languageLanguageOnly', 'false'])
child = spawn(`${binaryPath}`, ['serve', '--reqCredential', global.ad4mToken, '--dataPath', relativePath, '--port', port.toString(), '--ipfsPort', ipfsPort.toString(),'--languageLanguageOnly', 'false', '--hcAppPort', holochainAppPort.toString(), '--hcAdminPort', holochainAdminPort.toString()])
} else {
child = spawn(`${binaryPath}`, ['serve', '--reqCredential', global.ad4mToken, '--dataPath', relativePath, '--port', port.toString(), '--ipfsPort', ipfsPort.toString(), '--languageLanguageOnly', 'false'])
child = spawn(`${binaryPath}`, ['serve', '--reqCredential', global.ad4mToken, '--dataPath', relativePath, '--port', port.toString(), '--ipfsPort', ipfsPort.toString(), '--languageLanguageOnly', 'false', '--hcAppPort', holochainAppPort.toString(), '--hcAdminPort', holochainAdminPort.toString()])
}

const logFile = fs.createWriteStream(path.join(process.cwd(), 'ad4m-test.log'))
const logFile = fs.createWriteStream(path.join(process.cwd(), `ad4m-test-agent-${global.agents.length}.log`))

child.stdout.on('data', async (data) => {
logFile.write(data)
Expand All @@ -171,9 +158,23 @@ export function startServer(relativePath: string, bundle: string, meta: string,
}

if (data.toString().includes('AD4M init complete')) {
const clear = await installLanguage(child, binaryPath, bundle, meta, languageType, resolve, port, callback);

resolve(clear);
await installLanguage(child, binaryPath, bundle, meta, languageType, resolve, port, callback);

const clear = () => {
kill(child.pid!, async () => {
await findAndKillProcess('holochain')
await findAndKillProcess('lair-keystore')
deleteAllAd4mData(relativePath);
resolve(null);
})
};

resolve({
perspective: perspective,
languageAddress: languageAddress,
neighbourhood: neighbourhood,
clear
} as StartServerResponse);
}
});

Expand Down
2 changes: 1 addition & 1 deletion test-runner/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module globalThis {
var hideLogs: boolean;
var languageAddress: string;
var perspective: string;
var neighnourhood: string;
var neighbourhood: string;
var relativePath: string;
var ad4mHostVersion: string;
var ad4mToken: string;
Expand Down
17 changes: 15 additions & 2 deletions test-runner/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Ad4mClient, Link, LinkExpression, LinkQuery } from "@perspect3vism/ad4m
import getPort from "get-port";
import { startServer } from "../cli.js";
import { buildAd4mClient } from "../client.js";
import fs from "fs";

class AgentLinkClass {
client: Ad4mClient
Expand Down Expand Up @@ -101,9 +102,17 @@ export async function spawnLinkAgent() {

const relativePath = `ad4m-test-${global.agents.length}`;

const { languageAddress, clear, perspective, neighbourhood } = await startServer(relativePath, bundle!, meta!, 'linkLanguage', port, defaultLangPath);

let isJoining = global.agents.length > 0;
let { languageAddress, clear, perspective, neighbourhood } = await startServer(relativePath, bundle!, meta!, 'linkLanguage', port, defaultLangPath);

const client = await buildAd4mClient(port);

if (isJoining) {
const previousAgent = global.agents[global.agents.length - 1];
const neighbourhood = previousAgent.neighbourhood!;

console.log(`Agent number ${global.agents.length}, is joining neighbourhood: `, neighbourhood);
}

const agent = new AgentLinkClass(client, languageAddress, perspective, neighbourhood);

Expand All @@ -118,4 +127,8 @@ export async function spawnLinkAgent() {
})

return agent;
}

export function sleep(ms: number): Promise<any> {
return new Promise((resolve) => setTimeout(resolve, ms));
}