Files
2025-09-01 21:37:01 -04:00

10 KiB

Project Mycelium - Complete Mock Data Removal Plan

Date: 2025-08-14
Task: Remove all code-based mock data and enforce persistent-only data
Status: Implementation Active

Overview

Despite the architecture documentation claiming "100% Mock Data Elimination," extensive mock data infrastructure remains throughout the system. This plan systematically removes all 129+ mock patterns identified while ensuring the application continues to function with persistent storage only.

Current Mock Data Patterns Identified

Critical Mock Infrastructure:

  • MockUserData Factory Methods: user1() through user5() in src/models/user.rs
  • MockDataService Singleton: Complete service in src/services/mock_data.rs
  • User.mock_data Field: Extensively used across controllers
  • MockPaymentGateway: Mock payment processing in src/services/order.rs
  • Mock-dependent Controllers: Rental, Pool, Dashboard controllers
  • Mock Initialization: User persistence still initializes with mock data

Phase 1: Infrastructure & Data Model Changes

Goal: Establish persistent-only data patterns and remove mock dependencies

1.1 Remove MockUserData Factory Methods

  • Delete user1() through user5() methods from src/models/user.rs
  • Replace inline mock arrays with Vec::new() defaults
  • Ensure all fields have #[serde(default)] for backward compatibility
  • Update MockUserData::new_user() to return minimal default structures

Files to modify:

  • src/models/user.rs (lines 1311-2801)

1.2 Remove User.mock_data Field Dependency

  • Update User struct to make mock_data field optional/deprecated
  • Remove mock_data field access from all controllers
  • Route wallet balance, transactions through UserPersistence only
  • Add transition methods to extract data from persistent storage

Files to modify:

  • src/models/user.rs (User struct definition)
  • src/models/builders.rs (UserBuilder)

1.3 Remove MockDataService Infrastructure

  • Delete entire src/services/mock_data.rs file
  • Remove MockDataService imports across all controllers
  • Update src/services/mod.rs to remove mock_data module
  • Replace marketplace config with minimal persistent config

Files to modify:

  • src/services/mock_data.rs (DELETE)
  • src/services/mod.rs
  • All controllers importing MockDataService

Phase 2: Controller Refactoring

Goal: Route all data operations through UserPersistence only

2.1 Dashboard Controller Overhaul

  • Remove all mock_data field access in src/controllers/dashboard.rs
  • Route wallet balance through persistent storage (lines 44-55)
  • Replace mock service/app statistics with persistent data aggregation
  • Update service provider, farmer, app provider data initialization
  • Remove mock balance updates in wallet operations

Files to modify:

  • src/controllers/dashboard.rs (lines 44-55, 75-279, 2698-3059, 3328-3338, 4327-4330, 4803-4813)

2.2 Rental Controller Cleanup

  • Remove MockDataService dependencies (line 7)
  • Replace mock product lookups with persistent storage queries
  • Remove mock balance deduction logic (lines 82-174, 242-317, 384-401)
  • Update rental operations to use UserPersistence only

Files to modify:

  • src/controllers/rental.rs (lines 7, 35-36, 82-174, 194-196, 242-317, 337-339, 384-401, 430-432)

2.3 Pool Controller Refactoring

  • Remove mock_data usage (lines 92-136, 207-228)
  • Route all transaction and balance operations through UserPersistence
  • Replace mock transaction history updates

Files to modify:

  • src/controllers/pool.rs (lines 92-136, 207-228)

2.4 Marketplace Controller Cleanup

  • Remove MockDataService usage (lines 6, 127-131, 726-742)
  • Replace mock marketplace config with minimal persistent config
  • Remove mock product registration for user apps

Files to modify:

  • src/controllers/marketplace.rs (lines 6, 127-131, 706-742)

Phase 3: Service Layer Cleanup

Goal: Eliminate remaining mock services and payment gateways

3.1 Remove MockPaymentGateway

  • Delete MockPaymentGateway from order service (lines 82-84, 1119-1224)
  • Replace with persistent payment method handling only
  • Remove mock payment method fallbacks (lines 606-615, 1225-1227)
  • Update payment processing to use real gateways only

Files to modify:

  • src/services/order.rs (lines 82-84, 606-615, 1119-1224, 1225-1227)

3.2 User Persistence Cleanup

  • Remove initialize_user_with_mock_balance method (lines 349-370)
  • Replace with pure persistent data initialization
  • Ensure all new users get default empty structures, not mock data
  • Update session manager to not apply mock data

Files to modify:

  • src/services/user_persistence.rs (lines 349-370)
  • src/services/session_manager.rs (lines 141-158)

3.3 Farmer Service Mock Cleanup

  • Remove mock product generation (lines 432-454)
  • Route marketplace product creation through persistent storage only
  • Remove MockDataService dependencies

Files to modify:

  • src/services/farmer.rs (lines 432-454)

3.4 Product Service Mock Dependencies

  • Remove MockDataService usage (lines 3, 157-161, 398-401)
  • Ensure product aggregation uses only fixtures and persistent data
  • Remove mock product and category fallbacks

Files to modify:

  • src/services/product.rs (lines 3, 157-161, 398-401)

Phase 4: Configuration & Guards

Goal: Enforce persistent-only operation and prevent mock fallbacks

4.1 Production Guards Implementation

  • Remove enable_mock_data configuration option
  • Add compile-time checks to prevent mock usage
  • Remove all conditional mock paths from production code
  • Update configuration to make persistent-only the default

Files to modify:

  • src/config/builder.rs (lines 28-30, 77-79, 105, 157-166, 225-227, 289, 343-346, 493-530)

4.2 Model Updates for Persistence

  • Ensure all persistent data structures have #[serde(default)]
  • Remove MockUserData dependencies from builders
  • Update User model to not require mock_data field

Files to modify:

  • src/models/builders.rs (lines 12, 269, 307-309, 323, 1026, 1053-1101, 1219-1255)
  • src/models/currency.rs (lines 34, 161, 175, 190, 206, 221)
  • src/models/order.rs (lines 88-89)

4.3 Authentication & Other Controllers

  • Remove MockUserData from gitea auth controller (lines 7, 161)
  • Update wallet controller to clear mock data field (lines 93-94)

Files to modify:

  • src/controllers/gitea_auth.rs (lines 7, 161)
  • src/controllers/wallet.rs (lines 93-94)
  • src/controllers/order.rs (lines 641-643)

Phase 5: Service Dependencies & Grid

Goal: Clean up remaining service mock dependencies

5.1 Grid Service Mock Cleanup

  • Remove mock grid data creation (lines 97, 194-196)
  • Replace with proper error handling for missing grid data

Files to modify:

  • src/services/grid.rs (lines 97, 194-196)

5.2 Pool Service Analytics

  • Remove mock analytics generation (lines 64, 182-183)
  • Replace with real analytics from persistent data

Files to modify:

  • src/services/pool_service.rs (lines 64, 182-183)

Phase 6: Verification & Testing

Goal: Ensure system works correctly and update documentation

6.1 Compilation & Runtime Testing

  • Run cargo check to verify no compilation errors
  • Test with APP_ENABLE_MOCKS=0 to ensure no runtime mock dependencies
  • Verify all dashboard flows work with persistent data
  • Test marketplace functionality end-to-end

6.2 Test Updates

  • Update test files to remove mock dependencies
  • Ensure integration tests use fixture JSON instead of code-based mocks
  • Update mock gating tests to reflect new reality

Files to modify:

  • tests/service_booking_integration_test.rs (line 112)
  • tests/mock_gating.rs (lines 8-39)

6.3 Final Verification

  • Search for remaining mock patterns: grep -r "Mock\|mock_\|demo_\|sample_" src/
  • Verify no pub fn user[0-9]+ patterns remain
  • Ensure all persistent data operations work correctly

Phase 7: Documentation Updates

Goal: Update documentation to reflect actual implementation

7.1 Architecture Documentation

  • Update marketplace-architecture.md Progress Update section
  • Add note about code-based mock data removal completion
  • Document persistent-data-only architecture

Files to modify:

  • docs/dev/design/current/marketplace-architecture.md

7.2 TODO Documentation

  • Update marketplace-todo.md to mark task completed
  • Remove mock cleanup items from todo list
  • Add any follow-up persistence improvements needed

Files to modify:

  • docs/dev/design/current/marketplace-todo.md

Implementation Strategy

Critical Success Factors:

  1. Backward Compatibility: All persistent structures must have #[serde(default)]
  2. Default Values: Replace mock arrays with sensible defaults (Vec::new(), None, 0)
  3. Error Handling: Add proper error handling for missing data instead of mock fallbacks
  4. Gradual Migration: Keep User.mock_data field optional during transition
  5. Testing: Verify each phase before proceeding to next

Risk Mitigation:

  • Compilation Safety: Check cargo check after each major change
  • Data Safety: Ensure existing user_data/ JSON files continue to work
  • Functionality Safety: Test core flows after each controller update
  • Rollback Plan: Git commits for each phase allow easy rollback

Acceptance Criteria

  • cargo check passes with zero compilation errors
  • Application starts and runs with APP_ENABLE_MOCKS=0
  • No code-based mock user factories remain in codebase
  • Dashboard displays persistent data or proper empty states
  • All marketplace flows function using persistent storage only
  • No occurrences of mock patterns in grep search
  • Architecture documentation reflects actual implementation

Progress Tracking

This document will be updated with checkmarks () as each section is completed during implementation.