Refactor app_config.rs: collapse the ~18 default_* functions and group fields, with a doc-coverage test to stop drift

未關閉
#1,322 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
38/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
冷清
技術堆疊
rust
領域
backend

研究方向

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:

  1. A new field on the ~30-field AppConfig struct, usually with its own #[serde(default = "...")].

  2. 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
    18
    

    e.g. default_max_file_size, default_max_pending_rows, default_oidc_scopes.

  3. Sometimes a bespoke deserialize_with helper: deserialize_port, deserialize_socket_addr, deserialize_site_prefix, deserialize_duration_seconds.

  4. The env-var name is implicit (resolved by the config crate in load_from_file / env_config), so it never appears in code next to the field.

  5. A hand-maintained row in the configuration.md table. 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:

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 ~18 default_* 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

  • serde rename/flatten can 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 parsed AppConfig is unchanged.
  • Land the impl Default change 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 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

sqlpage/SQLPage 的其他 Issue

查看 sqlpage/SQLPage 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。