Add --no-dotenv flag to ullm binary and use it in tests instead of env_clear()

Prevents tests from loading .env and making real API calls without
manipulating environment state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-02-23 17:24:03 -05:00
parent a3605ec0d4
commit a3a7f9fb5c

View file

@ -9,6 +9,10 @@ use llm::generate::{self, GenerateParams};
#[derive(Parser)]
#[command(name = "ullm")]
struct Cli {
/// Skip loading .env file
#[arg(long, global = true)]
no_dotenv: bool,
#[command(subcommand)]
command: Command,
}
@ -217,8 +221,10 @@ async fn run_prompt(args: PromptArgs) -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
dotenvy::dotenv().ok();
let cli = Cli::parse();
if !cli.no_dotenv {
dotenvy::dotenv().ok();
}
match cli.command {
Command::Prompt {
@ -367,10 +373,8 @@ mod tests {
fn prompt_reads_from_stdin() {
// This test verifies stdin is read, but will fail at the API call stage
// since no API key is set. The error should NOT be "no prompt provided".
// env_clear() prevents .env loading from triggering real API calls.
let result = ullm()
.env_clear()
.args(["prompt", "--no-stream", "-m", "test-model"])
.args(["--no-dotenv", "prompt", "--no-stream", "-m", "test-model"])
.write_stdin("hello from stdin")
.assert()
.failure();
@ -383,10 +387,8 @@ mod tests {
#[test]
fn prompt_concatenates_stdin_and_arg() {
// Same as above — verifies it doesn't error on "no prompt"
// env_clear() prevents .env loading from triggering real API calls.
let result = ullm()
.env_clear()
.args(["prompt", "--no-stream", "-m", "test-model", "summarize this"])
.args(["--no-dotenv", "prompt", "--no-stream", "-m", "test-model", "summarize this"])
.write_stdin("some input text")
.assert()
.failure();