Enforce feature isolation and expand copy_count test coverage

- Gate env_logger init behind #[cfg(feature = "bin-logging")] in
  records.rs main() so the binary respects the feature flag
- Set default-features = false on the dev-dependency self-reference
  in Cargo.toml; previously default features were silently re-enabled
  during tests, making feature isolation accidental rather than real
- Bind guid.to_string() once per card in user_data.rs deck loop and
  reuse it via clone, replacing three allocations per locked card
- Add per-field help text to the Track subcommand args clarifying
  human-readable names ("Laguna Seca", "Dry") vs raw codes
- Document write_details_csv DashMap snapshot memory tradeoff
  (full clone, roughly doubled peak memory during the write)
- Extend my_cars fixture test: duplicate guids count as 2 copies
  with per-copy configs, and incomplete-tune cards still count in
  copy_count
This commit is contained in:
Jan-Peter von Hunnius 2026-08-15 21:30:38 +02:00
parent 1a844e7aa8
commit ec8be9d138
5 changed files with 35 additions and 9 deletions

View file

@ -249,6 +249,13 @@ pub fn write_trash_csv(
/// of track, surface condition, and RQ level. Results are sorted by RQ then track ID
/// for consistent output ordering.
///
/// # Memory
///
/// Takes a full snapshot of the `best_cars` DashMap (cloning every key and record
/// list) so it can be sorted and written without holding DashMap shard locks.
/// Peak memory roughly doubles for the duration of the write — accepted here
/// because this runs once at the end of analysis, not in a hot loop.
///
/// # Output Format
/// ```csv
/// RQ,TrackID,Condition,CarRQ,Brand,Model,Year,Config,Time

View file

@ -127,7 +127,14 @@ enum Commands {
/// Generate details.csv with all timing data
Details,
/// Show best car for a specific track/condition/RQ combination
Track { track: String, condition: String, rq: u8 },
Track {
/// Human-readable track name (e.g. "Laguna Seca", not the raw code "laguna")
track: String,
/// Human-readable surface condition (e.g. "Dry", "Wet"; not the raw code "00")
condition: String,
/// RQ level (car's RQ up to 113)
rq: u8,
},
/// Generate improve.csv (owned cars not in final config, sorted by best tracks)
Improve,
}
@ -152,6 +159,7 @@ enum Commands {
async fn main() {
// Default to warn level so library/bin warnings stay visible without RUST_LOG;
// RUST_LOG can still silence or raise verbosity.
#[cfg(feature = "bin-logging")]
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
if let Err(e) = run().await {
eprintln!("Error: {e}");

View file

@ -67,8 +67,9 @@ pub fn load_my_cars_data(path: &str) -> Result<MyCarsData, AppError> {
for card in deck {
if card.get("locked").and_then(|v| v.as_bool()).unwrap_or(false) {
if let Some(guid) = card.get("cardId").and_then(|v| v.as_str()) {
owned.insert(guid.to_string());
*copy_count.entry(guid.to_string()).or_insert(0) += 1;
let guid = guid.to_string();
owned.insert(guid.clone());
*copy_count.entry(guid.clone()).or_insert(0) += 1;
// Extract actual tune config: engineMajor + weightMajor + chassisMajor.
// Skip cards with incomplete tune data to avoid false "000" entries
// that would incorrectly appear as needing upgrade.
@ -77,7 +78,7 @@ pub fn load_my_cars_data(path: &str) -> Result<MyCarsData, AppError> {
let chassis = card.get("chassisMajor").and_then(|v| v.as_u64());
if let (Some(e), Some(w), Some(c)) = (engine, weight, chassis) {
let config = format!("{e}{w}{c}");
owned_configs.entry(guid.to_string()).or_default().push(config);
owned_configs.entry(guid).or_default().push(config);
} else {
log::warn!("locked card {guid} has incomplete tune data — skipped");
}