Skip to content

Let a Tesla Fleet API connection exist, read by an extension's source - #248

Merged
vcanuel merged 7 commits into
mainfrom
feat/tesla-fleet-connection
Nov 3, 2026
Merged

vcanuel merged 7 commits into
mainfrom
feat/tesla-fleet-connection

Conversation

@vcanuel

@vcanuel vcanuel commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

A Tesla read through Tesla's Fleet API, with an application the instance's operator registered at Tesla, becomes a connection of its own: tesla_fleet, beside the Owner API's tesla. The core reads none of its vehicles itself; a source an extension registers does (collector.AddSource, already exposed). The core only lets such a connection exist, shows its cars, and derives their readings.

Changes

  • Store: migration 0035_tesla_fleet.sql adds tesla_fleet to the checks of connections and api_calls. SetTeslaFleetToken, TeslaFleetToken, RotateTeslaFleetToken, TeslaFleetConnection and DeleteTeslaFleetToken keep its refresh token sealed, as the Owner API's, with which they share their code. A car that moves from a tesla connection to a tesla_fleet one keeps its history (AddVehicle). tesla.FleetSource names the provider.
  • Extension point: extensionNormalizers, beside registerExtensions in both binaries, adds an extension's normalizers to the derivation. derive.Sources was built before the extensions were registered, so an extension's source could not be derived. It adds none in the public build. Described in AGENTS.md.
  • API: tesla_fleet in the provider enum (OpenAPI regenerated), read with its own credential, whose state the API tells. The TeslaMate import, from the API or the command line, takes a Fleet API's Tesla.
  • Front end: a Fleet API's Tesla shows in the Tesla tab. Its state and notices (access withdrawn, not signed in, no longer in the account, daily calls) talk about signing in with Tesla rather than a refresh token, in en, fr and sv. With source.tesla off, only the Owner API's Teslas are told that Tesla is not offered.
  • Collector: unchanged. It already leaves alone a provider that no source reads, with one log per connection.

Screenshots

Before After
before after

The Tesla tab of an account whose Tesla has a tesla_fleet connection and no sign-in. Before: the car shows in no tab. After: it shows under Tesla, with its state.

Tests

  • task unit (Go lint, Go and web unit tests, web build), the Go tests with PostgreSQL (go test ./...), task lint-api (Redocly): pass.
  • New tests: the store's Fleet token (sealed, rotated, signed in again, removed; the car's history kept; isolation), the credential's state in the API, the TeslaMate import of a Fleet API's Tesla, the public build's empty normalizers, and the front end's texts and tab.
  • CodeRabbit CLI, run locally. Fixed: the "not offered" message shown to Fleet API Teslas. Not taken: "the OpenAPI document is out of sync" (it is regenerated, and TestOpenAPIFile passes); a NOT VALID constraint followed by VALIDATE (0025 and 0032 change the same checks directly, and api_calls is small); a Fleet sign-in button on the Connection page (no such flow exists in the core: an extension provides it).
  • Not run: the system tests (images, Compose end to end).

Closes #246

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for Tesla Fleet API connections, including sign-in, credential management, vehicle collection, and history imports.
    • Tesla Fleet vehicles now appear under the Tesla connection tab, with distinct status and usage messages.
  • Bug Fixes

    • Tesla Fleet vehicles can be imported from TeslaMate, and supported downstream sources are included when rebuilding vehicle history.
    • Tesla Owner API availability messages now distinguish Owner API access from Fleet API sign-in.

vcanuel and others added 4 commits November 3, 2026 23:12
A Tesla read through the Fleet API, with an application the instance's
operator registered at Tesla, is a provider of its own, tesla_fleet:
the Owner API source refreshes its tokens with the Owner API's client,
which would refuse them. The core reads none of its vehicles itself; a
source an extension registers does (collector.AddSource).

Its refresh token is kept as the Owner API's (connections.credential,
sealed), one per account beside it, through SetTeslaFleetToken and its
siblings, which share the Owner API's code. A car moves from one
connection to the other with its history.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both binaries build the derivation's normalizers before registering
their extensions: a source an extension adds to the collector could
not be derived. extensionNormalizers, beside registerExtensions, adds
none in the public build; a downstream build's twin adds its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The API's provider enum gains tesla_fleet, read with its credential as
the Owner API's, and the TeslaMate import takes its cars. The
connection page shows them in the Tesla tab, their state and notices
worded for a sign-in with Tesla rather than a refresh token, in the
three languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With source.tesla off, the Tesla tab told every Tesla it was no longer
read, those of the Fleet API too, which another source reads whatever
the flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

The change adds a Tesla Fleet provider and credential lifecycle. It extends API and TeslaMate paths to Fleet vehicles, includes extension normalizers in derivation, and updates the connection and collection interface with Fleet-specific states and messages.

Changes: Tesla Fleet API support

Layer / File(s) Summary
Fleet provider and credential lifecycle
internal/store/migrations/*, internal/api/read.go, internal/store/tesla.go, internal/tesla/normalize.go, internal/store/tesla_test.go
The provider schema and database checks accept tesla_fleet. Store methods manage Fleet tokens through shared credential helpers. Tests cover token operations, vehicle reassignment, and history retention.
API connection status and TeslaMate import
internal/api/read.go, internal/api/read_test.go, internal/api/teslamate.go, internal/api/teslamate_test.go, cmd/runsten-api/teslamate.go
The API reports Fleet credential states, and TeslaMate import checks accept Fleet vehicles.
Extension normalizers in derivation
AGENTS.md, cmd/runsten-api/*, cmd/runsten-collector/*
Both binaries combine extension-provided normalizers with built-in normalizers. Public builds return no extension normalizers. Collector rebuilds skip providers without a matching normalizer.
Fleet-specific connection and collection UI
web/src/features/watch-collection/*, web/src/pages/connection/*, web/src/pages/vehicle-settings/*, web/src/shared/i18n/locales/*, web/test/features/watch-collection/*, web/test/pages/connection/*
The interface identifies Fleet vehicles under Tesla, displays Fleet-specific credential and quota messages, and enables Tesla imports for Fleet vehicles. Tests and English, French, and Swedish translations cover the changes.

Possibly related issues

Possibly related PRs

  • runsten-app/runsten#241 — Adds the TeslaMate import path that this change extends to Fleet vehicles.
  • runsten-app/runsten#155 — Adds Tesla Owner connection and credential patterns that this change extends to Fleet connections.
  • runsten-app/runsten#150 — Adds Tesla Owner API normalization interfaces related to this change’s Fleet provider and extension-normalizer support.
Merge Risk: Minimal · up to 6f116

No concrete merge-blocking defect remains in the reviewed changes.

Security architecture risk: Low · up to 6f116

The inspected changes preserve account isolation, separate Fleet credentials from Owner API credentials, and retain vehicle identity during reassignment. No introduced security vulnerability was established. Fleet sign-in, collection, and recovery depend on extension implementations that were not available for review.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected import expansion remains bounded to a vehicle resolved within the authenticated account. Storage row-level security and the account/connection foreign key constrain credential operations and vehicle reassignment to that account; broader authority in an external Fleet extension is not established here.

Security Findings and Attack Paths

  • observed — The specifically routed public symbol is TestReadProviders, a public-build test asserting that Fleet is unsupported without its extension. It is not a production network entrypoint and does not itself expand attacker reachability.

Trust Boundaries and Controls

  • observed — Fleet credential storage preserves separate provider selection under account-scoped transactions. The reviewed public hooks do not implement Fleet OAuth or source registration, leaving callback identity binding and the authority used to enroll Fleet vehicles outside the inspected implementation.

Resilience and Maintainability Implications

  • inferred — The store-level operations preserve identity and support credential removal, but they do not establish an atomic Fleet sign-in-to-enrollment transition. Without the extension caller, partial enrollment failure, interrupted refresh recovery, concurrent revocation, and cleanup ownership remain unresolved rather than demonstrated defects.

Hardening Proposals

  • proposed — For the extension deployment, establish an explicit lifecycle contract covering OAuth account binding, partial vehicle enrollment, refresh interruption, concurrent replacement or revocation, and source/normalizer compatibility during rollback. This is a proposed integration safeguard, not an observed vulnerability.
Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#246] Directly linked issue. Coding requirements, checked against the migration at head and the PR summary:

1. Provider in checks. 0035_tesla_fleet.sql adds tesla_fleet to `connections_provider_…
Provide evidence for two items. (a) Show that account export and account deletion include connections rows with provider tesla_fleet. Cite the export code path and the deletion path, or a test that covers them. (b) Show the collector co…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "Let a Tesla Fleet API connection exist, read by an extension's source" describes the main change: a new tesla_fleet provider and connection storage, with reads done by an extension-register…
Description check Passed The description follows the repository template closely. It explains what changes and why, and it links the issue with "Closes #246". The testing section lists the tests run (task unit, go test, lint-…
Out of Scope Changes check Passed All changed areas relate to the tesla_fleet connection in #246 or to its required support. Changes cover the migration, Fleet token store methods, FleetSource constant, API provider and credential…
Full details: Title check

Explanation

The title "Let a Tesla Fleet API connection exist, read by an extension's source" describes the main change: a new tesla_fleet provider and connection storage, with reads done by an extension-registered source. It is specific and matches the changeset. It does not follow the requested imperative form, which asks for titles such as "Add ..." or "Fix ...". It uses "Let", which is imperative in form, so the title is close to the requirement. The title is 69 characters and is in English.

Full details: Description check

Explanation

The description follows the repository template closely. It explains what changes and why, and it links the issue with "Closes #246". The testing section lists the tests run (task unit, go test, lint-api) and the new tests added. The checklist items are not ticked, and the template's checkboxes for task unit, the API diff, the translations, and the absence of real secrets are not explicitly confirmed. The description also includes screenshots as the template requires for interface changes. The Changes section is detailed and covers the store, extension point, API, front end, and collector. The 'Closes #' reference is filled with 246, so the issue link is present.

Full details: Out of Scope Changes check

Explanation

All changed areas relate to the tesla_fleet connection in #246 or to its required support. Changes cover the migration, Fleet token store methods, FleetSource constant, API provider and credential state, TeslaMate import eligibility, Tesla tab and notices, localized texts in en, fr and sv, extensionNormalizers in both binaries, and the AGENTS.md note. The source.tesla flag change limits the 'not offered' message to Owner API Teslas. That change directly supports the Fleet connection's display. The summary shows no unrelated change. The reviewed evidence does not show any change that falls outside the scope of #246.

Full details: Linked Issues check

Explanation

[#246] Directly linked issue. Coding requirements, checked against the migration at head and the PR summary:

  1. Provider in checks. 0035_tesla_fleet.sql adds tesla_fleet to connections_provider_check and api_calls_api_check. Met.
  2. collector_status. The previous assessment required tesla_fleet in this check. The table has no provider column (0008_collector_status.sql). Its CHECKs cover only mode, fail_kind, and failure consistency. No provider check exists to update. The previous FAIL rested on a wrong premise and is withdrawn.
  3. Store methods. The summary lists SetTeslaFleetToken, TeslaFleetToken, RotateTeslaFleetToken, TeslaFleetConnection, and DeleteTeslaFleetToken, sealed like the Owner API token, with TestTeslaFleetToken. Met per summary.
  4. Vehicles and history. AddVehicle moves a car from tesla to tesla_fleet and keeps its history. Brand mapping in ConnectionPage.vue shows tesla_fleet under Tesla. Met per summary and tests.
  5. Collector leaves a tesla_fleet connection alone. The PR states this behavior is unchanged and already present, with one log per connection. The issue asks for no per-pass logs. This was not checked in the collector code, so it is unverified.
  6. Export and deletion. The issue requires tesla_fleet connections in account export and deletion. Neither the PR description nor the change summary shows an export change. DeleteTeslaFleetToken covers only token deletion. Whether generic connection export and account deletion include tesla_fleet rows is not established.
  7. Extension normalizers. extensionNormalizers is added in both binaries, with the public build returning nil, and TestNoExtensionNormalizers and TestReadProviders added. Met per summary.

The unresolved items are 5 and 6.

Resolution

Provide evidence for two items. (a) Show that account export and account deletion include connections rows with provider tesla_fleet. Cite the export code path and the deletion path, or a test that covers them. (b) Show the collector code path for a tesla_fleet connection with no source, and confirm it logs once per connection and not on every pass.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 3431589 and 6f11683.

Files selected for processing: 1
  • cmd/runsten-collector/extensions_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment thread cmd/runsten-collector/main.go Resolved
Comment thread web/src/shared/i18n/locales/en.json Resolved
vcanuel and others added 2 commits November 3, 2026 23:32
The rebuild command recomputed every vehicle's events: one of a
provider only an extension reads, rebuilt by a build without it, would
have lost its trips and charges, its readings left unread. It is now
skipped, and logged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flag source.tesla stops the Owner API only: a Tesla of another
source is still read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread cmd/runsten-collector/main_test.go Resolved
A downstream build adds its normalizers: the test that no extension's
provider is read holds for the public build only (!premium).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vcanuel
vcanuel enabled auto-merge November 3, 2026 22:53
@vcanuel
vcanuel merged commit aa597f2 into main Nov 3, 2026
7 of 8 checks passed
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.

Tesla Fleet API connections, read by a source an extension registers

1 participant