Skip to content

fix: preserve brackets in vehicle crew data to fix side coloring#90

Merged
fank merged 2 commits intomainfrom
fix/vehicle-crew-bracket-stripping
Feb 12, 2026
Merged

fix: preserve brackets in vehicle crew data to fix side coloring#90
fank merged 2 commits intomainfrom
fix/vehicle-crew-bracket-stripping

Conversation

@fank
Copy link
Member

@fank fank commented Feb 12, 2026

Summary

  • Vehicle crew arrays from the game (e.g. [20,21]) had their brackets stripped by the handler, storing 20,21 instead
  • During JSON export, json.Unmarshal("20,21") failed for multi-crew vehicles → empty crew [] in output
  • Single-crew vehicles exported a bare scalar (108) instead of an array ([108])
  • The web frontend derives vehicle side/color from crew members' factions, so all vehicles appeared without side colors

Root cause: handlers.go line 546-548 stripped [ and ] from crew data before storing

Fix:

  • Stop stripping brackets in LogVehicleState — store the raw JSON array string as received from the game
  • Parse crew as JSON in the legacy DB export path (main.go) to match the memory export path

Test plan

  • TestLogVehicleState_CrewPreservesBrackets — handler preserves brackets for multi-crew, single-crew, empty, and large arrays
  • TestBuildWithVehicleCrewIDArray — builder correctly parses [20,21], [20], and [] crew formats
  • TestVehicleCrewExportIntegration — full pipeline (memory backend → builder → JSON file → JSON parse) with crew array round-trip
  • Full test suite passes (go test ./...)

The handler was stripping brackets from crew arrays received from the
game (e.g. "[20,21]" → "20,21"). During JSON export, json.Unmarshal
would then fail for multi-crew vehicles, producing empty crew arrays.
Single-crew vehicles exported a scalar instead of a one-element array.

This caused the web frontend to show all vehicles without side colors,
since it derives vehicle side from the first crew member's faction.

- Stop stripping brackets in LogVehicleState handler
- Parse crew as JSON in legacy DB export path (main.go)
- Add regression tests at handler, builder, and integration levels
@gemini-code-assist
Copy link

Summary of Changes

Hello @fank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical data integrity issue affecting vehicle crew information. Previously, the system was inadvertently stripping JSON array brackets from crew data, which led to parsing failures during export and consequently, incorrect or missing vehicle side colors in the user interface. The changes ensure that crew data is stored and processed as valid JSON arrays throughout the application's lifecycle, thereby restoring proper functionality and visual representation.

Highlights

  • Vehicle Crew Data Preservation: The pull request fixes an issue where vehicle crew arrays (e.g., [20,21]) were having their brackets stripped during processing, leading to incorrect data storage as 20,21.
  • JSON Export Correction: This stripping caused json.Unmarshal to fail for multi-crew vehicles during JSON export, resulting in empty crew arrays and incorrect vehicle side coloring in the web frontend.
  • Data Handling Logic Update: The fix involves stopping the bracket stripping in the LogVehicleState handler and explicitly parsing crew data as JSON in the legacy DB export path to ensure data integrity.
  • Comprehensive Test Coverage: New tests have been added to validate that crew data, including multi-crew, single-crew, and empty arrays, is correctly preserved and exported through the entire data pipeline.
Changelog
  • cmd/ocap_recorder/main.go
    • Updated vehicle state export logic to correctly unmarshal crew data as JSON arrays, handling potential parsing errors by defaulting to an empty array.
  • internal/handlers/handlers.go
    • Removed the explicit stripping of square brackets from vehicle crew data, ensuring that the raw JSON array string is preserved when logging vehicle states.
  • internal/handlers/handlers_test.go
    • Added TestLogVehicleState_CrewPreservesBrackets to verify that the LogVehicleState function correctly maintains the bracketed format of crew data for various array types.
  • internal/storage/memory/export/v1/builder_test.go
    • Introduced TestBuildWithVehicleCrewIDArray to confirm that the export builder accurately parses and processes multi-crew, single-crew, and empty crew ID arrays from stored vehicle states.
  • internal/storage/memory/export_test.go
    • Added TestVehicleCrewExportIntegration as an end-to-end test to validate the complete pipeline for vehicle crew data, from memory backend storage to JSON export and parsing, ensuring data round-trip integrity.
Activity
  • The author fank initiated this pull request to address a bug where vehicle crew data was not being handled correctly, leading to display issues.
  • The pull request includes a detailed problem description, root cause analysis, and a clear explanation of the proposed solution.
  • A comprehensive test plan has been provided, outlining new unit and integration tests to validate the fix and prevent regressions.
  • The author has confirmed that the full test suite passes after implementing these changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a bug where brackets were stripped from vehicle crew data, leading to JSON parsing errors during export. The changes correctly preserve the brackets in the handler and add JSON parsing logic in the legacy DB export path to align with the memory export path. The new unit and integration tests are well-written and thoroughly cover the fix for various crew data formats. I've suggested a minor simplification to the new JSON parsing logic for improved conciseness.

json.Unmarshal already returns an error for empty strings, so the
explicit empty-string guard is unnecessary.
@github-actions
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/extension/v5/cmd/ocap_recorder 0.00% (ø)
github.com/OCAP2/extension/v5/internal/handlers 16.30% (+6.43%) 👍
github.com/OCAP2/extension/v5/internal/storage/memory 96.24% (ø)
github.com/OCAP2/extension/v5/internal/storage/memory/export/v1 100.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/extension/v5/cmd/ocap_recorder/main.go 0.00% (ø) 0 0 0
github.com/OCAP2/extension/v5/internal/handlers/handlers.go 16.30% (+6.43%) 767 (-3) 125 (+49) 642 (-52) 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/extension/v5/internal/handlers/handlers_test.go
  • github.com/OCAP2/extension/v5/internal/storage/memory/export/v1/builder_test.go
  • github.com/OCAP2/extension/v5/internal/storage/memory/export_test.go

@fank fank merged commit fdccaa9 into main Feb 12, 2026
3 checks passed
@fank fank deleted the fix/vehicle-crew-bracket-stripping branch February 12, 2026 22:56
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.

1 participant