import assert from "node:assert/strict"; import { readFile, realpath } from "node:fs/promises"; import { join } from "node:path"; import { pathToFileURL } from "node:url"; const loadContracts = async (root) => { const [{ contractsForToolFamilies }, { toolContract }] = await Promise.all([ import(pathToFileURL(join(root, "dist/contracts/toolFamilies.js")).href), import(pathToFileURL(join(root, "dist/contracts/toolContracts.js")).href), ]); assert.equal(typeof contractsForToolFamilies, "function"); assert.equal(typeof toolContract, "function"); return { contractsForToolFamilies, toolContract }; }; /** Preserve runtime admission while binding fixtures to the selected contracts. */ export async function matchingClientRuntimeContracts( selectedRoot, checkoutRoot, ) { const [selectedPath, checkoutPath] = await Promise.all([ realpath(selectedRoot), realpath(checkoutRoot), ]); if (selectedPath === checkoutPath) return loadContracts(selectedPath); const [selectedPackage, checkoutPackage] = await Promise.all([ readFile(join(selectedPath, "package.json"), "utf8").then(JSON.parse), readFile(join(checkoutPath, "package.json"), "utf8").then(JSON.parse), ]); assert.equal( selectedPackage.name, checkoutPackage.name, `REA_VERIFY_RUNTIME_ROOT must be a ${checkoutPackage.name} package`, ); assert.equal( selectedPackage.version, checkoutPackage.version, `REA_VERIFY_RUNTIME_ROOT must match this checkout's package version (${checkoutPackage.version}); got ${selectedPackage.version}.`, ); const [selected, checkout] = await Promise.all([ loadContracts(selectedPath), loadContracts(checkoutPath), ]); assert.deepEqual( selected .contractsForToolFamilies(undefined) .map(({ name }) => name) .sort(), checkout .contractsForToolFamilies(undefined) .map(({ name }) => name) .sort(), "REA_VERIFY_RUNTIME_ROOT tool names must match this checkout", ); return selected; }