Fix main: coerce the IMAP config so a ${VAR} string cannot flip it - #240
Merged
Conversation
The IMAP source landed on a base that predated ${ENV_VAR} interpolation, so
none of its config builders carry @Coerced and each casts eagerly. Every
value can now arrive as a string, and the eager casts are wrong for one:
bool("false") is True, so enabled: ${IMAP_ON} turns the source on, and the
list[str] comprehension iterates a bare string into one rule per character.
ImapAccountConfig also indexed d["host"] directly, which raises at config
load on a half-written entry. Drop such an account in the registry instead,
next to the existing no-password skip, so one bad entry cannot stop the
daemon from starting.
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.
Two tests have been failing on
mainsince #236 merged —tests/test_config_env.py::TestScalarCoercion::{test_every_declared_scalar_survives_a_string_value, test_every_declared_list_field_wraps_a_bare_scalar}. #235 merged three minutes later and inherited the same two failures.Not a flake, and not something #236 could have seen: its only CI run was 2026-07-30 19:37 UTC, and the sweep tests that catch this landed on
mainat 02:58 UTC on 2026-08-01 with the${ENV_VAR}interpolation work. A base-branch push does not retrigger PR CI, so the branch merged on a two-day-old green tick.What was actually broken
None of the four
Imap*config dataclasses carry@coerced, and each casts eagerly in its builder — the exact patternnerve/coerce.pywarns about. Now that any value can arrive as a${VAR}string, three of those casts are wrong:ImapMatchConfig—[str(s) for s in d.get("sender_contains", [])]iterates a bare string, sosender_contains: ${SENDER}becomes one rule per character (["a", "l", "e", ...]) and matches nearly every message.ImapSyncConfig/ImapVisionConfig—bool("false")isTrue, soenabled: ${IMAP_ON}set tofalseturns the source on. This one was hidden behind theKeyErrorbelow until it was fixed.ImapAccountConfig—d["host"]/d["username"]are indexed directly, so a half-written account entry raises at config load and the daemon does not start.The fix
@coercedon all four builders, raw values handed straight to the constructor, and the account entry made total: a missinghostorusernameis now dropped in the registry alongside the existing no-password skip, with the same warning shape, instead of raising at load.Four regression tests in
tests/test_imap_source.pypin the string-valued shapes and the registry skip, so this does not depend on the sweep alone to stay fixed.Verification
pytest tests/— 2923 passed (mainis currently 2 failed / 2917 passed).No behaviour change for a well-formed YAML config: real booleans, ints and lists reach the constructor unchanged.