fix(config): keep embedded-constructed structs constructible (un-break coordinode)#46
Conversation
The previous blanket #[non_exhaustive] broke embedded consumers that build the config programmatically with struct literals (runtime upstream port, listen address, baked-in descriptors) instead of loading YAML. Scope non_exhaustive correctly: remove it from the wiring structs an embedding consumer legitimately constructs (ProxyConfig, UpstreamConfig, ListenConfig, ServiceConfig, and the DescriptorSource enum); keep it on the leaf auth/shield/oidc/etc. structs that are deserialized, not hand-built, and that actually churn. Add ProxyConfig::from_yaml_str for embedding a baked-in config without a file, and a separate-crate integration test that reproduces the embedded construction pattern so a re-added non_exhaustive is caught at compile time. Removing non_exhaustive is a relaxation (more permissive), so this is a non-breaking patch. Closes #45
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesEmbedded Config Constructibility
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
| Filename | Overview |
|---|---|
| src/config.rs | Removes #[non_exhaustive] from five wiring structs/enum, adds from_yaml_str convenience method (and delegates from_file to it). The leaf auth/shield/oidc structs retain #[non_exhaustive]; the refactoring is functionally equivalent to the old from_file body. |
| tests/embedded.rs | New external-crate integration test that reproduces the coordinode embedding pattern; includes a structural-literal test and a from_yaml_str parse test. Comment on forwarded_headers correctly warns about bypassing serde defaults. |
Reviews (2): Last reviewed commit: "docs(test): clarify forwarded_headers in..." | Re-trigger Greptile
A programmatic config literal bypasses serde defaults, so note that the single header is arbitrary for this constructibility test and that real embeddings must set the headers they need (or load via from_file / from_yaml_str where the default list applies). Part of #45
Summary
The blanket
#[non_exhaustive](shipped in 2.0.0) broke embedded consumers that build the config programmatically with struct literals, rather than loading YAML. coordinode does exactly this incoordinode-serverto inject the runtime upstream port, listen address, and baked-in descriptors:With
#[non_exhaustive]on those structs, this stops compiling for any external crate.Fix: scope non_exhaustive correctly
ProxyConfig,UpstreamConfig,ListenConfig,ServiceConfig, and theDescriptorSourceenum.Principle:
#[non_exhaustive]belongs on deserialized-only leaf config, not on the wiring structs consumers construct programmatically.Dev UX
ProxyConfig::from_yaml_str(&str)so an embedded build can load a baked-in config (include_str!) without touching the filesystem.tests/embedded.rs— a separate-crate integration test that reproduces coordinode's exact construction (ProxyConfig literal + DescriptorSource::Embedded + ProxyServer). Because it's an external crate, it seesnon_exhaustivelike a real consumer: if any wiring struct regains it, this test fails to compile and the regression is caught.Versioning
Removing
#[non_exhaustive]is a relaxation (more permissive), so this is a non-breaking patch (2.0.1), not a major bump. cargo-semver-checks is satisfied.Testing
cargo nextest run --features redis: 121 passed (incl. the 2 new external-crate embedded tests). clippy (all-features) + fmt clean.Closes #45