From a7d45969d593eb1fa4b89301b5c4a7e6d0524882 Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Mon, 30 Jun 2025 16:51:46 +0200 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=8F=97=EF=B8=8F=20=20small=20cli?= =?UTF-8?q?=20fixes=20(#108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added a parameter `--all` to `bun cli launch` (now coherent with `bun cli stop`) - Equivalent to run `bun cli launch --d --bd --lk --dc --fv --sv --uv --sp --r --cn` - Removed `bun start:all` command - Added a kurtosis cluster type check - The problem was that we now support deploying and launching the CLI tool with different types of clusters. If you're deploying, your kurtosis cluster most likely needs to point to a `kubernetes` type cluster, if you're running `bun cli launch` you need to use native docker containers. This PR adds a check and warns the user to point to the right config. - *Disclaimer*: we don't know the cluster name of the user so we can't force it to be anything 🫠 --- test/cli/handlers/common/checks.ts | 44 +++++++++++++++++++++++++ test/cli/handlers/launch/index.ts | 49 +++++++++++++++++++++++++++- test/cli/handlers/launch/kurtosis.ts | 9 ++++- test/cli/index.ts | 1 + test/package.json | 1 - 5 files changed, 101 insertions(+), 3 deletions(-) diff --git a/test/cli/handlers/common/checks.ts b/test/cli/handlers/common/checks.ts index 57d3dd5b..e33ee0b4 100644 --- a/test/cli/handlers/common/checks.ts +++ b/test/cli/handlers/common/checks.ts @@ -111,6 +111,50 @@ const checkKurtosisInstalled = async (): Promise => { return true; }; +export const checkKurtosisCluster = async (kubernetes?: boolean): Promise => { + // First check if kurtosis cluster get works + const { exitCode, stderr, stdout } = await $`kurtosis cluster get`.nothrow().quiet(); + + if (exitCode !== 0) { + logger.warn(`⚠️ Kurtosis cluster get failed: ${stderr.toString()}`); + logger.info("ℹ️ Assuming local launch mode and continuing."); + return true; + } + + const currentCluster = stdout.toString().trim(); + logger.debug(`Current Kurtosis cluster: ${currentCluster}`); + + // Try to get the cluster type from config, but don't fail if config path is not reachable + const clusterTypeResult = + await $`CURRENT_CLUSTER=${currentCluster} && sed -n "/^ $CURRENT_CLUSTER:$/,/^ [^ ]/p" "$(kurtosis config path)" | grep "type:" | sed 's/.*type: "\(.*\)"/\1/'` + .nothrow() + .quiet(); + + if (clusterTypeResult.exitCode !== 0) { + logger.warn("⚠️ Failed to read Kurtosis cluster type from config"); + logger.debug(clusterTypeResult.stderr.toString()); + logger.info("ℹ️ Assuming local launch mode and continuing gracefully"); + return true; // Continue gracefully for local launch + } + + const clusterType = clusterTypeResult.stdout.toString().trim(); + logger.debug(`Kurtosis cluster type: ${clusterType}`); + + // Validate cluster type against expected type + if (kubernetes && clusterType !== "kubernetes") { + logger.error(`❌ Kurtosis cluster type is "${clusterType}" but kubernetes is required`); + return false; + } + + if (!kubernetes && clusterType !== "docker") { + logger.error(`❌ Kurtosis cluster type is "${clusterType}" but docker is required`); + return false; + } + + logger.success(`Kurtosis cluster type "${clusterType}" is compatible`); + return true; +}; + const checkDockerRunning = async (): Promise => { const { exitCode, stderr, stdout } = await $`docker system info`.nothrow().quiet(); if (exitCode !== 0) { diff --git a/test/cli/handlers/launch/index.ts b/test/cli/handlers/launch/index.ts index 06c8756e..0d7c5a2e 100644 --- a/test/cli/handlers/launch/index.ts +++ b/test/cli/handlers/launch/index.ts @@ -13,6 +13,7 @@ import { performValidatorOperations, performValidatorSetUpdate } from "./validat // Non-optional properties should have default values set by the CLI export interface LaunchOptions { + all?: boolean; datahaven?: boolean; buildDatahaven?: boolean; datahavenBuildExtraArgs: string; @@ -101,7 +102,53 @@ export const launch = async (options: LaunchOptions) => { export const launchPreActionHook = ( thisCmd: Command<[], LaunchOptions & { [key: string]: any }> ) => { - const { blockscout, verified, fundValidators, setupValidators, deployContracts } = thisCmd.opts(); + const { + all, + blockscout, + verified, + fundValidators, + setupValidators, + deployContracts, + datahaven, + buildDatahaven, + launchKurtosis, + relayer, + setParameters, + updateValidatorSet + } = thisCmd.opts(); + + // Check for conflicts with --all flag + if ( + all && + (datahaven === false || + buildDatahaven === false || + launchKurtosis === false || + deployContracts === false || + fundValidators === false || + setupValidators === false || + updateValidatorSet === false || + setParameters === false || + relayer === false) + ) { + thisCmd.error( + "--all cannot be used with --no-datahaven, --no-build-datahaven, --no-launch-kurtosis, --no-deploy-contracts, --no-fund-validators, --no-setup-validators, --no-update-validator-set, --no-set-parameters, or --no-relayer" + ); + } + + // If --all is set, enable all components + if (all) { + thisCmd.setOptionValue("datahaven", true); + thisCmd.setOptionValue("buildDatahaven", true); + thisCmd.setOptionValue("launchKurtosis", true); + thisCmd.setOptionValue("deployContracts", true); + thisCmd.setOptionValue("fundValidators", true); + thisCmd.setOptionValue("setupValidators", true); + thisCmd.setOptionValue("updateValidatorSet", true); + thisCmd.setOptionValue("setParameters", true); + thisCmd.setOptionValue("relayer", true); + thisCmd.setOptionValue("cleanNetwork", true); + } + if (verified && !blockscout) { thisCmd.error("--verified requires --blockscout to be set"); } diff --git a/test/cli/handlers/launch/kurtosis.ts b/test/cli/handlers/launch/kurtosis.ts index b9d5990a..b73278a5 100644 --- a/test/cli/handlers/launch/kurtosis.ts +++ b/test/cli/handlers/launch/kurtosis.ts @@ -1,5 +1,5 @@ import { $ } from "bun"; -import type { LaunchOptions } from "cli/handlers"; +import { checkKurtosisCluster, type LaunchOptions } from "cli/handlers"; import { confirmWithTimeout, logger, printDivider, printHeader } from "utils"; import { checkKurtosisEnclaveRunning, @@ -38,6 +38,13 @@ export const launchKurtosis = async ( return; } + if (!(await checkKurtosisCluster())) { + logger.error( + "❌ Kurtosis cluster is not configured for local launch, run `kurtosis cluster get`" + ); + return; + } + if (await checkKurtosisEnclaveRunning(options.kurtosisEnclaveName)) { logger.info("ℹ️ Kurtosis Ethereum network is already running."); diff --git a/test/cli/index.ts b/test/cli/index.ts index 21ce8709..d546a874 100644 --- a/test/cli/index.ts +++ b/test/cli/index.ts @@ -109,6 +109,7 @@ program ` ) .description("Launch a full E2E DataHaven & Ethereum network and more") + .option("--A, --all", "Launch all components without prompting") .option("--d, --datahaven", "(Re)Launch DataHaven network") .option("--nd, --no-datahaven", "Skip launching DataHaven network") .option("--bd, --build-datahaven", "Build DataHaven node local Docker image") diff --git a/test/package.json b/test/package.json index f58bd24e..8a979467 100644 --- a/test/package.json +++ b/test/package.json @@ -17,7 +17,6 @@ "start:e2e:local": "LOG_LEVEL=debug bun start:e2e:ci --bd", "start:e2e:ci": "bun cli launch --datahaven --no-build-datahaven --launch-kurtosis --deploy-contracts --fund-validators --setup-validators --update-validator-set --set-parameters --relayer --clean-network --slot-time 2", "start:e2e:minrelayer": "bun cli launch --relayer --deploy-contracts --no-setup-validators --no-update-validator-set --no-fund-validators --datahaven", - "start:all": "bun cli launch --datahaven --build-datahaven --launch-kurtosis --deploy-contracts --fund-validators --setup-validators --update-validator-set --relayer --blockscout --verified --clean-network --set-parameters", "stop:docker:datahaven": "docker rm -f $(docker ps -aq --filter name='^datahaven-') 2>/dev/null || true; docker network rm datahaven-net || true", "stop:docker:relayer": "docker rm -f $(docker ps -aq --filter name='^snowbridge-') 2>/dev/null || true", "stop:e2e": "bun cli stop --all",