From 699d9e1576d915565274eb4bad6e99a80706e38f Mon Sep 17 00:00:00 2001 From: Chip Morningstar Date: Sun, 1 Oct 2023 00:48:22 -0700 Subject: [PATCH] refactor: move benchmarkerator and test support code into their own packages --- .github/workflows/test-all-packages.yml | 6 ++ packages/agoric-cli/src/sdk-package-names.js | 2 + .../doc}/benchmarkerator.md | 7 +- packages/benchmark/package.json | 66 +++++++++++++++++++ .../src}/benchmarkerator.js | 15 ++++- packages/benchmark/tsconfig.json | 17 +++++ packages/boot/package.json | 2 + .../bench-vaults-performance.js | 6 +- .../test/bootstrapTests/benchmark-vaults.js | 2 +- .../boot/test/bootstrapTests/liquidation.ts | 4 +- .../test/bootstrapTests/test-demo-config.ts | 2 +- .../test/bootstrapTests/test-vats-restart.ts | 7 +- .../bootstrapTests/test-vaults-integration.ts | 6 +- .../bootstrapTests/test-vaults-upgrade.ts | 6 +- .../test/bootstrapTests/test-zcf-upgrade.ts | 9 ++- .../boot/test/upgrading/test-upgrade-vats.js | 2 +- packages/test-support/package.json | 51 ++++++++++++++ .../src}/drivers.ts | 0 packages/test-support/src/index.js | 2 + .../src}/supports.ts | 3 +- packages/test-support/tsconfig.json | 14 ++++ 21 files changed, 203 insertions(+), 26 deletions(-) rename packages/{boot/test/bootstrapTests => benchmark/doc}/benchmarkerator.md (96%) create mode 100644 packages/benchmark/package.json rename packages/{boot/test/bootstrapTests => benchmark/src}/benchmarkerator.js (97%) create mode 100644 packages/benchmark/tsconfig.json create mode 100644 packages/test-support/package.json rename packages/{boot/test/bootstrapTests => test-support/src}/drivers.ts (100%) create mode 100644 packages/test-support/src/index.js rename packages/{boot/test/bootstrapTests => test-support/src}/supports.ts (99%) create mode 100644 packages/test-support/tsconfig.json diff --git a/.github/workflows/test-all-packages.yml b/.github/workflows/test-all-packages.yml index ecbfdd5ab6f..f7dc0c1daa0 100644 --- a/.github/workflows/test-all-packages.yml +++ b/.github/workflows/test-all-packages.yml @@ -124,6 +124,9 @@ jobs: - name: yarn test (assert) if: (success() || failure()) run: cd packages/assert && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT + - name: yarn test (benchmark) + if: (success() || failure()) + run: cd packages/benchmark && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT - name: yarn test (deployment) if: (success() || failure()) run: cd packages/deployment && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT @@ -157,6 +160,9 @@ jobs: - name: yarn test (swing-store) if: (success() || failure()) run: cd packages/swing-store && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT + - name: yarn test (test-support) + if: (success() || failure()) + run: cd packages/test-support && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT - name: yarn test (cosmic-proto) if: (success() || failure()) run: cd packages/cosmic-proto && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT diff --git a/packages/agoric-cli/src/sdk-package-names.js b/packages/agoric-cli/src/sdk-package-names.js index 2db4676d928..df8d4f3062c 100644 --- a/packages/agoric-cli/src/sdk-package-names.js +++ b/packages/agoric-cli/src/sdk-package-names.js @@ -5,6 +5,7 @@ export default [ "@agoric/access-token", "@agoric/assert", "@agoric/base-zone", + "@agoric/benchmark", "@agoric/boot", "@agoric/builders", "@agoric/cache", @@ -37,6 +38,7 @@ export default [ "@agoric/swingset-vat", "@agoric/swingset-xsnap-supervisor", "@agoric/telemetry", + "@agoric/test-support", "@agoric/time", "@agoric/vat-data", "@agoric/vats", diff --git a/packages/boot/test/bootstrapTests/benchmarkerator.md b/packages/benchmark/doc/benchmarkerator.md similarity index 96% rename from packages/boot/test/bootstrapTests/benchmarkerator.md rename to packages/benchmark/doc/benchmarkerator.md index af1b5871a24..9af96f9bc40 100644 --- a/packages/boot/test/bootstrapTests/benchmarkerator.md +++ b/packages/benchmark/doc/benchmarkerator.md @@ -39,16 +39,11 @@ yourself).[^2] Those will themselves be deprecated and/or moved into `benchmarks`. However, as of this writing that has not yet been done. -The first thing a benchmark should do is import The Benchmarkerator:[^3] +The first thing a benchmark should do is import The Benchmarkerator: ``` import { bench } from '@agoric/benchmark'; ``` -[^3]: As of this writing The Benchmarkerator actually lives in - `@agoric/boot/test/boostrapTests/benchmarkerator.js`. This should be - changed soon, hopefully before the first PR containing this writeup is - landed, in which case you will never see this footnote. - Note that this importation usually should be the very first thing you do, much as you typically import `@agoric/swingset-vat/tools/prepare-test-env-ava.js` or `@agoric/zoe/tools/prepare-test-env-ava.js` or the like as the first thing in a diff --git a/packages/benchmark/package.json b/packages/benchmark/package.json new file mode 100644 index 00000000000..c2bfeff1a96 --- /dev/null +++ b/packages/benchmark/package.json @@ -0,0 +1,66 @@ +{ + "name": "@agoric/benchmark", + "version": "0.1.0", + "private": true, + "description": "Benchmark support", + "type": "module", + "main": "./src/benchmarkerator.js", + "exports": { + ".": "./src/benchmarkerator.js" + }, + "repository": "https://github.com/Agoric/agoric-sdk", + "scripts": { + "build": "exit 0", + "test": "exit 0", + "test:xs": "exit 0", + "lint-fix": "yarn lint:eslint --fix", + "lint": "run-s --continue-on-error lint:*", + "lint:types": "tsc", + "lint:eslint": "eslint ." + }, + "keywords": [], + "author": "Agoric", + "license": "Apache-2.0", + "dependencies": { + "@agoric/assert": "^0.6.0", + "@agoric/cosmic-swingset": "^0.41.3", + "@agoric/internal": "^0.3.2", + "@agoric/inter-protocol": "^0.16.1", + "@agoric/test-support": "^0.1.0", + "@agoric/vats": "^0.15.1", + "@agoric/zoe": "^0.26.2", + "@endo/init": "^0.5.59" + }, + "devDependencies": {}, + "files": [ + "CHANGELOG.md", + "src/", + "scripts/", + "tools/", + "*.json", + "globals.d.ts", + "exported.js" + ], + "engines": { + "node": ">=14.15.0" + }, + "ava": { + "extensions": { + "js": true, + "ts": "module" + }, + "files": [ + "test/**/test-*.js", + "test/**/test-*.ts" + ], + "nodeArguments": [ + "--loader=tsx", + "--no-warnings" + ], + "require": [ + "@endo/init/debug.js" + ], + "timeout": "20m", + "workerThreads": false + } +} diff --git a/packages/boot/test/bootstrapTests/benchmarkerator.js b/packages/benchmark/src/benchmarkerator.js similarity index 97% rename from packages/boot/test/bootstrapTests/benchmarkerator.js rename to packages/benchmark/src/benchmarkerator.js index eb6e4e751fd..79aa734c3c3 100644 --- a/packages/boot/test/bootstrapTests/benchmarkerator.js +++ b/packages/benchmark/src/benchmarkerator.js @@ -4,11 +4,19 @@ import fs from 'node:fs'; import '@endo/init/pre-bundle-source.js'; import '@endo/init'; +// XXX The following four imports are present only to make `tsc` shut up. They do no actual work. +import '@agoric/vats/exported.js'; +import '@agoric/inter-protocol/exported.js'; +import '@agoric/zoe/exported.js'; +import '@agoric/cosmic-swingset/src/launch-chain.js'; + import { Fail } from '@agoric/assert'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; -import { makeSwingsetTestKit } from './supports.ts'; -import { makeWalletFactoryDriver } from './drivers.ts'; +import { + makeSwingsetTestKit, + makeWalletFactoryDriver, +} from '@agoric/test-support'; // When I was a child my family took a lot of roadtrips around California to go // camping and backpacking and so on. It was not uncommon in those days (nor is @@ -38,7 +46,7 @@ import { makeWalletFactoryDriver } from './drivers.ts'; * @typedef {{ * options: Record, * argv: string[], - * actors: Record, + * actors: Record, * title?: string, * rounds?: number, * config?: Record, @@ -586,4 +594,5 @@ export const makeBenchmarkerator = async () => { /** * The normal singleton benchmarkerator. */ +// eslint-disable-next-line @jessie.js/safe-await-separator export const bench = await makeBenchmarkerator(); diff --git a/packages/benchmark/tsconfig.json b/packages/benchmark/tsconfig.json new file mode 100644 index 00000000000..3e84468c37d --- /dev/null +++ b/packages/benchmark/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "allowImportingTsExtensions": true, + "allowSyntheticDefaultImports": true, + "checkJs": true, + "maxNodeModuleJsDepth": 2, + }, + "include": [ + "*.js", + "scripts/**/*.js", + "src/**/*.js", + "test/**/*.js", + "test/**/*.ts", + "tools/**/*.js", + ], +} diff --git a/packages/boot/package.json b/packages/boot/package.json index 570a86cd7a7..cbadaac381a 100644 --- a/packages/boot/package.json +++ b/packages/boot/package.json @@ -38,6 +38,7 @@ }, "devDependencies": { "@agoric/assert": "^0.6.0", + "@agoric/benchmark": "^0.1.0", "@agoric/cosmic-swingset": "^0.41.3", "@agoric/deploy-script-support": "^0.10.3", "@agoric/governance": "^0.10.3", @@ -47,6 +48,7 @@ "@agoric/swing-store": "^0.9.1", "@agoric/swingset-liveslots": "^0.10.2", "@agoric/swingset-vat": "^0.32.2", + "@agoric/test-support": "^0.1.0", "@agoric/time": "^0.3.2", "ava": "^5.3.0", "c8": "^7.13.0", diff --git a/packages/boot/test/bootstrapTests/bench-vaults-performance.js b/packages/boot/test/bootstrapTests/bench-vaults-performance.js index cd76d1ad3eb..53c63111507 100644 --- a/packages/boot/test/bootstrapTests/bench-vaults-performance.js +++ b/packages/boot/test/bootstrapTests/bench-vaults-performance.js @@ -12,8 +12,10 @@ import engineGC from '@agoric/internal/src/lib-nodejs/engine-gc.js'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; -import { makeSwingsetTestKit } from './supports.ts'; -import { makeWalletFactoryDriver } from './drivers.ts'; +import { + makeSwingsetTestKit, + makeWalletFactoryDriver, +} from '@agoric/test-support'; /** * @type {import('ava').TestFn< diff --git a/packages/boot/test/bootstrapTests/benchmark-vaults.js b/packages/boot/test/bootstrapTests/benchmark-vaults.js index 4f6e50d8656..2632f6bb343 100644 --- a/packages/boot/test/bootstrapTests/benchmark-vaults.js +++ b/packages/boot/test/bootstrapTests/benchmark-vaults.js @@ -1,4 +1,4 @@ -import { bench } from './benchmarkerator.js'; +import { bench } from '@agoric/benchmark'; // eslint-disable-next-line import/order import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; diff --git a/packages/boot/test/bootstrapTests/liquidation.ts b/packages/boot/test/bootstrapTests/liquidation.ts index f2793746f9d..3ea7c326bd9 100644 --- a/packages/boot/test/bootstrapTests/liquidation.ts +++ b/packages/boot/test/bootstrapTests/liquidation.ts @@ -13,8 +13,8 @@ import { makeGovernanceDriver, makePriceFeedDriver, makeWalletFactoryDriver, -} from './drivers.ts'; -import { makeSwingsetTestKit } from './supports.ts'; + makeSwingsetTestKit, +} from '@agoric/test-support'; export type LiquidationSetup = { vaults: { diff --git a/packages/boot/test/bootstrapTests/test-demo-config.ts b/packages/boot/test/bootstrapTests/test-demo-config.ts index ba561ae30b7..7cf84e6b18c 100644 --- a/packages/boot/test/bootstrapTests/test-demo-config.ts +++ b/packages/boot/test/bootstrapTests/test-demo-config.ts @@ -3,7 +3,7 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { PowerFlags } from '@agoric/vats/src/walletFlags.js'; import type { TestFn } from 'ava'; -import { makeSwingsetTestKit, keyArrayEqual } from './supports.ts'; +import { makeSwingsetTestKit, keyArrayEqual } from '@agoric/test-support'; const { keys } = Object; diff --git a/packages/boot/test/bootstrapTests/test-vats-restart.ts b/packages/boot/test/bootstrapTests/test-vats-restart.ts index bb24718cef5..3cb64c0e3cb 100644 --- a/packages/boot/test/bootstrapTests/test-vats-restart.ts +++ b/packages/boot/test/bootstrapTests/test-vats-restart.ts @@ -10,8 +10,11 @@ import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board- import { TestFn } from 'ava'; import { BridgeHandler } from '@agoric/vats'; import type { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js'; -import { makeProposalExtractor, makeSwingsetTestKit } from './supports.ts'; -import { makeWalletFactoryDriver } from './drivers.ts'; +import { + makeProposalExtractor, + makeSwingsetTestKit, + makeWalletFactoryDriver, +} from '@agoric/test-support'; const { Fail } = assert; diff --git a/packages/boot/test/bootstrapTests/test-vaults-integration.ts b/packages/boot/test/bootstrapTests/test-vaults-integration.ts index 53df2ad119f..8659f5d7321 100644 --- a/packages/boot/test/bootstrapTests/test-vaults-integration.ts +++ b/packages/boot/test/bootstrapTests/test-vaults-integration.ts @@ -13,8 +13,10 @@ import { } from '@agoric/vats/tools/board-utils.js'; import type { TestFn } from 'ava'; import { ParamChangesOfferArgs } from '@agoric/inter-protocol/src/econCommitteeCharter.js'; -import { makeWalletFactoryDriver } from './drivers.ts'; -import { makeSwingsetTestKit } from './supports.ts'; +import { + makeSwingsetTestKit, + makeWalletFactoryDriver, +} from '@agoric/test-support'; // presently all these tests use one collateral manager const collateralBrandKey = 'ATOM'; diff --git a/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts b/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts index 1b2d45f2e10..5243f7d87e7 100644 --- a/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts +++ b/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts @@ -15,8 +15,10 @@ import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board- import { ExecutionContext, TestFn } from 'ava'; import { FakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; import { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js'; -import { makeWalletFactoryDriver } from './drivers.ts'; -import { makeSwingsetTestKit } from './supports.ts'; +import { + makeSwingsetTestKit, + makeWalletFactoryDriver, +} from '@agoric/test-support'; // presently all these tests use one collateral manager const collateralBrandKey = 'ATOM'; diff --git a/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts b/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts index ac6a812bf12..b589115ef22 100644 --- a/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts +++ b/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts @@ -11,9 +11,12 @@ import path from 'path'; import { BridgeHandler } from '@agoric/vats'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; import { TestFn } from 'ava'; -import { makeZoeDriver } from './drivers.ts'; -import { matchAmount } from './supports.js'; -import { makeProposalExtractor, makeSwingsetTestKit } from './supports.ts'; +import { + matchAmount, + makeZoeDriver, + makeProposalExtractor, + makeSwingsetTestKit, +} from '@agoric/test-support'; const filename = new URL(import.meta.url).pathname; const dirname = path.dirname(filename); diff --git a/packages/boot/test/upgrading/test-upgrade-vats.js b/packages/boot/test/upgrading/test-upgrade-vats.js index 0594f805426..c074375d2be 100644 --- a/packages/boot/test/upgrading/test-upgrade-vats.js +++ b/packages/boot/test/upgrading/test-upgrade-vats.js @@ -9,7 +9,7 @@ import { matchAmount, matchIter, matchRef, -} from '../bootstrapTests/supports.ts'; +} from '@agoric/test-support'; /** * @type {import('ava').TestFn<{}>} diff --git a/packages/test-support/package.json b/packages/test-support/package.json new file mode 100644 index 00000000000..559d95f44bb --- /dev/null +++ b/packages/test-support/package.json @@ -0,0 +1,51 @@ +{ + "name": "@agoric/test-support", + "version": "0.1.0", + "description": "Support libraries for testing on chain", + "type": "module", + "main": "./src/index.js", + "exports": { + ".": "./src/index.js" + }, + "repository": "https://github.com/Agoric/agoric-sdk", + "author": "Agoric", + "license": "Apache-2.0", + "scripts": { + "build": "exit 0", + "test": "exit 0", + "test:xs": "exit 0", + "lint-fix": "yarn lint:eslint --fix", + "lint": "run-s --continue-on-error lint:*", + "lint:types": "tsc", + "lint:eslint": "eslint ." + }, + "dependencies": { + "@endo/eventual-send": "^0.17.5", + "@endo/stream": "^0.3.28", + "@agoric/assert": "^0.6.0", + "@agoric/cosmic-swingset": "^0.41.3", + "@agoric/inter-protocol": "^0.16.1", + "@agoric/internal": "^0.3.2", + "@agoric/kmarshal": "^0.1.0", + "@agoric/smart-wallet": "^0.5.3", + "@agoric/swing-store": "^0.9.1", + "@agoric/swingset-vat": "^0.32.2", + "@agoric/time": "^0.3.2", + "@agoric/vats": "^0.15.1", + "ava": "^5.3.0", + "import-meta-resolve": "^2.2.1" + }, + "devDependencies": {}, + "publishConfig": { + "access": "public" + }, + "ava": { + "files": [ + "test/**/test-*.js" + ], + "require": [ + "@endo/init/debug.js" + ], + "timeout": "2m" + } +} diff --git a/packages/boot/test/bootstrapTests/drivers.ts b/packages/test-support/src/drivers.ts similarity index 100% rename from packages/boot/test/bootstrapTests/drivers.ts rename to packages/test-support/src/drivers.ts diff --git a/packages/test-support/src/index.js b/packages/test-support/src/index.js new file mode 100644 index 00000000000..d8febecbbf8 --- /dev/null +++ b/packages/test-support/src/index.js @@ -0,0 +1,2 @@ +export * from './supports.ts'; +export * from './drivers.ts'; diff --git a/packages/boot/test/bootstrapTests/supports.ts b/packages/test-support/src/supports.ts similarity index 99% rename from packages/boot/test/bootstrapTests/supports.ts rename to packages/test-support/src/supports.ts index b0cc8cf39b7..15946d76b50 100644 --- a/packages/boot/test/bootstrapTests/supports.ts +++ b/packages/test-support/src/supports.ts @@ -16,6 +16,7 @@ import { initSwingStore } from '@agoric/swing-store'; import { loadSwingsetConfigFile } from '@agoric/swingset-vat'; import { krefOf, kunser } from '@agoric/kmarshal'; import { TimeMath, Timestamp } from '@agoric/time'; +import '@agoric/vats/exported.js'; import { boardSlottingMarshaller, slotToBoardRemote, @@ -213,7 +214,7 @@ interface Powers { export const makeProposalExtractor = ({ childProcess, fs }: Powers) => { const getPkgPath = (pkg, fileName = '') => - new URL(`../../../${pkg}/${fileName}`, import.meta.url).pathname; + new URL(`../../${pkg}/${fileName}`, import.meta.url).pathname; const importSpec = spec => importMetaResolve(spec, import.meta.url).then(u => new URL(u).pathname); diff --git a/packages/test-support/tsconfig.json b/packages/test-support/tsconfig.json new file mode 100644 index 00000000000..0bd02ce5554 --- /dev/null +++ b/packages/test-support/tsconfig.json @@ -0,0 +1,14 @@ +// This file can contain .js-specific Typescript compiler config. +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "allowImportingTsExtensions": true, + "allowSyntheticDefaultImports": true, + "checkJs": true, + "maxNodeModuleJsDepth": 2, + }, + "include": [ + "src/**/*.js", + "test/**/*.js" + ] +}