Skip to content

feat: replace HIVE_LEAN_TEST_DRIVER env var with test-driver subcommand#375

Open
IbrahimIjai wants to merge 1 commit into
lambdaclass:mainfrom
IbrahimIjai:feat/issue-359-test-driver-subcommand
Open

feat: replace HIVE_LEAN_TEST_DRIVER env var with test-driver subcommand#375
IbrahimIjai wants to merge 1 commit into
lambdaclass:mainfrom
IbrahimIjai:feat/issue-359-test-driver-subcommand

Conversation

@IbrahimIjai
Copy link
Copy Markdown

@IbrahimIjai IbrahimIjai commented May 15, 2026

🗒️ Description / Motivation

The hive test driver was previously activated by setting HIVE_LEAN_TEST_DRIVER=1 in the environment before starting the binary. It was implicit and brittle if the env var was set, the binary would quietly run in test-driver mode and ignore the normal consensus flags, and --help gave no hint this mode even existed.

This PR replaces the env-var mechanism with an explicit test-driver subcommand, making the two operating modes structurally separate in the CLI rather than diverging silently at runtime:

  • ethlambda node <...all existing flags...> — normal consensus node (unchanged behaviour)
  • ethlambda test-driver [--http-address] [--api-port] [--metrics-port] — hive test driver mode

This solves the discoverability and footgun problem: the mode is now visible in --help, each mode owns its own argument set, and the two launch paths can't be confused.

What Changed

  • bin/ethlambda/src/main.rs — replaced the flat CliOptions with a Cli struct and a Commands subcommand enum. Split arguments into NodeArgs and TestDriverArgs so each mode declares only the flags it needs. Extracted the node startup logic into run_node() so the two modes have parallel entry points.
  • crates/net/rpc/src/test_driver.rs — removed TEST_DRIVER_ENV, test_driver_enabled(), parse_truthy_env_value(), and their tests. The env-var activation path is gone entirely. Updated the module doc comment to reflect the new entry point.

Correctness / Behavior Guarantees

  • The test-driver subcommand calls run_test_driver with an RpcConfig built from the same fields (http_address, api_port, metrics_port) that the env-var path used, so the test-driver RPC surface is unchanged.
  • The node subcommand path is a straight extraction of the previous main body into run_node() — no consensus flags, defaults, or startup order are modified.
  • The two modes are now mutually exclusive at parse time. It is no longer possible to launch the binary with consensus flags and have them silently ignored.
  • Breaking change for callers: HIVE_LEAN_TEST_DRIVER=1 is no longer recognised. The hive client shim for ethlambda must be updated to invoke ethlambda test-driver (passing --http-address 0.0.0.0 if it was relying on that default) instead of setting the env var.

Tests Added / Run

  • Removed the parse_truthy_env_value unit tests in crates/net/rpc/src/test_driver.rs (the function they covered no longer exists).
  • No new unit tests added — the change is a CLI restructuring; clap's derive macros handle argument parsing.
  • Manual verification:
    • cargo run -- node <existing flags> boots a normal consensus node as before.
    • cargo run -- test-driver boots the hive test driver RPC server.
    • cargo run -- --help shows both subcommands.
      Commands run:
      make fmt
      make lint
      cargo test --workspace --release

Related Issues / PRs

✅ Verification Checklist

  • Ran make fmt — clean
  • Ran make lint (clippy with -D warnings) — clean
  • Ran cargo test --workspace --release — all passing

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 15, 2026

Greptile Summary

This PR replaces the implicit HIVE_LEAN_TEST_DRIVER=1 env-var activation mechanism with an explicit test-driver subcommand, making the two operating modes (node / test-driver) structurally separate in the CLI rather than silently diverging at runtime.

  • bin/ethlambda/src/main.rs: introduces a Cli + Commands enum, separates NodeArgs from TestDriverArgs, and extracts run_node() so each mode owns its argument set and launch path.
  • crates/net/rpc/src/test_driver.rs: deletes TEST_DRIVER_ENV, test_driver_enabled(), parse_truthy_env_value(), and their tests — the env-var path is gone entirely.
  • The hive client shim must be updated to invoke ethlambda test-driver (and pass --http-address 0.0.0.0 if it was doing so before) rather than setting the env var.

Confidence Score: 5/5

Safe to merge — the change is a clean structural refactor that makes the two operating modes explicit and mutually exclusive at the CLI level.

Both changed files are touched only to remove dead env-var code and reshape the CLI parser. The test-driver logic itself is unchanged; run_test_driver and run_node are called with equivalent arguments to before. The only downstream action required is updating the hive shim, which the PR explicitly calls out.

No files require special attention. The hive client shim (not part of this repo) will need a corresponding update to call ethlambda test-driver instead of setting the env var.

Important Files Changed

Filename Overview
bin/ethlambda/src/main.rs Replaces flat CliOptions with Cli + Commands subcommand enum; extracts run_node(); adds TestDriverArgs. Logic is correct — a minor redundant return in the TestDriver match arm is the only style nit.
crates/net/rpc/src/test_driver.rs Removes TEST_DRIVER_ENV constant, test_driver_enabled(), parse_truthy_env_value(), and their associated tests; updates module doc comment. Clean deletion with no remaining references.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ethlambda binary starts] --> B[Init tracing + metrics]
    B --> C[clap::parse Cli]
    C --> D{cli.command}
    D -- "test-driver\n--http-address --api-port --metrics-port" --> E[Build RpcConfig from TestDriverArgs]
    E --> F[run_test_driver]
    F --> G[start_test_driver_rpc_server\n/lean/v0/test_driver/...]
    D -- "node\n--genesis --validators ... all node flags" --> H[run_node]
    H --> I[Build RpcConfig from NodeArgs]
    I --> J[Load genesis / keys / storage]
    J --> K[Spawn BlockChain + P2P actors]
    K --> L[start_rpc_server\nnormal consensus API]
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
bin/ethlambda/src/main.rs:160-171
The `return` keyword in the `TestDriver` arm is redundant — the `match` is already the tail expression of `main()`, so dropping `return` makes both arms consistent and more idiomatic Rust.

```suggestion
    match cli.command {
        Commands::TestDriver(args) => {
            let rpc_config = RpcConfig {
                http_address: args.http_address,
                api_port: args.api_port,
                metrics_port: args.metrics_port,
            };
            info!("Booting in test-driver mode");
            run_test_driver(rpc_config).await
        }
        Commands::Node(options) => run_node(*options).await,
    }
```

Reviews (1): Last reviewed commit: "feat: replace HIVE_LEAN_TEST_DRIVER env ..." | Re-trigger Greptile

Comment thread bin/ethlambda/src/main.rs
Comment on lines +160 to 171
match cli.command {
Commands::TestDriver(args) => {
let rpc_config = RpcConfig {
http_address: args.http_address,
api_port: args.api_port,
metrics_port: args.metrics_port,
};
info!("Booting in test-driver mode");
return run_test_driver(rpc_config).await;
}
Commands::Node(options) => run_node(*options).await,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The return keyword in the TestDriver arm is redundant — the match is already the tail expression of main(), so dropping return makes both arms consistent and more idiomatic Rust.

Suggested change
match cli.command {
Commands::TestDriver(args) => {
let rpc_config = RpcConfig {
http_address: args.http_address,
api_port: args.api_port,
metrics_port: args.metrics_port,
};
info!("Booting in test-driver mode");
return run_test_driver(rpc_config).await;
}
Commands::Node(options) => run_node(*options).await,
}
match cli.command {
Commands::TestDriver(args) => {
let rpc_config = RpcConfig {
http_address: args.http_address,
api_port: args.api_port,
metrics_port: args.metrics_port,
};
info!("Booting in test-driver mode");
run_test_driver(rpc_config).await
}
Commands::Node(options) => run_node(*options).await,
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: bin/ethlambda/src/main.rs
Line: 160-171

Comment:
The `return` keyword in the `TestDriver` arm is redundant — the `match` is already the tail expression of `main()`, so dropping `return` makes both arms consistent and more idiomatic Rust.

```suggestion
    match cli.command {
        Commands::TestDriver(args) => {
            let rpc_config = RpcConfig {
                http_address: args.http_address,
                api_port: args.api_port,
                metrics_port: args.metrics_port,
            };
            info!("Booting in test-driver mode");
            run_test_driver(rpc_config).await
        }
        Commands::Node(options) => run_node(*options).await,
    }
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@dicethedev
Copy link
Copy Markdown
Contributor

The hive test driver was previously activated by setting HIVE_LEAN_TEST_DRIVER=1
in the environment before starting the binary. This was implicit — the binary would
silently ignore all required consensus flags if

It would be nice next time to follow the PR description template attached to the GitHub workflow 🚀

@IbrahimIjai
Copy link
Copy Markdown
Author

The hive test driver was previously activated by setting HIVE_LEAN_TEST_DRIVER=1
in the environment before starting the binary. This was implicit — the binary would
silently ignore all required consensus flags if

It would be nice next time to follow the PR description template attached to the GitHub workflow 🚀

Thank you sir, let me update

@IbrahimIjai
Copy link
Copy Markdown
Author

The hive test driver was previously activated by setting HIVE_LEAN_TEST_DRIVER=1
in the environment before starting the binary. This was implicit — the binary would
silently ignore all required consensus flags if

It would be nice next time to follow the PR description template attached to the GitHub workflow 🚀

Done now... just updated the description to follow the template. Would love your feedback when you are open

@dicethedev
Copy link
Copy Markdown
Contributor

Done now... just updated the description to follow the template. Would love your feedback when you are open

@MegaRedHand will make his reviews. No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change how hive test driver is enabled

3 participants