refactor(config): replace hand-written validation with struct tags#761
Merged
refactor(config): replace hand-written validation with struct tags#761
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors configuration validation in internal/config from ad-hoc if blocks in LoadFromPath to declarative go-playground/validator/v10 struct tags + a centralized error formatter, and removes the long-deprecated documents.cache_ttl_days setting across code/docs/tests.
Changes:
- Add tag-based validation (
validate:"...") for providers, thinking levels, max pages, cache TTL, and OCR confidence threshold, with a new validator setup/formatter ininternal/config/validate.go. - Remove deprecated
documents.cache_ttl_daysand its related show-config annotations, docs entries, env var mappings, and tests. - Add
validator/v10dependency and update Nix vendor hash.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/validate.go | Introduces validator instance, custom validations, and user-facing error formatting for tag-based validation. |
| internal/config/config.go | Adds validate: tags, removes cache_ttl_days, and replaces manual validation with cfg.validate(path). |
| internal/config/show.go | Removes deprecated-path annotation for documents.cache_ttl_days (deprecated map now empty). |
| internal/config/show_test.go | Drops deprecated cache_ttl_days expectations/tests from ShowConfig coverage. |
| internal/config/config_test.go | Removes tests and env var mapping entries for deprecated cache_ttl_days. |
| docs/content/docs/reference/configuration.md | Removes documentation for deprecated MICASA_DOCUMENTS_CACHE_TTL_DAYS / cache_ttl_days. |
| go.mod / go.sum | Adds github.com/go-playground/validator/v10 and indirect deps. |
| flake.nix | Updates vendorHash for Nix builds after dependency changes. |
caf9f4e to
79a6e60
Compare
79a6e60 to
43c596d
Compare
Use go-playground/validator/v10 for config validation instead of ~100 lines of manual checks. Custom validators handle provider names, positive durations, and non-negative durations. Error messages preserve the existing dotted-path format users expect. Also removes the deprecated `documents.cache_ttl_days` field -- it was only kept for backward compatibility and `cache_ttl` has been the canonical setting since its introduction. closes #737 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43c596d to
0910307
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
go-playground/validator/v10struct tagsvalidate:"provider"), positive durations (validate:"positive_duration"), and non-negative durations (validate:"nonneg_duration")chat.llm.provider: unknown provider "foo")documents.cache_ttl_daysfield --cache_ttlhas been the canonical setting since its introduction; existing configs using the removed key get an actionable error viacheckRemovedKeyscloses #737
🤖 Generated with Claude Code