function check_platform_consistency
Validates platform consistency between authentication module and upload manager by comparing User-Agent platform detection with hardcoded source IDs in the upload manager code.
/tf/active/vicechatdev/e-ink-llm/cloudtest/check_platform_consistency.py
11 - 58
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
authupload_managerjson
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
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function verify_document_status 51.1% similar
-
function test_upload_endpoint 50.9% similar
-
function test_remarkable_authentication 50.9% similar
-
class DryRunUploadComparison 50.1% similar
-
function main_v6 50.1% similar