Skip to content

refactor: tidy and harden the config surface#15

Merged
rrbe merged 2 commits into
masterfrom
refactor/flatten-metadata-config
May 31, 2026
Merged

refactor: tidy and harden the config surface#15
rrbe merged 2 commits into
masterfrom
refactor/flatten-metadata-config

Conversation

@rrbe
Copy link
Copy Markdown
Owner

@rrbe rrbe commented May 29, 2026

Config-surface cleanup + hardening, prompted by noticing [metadata] was a one-key section inconsistent with the other top-level switches.

1. Flatten metadata (cosmetic + consistency)

[metadata] show was a table holding a single boolean — inconsistent with the sibling top-level switches theme and bell. Flattened to a top-level metadata key.

# before            after
[metadata]
show = true    metadata = true

Config.metadata: Option<bool>, mirroring bell: None/Some(true) show, Some(false) hides. Using Option<bool> (not a bare bool) keeps the derived Default correct. The frontmatter feature is still unreleased, so there's no config-compat burden.

2. theme is now a typed enum (fixes a silent failure)

theme was a free String; resolve_theme mapped any unrecognized value to auto-detect via a catch-all _ => detect(), so a typo like theme = "drak" silently behaved as auto with zero feedback. It's now a ThemeChoice { Auto, Dark, Light } enum:

  • Config file: an invalid value is a hard parse error, surfaced by load's existing one-line warning.
  • --theme: a matching FromStr warns on an unrecognized value instead of swallowing it.

Non-breaking — theme = "dark" / "light" / "auto" parse identically.

3. Strict config parsing (deny_unknown_fields)

Added #[serde(deny_unknown_fields)] to the config structs, so a typo'd key (e.g. bel for bell) is reported via the invalid-config warning rather than silently ignored. The serde error names the offending key and lists the valid ones. Non-breaking for any well-formed existing config (no config key has ever been removed/renamed in a release).

Deliberately NOT done: collapsing [font.heading][font]

[font.heading] is the same "is this nesting earned?" smell as [metadata], but HeadingFontConfig has shipped since v0.1.0. Collapsing it would silently break every existing user's font config (and with #3, hard-error and drop their entire config). The reason flattening metadata was free is that it was unreleased; [font.heading] is the inverse case, so it's left as-is.

Tests

Added unit tests for known/invalid theme values, unknown-key rejection, and ThemeChoice::FromStr. make check passes clean.

🤖 Generated with Claude Code

rrbe and others added 2 commits May 30, 2026 00:05
The `[metadata] show` table held a single boolean, inconsistent with the
sibling top-level switches `theme` and `bell`. Flatten it to a top-level
`metadata` key implemented as `Option<bool>` (like `bell`): `None` (key
absent) and `Some(true)` render frontmatter, `Some(false)` hides it. Using
`Option<bool>` keeps the derived `Default` correct — a bare `bool` would
default to `false` and silently hide metadata on missing/invalid config.

The frontmatter feature has not shipped in a release yet, so there is no
config-compat burden. Updates config.example.toml, the CLI test, CHANGELOG,
CONTEXT.md, the feature-coverage doc, and appends an amendment to ADR 0001.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Two config-robustness fixes found while reviewing the rest of the config
surface after the metadata flatten:

- `theme` was a free `String` whose unrecognized values silently fell back
  to auto-detect (`resolve_theme`'s `_ => detect()`). It is now a typed
  `ThemeChoice` enum, so an invalid value in the config file is a hard parse
  error routed through `load`'s one-line warning. `--theme` gets a matching
  `FromStr` and warns on an unrecognized value instead of swallowing it.
- Added `#[serde(deny_unknown_fields)]` to the config structs so a typo'd key
  (e.g. `bel` for `bell`) is reported rather than silently dropped.

Both are non-breaking for valid existing configs — `theme = "dark"` etc. parse
identically. The released `[font.heading]` nesting is deliberately left as-is:
collapsing it would break existing user configs for a cosmetic gain.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rrbe rrbe changed the title refactor: flatten metadata config to a top-level boolean refactor: tidy and harden the config surface May 29, 2026
@rrbe rrbe merged commit e5674fc into master May 31, 2026
5 checks passed
@rrbe rrbe deleted the refactor/flatten-metadata-config branch May 31, 2026 15:46
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