Skip to content

Fix main: coerce the IMAP config so a ${VAR} string cannot flip it - #240

Merged
pufit merged 1 commit into
mainfrom
pufit/fix-imap-config-coercion
Aug 1, 2026
Merged

Fix main: coerce the IMAP config so a ${VAR} string cannot flip it#240
pufit merged 1 commit into
mainfrom
pufit/fix-imap-config-coercion

Conversation

@pufit

@pufit pufit commented Aug 1, 2026

Copy link
Copy Markdown
Member

Two tests have been failing on main since #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 main at 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 pattern nerve/coerce.py warns 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, so sender_contains: ${SENDER} becomes one rule per character (["a", "l", "e", ...]) and matches nearly every message.
  • ImapSyncConfig / ImapVisionConfigbool("false") is True, so enabled: ${IMAP_ON} set to false turns the source on. This one was hidden behind the KeyError below until it was fixed.
  • ImapAccountConfigd["host"] / d["username"] are indexed directly, so a half-written account entry raises at config load and the daemon does not start.

The fix

@coerced on all four builders, raw values handed straight to the constructor, and the account entry made total: a missing host or username is 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.py pin 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 (main is currently 2 failed / 2917 passed).

No behaviour change for a well-formed YAML config: real booleans, ints and lists reach the constructor unchanged.

Generated by Nerve

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.
@pufit
pufit merged commit 8023c2f into main Aug 1, 2026
2 checks passed
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.

1 participant