🔍 Code Extractor

function check_platform_consistency

Maturity: 34

Validates platform consistency between authentication module and upload manager by comparing User-Agent platform detection with hardcoded source IDs in the upload manager code.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/check_platform_consistency.py
Lines:
11 - 58
Complexity:
moderate

Purpose

This diagnostic function checks for platform mismatches between the RemarkableAuth module's User-Agent header and the source ID used in the RemarkableUploadManager. It detects the platform (Windows/macOS) from the auth User-Agent, determines the expected source ID, then reads the upload_manager.py source code to find the actual source ID being used. This helps identify configuration issues where the platform detection and upload source don't align, which could cause API compatibility problems.

Source Code

def check_platform_consistency():
    print("🔍 Platform Consistency Check")
    print("=" * 40)
    
    # Check auth module
    auth = RemarkableAuth()
    user_agent = auth.session.headers.get('User-Agent', 'Unknown')
    print(f"📱 Auth User-Agent: {user_agent}")
    
    # Determine platform from User-Agent
    if 'win' in user_agent.lower():
        expected_source = "com.remarkable.windows"
        platform = "Windows"
    elif 'macos' in user_agent.lower() or 'mac' in user_agent.lower():
        expected_source = "com.remarkable.macos"
        platform = "macOS"
    else:
        expected_source = "com.remarkable.unknown"
        platform = "Unknown"
    
    print(f"🖥️  Detected Platform: {platform}")
    print(f"📋 Expected Source ID: {expected_source}")
    
    # Check upload_manager source
    from upload_manager import RemarkableUploadManager
    database_path = "remarkable_replica_v2/replica_database.json"
    
    # We can't instantiate without a session, so let's check the source code
    with open('upload_manager.py', 'r') as f:
        content = f.read()
        if 'com.remarkable.windows' in content:
            actual_source = "com.remarkable.windows"
        elif 'com.remarkable.macos' in content:
            actual_source = "com.remarkable.macos"
        else:
            actual_source = "Unknown"
    
    print(f"⬆️  Upload Manager Source: {actual_source}")
    
    # Check consistency
    if expected_source == actual_source:
        print("✅ Platform consistency: GOOD")
        return True
    else:
        print("❌ Platform consistency: MISMATCH!")
        print(f"   Auth suggests: {expected_source}")
        print(f"   Upload uses: {actual_source}")
        return False

Return Value

Returns a boolean value: True if the platform detected from auth User-Agent matches the source ID in upload_manager.py (consistency check passes), False if there's a mismatch between expected and actual source IDs.

Dependencies

  • auth
  • upload_manager
  • json

Required Imports

from auth import RemarkableAuth
import json
from upload_manager import RemarkableUploadManager

Usage Example

# Run the platform consistency check
result = check_platform_consistency()

if result:
    print("Platform configuration is consistent")
else:
    print("Warning: Platform mismatch detected - review auth and upload_manager configurations")

# Example output:
# 🔍 Platform Consistency Check
# ========================================
# 📱 Auth User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
# 🖥️  Detected Platform: Windows
# 📋 Expected Source ID: com.remarkable.windows
# ⬆️  Upload Manager Source: com.remarkable.windows
# ✅ Platform consistency: GOOD

Best Practices

  • This function performs file I/O by reading upload_manager.py - ensure the file exists and is readable
  • The function uses string matching to detect source IDs in code, which is fragile and may break if upload_manager.py structure changes
  • Consider refactoring to use proper configuration files instead of parsing source code
  • The function prints output directly - consider returning structured data for programmatic use
  • Platform detection relies on User-Agent string format - ensure RemarkableAuth sets appropriate User-Agent headers
  • The database_path variable is defined but never used - this may indicate incomplete implementation
  • This is a diagnostic tool and should not be used in production code paths

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function verify_document_status 51.1% similar

    Verifies the current status and metadata of a specific test document in the reMarkable cloud sync system by querying the sync API endpoints and analyzing the document's location and properties.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/verify_document_status.py
  • function test_upload_endpoint 50.9% similar

    A test function that validates the reMarkable Cloud API file upload endpoint by attempting to upload a test JSON file and verifying the GET endpoint functionality.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_upload_endpoint.py
  • function test_remarkable_authentication 50.9% similar

    Asynchronous test function that validates reMarkable Cloud authentication and verifies access to the root folder by listing its contents.

    From: /tf/active/vicechatdev/e-ink-llm/test_remarkable.py
  • class DryRunUploadComparison 50.1% similar

    A diagnostic class that compares a custom PDF upload implementation against real reMarkable app behavior by analyzing captured network logs without making actual API calls.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/dry_run_comparison.py
  • function main_v6 50.1% similar

    Integration test function that validates the fixed upload implementation for reMarkable cloud sync by creating a test PDF document, uploading it with corrected metadata patterns, and verifying its successful appearance in the reMarkable ecosystem.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_fixed_upload.py
← Back to Browse