Repository navigation
Typed TOML config with env override layer for PACE_* switches - #57
Conversation
… exists macOS has neither /etc/machine-id nor /etc/hostname and COMPUTERNAME is unset, so the fallback chain legitimately ends at "unknown" and the assertion premise never holds; cargo test stayed red on dev machines.
…g table All 21 PACE_* switches (7 of which were read at runtime but missing from the old src/config.rs table: PACE_EXTRA_CA, PACE_IGNORE_DAILY_LIMIT, PACE_PREFER_STADIUM, PACE_CENTER_LAT, PACE_CENTER_LNG, PACE_FIXED_POINT, PACE_FORCE_NORMAL_POINT) are defined exactly once - key, env name, parser, default, effect. The same table drives config.toml parsing, env parsing and the `pace-forge config` listing, so the documented list can no longer drift from what actually gets read. Precedence is env > config.toml > built-in defaults. Loading is fail-fast: unknown keys, out-of-vocabulary values and half-specified fence anchors are collected and reported together before anything runs. A process-wide read-only snapshot (store/global, Guard for tests) serves the values. Shared deps move to workspace = true.
…alls
main.rs parses --config, loads the config and stores the snapshot before
dispatching; the 25 scattered std::env::var("PACE_*") call sites across
api/web/track now read config::global(). Parsing semantics are aligned
with the old code per key (which keys trim, which keep raw text,
run_mode accepts any integer, enum vocabularies match raw text, tz and
bulge ranges are unchanged), so valid inputs behave exactly as before.
Deliberate behavior changes, all declared in IRmsk#53 and CHANGELOG:
- invalid values abort startup with a config error instead of silently
falling back to defaults (the point of the refactor)
- PACE_IGNORE_DAILY_LIMIT=0 now disables the bypass; the old presence
check enabled it for any value including 0
- bool switches accept a unified 0/1/true/false/yes/no vocabulary
(case-insensitive); every documented value behaves as before
- PACE_DUMP_POLICY="" no longer acts as a directory name
The crosscheck CLI test now locks the fail-fast contract for invalid
PACE_TZ_OFFSET_SEC values.
config.example.toml lists every key with comments; README gains a config section covering search order, precedence and the per-key source labels in `pace-forge config`; CONTRIBUTING points contributors at the registry as the single place to add a switch; CHANGELOG records the migration notes and the two behavior fixes (IGNORE_DAILY_LIMIT=0 semantics, the machine-identity test on source-less hosts).
The 21-row switch table duplicated config.example.toml line for line (defaults, effects, env names) and nobody enjoys reading a wall of rows in a terminal. The reference belongs to the docs: config.example.toml (all keys, commented) plus the README config section. The one piece of live information the table had - which switches are currently non-default and which layer they come from - stays in the web startup log line. With the table gone, the registry no longer carries the display-only default/effect strings either; entries keep only what code needs (key, env name, parser). The unknown-key error now points at config.example.toml alone.
lib.rs had grown past 1400 lines holding seven unrelated concerns plus the test matrix. Now: value (parsed values and sources), model (typed config structs and key_values), parser (per-key parsers), registry (entry table), load (file discovery, TOML/env layers, cross validation), runtime (process snapshot and startup summary), tests (the equivalence/boundary matrix). The public API is unchanged - lib.rs only declares modules and re-exports, so pace_forge::config::* paths stay exactly as they are.
|
Two follow-up commits pushed to this branch: 1. On reflection, the 21-row switch table this PR added to
The registry also stopped carrying display-only default/effect strings, so entries now hold only what code needs (key, env name, parser). Unknown-key errors point at 2. crate split into modules (96e2866)
Both verified: 525 lib tests + 21 config-crate tests + integration green, clippy 0 warnings, fmt clean. Smoke-checked on the real binary: |
#58) Phase 1 of the proposal, the near-zero-cost part: - [workspace.lints.rust]: unsafe_code = forbid, unsafe_op_in_unsafe_fn = deny. The crate has no unsafe left after #57 removed the env writes in tests. - [workspace.lints.clippy]: allow_attributes and allow_attributes_without_reason denied, so suppressions are written as #[expect(.., reason = ..)] and complain once they go stale; undocumented_unsafe_blocks and multiple_unsafe_ops_per_block denied. - The config crate now inherits the workspace lints instead of its own copy. - The five remaining #[allow]s: - two dead_code ones covered items that only tests use, so they are #[cfg(test)] now and the suppression is gone; - two too_many_arguments became #[expect] with a reason; - one (detail_payload_rrid) was stale, the function no longer has too many arguments, so it is simply removed. missing_docs, pedantic and the cast denies are deliberately not enabled yet: CI is -D warnings and they need their cleanup in the same change.
|
合了,这个 PR 我核得最细:全门、release 构建、cargo-deny,还实际跑了写错值(退出码 2,报错说得很清楚)、未知键、不带参数启动。都没问题。 有一件事想直说:后加的那个 commit 把 我先合了,没改你的代码。你要是愿意,我想请你补一个很薄的 |
Closes #52.
Summary
Replaces the scattered
std::env::var("PACE_*")reads (25 call sites) and the hand-writtenENTRIESdocumentation table with a typed config layer in a new leaf crate,crates/pace-forge-config:PACE_*env >config.toml> built-in defaults. File discovery:--config <path>/PACE_CONFIG>./config.toml>~/.pace-forge/config.toml. Egress proxy keeps its extra top layer (web-saved setting first), unchanged.pace-forge config, so the documented list can no longer drift from what actually gets read (issue Proposal: typed TOML config with env override layer for PACE_* switches #53 documents seven runtime-read vars missing from the old table, with file:line evidence).parse().ok().unwrap_or(default)silent fallbacks.main.rsloads once before dispatching; everything else readsconfig::global()(anArc<Config>). Tests inject viaGuard::replace, which serializes internally and restores on drop — no moreset_varin tests.pace-forge configkeeps its table and now shows, per switch, the current value and which layer it came from (env / config.toml / default). Secrets stay masked. Web startup keeps the non-default line.Behavior changes (all declared in #53)
For every documented input value, behavior is byte-identical to before — per-key parsing was aligned against the old code (which keys trim, which keep raw text,
run_modeaccepts any integer, enum vocabularies match raw text, tz/bulge ranges unchanged). The deltas:PACE_IGNORE_DAILY_LIMIT=0now disables the bypass. The old presence check (is_ok()) enabled it for any value, including0.0/1/true/false/yes/novocabulary. The old parsers were inconsistent per key (fence_fullaccepted only"1",fixed_strictalso accepted"TRUE"); every previously documented value behaves as before.PACE_DUMP_POLICY=""no longer acts as a directory name.Also,
key_sources_fall_back_past_the_posix_defaultsnow skips on hosts with no machine-identity source (macOS has neither/etc/machine-idnor/etc/hostnameandCOMPUTERNAMEis unset) — it keptcargo testred on dev machines, unrelated to this refactor.Verification
cargo test: 525 lib tests + integration tests green (includes a new boundary/vocabulary matrix in the config crate: numeric range edges, inf/nan/whitespace digits, full enum vocabularies, legacyPACE_FORCE_NORMAL_POINTmapping, precedence, anchor pairing, guard restore, secret masking; and main-crate mapping-equivalence tests for fixed_point / pt_scheme / run_area_id / strict / anchor / tz / hw headers).cargo clippy --all-targets: 0 warnings.cargo fmt --checkclean.--configsource labels, env-over-toml override, and exit code 2 with a collected error list for invalid env values, unknown TOML keys, and missing--configfiles.