From 4bf197e0d1fb24cab3221e66d3cab068f6011749 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Tue, 21 Jan 2025 22:38:08 -0500 Subject: [PATCH 01/10] fix graph test --- packages/cli/package.json | 1 - packages/cli/src/commands/binary-install.d.ts | 1 - packages/cli/src/commands/test.ts | 60 +++++++++++++------ pnpm-lock.yaml | 36 ++--------- 4 files changed, 47 insertions(+), 51 deletions(-) delete mode 100644 packages/cli/src/commands/binary-install.d.ts diff --git a/packages/cli/package.json b/packages/cli/package.json index 6fd6dbd3a..fbd723ccd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -39,7 +39,6 @@ "@pinax/graph-networks-registry": "^0.6.5", "@whatwg-node/fetch": "^0.10.1", "assemblyscript": "0.19.23", - "binary-install": "^1.1.0", "chokidar": "4.0.1", "debug": "4.3.7", "docker-compose": "1.1.0", diff --git a/packages/cli/src/commands/binary-install.d.ts b/packages/cli/src/commands/binary-install.d.ts deleted file mode 100644 index 6cbce6ef3..000000000 --- a/packages/cli/src/commands/binary-install.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'binary-install'; diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 9fb698bee..e4a9e926a 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -1,13 +1,14 @@ import { exec, spawn } from 'node:child_process'; +import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; -import { Binary } from 'binary-install'; +import { pipeline } from 'node:stream/promises'; +import { fileURLToPath } from 'node:url'; import { filesystem, patching, print, system } from 'gluegun'; import yaml from 'js-yaml'; import semver from 'semver'; import { Args, Command, Flags } from '@oclif/core'; import { GRAPH_CLI_SHARED_HEADERS } from '../constants.js'; -import fetch from '../fetch.js'; export default class TestCommand extends Command { static description = 'Runs rust binary for subgraph testing.'; @@ -144,7 +145,6 @@ async function runBinary( }, ) { const coverageOpt = opts.coverage; - const forceOpt = opts.force; const logsOpt = opts.logs; const versionOpt = opts.version; const latestVersion = opts.latestVersion; @@ -152,24 +152,50 @@ async function runBinary( const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt); - const url = `https://github.com/LimeChain/matchstick/releases/download/${ - versionOpt || latestVersion - }/${platform}`; + const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`; + const binDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'node_modules', '.bin'); + const binPath = path.join(binDir, `matchstick-${platform}`); if (logsOpt) { this.log(`Download link: ${url}`); + this.log(`Binary path: ${binPath}`); } - const binary = new Binary(platform, url, versionOpt || latestVersion); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - forceOpt ? await binary.install(true) : await binary.install(false); - const args = []; + try { + if (!fs.existsSync(binPath)) { + this.log(`Downloading matchstick binary: ${url}`); + await fs.promises.mkdir(binDir, { recursive: true }); + const response = await fetch(url); + if (!response.ok) throw new Error(`Failed to download binary: ${response.statusText}`); + if (!response.body) throw new Error('No response body received'); + + const fileStream = fs.createWriteStream(binPath); + await pipeline(response.body, fileStream); + await fs.promises.chmod(binPath, '755'); + } - if (coverageOpt) args.push('-c'); - if (recompileOpt) args.push('-r'); - if (datasource) args.push(datasource); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - args.length > 0 ? binary.run(...args) : binary.run(); + const args = []; + if (coverageOpt) args.push('-c'); + if (recompileOpt) args.push('-r'); + if (datasource) args.push(datasource); + + const child = spawn(binPath, args, { stdio: 'inherit' }); + await new Promise((resolve, reject) => { + child.on('close', code => { + if (code === 0) { + resolve(code); + } else { + reject(new Error(`Process exited with code ${code}`)); + } + }); + child.on('error', reject); + }); + } catch (e) { + this.warn(`Failed to run matchstick binary: ${e.message}`); + this.warn('Recommendation: Use the -d flag to run tests in Docker instead:'); + this.warn(' graph test -d\n'); + this.error('Failed to run matchstick tests', { exit: 1 }); + } } async function getPlatform( @@ -283,10 +309,6 @@ async function runDocker( const latestVersion = opts.latestVersion; const recompileOpt = opts.recompile; - // Remove binary-install binaries, because docker has permission issues - // when building the docker images - filesystem.remove('./node_modules/binary-install/bin'); - // Get current working directory const current_folder = filesystem.cwd(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecdbb63ea..1f8bac320 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -257,15 +257,12 @@ importers: assemblyscript: specifier: 0.19.23 version: 0.19.23 - binary-install: - specifier: ^1.1.0 - version: 1.1.0(debug@4.3.7) chokidar: specifier: 4.0.1 version: 4.0.1 debug: specifier: 4.3.7 - version: 4.3.7(supports-color@5.5.0) + version: 4.3.7(supports-color@8.1.1) docker-compose: specifier: 1.1.0 version: 1.1.0 @@ -4427,9 +4424,6 @@ packages: axios@0.21.4: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} - axios@0.26.1: - resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} - axios@1.7.9: resolution: {integrity: sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==} @@ -4527,10 +4521,6 @@ packages: resolution: {integrity: sha512-v7ms6N/H7iciuk6QInon3/n2mu7oRX+6knJ9xFPsJ3rQePgAqcR3CRTwUheFd8SLbiq4LL7Z4G/44L9zscdt9A==} engines: {node: '>=10'} - binary-install@1.1.0: - resolution: {integrity: sha512-rkwNGW+3aQVSZoD0/o3mfPN6Yxh3Id0R/xzTVBVVpGNlVz8EGwusksxRlbk/A5iKTZt9zkMn3qIqmAt3vpfbzg==} - engines: {node: '>=10'} - binaryen@101.0.0-nightly.20210723: resolution: {integrity: sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA==} hasBin: true @@ -15376,12 +15366,6 @@ snapshots: transitivePeerDependencies: - debug - axios@0.26.1(debug@4.3.7): - dependencies: - follow-redirects: 1.15.9(debug@4.3.7) - transitivePeerDependencies: - - debug - axios@1.7.9: dependencies: follow-redirects: 1.15.9(debug@4.3.7) @@ -15573,14 +15557,6 @@ snapshots: transitivePeerDependencies: - debug - binary-install@1.1.0(debug@4.3.7): - dependencies: - axios: 0.26.1(debug@4.3.7) - rimraf: 3.0.2 - tar: 6.2.1 - transitivePeerDependencies: - - debug - binaryen@101.0.0-nightly.20210723: {} binaryen@102.0.0-nightly.20211028: {} @@ -17494,7 +17470,7 @@ snapshots: follow-redirects@1.15.9(debug@4.3.7): optionalDependencies: - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) for-each@0.3.3: dependencies: @@ -18063,7 +18039,7 @@ snapshots: http-call@5.3.0: dependencies: content-type: 1.0.5 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) is-retry-allowed: 1.2.0 is-stream: 2.0.1 parse-json: 4.0.0 @@ -19666,7 +19642,7 @@ snapshots: async-retry: 1.3.3 chalk: 4.1.2 change-case: 4.1.2 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) ejs: 3.1.10 find-yarn-workspace-root: 2.0.0 fs-extra: 8.1.0 @@ -21767,7 +21743,7 @@ snapshots: vite-node@2.1.8(@types/node@22.10.1): dependencies: cac: 6.7.14 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) es-module-lexer: 1.5.4 pathe: 1.1.2 vite: 5.4.11(@types/node@22.10.1) @@ -21821,7 +21797,7 @@ snapshots: '@vitest/spy': 2.1.8 '@vitest/utils': 2.1.8 chai: 5.1.2 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) expect-type: 1.1.0 magic-string: 0.30.14 pathe: 1.1.2 From 88ea87453b6853ef23769c63aa4c890fcb463446 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Tue, 21 Jan 2025 23:29:55 -0500 Subject: [PATCH 02/10] refactor binary exec --- packages/cli/src/commands/test.ts | 44 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index e4a9e926a..93a0c4b23 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -1,4 +1,5 @@ import { exec, spawn } from 'node:child_process'; +import events from 'node:events'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; @@ -161,40 +162,35 @@ async function runBinary( this.log(`Binary path: ${binPath}`); } - try { - if (!fs.existsSync(binPath)) { - this.log(`Downloading matchstick binary: ${url}`); + if (!fs.existsSync(binPath)) { + this.log(`Downloading matchstick binary: ${url}`); + try { await fs.promises.mkdir(binDir, { recursive: true }); const response = await fetch(url); - if (!response.ok) throw new Error(`Failed to download binary: ${response.statusText}`); + if (!response.ok) throw new Error(`Status: ${response.statusText}`); if (!response.body) throw new Error('No response body received'); const fileStream = fs.createWriteStream(binPath); await pipeline(response.body, fileStream); await fs.promises.chmod(binPath, '755'); + } catch (e) { + this.warn(`Failed to download matchstick binary: ${e.message}`); + this.warn('Consider using -d flag to run tests in Docker instead:'); + this.warn(' graph test -d'); + process.exit(1); } + } - const args = []; - if (coverageOpt) args.push('-c'); - if (recompileOpt) args.push('-r'); - if (datasource) args.push(datasource); + const args = []; + if (coverageOpt) args.push('-c'); + if (recompileOpt) args.push('-r'); + if (datasource) args.push(datasource); - const child = spawn(binPath, args, { stdio: 'inherit' }); - await new Promise((resolve, reject) => { - child.on('close', code => { - if (code === 0) { - resolve(code); - } else { - reject(new Error(`Process exited with code ${code}`)); - } - }); - child.on('error', reject); - }); - } catch (e) { - this.warn(`Failed to run matchstick binary: ${e.message}`); - this.warn('Recommendation: Use the -d flag to run tests in Docker instead:'); - this.warn(' graph test -d\n'); - this.error('Failed to run matchstick tests', { exit: 1 }); + const child = spawn(binPath, args, { stdio: 'inherit' }); + const [code] = await events.once(child, 'exit'); + if (code !== 0) { + this.warn('Matchstick tests failed'); + process.exit(1); } } From ec5d646822e1053bdc53e6e78d6717570c403915 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Tue, 21 Jan 2025 23:40:34 -0500 Subject: [PATCH 03/10] rephrase error --- packages/cli/src/commands/test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 93a0c4b23..f98b54335 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -174,8 +174,8 @@ async function runBinary( await pipeline(response.body, fileStream); await fs.promises.chmod(binPath, '755'); } catch (e) { - this.warn(`Failed to download matchstick binary: ${e.message}`); - this.warn('Consider using -d flag to run tests in Docker instead:'); + this.warn(`Failed to download matchstick binary for your platform: ${e.message}`); + this.warn('Consider using -d flag to run it in Docker instead:'); this.warn(' graph test -d'); process.exit(1); } From e593c9ff596b0a748e3fc553adbb1d2e667b6518 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Tue, 21 Jan 2025 23:40:58 -0500 Subject: [PATCH 04/10] future-proof Mx cpu detection --- packages/cli/src/commands/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index f98b54335..c4acf0ed4 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -202,7 +202,7 @@ async function getPlatform( const type = os.type(); const arch = os.arch(); const cpuCore = os.cpus()[0]; - const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|M3|M4|processor)/.test(cpuCore.model); + const isAppleSilicon = arch === 'arm64' && /Apple (M[0-9]|processor)/.test(cpuCore.model); const linuxInfo = type === 'Linux' ? await getLinuxInfo.bind(this)() : {}; const linuxDistro = linuxInfo.name; const release = linuxInfo.version || os.release(); From 80c1c7d2298a77aae4f861dd9699d61d3991779f Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Tue, 21 Jan 2025 23:43:43 -0500 Subject: [PATCH 05/10] changeset --- .changeset/afraid-cycles-act.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/afraid-cycles-act.md diff --git a/.changeset/afraid-cycles-act.md b/.changeset/afraid-cycles-act.md new file mode 100644 index 000000000..e9bfcab04 --- /dev/null +++ b/.changeset/afraid-cycles-act.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +fix bug with graph test #1904 From 2b9dfc98e71e4f2da49bfe10691e348c7cc40a15 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 22 Jan 2025 19:55:03 +0000 Subject: [PATCH 06/10] chore(dependencies): updated changesets for modified dependencies --- .changeset/@graphprotocol_graph-cli-1914-dependencies.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/@graphprotocol_graph-cli-1914-dependencies.md diff --git a/.changeset/@graphprotocol_graph-cli-1914-dependencies.md b/.changeset/@graphprotocol_graph-cli-1914-dependencies.md new file mode 100644 index 000000000..5e220d3bd --- /dev/null +++ b/.changeset/@graphprotocol_graph-cli-1914-dependencies.md @@ -0,0 +1,5 @@ +--- +"@graphprotocol/graph-cli": patch +--- +dependencies updates: + - Removed dependency [`binary-install@^1.1.0` ↗︎](https://www.npmjs.com/package/binary-install/v/1.1.0) (from `dependencies`) From 3ce1718007e4189729cdb2379c00b8fd5d2e5512 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Thu, 23 Jan 2025 17:21:43 -0500 Subject: [PATCH 07/10] handle unknown platform better --- packages/cli/src/commands/test.ts | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index c4acf0ed4..732b25c30 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -150,21 +150,22 @@ async function runBinary( const versionOpt = opts.version; const latestVersion = opts.latestVersion; const recompileOpt = opts.recompile; + let binPath = ''; - const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt); + try { + const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt); - const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`; - const binDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'node_modules', '.bin'); - const binPath = path.join(binDir, `matchstick-${platform}`); + const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`; + const binDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'node_modules', '.bin'); + binPath = path.join(binDir, `matchstick-${platform}`); - if (logsOpt) { - this.log(`Download link: ${url}`); - this.log(`Binary path: ${binPath}`); - } + if (logsOpt) { + this.log(`Download link: ${url}`); + this.log(`Binary path: ${binPath}`); + } - if (!fs.existsSync(binPath)) { - this.log(`Downloading matchstick binary: ${url}`); - try { + if (!fs.existsSync(binPath)) { + this.log(`Downloading matchstick binary: ${url}`); await fs.promises.mkdir(binDir, { recursive: true }); const response = await fetch(url); if (!response.ok) throw new Error(`Status: ${response.statusText}`); @@ -173,12 +174,12 @@ async function runBinary( const fileStream = fs.createWriteStream(binPath); await pipeline(response.body, fileStream); await fs.promises.chmod(binPath, '755'); - } catch (e) { - this.warn(`Failed to download matchstick binary for your platform: ${e.message}`); - this.warn('Consider using -d flag to run it in Docker instead:'); - this.warn(' graph test -d'); - process.exit(1); } + } catch (e) { + this.warn(`Failed to download matchstick binary for your platform: ${e.message}`); + this.warn('Consider using -d flag to run it in Docker instead:'); + this.warn(' graph test -d'); + process.exit(1); } const args = []; From 95445894e3b1900b7e10a5204ba4de9ce7c08605 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Thu, 23 Jan 2025 18:40:50 -0500 Subject: [PATCH 08/10] show error in stderr --- packages/cli/src/commands/test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 732b25c30..22911ce18 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -176,10 +176,11 @@ async function runBinary( await fs.promises.chmod(binPath, '755'); } } catch (e) { - this.warn(`Failed to download matchstick binary for your platform: ${e.message}`); - this.warn('Consider using -d flag to run it in Docker instead:'); - this.warn(' graph test -d'); - process.exit(1); + this.error(` +Failed to download matchstick binary for your platform: ${e.message} +Consider using -d flag to run it in Docker instead: + graph test -d +`); } const args = []; @@ -190,8 +191,7 @@ async function runBinary( const child = spawn(binPath, args, { stdio: 'inherit' }); const [code] = await events.once(child, 'exit'); if (code !== 0) { - this.warn('Matchstick tests failed'); - process.exit(1); + this.error('Matchstick failed'); } } From 35be6b51c173ad45c64771904226037d2c1e33f6 Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Thu, 23 Jan 2025 18:41:00 -0500 Subject: [PATCH 09/10] allow ubuntu-24 --- packages/cli/src/commands/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 22911ce18..90c7d0074 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -227,7 +227,7 @@ async function getPlatform( } return 'binary-macos-12'; } - if (type === 'Linux' && majorVersion === 22) { + if (type === 'Linux' && (majorVersion === 22 || majorVersion === 24)) { return 'binary-linux-22'; } } else { From 7ec9ecdeca76e50b541dd2f4e75bedd2101c0e9f Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Thu, 23 Jan 2025 19:26:50 -0500 Subject: [PATCH 10/10] change error message --- packages/cli/src/commands/test.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 90c7d0074..d8e6fba03 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -176,11 +176,10 @@ async function runBinary( await fs.promises.chmod(binPath, '755'); } } catch (e) { - this.error(` -Failed to download matchstick binary for your platform: ${e.message} -Consider using -d flag to run it in Docker instead: - graph test -d -`); + this.error( + `Failed to get matchstick binary: ${e.message}\nConsider using -d flag to run it in Docker instead:\n graph test -d`, + { exit: 1 }, + ); } const args = []; @@ -191,7 +190,7 @@ Consider using -d flag to run it in Docker instead: const child = spawn(binPath, args, { stdio: 'inherit' }); const [code] = await events.once(child, 'exit'); if (code !== 0) { - this.error('Matchstick failed'); + this.error('Matchstick failed', { exit: 1 }); } }