Skip to content

EDGE-770 Lte upload rework#558

Draft
mazar-farran wants to merge 19 commits intobeefrom
lte-upload-rework
Draft

EDGE-770 Lte upload rework#558
mazar-farran wants to merge 19 commits intobeefrom
lte-upload-rework

Conversation

@mazar-farran
Copy link
Collaborator

  • Add a link to the ticket in the PR title or add a description of work in the PR title
  • dashcam firmware was loaded on a device and successfully runs

@mazar-farran mazar-farran changed the title Lte upload rework EDGE-770 Lte upload rework Dec 1, 2025
@mazar-farran
Copy link
Collaborator Author

Screenshot 2025-12-02 at 1 29 01 PM

Looks healthy

@mazar-farran mazar-farran requested a review from punov December 2, 2025 21:29
@mazar-farran
Copy link
Collaborator Author

Posponing this until after high priority feature requests are resolved

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 11, 2026

Greptile Overview

Greptile Summary

Refactored LTE upload service with improved type safety and testability by extracting types to a dedicated file, replacing string-based state management with typed interfaces, and separating error handling logic into dedicated functions. Tests were rewritten to be more isolated and comprehensive, with better mocking strategies.

Key Changes:

  • Introduced FrameKmStorage class extending SqlStorage with typed getFrameKmItem/setFrameKmItem methods
  • Moved error classes and state types from service file to types/getFrameKms.ts
  • Refactored SqlStorage to accept database instance in constructor instead of lazy initialization
  • Extracted error handling into handleMissingFrameKmError, handleFrameKmRequestError, handleFrameKmUploadError, handleFrameKmCommitError, and handleFrameKmUnknownError functions
  • Removed automatic cleanup of old framekms (date-based deletion logic)
  • Made processFrameKms and checkForNewFrameKms exported for testing
  • Added comprehensive test coverage for error scenarios including 40X responses, commit failures, and data saver mode

Issues Found:

  • Critical bug in FrameKmStorage.getFrameKmItem where JSON.parse(undefined) will throw when key doesn't exist

Confidence Score: 3/5

  • Safe to merge after fixing the critical null handling bug in getFrameKmItem
  • Score reflects one critical bug that will cause runtime errors when getFrameKmItem is called on a non-existent key. The refactoring itself is well-structured with improved type safety and comprehensive test coverage, but the null check is essential for production stability.
  • Pay close attention to src/services/getFrameKmsService.ts - fix the getFrameKmItem method before merging

Important Files Changed

Filename Overview
tests/services/getFrameKmService.test.ts Refactored tests to use new storage API, added tests for error scenarios, data saver mode, and commit failures
src/index.ts Updated initializeLTEStorage to pass database instance explicitly
src/services/getFrameKmsService.ts Major refactor with typed state management, extracted error handlers, removed old framekm cleanup logic, and fixed database initialization - contains potential null handling bug
src/types/getFrameKms.ts New type definitions file for frame km states, error classes, and package types

Sequence Diagram

sequenceDiagram
    participant Service as GetFrameKmsService
    participant Storage as FrameKmStorage
    participant API as Backend API
    participant S3 as S3 Storage

    Service->>Storage: checkForNewFrameKms()
    Storage-->>Service: Return framekm list
    
    Service->>Storage: getFrameKmItem(framekm)
    Storage-->>Service: status: INIT
    
    Service->>API: postFrameKmRequest(framekm)
    API-->>Service: {id, type, signedContentUrls, frameIndicesToUpload}
    Service->>Storage: setFrameKmItem(framekm, REQUEST_SUCCESS)
    
    alt Data Saver with frames
        Service->>Service: packCustomFrameKm()
    else Data Saver without frames
        Service->>Storage: setFrameKmItem(framekm, UPLOAD_SUCCESS, multiparts:[])
    end
    
    Service->>Storage: getFrameKmItem(framekm)
    Storage-->>Service: status: REQUEST_SUCCESS
    
    loop For each signed URL
        Service->>S3: Upload framekm part
        S3-->>Service: ETag
    end
    
    Service->>Storage: setFrameKmItem(framekm, UPLOAD_SUCCESS)
    
    Service->>Storage: getFrameKmItem(framekm)
    Storage-->>Service: status: UPLOAD_SUCCESS
    
    Service->>API: commitFrameKm(id, multiparts)
    API-->>Service: Success
    Service->>Storage: setFrameKmItem(framekm, COMMIT_SUCCESS)
    Service->>Service: cleanup(framekm)
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +133 to +136
async getFrameKmItem<T extends FrameKmItem>(key: string) {
const value = await super.getItem(key);
return JSON.parse(value) as T;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.parse(value) will throw "Unexpected token u in JSON" when value is undefined (when key doesn't exist).

Suggested change
async getFrameKmItem<T extends FrameKmItem>(key: string) {
const value = await super.getItem(key);
return JSON.parse(value) as T;
}
async getFrameKmItem<T extends FrameKmItem>(key: string) {
const value = await super.getItem(key);
if (!value) {
throw new Error(`FrameKm item not found: ${key}`);
}
return JSON.parse(value) as T;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants