Skip to content

Finalize Phase 5: tests/docs/edge-cases after export unification (follow-up to #24) #27

@coderabbitai

Description

@coderabbitai

Summary

PR #25 functionally resolves the core of #24 (duplication removed; CLI now delegates to library; path generation unified). To fully meet the success criteria outlined in #24’s plan, the following follow-ups remain.

References:

Remaining work (high-value follow-ups)

  1. Library-level export integration tests

    • Create tests/tests_export_integration.rs (or similar) to exercise:
      • export_to_csv, export_to_gpx (with/without log_start_datetime), export_to_event
      • Multi-log suffix behavior (.NN), output_dir override, and defaulting to input’s parent dir
      • Byte-for-byte comparisons against known-good fixtures where applicable
    • Validate failure modes (nonexistent output_dir, unwritable paths) and error surfaces.
  2. GPX-only export: ensure output_dir is created

    • In src/export.rs::export_to_gpx(), mirror export_to_csv’s directory creation behavior (create_dir_all).
    • Add a test that requests GPX export into a fresh (nonexistent) directory.
  3. Early-return path calculation cleanup

    • When gps_coordinates.is_empty(), return Ok(()) without computing paths (avoid coupling logic to CLI messaging).
    • Keep CLI messaging relying on compute_export_paths() for consistent file names.
  4. Naming and fallback consistency

    • Unify base-name fallback (e.g., use “blackbox” everywhere) across CSV/GPX/event and CLI status messages.
    • Consider reusing compute_export_paths() inside export_to_gpx/export_to_event to prevent drift.
  5. Optional API enhancement (follow-up discussion)

    • Have export functions return a small “ExportReport { csv_path, gpx_path, event_path }” for the files actually written. This allows the CLI to print the exact paths and reduces duplication.

AI-instructional implementation plan

A) Tests

  1. Add tests under tests/ with fixture inputs in tests/fixtures/.
  2. Use tempdir to isolate outputs; exercise ExportOptions variants and multi-log inputs.
  3. Assert naming (.NN), directory resolution, and presence/absence of formats as configured.
  4. Include one large-GPS-log case to validate timestamp generation pathways.

B) GPX directory creation

  1. src/export.rs::export_to_gpx():
    • Resolve output_dir as today; if !exists, create_dir_all(output_dir)? before File::create.
  2. Unit/integration test to cover the GPX-only case.

C) Early-return simplification

  1. If gps_coordinates.is_empty(), return Ok(()) immediately.
  2. Ensure CLI status printing continues to use compute_export_paths().

D) Naming/fallback consistency

  1. Choose a single fallback base name (“blackbox”).
  2. Audit export_to_csv/export_to_gpx/export_to_event + any CLI helpers; align constants.
  3. Prefer compute_export_paths() within export functions (or ensure any local logic is identical).

E) Documentation

  1. Add a short “Exporting Data” section with examples to README or CRATE_USAGE.md.
  2. Document ExportOptions defaults and typical CLI mappings.

Acceptance criteria

  • New tests pass across platforms; coverage includes multi-log and directory-creation paths.
  • GPX-only export does not fail when output_dir is absent.
  • Early-return produces no message/path mismatch; CLI messages remain correct via compute_export_paths().
  • Fallback naming is consistent in code and printed messages.
  • Documentation reflects the unified export layer and examples compile.

Requested by: @nerdCopter on 2025-12-08

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions