Skip to content

Support DISABLE_INTERACTIVE_MODE in .env file #25

@snytkine

Description

@snytkine

Summary

Currently DISABLE_INTERACTIVE_MODE=true can only be set as a real OS environment variable or JVM system property (-DDISABLE_INTERACTIVE_MODE=true). Users should also be able to set it in a .env file so that CI pipelines and project-level tooling don't need to manage a separate environment variable.

Problem

Two places in the code read DISABLE_INTERACTIVE_MODE from Spring's Environment:

  1. InteractiveModeRunnerConfiguration.resolveRunner() — selects NonInteractiveShellRunner vs JLineShellRunner at application startup
  2. RunSuiteCommand.isNonInteractive() — controls output behavior (exit codes, error rendering, concise summary)

The existing DotEnvLoader is only called inside RunSuiteCommand.runSuite(), after Spring Shell has already parsed the command arguments. By then, runner selection has already happened. So the suite-directory .env is too late for runner selection.

Proposed Solution

Register a Spring Boot EnvironmentPostProcessor that loads a .env file from the current working directory (CWD) and adds its entries to Spring's Environment as a low-priority property source. This happens before any beans are created, so both InteractiveModeRunnerConfiguration and RunSuiteCommand.isNonInteractive() automatically see the value — no changes to those classes needed.

Priority order (highest to lowest):

  1. OS environment variable
  2. JVM system property (-D...)
  3. CWD .env file ← new
  4. application.properties

Implementation Plan

1. Create DotEnvEnvironmentPostProcessor

src/main/java/.../config/DotEnvEnvironmentPostProcessor.java

  • Implements org.springframework.boot.env.EnvironmentPostProcessor
  • Uses io.github.cdimascio.dotenv.Dotenv directly (Spring beans are not available at this lifecycle stage)
  • Loads .env from System.getProperty("user.dir") with .ignoreIfMissing()
  • Adds a MapPropertySource("cwdDotenv", map) via environment.getPropertySources().addLast(...) so OS env vars always win

2. Register in META-INF/spring.factories

src/main/resources/META-INF/spring.factories (new file)

org.springframework.boot.env.EnvironmentPostProcessor=\
  io.github.snytkine.apitester.api_tester_cli.config.DotEnvEnvironmentPostProcessor

3. Update GraalVM native-image hints

reflect-config.json — add constructor entry for DotEnvEnvironmentPostProcessor

resource-config.json — add META-INF/spring.factories so it is bundled in the native binary

4. Tests

src/test/java/.../config/DotEnvEnvironmentPostProcessorTest.java

  • Write a .env to a temp dir, set user.dir to that dir, call postProcessEnvironment(), assert the property is visible
  • Assert OS env / system property overrides .env value
  • Assert missing .env does not throw

Files to change

File Action
src/main/java/.../config/DotEnvEnvironmentPostProcessor.java Create
src/main/resources/META-INF/spring.factories Create
src/main/resources/META-INF/native-image/.../reflect-config.json Add 1 entry
src/main/resources/META-INF/native-image/.../resource-config.json Add 1 entry
src/test/java/.../config/DotEnvEnvironmentPostProcessorTest.java Create

No changes required to InteractiveModeRunnerConfiguration or RunSuiteCommand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions