Refactor app_config.rs: collapse the ~18 default_* functions and group fields, with a doc-coverage test to stop drift
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with src/app_config.rs, especially AppConfig, its default_* and deserialization helpers, and configuration.md; then inspect the existing config-loading and test setup. The proposal spans default handling, nested structs, serialization compatibility, and documentation coverage, so split the work as suggested and add round-trip tests for existing file and environment layouts. Done means config keys and behavior remain compatible and a test catches public fields missing from the docs.
由索引模型根据 Issue 内容生成。
描述
Splitting the "app_config.rs is a large multi-responsibility module" item out of #1249 into a concrete, actionable refactor.
Problem
Adding a single config option to src/app_config.rs touches 5+ disconnected places, and nothing makes the compiler tell you when you forgot one:
-
A new field on the ~30-field
AppConfigstruct, usually with its own#[serde(default = "...")]. -
A standalone top-level
default_*()free function returning a literal, declared far away from the field it belongs to. There are 18 of them today:$ grep -c "fn default_" src/app_config.rs 18e.g.
default_max_file_size,default_max_pending_rows,default_oidc_scopes. -
Sometimes a bespoke
deserialize_withhelper:deserialize_port,deserialize_socket_addr,deserialize_site_prefix,deserialize_duration_seconds. -
The env-var name is implicit (resolved by the
configcrate inload_from_file/env_config), so it never appears in code next to the field. -
A hand-maintained row in the
configuration.mdtable. Nothing ties the field to its default to its doc row.
Concrete drift this already caused
The doc comment on max_uploaded_file_size disagrees with its own default function:
- field doc comment, L224:
Maximum size of uploaded files in bytes. The default is 10MiB (10 * 1024 * 1024 bytes) default_max_file_size, L625-L627 actually returns5 * 1024 * 1024(5 MiB)configuration.mdL27 says5242880/ "Defaults to 5 MiB"
So the inline Rust comment drifted to claim 10 MiB while the real default and the docs table both say 5 MiB. Exactly the silent drift this structure invites.
Proposed change
- Move the literal defaults into a single
impl Default for AppConfig(or a const-backed table) and use#[serde(default)], eliminating the ~18default_*free functions and putting each default next to its field. - Group the flat struct into nested domain sub-structs (database, oidc, https, telemetry, markdown) with
#[serde(flatten)], so related field + default + validation co-locate and the file shrinks. - Add a doc-coverage test asserting every public config field name appears in
configuration.md, killing drift mechanically (a value-coverage assertion could also catch the 5/10 MiB case).
Risks and mitigations
serderename/flattencan change the accepted file keys / env var names. Mitigate by keeping field names byte-for-byte identical and adding round-trip tests that load representative existing config files / env layouts and assert the parsedAppConfigis unchanged.- Land the
impl Defaultchange separately from the sub-struct grouping, so each PR is small and the bisect surface stays tight.
Expected win
One place to edit per option, defaults next to their fields, and doc drift caught by a test instead of by a user.
Refs #1249.
- 主要语言
- Rust
- 星标
- 2.6k
- 派生
- 175
- 平均合并
- 14 小时 16 分钟
- 30 天内合并 PR
- 43
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sqlpage/SQLPage 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
sqlpage/SQLPage#1218 · 3 条评论 ·
维护者通常 1 天内回复
-
There is no convenient way to reproduce issues可能已有人在做 @81reap 于 26 天前认领。 未关闭enhancement
sqlpage/SQLPage#1566 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Confusing sort interface可能已有人在做 @lovasoa 于 73 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 20/100
sqlpage/SQLPage#1442 · 3 条评论 ·
维护者通常 1 天内回复
-
Mutation Testing Results :: Dead Code + Missing Tests可能重新可做 @81reap 于 61 天前认领,目前没有进行中的 PR。 未关闭
sqlpage/SQLPage#1396 · 5 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
symposium-dev/symposium#530 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
topgrade-rs/topgrade#2540 ·
维护者通常 1 天内回复
-
Invalid JSON options for ngram and edge_ngram silently use defaults可能已有人在做 @Tilendlesa 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
noemaforge/vimanam#153 ·
维护者通常 1 天内回复