Skip to content

Lazy validation: only resolve expressions for the active context #144

@MattDevy

Description

@MattDevy

Summary

Expression resolution currently runs eagerly across all contexts in the config, not just the active one. This means if an inactive context references an unset environment variable, the CLI will fail even though that context isn't being used.

Example

current_context: local
contexts:
  local:
    elasticsearch:
      auth:
        api_key: $(env:LOCAL_KEY)
  staging:
    elasticsearch:
      auth:
        api_key: $(env:STAGING_KEY)

Running with current_context: local will fail if STAGING_KEY is unset, because all expressions are resolved before Zod validation.

Proposed Solution

Split validation into two stages:

  1. Structural validation of the outer config shape (all contexts, but without resolving expressions)
  2. Full validation of only the active context after expression resolution

This requires restructuring the validation pipeline so that Zod doesn't reject unresolved expressions (like $(env:X)) as invalid values during the first pass.

Context

Discussion from #143 between @MattDevy and @JoshMock.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions