refactor(config): extract config out of daemon.rs to fix cohesion gate - #76
Conversation
…cohesion Move the CONFIG responsibility (RuntimeMode, DaemonConfig + serde defaults, DaemonConfig::load, validate_pub_socket_opts, pub_endpoint) out of daemon.rs into a new src/config.rs and re-export it from daemon.rs so every public and crate-internal path resolves unchanged. Pure code movement + re-exports: no behavior, signature, error-message, serde-attribute, or wire-payload changes. Fixes the CodeScene 'Prevent hotspot decline' / Low Cohesion gate that failed on merged PR #74 by lowering daemon.rs's distinct-responsibility count.
|
Skipping PR review because a bot author is detected. If you want to trigger CodeAnt AI, comment |
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 2 |
| Duplication | -4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Reduce Code Duplication in src/config.rs by factoring the shared valid TOML body into config_toml_with_log_level/base_config_toml helpers and a load_base_config helper, and by folding the four reject cases (unknown log level, zero sndhwm, negative sndhwm, negative linger) into a single table-driven test. All prior coverage and error-substring assertions are preserved; only the #[cfg(test)] module changed.
There was a problem hiding this comment.
Code Health Improved
(1 files improve in Code Health)
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
View Improvements
| File | Code Health Impact | Categories Improved |
|---|---|---|
| daemon.rs | 5.22 → 5.37 | Low Cohesion, Code Duplication |
Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
Problem
PR #74 (bounded PUB lifecycle / loss semantics / safe bind defaults — issue #68 / LIM-1320) merged to
mainwhile the CodeScene code-health gate was failing: "Prevent hotspot decline — Low Cohesion" onsrc/daemon.rs("at least 6 different responsibilities amongst its 46 functions, threshold = 3"). Build and test CI were green and the functional review findings were fixed, but merging over a red quality gate leftmainin a not-clean state.This is a fix-forward for that gate. It does not revert #74 — the bounded-PUB-lifecycle work stays on
main.Change
Pure move + re-export (zero behavior change): the CONFIG responsibility is extracted from
src/daemon.rsinto a newsrc/config.rssubmodule.Moved byte-for-byte (doc comments +
#[serde(default)]attributes intact):RuntimeModeenum andDaemonConfigstruct (+ all field docs)default_spine_pub_*serde-default fnsimpl DaemonConfig { pub fn load }validate_pub_socket_opts(pub(crate)) andpub_endpointwrite_config_tomlhelpersrc/lib.rsgainspub mod config;;src/daemon.rsre-exportspub use crate::config::{DaemonConfig, RuntimeMode, pub_endpoint};.Public API unchanged
All existing paths still resolve via re-exports —
brainstem_daemon::daemon::{DaemonConfig, RuntimeMode, pub_endpoint},DaemonConfig::load, and thelib.rsre-exportsbrainstem_daemon::{DaemonConfig, RuntimeMode}. No call site was edited (checkpoint, binary, smoke test).validate_pub_socket_optsstayspub(crate)atcrate::config::validate_pub_socket_opts, still wired into theloadpath (its only caller moved with it, so no re-export is needed and none is added — that would be an unused import underclippy -D warnings).Effect
src/daemon.rs: 2782 → 2415 lines (−367); one full cohesive responsibility (config definition + loading + validation + endpoint helper) removed as a cluster — directly targeting the cohesion metric.Validation
cargo fmt --checksilent;clippy --locked --all-targets -- -D warningsclean;build --lockedok;test --locked154 passed / 0 failed / 1 ignored.CC=gcc CXX=g++, 1.98.1):clippy --all-targets --all-features -D warningsclean;build --all-featuresok;test --all-features176 lib + 9 smoke passed / 0 failed.ZmqSpikeSinkaccounting untouched.Limitations
daemon.rsis still over threshold, the next cleanest extraction is the control-plane HTTP wiring (start_control/bind_control/spawn_control_task/stop_control) into a control submodule.Tracking
Follow-up to #74; part of #68 / LIM-1320. Non-closing reference — #68 (v0.3.0 qualification blocker) stays open.
🤖 Delivered by the Kiro agent.
Summary by cubic
Pure move-and-re-export refactor that extracts the config responsibility out of
daemon.rsinto a newsrc/config.rsto clear the CodeScene low-cohesion gate that failed on PR #74, and consolidates the moved config tests to reduce code duplication.daemon.rsre-exportsDaemonConfig,RuntimeMode, andpub_endpoint, so every existing path and call site keeps resolving unchanged.config_toml_with_log_levelandbase_config_toml; the four reject cases fold into one table-driven test with preserved assertions.validate_pub_socket_optsstayspub(crate).fmt,clippy -D warnings,build, andtest(154 passed), plus the corpus-ipc gate; CodeScene itself only runs in CI.Written for commit f59cd0b. Summary will update on new commits.