Skip to content

refactor(config): replace hand-written validation with struct tags#761

Merged
cpcloud merged 1 commit intomainfrom
worktree-twinkling-toasting-parrot
Mar 12, 2026
Merged

refactor(config): replace hand-written validation with struct tags#761
cpcloud merged 1 commit intomainfrom
worktree-twinkling-toasting-parrot

Conversation

@cpcloud
Copy link
Owner

@cpcloud cpcloud commented Mar 12, 2026

Summary

  • Replace ~100 lines of hand-written config validation with go-playground/validator/v10 struct tags
  • Add custom validators for provider names (validate:"provider"), positive durations (validate:"positive_duration"), and non-negative durations (validate:"nonneg_duration")
  • Error messages preserve the existing dotted-path format (e.g. chat.llm.provider: unknown provider "foo")
  • Remove deprecated documents.cache_ttl_days field -- cache_ttl has been the canonical setting since its introduction; existing configs using the removed key get an actionable error via checkRemovedKeys
  • Update docs and tests to reflect the removal

closes #737

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 12, 2026 12:38
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 92.70833% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.67%. Comparing base (102f15a) to head (0910307).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/config/validate.go 92.22% 6 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
internal/config/config.go 87.90% <100.00%> (-1.82%) ⬇️
internal/config/show.go 74.58% <ø> (-1.67%) ⬇️
internal/config/validate.go 92.22% <92.22%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 in internal/config/validate.go.
  • Remove deprecated documents.cache_ttl_days and its related show-config annotations, docs entries, env var mappings, and tests.
  • Add validator/v10 dependency 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.

@cpcloud cpcloud force-pushed the worktree-twinkling-toasting-parrot branch from caf9f4e to 79a6e60 Compare March 12, 2026 12:44
Copilot AI review requested due to automatic review settings March 12, 2026 12:48
@cpcloud cpcloud force-pushed the worktree-twinkling-toasting-parrot branch from 79a6e60 to 43c596d Compare March 12, 2026 12:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

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>
@cpcloud cpcloud force-pushed the worktree-twinkling-toasting-parrot branch from 43c596d to 0910307 Compare March 12, 2026 13:00
@cpcloud cpcloud merged commit 6a0b1d6 into main Mar 12, 2026
25 checks passed
@cpcloud cpcloud deleted the worktree-twinkling-toasting-parrot branch March 12, 2026 15:05
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.

refactor(config): formalize config validation

2 participants