Skip to content

coerce-value-typeadapter->preset-validation#3156

Merged
liquidsec merged 1 commit into
preset-validationfrom
coerce-value-typeadapter
Jun 8, 2026
Merged

coerce-value-typeadapter->preset-validation#3156
liquidsec merged 1 commit into
preset-validationfrom
coerce-value-typeadapter

Conversation

@liquidsec

Copy link
Copy Markdown
Collaborator

No description provided.

coerce_value now validates each config value against its field's real
pydantic TypeAdapter (a "TryParse"): attempt the value, return it coerced
on success, and leave it unchanged on ValidationError so the schema pass
reports the real error rather than coercion silently swallowing it.

config_type_index is rebuilt by walking the materialized config schema
(global config + every module's exec'd Config), memoizing one TypeAdapter
per annotation. Nested models are recursed into via _field_submodel, so
modules.<name>.<option> keys fall out of the same walk -- replacing the two
divergent build paths (static BBOTConfig walk + preloaded AST strings).

The single materialized schema is now the source of truth for BOTH
validation and coercion, and coercion sees each field's true declared type
(Literal members, Annotated validators, unions) instead of a flattened set
of base type-names.

Deletes the now-dead helpers and tables:
  - accepted_types_from_string / accepted_types_from_annotation
  - _COLLECTION_NAMES / _TRUE_WORDS / _FALSE_WORDS
  - their __all__ entries
args.py: rename the coerce_value arg accepted -> adapter; update docstrings.

All coercion special cases are preserved:
  - numeric YAML value -> str field (ConfigDict(coerce_numbers_to_str=True))
  - raw CLI strings kept lossless ("1.10", "0755" stay strings, not floats)
  - bool words: true/false/yes/no/on/off/1/0
  - list/dict literals parsed for collection-typed fields
  - os.PathLike -> str (pydantic won't, so we pre-convert)
  - date-shaped strings stay strings (_yaml_scalar guard)
  - empty string stays ""
  - invalid YAML is non-fatal (kept as the raw string)

Behavior change: field validators now run during coercion, so e.g.
SeverityLiteral upcases "low" -> "LOW". Scoped to baddns* min_severity /
min_confidence; strictly more correct; covered by tests.

Tested (clean HOME): 64/64 test_cli/test_validate_preset/test_presets/
test_config, plus 14/14 test_modules_basic + baddns end-to-end. Index =
832 adapters built in ~82ms, cached thereafter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Performance Benchmark Report

⚠️ No current benchmark data available

This might be because:

  • Benchmarks failed to run
  • No benchmark tests found
  • Dependencies missing

@liquidsec liquidsec merged commit be1d3b9 into preset-validation Jun 8, 2026
16 checks passed
@liquidsec liquidsec deleted the coerce-value-typeadapter branch June 8, 2026 21:27
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.39216% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 90%. Comparing base (c4e4168) to head (edcd7c4).
⚠️ Report is 2 commits behind head on preset-validation.

Files with missing lines Patch % Lines
bbot/core/config/models.py 75% 5 Missing ⚠️
bbot/core/modules.py 82% 5 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           preset-validation   #3156   +/-   ##
=================================================
+ Coverage                 90%     90%   +1%     
=================================================
  Files                    447     447           
  Lines                  40444   40400   -44     
=================================================
- Hits                   36294   36258   -36     
+ Misses                  4150    4142    -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants