From 4f12b72caabaf98535888120384cb57b46c175f0 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 6 Jun 2023 11:41:30 -0700 Subject: [PATCH 1/5] test(bootstrap): refactor buildProposal for re-use --- packages/vats/test/bootstrapTests/supports.js | 111 +++++++++++++++++- .../test/bootstrapTests/test-vats-restart.js | 106 +---------------- 2 files changed, 110 insertions(+), 107 deletions(-) diff --git a/packages/vats/test/bootstrapTests/supports.js b/packages/vats/test/bootstrapTests/supports.js index 2ad85a28a13..9e41b7652b1 100644 --- a/packages/vats/test/bootstrapTests/supports.js +++ b/packages/vats/test/bootstrapTests/supports.js @@ -1,8 +1,10 @@ // @ts-check -import { promises as fs } from 'fs'; +/* global process */ +import * as fsAmbient from 'fs'; import { resolve as importMetaResolve } from 'import-meta-resolve'; import { basename } from 'path'; import { inspect } from 'util'; +import childProcessAmbient from 'child_process'; import { Fail } from '@agoric/assert'; import { buildSwingset } from '@agoric/cosmic-swingset/src/launch-chain.js'; @@ -191,7 +193,7 @@ export const getNodeTestVaultsConfig = async ( config.defaultManagerType = 'local'; // speed up build (60s down to 10s in testing) config.bundleCachePath = bundleDir; - await fs.mkdir(bundleDir, { recursive: true }); + await fsAmbient.promises.mkdir(bundleDir, { recursive: true }); if (config.coreProposals) { // remove Pegasus because it relies on IBC to Golang that isn't running @@ -201,10 +203,107 @@ export const getNodeTestVaultsConfig = async ( } const testConfigPath = `${bundleDir}/${basename(specifier)}`; - await fs.writeFile(testConfigPath, JSON.stringify(config), 'utf-8'); + await fsAmbient.promises.writeFile( + testConfigPath, + JSON.stringify(config), + 'utf-8', + ); return testConfigPath; }; +/** + * @param {object} powers + * @param {Pick} powers.childProcess + * @param {typeof import('node:fs/promises')} powers.fs + */ +const makeProposalExtractor = ({ childProcess, fs }) => { + const getPkgPath = (pkg, fileName = '') => + new URL(`../../../${pkg}/${fileName}`, import.meta.url).pathname; + + const runPackageScript = async (pkg, name, env) => { + console.warn(pkg, 'running package script:', name); + const pkgPath = getPkgPath(pkg); + return childProcess.execFileSync('yarn', ['run', name], { + cwd: pkgPath, + env, + }); + }; + + const loadJSON = async filePath => + harden(JSON.parse(await fs.readFile(filePath, 'utf8'))); + + // XXX parses the output to find the files but could write them to a path that can be traversed + /** @param {string} txt */ + const parseProposalParts = txt => { + const evals = [ + ...txt.matchAll(/swingset-core-eval (?\S+) (?