Skip to content

test(config): comprehensive test suite for _apply_env_overrides and from_file (+66 tests) - #172

Open
manus-use wants to merge 6 commits into
mainfrom
feat/test-config-env-overrides
Open

test(config): comprehensive test suite for _apply_env_overrides and from_file (+66 tests)#172
manus-use wants to merge 6 commits into
mainfrom
feat/test-config-env-overrides

Conversation

@manus-use

Copy link
Copy Markdown
Owner

Summary

Comprehensive test suite for Config._apply_env_overrides() and Config.from_file() — the untested configuration loading pipeline that maps environment variables to config fields.

What's tested (66 new tests)

MANUS_LLM_* overrides — always-override semantics (12 tests)

  • MANUS_LLM_PROVIDER always overrides configured provider
  • MANUS_LLM_MODEL always overrides configured model
  • MANUS_LLM_BASE_URL always overrides configured base_url
  • MANUS_LLM_TEMPERATURE float parsing and override
  • MANUS_LLM_MAX_TOKENS int parsing and override
  • Empty string treated as unset (no override)

API key resolution — fill-when-None semantics (7 tests)

  • OPENAI_API_KEY fills openai provider key only when None
  • ANTHROPIC_API_KEY fills anthropic provider key only when None
  • Bedrock/Ollama/unknown providers don't get env-based keys
  • Explicit config.toml keys are never overwritten by env

AWS region resolution (5 tests)

  • Priority: MANUS_AWS_REGION > AWS_DEFAULT_REGION > AWS_REGION
  • Returns None when no env vars set
  • Config-set region not overwritten

Integration configs (15 tests)

  • OTX: MANUS_OTX_API_KEY fill-when-None
  • GitHub: MANUS_GITHUB_TOKEN > GITHUB_TOKEN priority
  • Lark: MANUS_LARK_API_TOKEN > LARK_API_TOKEN, same for document URL
  • Webhooks: MANUS_WEBHOOK_CVE_SUBMIT_URL
  • MCP: MANUS_MCP_SERVER_URL

Config.from_file() search paths (7 tests)

  • Explicit path loading
  • CWD config.toml auto-discovery
  • config/config.toml fallback
  • ~/.manus-agent/config.toml last resort
  • Missing path returns defaults
  • All TOML sections loaded correctly

from_file() + env override priority (4 tests)

  • Env vars override TOML values for MANUS_LLM_*
  • API keys from TOML preserved (fill-when-None)
  • API keys absent in TOML filled from env

_load_dotenv() behavior (8 tests)

  • CWD .env found and loaded
  • config/.env fallback
  • ~/.manus-agent/.env fallback
  • CWD takes priority over config/
  • No .env file doesn't error
  • Missing python-dotenv is graceful no-op
  • Existing shell vars not overwritten (override=False)

Combined scenarios (3 tests)

  • Full env-only configuration (no file)
  • Partial env override preserving file values
  • Empty env var strings treated as unset

Testing approach

  • Pure unit tests with mock.patch.dict(os.environ, ...) for isolation
  • tmp_path and monkeypatch.chdir for filesystem tests
  • No network calls, no external dependencies
  • Tests verify both the documented semantics (always-override vs fill-when-None) and edge cases

Why this matters

_apply_env_overrides() is a Pydantic @model_validator that runs on every Config() construction — it's the central env→config mapping pipeline. Previously untested, meaning:

  • Typos in env var names would go undetected
  • Priority rule regressions (e.g. env accidentally overwriting explicit config) would be silent
  • New integration configs added without env var tests could have broken mappings

All 66 tests pass. No existing tests affected.

manusjs added 6 commits July 10, 2026 08:18
…rom_file (+66 tests)

Add tests covering the entire Config environment-variable override pipeline:

- MANUS_LLM_PROVIDER/MODEL/BASE_URL/TEMPERATURE/MAX_TOKENS (always-override semantics)
- Provider-specific API key resolution (fill-when-None semantics)
- AWS region resolution from MANUS_AWS_REGION/AWS_DEFAULT_REGION/AWS_REGION
- Integration configs: OTX, GitHub, Lark, Webhooks, MCP env vars
- Config.from_file() search-path discovery (CWD, config/, ~/.manus-agent/)
- _load_dotenv() file search, priority, override=False behavior
- Combined scenarios: full env-only config, partial overrides, empty-string handling
- Priority verification: env vars > config.toml > pydantic defaults

These 66 tests cover the previously untested _apply_env_overrides() model
validator and from_file() configuration loading logic, ensuring that all
documented env-var mappings work correctly and that the priority rules
(always-override for MANUS_LLM_*, fill-when-None for API keys/tokens) are
enforced.
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.

1 participant