Skip to content

feat: lazy validation, only resolve expressions for the active context#148

Merged
MattDevy merged 2 commits into
mainfrom
MattDevy/feat/lazy-config-validation
Apr 14, 2026
Merged

feat: lazy validation, only resolve expressions for the active context#148
MattDevy merged 2 commits into
mainfrom
MattDevy/feat/lazy-config-validation

Conversation

@MattDevy
Copy link
Copy Markdown
Contributor

Summary

  • Restructure loadConfig to use two-stage validation: structural first, then full validation only on the active context
  • Add StructuralConfigSchema that validates the outer config shape (current_context, contexts keys, commands) without deeply validating context values
  • Resolve expressions only for the active context and commands section (in parallel via Promise.all)
  • Inactive contexts with unresolvable expressions (e.g. unset env vars) no longer cause failures

Closes #144

Test plan

  • Active context resolves while inactive context has unset env var (core bug fix)
  • Active context with unresolvable expression still fails
  • --use-context override resolves only the selected context
  • Structural validation catches: missing current_context, empty contexts, nonexistent context ref
  • Commands section still resolves and validates
  • Invalid URL in active context rejected after expression resolution
  • All 145 tests pass (133 existing + 8 new + 4 store)
  • Clean tsc and eslint

MattDevy and others added 2 commits April 14, 2026 18:58
Inactive contexts with unresolved expressions (e.g. unset env vars)
no longer cause loadConfig to fail. The pipeline now structurally
validates the outer config shape first, then resolves expressions
and runs full Zod validation only on the active context and commands.

Closes #144
@MattDevy MattDevy marked this pull request as ready for review April 14, 2026 17:59
@MattDevy MattDevy requested a review from JoshMock April 14, 2026 17:59
Comment thread src/config/loader.ts

// Step 6: build and return ResolvedConfig
const ctx = contextParsed.data
const resolved: ResolvedContext = {}
Copy link
Copy Markdown
Contributor

@margaretjgu margaretjgu Apr 14, 2026

Choose a reason for hiding this comment

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

lgtm! since LoadConfig now contains the same lines from resolveContext, i think we can either refactor resolveContext so loadConfig can still call it (instead of duplicating), or add a comment saying this function is no longer used by loadConfig, kept for external callers...for future maintenance if we need ot update the context in two places.

not urgent just nitpick

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whoops sorry, got trigger happy on merging!

I'll raise a PR to fix this!

@MattDevy MattDevy merged commit 77dbd5f into main Apr 14, 2026
18 checks passed
@MattDevy MattDevy deleted the MattDevy/feat/lazy-config-validation branch April 14, 2026 18:21
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.

Lazy validation: only resolve expressions for the active context

2 participants