Repository navigation
refactor(app): split lib.rs, config.rs and cli.rs into directories - #351
Conversation
Signed-off-by: InstaZDLL <github.105mh@8shield.net>
…, router and openapi Signed-off-by: InstaZDLL <github.105mh@8shield.net>
…family Signed-off-by: InstaZDLL <github.105mh@8shield.net>
… command family Signed-off-by: InstaZDLL <github.105mh@8shield.net>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Contrats et chargement de la configuration src/config/*, src/config.rs |
La configuration monolithique est remplacée par des modules de types, de parsing et de validation. Les paramètres couvrent notamment les limites, les intégrations et les variables d’environnement. |
État et initialisation de l’application src/app/boot.rs, src/app/state.rs, src/app/mod.rs, src/lib.rs |
initialize ouvre la base et lance le démarrage. Celui-ci applique les migrations, prépare les services et construit AppState. shutdown_signal attend les signaux de terminaison décrits. Les éléments applicatifs sont réexportés depuis app. |
Routage HTTP
| Layer / File(s) | Summary |
|---|---|
Routage et documentation OpenAPI src/app/router.rs, src/app/openapi.rs, src/app/tests.rs |
Le routeur configure les identifiants de requête, les traces, la compression, les délais et CORS. Les chemins sensibles sont expurgés dans les traces. Le document OpenAPI décrit les routes, la sécurité et les réponses des mutations; les tests vérifient ces annotations. |
Commandes administratives
| Layer / File(s) | Summary |
|---|---|
Interface et dispatch des commandes src/cli/args.rs, src/cli/mod.rs, src/cli.rs |
L’interface CLI et son répartiteur sont déplacés dans des modules dédiés. Ils déclarent les commandes et arguments, puis dirigent les commandes vers leurs gestionnaires. |
Comptes, bibliothèques et scrobbling src/cli/account.rs, src/cli/library.rs, src/cli/scrobble.rs, src/cli/tests.rs |
Les gestionnaires ajoutent les opérations de comptes, d’identifiants et de jetons, de bibliothèques et de scrobbling. Ils appliquent les contrôles d’accès et validations décrits par les commandes. |
Base de données et clés src/cli/database.rs, src/cli/key.rs |
Les commandes ajoutent la sauvegarde et la restauration de la base avec sa clé. key rotate et key adopt présentent un inventaire et, après confirmation, sauvegardent la paire avant de modifier la clé et les données associées. |
Priority:
Estimated code review effort: 5 (Critical) | ~120 minutes
Change: Refactor
Sequence Diagram(s)
sequenceDiagram
participant initialize
participant Database
participant boot
participant AppState
initialize->>Database: ouvre la base
initialize->>boot: démarre l’application
boot->>Database: sauvegarde et applique les migrations
boot->>AppState: construit l’état avec les services configurés
Merge Risk: 
Minimal · up to 2c690
-
This change reorganizes configuration, application startup, routing and CLI code into smaller modules without intended behavior changes. No concrete regression was found, so it looks safe to merge after the normal CI checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
La description explique les objectifs, les changements, les tests exécutés, les écarts au plan et les points connus. Elle ne reprend pas les rubriques exactes du modèle, les cases du plan de test ni la confirmation AGPL-3.0-only et DCO, mais le contenu requis est globalement présent.
-
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
Phase A of the backend restructuring, for the three files at the top of the crate:
src/lib.rs,src/config.rsandsrc/cli.rs. Moves only. No function was renamed, no signature or logic changed, and no public path moved: everything that resolved aswaveflow_server::X,crate::config::Xorcrate::cli::Xstill does, through explicitpub uselines. No file undertests/was touched, andmain.rsandbuild.rscompile unchanged.Commits
git mv src/config.rs src/config/mod.rsandgit mv src/cli.rs src/cli/mod.rs, alone, so git records the renames.src/lib.rs→src/app/.src/config/mod.rs→ one file per settings family.src/cli/mod.rs→ arguments plus one file per command family.Old → new
src/lib.rs→src/app/(a private module, re-exported at the root)pub moddeclarations, crate//!doc,pub use config::Configsrc/lib.rs, pluspub use app::{app, initialize, shutdown_signal, ApiDoc, AppState, OPENAPI_JSON_PATH, SCALAR_PATH}AppState,negotiation_body_limit,chunk_body_limitapp/state.rsinitialize,boot,shutdown_signalapp/boot.rsapp,REQUEST_ID_HEADER,CREDENTIAL_BEARING_PREFIXES,trace_pathapp/router.rsOPENAPI_JSON_PATH,SCALAR_PATH,ApiDoc,SecurityAddon,BEARER_SECURITY_SCHEME,PUBLIC_OPERATIONS,clear_security_on_public_operations,annotate_scope_refusals,annotate_mutation_headers,openapi_responseapp/openapi.rsmod tests(5 tests)app/tests.rssrc/config.rs→src/config///!doc,Config, itsDebugconfig/mod.rs(with themod/pub uselines)impl Config { fn from_env },parse_link_roots,DEFAULT_DB_ACQUIRE_TIMEOUT_MSconfig/from_env.rsimpl Config { fn for_data_dir }config/for_data_dir.rsparse_env,parse_bool_env,parse_positive_env,read_trimmed_envconfig/env.rsUploadLimits,CanvasLimits,LibraryEventRetention,validate_uploads,validate_canvasconfig/limits.rsPodcastSettings,RemoteArtworkSettings,parse_podcast_settingsconfig/podcasts.rsMetadataSettings(+off,Debug),LyricsSettings(+off),parse_metadata_settings,parse_lyrics_settings,parse_metadata_providers,parse_lyrics_providersconfig/metadata.rsScrobbleLimits,DEFAULT_SCROBBLE_MAX_ATTEMPTS,DEFAULT_SCROBBLE_DESTINATION,LastFmApplication(+Debug),ScrobbleDestination,test_destinations,parse_destinationsconfig/scrobbling.rsSETUP_TOKEN_MIN_CHARS,parse_setup_token,normalize_public_url,parse_proxy_addressesconfig/access.rsDEFAULT_PID_ALBUM/_TRACK/_ARTIST,PidSpecKind,parse_pid_spec,default_pid_spec,default_pid_specsconfig/pid.rsmod tests(12 tests)config/tests.rssrc/cli.rs→src/cli///!doc,execute,require_admin,read_secret_env,non_blank,validate_usernamecli/mod.rsCli,Commandand every*Command/*Argscli/args.rskey,read_instance_key,Intent,open_for_key_change,rotate_key,adopt_key,report_reading,print_inventory,sync_file,sync_directory,copy_the_pair_aside,install_new_key,report_donecli/key.rsbackup,restorecli/database.rsadd_library,library_refusal,wait_for_scan,rename_library,set_library_path,set_library_links,delete_library,list_unavailable,purge_unavailable,restore_purged,set_library_watch,set_member,set_uploads,set_canvas,remove_membercli/library.rscreate_account,set_credential,revoke_credential,create_tokencli/account.rsscrobble_provider,link_scrobble,authorize_lastfm,exchange_lastfm,unlink_scrobble,scrobble_statuscli/scrobble.rsmod tests(2 tests)cli/tests.rsLine counts
src/lib.rssrc/lib.rsapp/mod.rsapp/state.rsapp/boot.rsapp/router.rsapp/openapi.rsapp/tests.rssrc/config.rsconfig/mod.rsconfig/from_env.rsconfig/for_data_dir.rsconfig/env.rsconfig/limits.rsconfig/podcasts.rsconfig/metadata.rsconfig/scrobbling.rsconfig/access.rsconfig/pid.rsconfig/tests.rssrc/cli.rscli/mod.rscli/args.rscli/key.rscli/database.rscli/library.rscli/account.rscli/scrobble.rscli/tests.rsThe largest code file is
app/openapi.rsat 625 lines, most of it the#[openapi(...)]path and schema lists; the largesttests.rsisconfig/tests.rsat 409.Proof that nothing was lost
cargo test --all-features -- --list | grep -c ': test$': 663 before, 663 after. The sorted lists differ only in the five tests that sat at the crate root:tests::Xis nowapp::tests::X. Everyconfig::tests::*andcli::tests::*name is unchanged.uselines, the new//!headers, theimpl Config {wrappers, signatures rustfmt rewrapped becausepub(super)made them longer, and the test path edits listed below.cargo fmt --all --check,cargo clippy --all-targets --all-features -- -D warningsandcargo test --all-features(full suite) all pass.What changed apart from position
pub. Inapp:negotiation_body_limit,chunk_body_limit,PUBLIC_OPERATIONS,openapi_response,CREDENTIAL_BEARING_PREFIXESandtrace_pathbecamepub(super). Inconfig: the parsers, validators and readers thatfrom_env.rs,for_data_dir.rsortests.rsreach from a sibling file. Incli: the handlersexecutedispatches to,backup,ExchangeLastFmArgs::TOKEN_ENV, and the 67 private fields of the*Argsstructs. Those fields are read from the handler files now, so they arepub(super): visible insidecliand nowhere else.app/tests.rs:super::PUBLIC_OPERATIONSbecamesuper::openapi::PUBLIC_OPERATIONS,super::CREDENTIAL_BEARING_PREFIXESbecamesuper::router::…, andsuper::api::becamecrate::api::. Inconfig/tests.rs: the imports name the child modules, andsuper::parse_lyrics_providersbecamesuper::metadata::parse_lyrics_providers.Where this departs from the plan, and why
appis a private module. Everything in it was public at the crate root and still is, throughpub useinlib.rs. Making the module private adds no second public path for phase B to keep or retire.state.rs, notrouter.rs. They compute threeAppStatefields, the field docs describe them, and onlybootcalls them. The router never does.shutdown_signalis inboot.rs. A file of its own would have held 26 lines.OPENAPI_JSON_PATHandSCALAR_PATHare inopenapi.rs. They are where the document and its reference are served.reference.rsstill readscrate::SCALAR_PATH.Config::from_envwas not broken into per-family parsers. Extracting new functions out of its body would be a restructuring of logic, not a move. It went whole intofrom_env.rs(392 lines), and the test fixturefor_data_dirwent into a file of its own. Families that already had a parser (parse_podcast_settings,parse_metadata_settings,parse_destinations, …) took it with them. Splittingfrom_envitself is left for a later phase.limits.rs: all three bound what the server keeps on its own disk, and retention alone would be a 15-line file. Remote artwork lives with podcasts because it is defined in RFC-025 beside them. The public URL, trusted proxies and setup token shareaccess.rs.parse_link_rootsandDEFAULT_DB_ACQUIRE_TIMEOUT_MSstay withfrom_env, their only user apart from one test.config/pid.rs(49),config/access.rs(53),config/env.rs(59) andcli/database.rs(68) are short, but each is a family the plan named, with more than one caller. Folding any of them intofrom_env.rswould have mixed it with unrelated settings.tests.rsper directory.app/tests.rsmixes tests ofopenapi.rsandrouter.rs, and one of them,every_public_ticket_route_has_a_redaction_prefix, exists to tie the two tables together.config/tests.rsspans five families. Giving each test a file beside its code would have meant directories for 50-line files.Noticed, deliberately not changed
CLAUDE.mdandAGENTS.mdsay "All environment access lives insrc/config.rs". It now lives insrc/config/. The wording is left for phase B, as agreed.CREDENTIAL_BEARING_PREFIXESsays the canvas route is listed "two hundred lines above" inPUBLIC_OPERATIONS, and the doc onevery_public_ticket_route_has_a_redaction_prefixsays "two hundred lines from a redaction list". The two lists are in different files now. Both comments were kept verbatim.climodule doc still reads "Administrative CLI used before the M4 web administration surface exists". M4 has landed.canvas_body_limitfalls back tousize::MAX(unwrap_or(usize::MAX)inboot).chunk_body_limit, now instate.rs, documents that a ceiling falling back to "no ceiling" is the one mistake it must never make.from_envrefuses the unrepresentable value, so the branch is unreachable from the environment. AConfigbuilt by hand is not validated, though, and the two helpers disagree on principle.from_envreads seven settings where zero is allowed (API token TTL, scan interval, unavailable retention, purge grace, quality parallelism, migration backups, podcast refresh) with the samevar / unwrap_or_else / parse / map_errblock written out each time.parse_metadata_settingsandparse_lyrics_settingseach define the samedaysclosure. A shared reader inenv.rswould remove both repetitions, but that is a logic change.Summary by CodeRabbit
Nouvelles fonctionnalités
Améliorations