test: 🏗️ small cli fixes (#108)

- 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 🫠
This commit is contained in:
Gonza Montiel 2025-06-30 16:51:46 +02:00 committed by GitHub
parent c3e6f1258b
commit a7d45969d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 101 additions and 3 deletions

View file

@ -111,6 +111,50 @@ const checkKurtosisInstalled = async (): Promise<boolean> => {
return true;
};
export const checkKurtosisCluster = async (kubernetes?: boolean): Promise<boolean> => {
// 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<boolean> => {
const { exitCode, stderr, stdout } = await $`docker system info`.nothrow().quiet();
if (exitCode !== 0) {

View file

@ -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");
}

View file

@ -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.");

View file

@ -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")

View file

@ -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",