Skip to content

Commit 0e62303

Browse files
atulmguptaCopilot
andauthored
Muse spark (#106)
* feat(charging): overlay Tesla bills, fix energy baseline Two related charging-accuracy fixes: 1. Charge energy delta baselines now use State() strictly before StartedAt instead of at StartedAt, since Fleet Telemetry can emit the session-start batch after energy has already begun accumulating, causing undercounted energy in both the live handler and the completed-session tracker. 2. New Tesla Supercharger invoice overlay: ChargingHandler.Get resolves the vehicle's VIN and matches it against tesla_charging_history via a new FindBestMatch repo method (closest charge_start_datetime within a 2h window). When a match is found, billed energy/cost/currency/rate are added to the response and preferred for display on the frontend KPI tiles, with vehicle-measured energy shown as a secondary subtitle. * Fix FSD trip meter glitch attribution Treat spurious trip-meter resets and implausible counter jumps as discontinuities instead of driven distance. Adds reset/restore cursor logic and tests so include_fields zero snap-backs do not inflate FSD or driving aggregates. * Add Grok dynamics briefing Adds a live Grok powertrain read to Driving Dynamics using motor and chassis signals, with interpretation logic and tests. Also adds shared client-side pagination for FSD insight lists and DataTable-backed FSD tables. * Add telemetry honesty insights Adds honesty-focused UI across the fleet dashboard, status bar, charging, battery, driving, and FSD views. Surfaces Supercharger bill site/fee metadata, preserves signal ingest timestamps for Tesla physics clocks, paginates physics evidence instead of truncating it, and fixes nav highlighting to prefer the most specific active route. * feat(driving): scope dynamics history by trip Add trip selection and date-scoped motor history, preserve active drives, and evenly sample backend history responses across the selected window. * fix(charging): correct history attribution Preserve and backfill charge coordinates without creating geofences from stale GPS, use Tesla billed energy for tariff pricing, and resolve date windows in the vehicle timezone. * Fix sparse FSD drive detail attribution Expand the drive detail FSD insights range to look around 24 hours so sparse counter bookends are included, preventing unknown/blank attribution for valid deltas. Adds backend and frontend regression coverage for the wider range behavior. * Scope FSD insights to drive detail Adds drive_id support for FSD insights with a 7-day bookend lookup and focused attribution, while filtering negligible fidget drives so they do not steal sparse counter deltas. Updates drive detail and list UI to use the drive-scoped hook and omit unknown FSD badges. * feat: add charging autopilot, OCPP, TCO ledger, and session insights Wire always-on charge autopilot, shared-charger queue planning, OCPP charge points, Tesla bill variance, session share reports, TCO fixed ledger, and related warranty, silence, and trip copilot surfaces. Register new i18n namespaces (autopilot, chargeQueue, ocpp) so the strict namespace audit and Docker web build pass. Fix TypeScript i18n count types, geofence hook typing, and AutomationFull.conflicts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat(charging): add charge autopilot Add per-vehicle autopilot profiles, TOU-based charge previews, health guardrails, and savings tracking. Integrate the configuration and preview panel into Smart Charge with API and UI tests. * feat: expand charging and automation insights Add next-charge recommendations comparing home TOU costs with Supercharger quotes, surfaced on dashboards and vehicle details. Expand automation, routine, and alert template catalogs with category filtering, localization, and tests. * Expand automation and alert templates Adds ecosystem automation presets and routine templates covering more Tesla commands, locations, charging, climate, media, and security scenarios. Updates catalogue tests and alert rule template coverage thresholds for the expanded preset set. * feat: storm guardian severe-weather auto-prep Watches Open-Meteo forecasts at each armed vehicle's home coords and pre-charges before storms: hourly evaluator raises the charge limit on fresh warnings when SOC is below target. Includes status/config/events API, StormGuardPanel on Emergency Resilience, and backend+UI tests. * feat: cabin comfort autopilot with calendar-aware preconditioning Polls a per-vehicle ICS subscription, finds the next offsite event in the lead window, and preconditions once per event (5-minute evaluator). Includes next/config/now/runs API, ComfortPanel on Automations, offline refusal for the actuation endpoint, and backend+UI tests. * feat: warranty claim autopilot drafts service tickets BuildClaimDraft assembles a ready-to-paste ticket from the owner issue, live warranty countdown, matched TSBs, ranked symptoms, and evidence. New claim-draft endpoint, ClaimDraftPanel on Service Intelligence, and backend+UI tests. * feat: ghost-driver alerting for unknown-driver drives Flags recent drives that fit no named profile and sit far from their cluster centroid (median-adaptive score, deterministic pure function). New GET /driver-attribution/ghost-drives endpoint plus a GhostDrivesPanel on the Driver Attribution page with alert banner, score table, and one-click labelling that re-anchors the cluster. * feat: supercharger wait-time oracle from fleet history Predicts queue waits per site and arrival time: hour-of-week demand from tesla_charging_sessions feeds Little's-law load plus an Erlang-C queue model (stalls estimated from peak overlap, documented lower bound). Read-only GET /waitoracle/sites + /forecast; WaitOraclePanel on the fleet sessions page with site/arrival pickers, verdict hero, best-hour suggestion, and the full-day wait curve. * fix(fsd): accept quantized FSD mileage ticks Allow one Tesla 1-mile wire quantum above the physical travel threshold so valid 10-second counter samples are retained, while still rejecting implausible jumps. Add unit and drive analytics regression coverage. * fix: align wait-oracle, ghost, claim, comfort, storm with conventions Route new panels through Icons, SI seconds for wait forecasts, queryPolicy/scopedPath on hooks, ICS host allowlist, catalog i18n keys, and useDataState fatalError surfaces. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat(journey): trip sessions with status machine and versioned plans Slice 1 of Journey Autopilot: persistent journey_sessions (planned/active/paused/completed/aborted, one active per vehicle, race-safe conditional transitions) plus append-only versioned plans for future replan diffs. New /journeys page with session manager: plan form, status filter, lifecycle actions driven by server next_statuses, plan history. Also regenerates routetemplates_gen.go, absorbing 19 previously unregenerated routes so the freshness gate passes. * docs: redesign site and add feature catalogue Refresh the VitePress theme, navigation, landing pages, and onboarding. Add generated screen catalogues, Markdown page tools, and new homepage visuals. * fix(journey): clamp limits and localize status Cap journey list limits at 100 with safe defaults and tests. Localize status labels and inherit theme-aware icon colors. * feat(i18n): add journey status labels Add English translations for planned, active, paused, completed, and aborted journey statuses. * test(trips): align journey panel i18n Update localized JourneyPanel assertions and align journey namespace ordering in English manifests. * refactor: tighten package boundaries Extract weekly FSD digest logic from the API package, remove unused helpers, document migrations 235–242, clean up translations and lint findings, and refresh gRPC and telemetry dependencies. * chore: document packages and update grpc Adds package documentation and layer annotations, upgrades gRPC to v1.83.2, and removes an unused React test import. * fix(ci): empty-state audit exemptions and Gitleaks policy fixture mount EmptyState CTA audit now passes with documented no-action comments. Gitleaks policy self-test writes fixtures under the workspace and scans directories so Docker bind-mounts work on self-hosted runners. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): arch ratchet, chart-legend, CodeQL node, visual snapshots Move fleet state handler into handler/v1/fleetstate so internal/handler/v1 stays under the max_files ratchet. Waive SharedSessionReport legend toggle. Install Node before CodeQL JS extraction. Refresh Windows visual baselines from the failing Playwright actuals. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): restore CodeQL SHA pin and run SI gate on ubuntu-latest Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): run SI canonical gate on push so the required workflow has jobs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(web): classify new mutation hooks for live-mode audit Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(web): waive FSD observatory pagination in virtualization audit Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(web): unblock frontend vitest QueryClient, breadcrumbs, and panel tests Stub chart annotation hooks globally, parent Tesla Physics nested routes, and keep ChartContainer/page tests from requiring a QueryClient. Align Power Flow / Temperature Impact / Ghost Drives tests with current UI and surface ghost-scan errors instead of an empty table. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(web): show warranty claim draft when query data is present Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(web): restore i18n provider and annotation hook tests under global stubs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(web): unblock remaining frontend vitest failures Clamp Intl fraction digits to 0-20, add a no-op toast fallback when ToastProvider is missing, unique Smart Charge field ids, catalog /journeys, and test matchers for Beta/required labels/driver payload. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): stop si-canonical-gate 0s push failures Drop the push trigger (matches main) and only read runner input on workflow_dispatch so GitHub does not reject the workflow file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): run si-canonical-gate on push with a valid runner Keep the push trigger so required checks fire, but never read inputs.runner except on workflow_dispatch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): always run si-canonical-gate on push and PR Required checks plus path filters produced 0-job workflow-file failures. Run on every push/PR with ubuntu-latest so the job starts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): move SI canonical gate Python out of invalid YAML Unindented heredocs made GitHub treat the workflow as a file issue (0 jobs). Run the checks from .github/scripts/si_canonical_gate.py. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): repair span-budget, proto-gen, and load-test gates Enable CGO for -race on ubuntu-latest, drop make from proto-gen-check, and capture teslasync-api logs in the nightly k6 job. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): run k6 on host network so load-test reaches the API grafana/k6-action isolated localhost from compose-published :8080. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ci): treat 4xx as smoke-ok and write k6 summary in script cwd Unauthenticated CI hits ForwardAuth 401/403; only 5xx should fail api_errors. Write summary.json next to the script so the k6 container can persist it. * fix(ci): persist k6 summary.json with host uid on bind mount The grafana/k6 image is non-root, so handleSummary could not write tests/k6/summary.json and the artifact upload warned with no files. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 55a2804 commit 0e62303

135 files changed

Lines changed: 859 additions & 765 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env python3
2+
"""SI canonical gate — Phase-44 / F7.
3+
4+
Inspects /tmp/si.diff (unified=0, added lines only) for new legacy
5+
unit-suffixed identifiers and deprecated frontend conversion callers.
6+
"""
7+
8+
from __future__ import annotations
9+
10+
import re
11+
import sys
12+
from pathlib import Path
13+
14+
DIFF_PATH = Path("/tmp/si.diff")
15+
16+
ALLOWED_PREFIXES = [
17+
"internal/ai/tools/",
18+
"internal/api/ai_watch_face_nl_response_handler",
19+
"internal/api/range_projection_handler",
20+
"docs/",
21+
"migrations/",
22+
]
23+
24+
BANNED = [
25+
re.compile(r"\b\w*(?:Distance|Range|Odometer|StartOdometer|EndOdometer)Mi\b"),
26+
re.compile(r"\b\w*(?:Duration|Idle|Active)Min\b"),
27+
re.compile(
28+
r"\b\w*(?:Energy|Charge|Regen|EnergyUsed|EnergyAdded|EnergyDelivered)Kwh\b"
29+
),
30+
re.compile(r"\b\w*(?:Power|AvgPower|MaxPower|ChargerPower)Kw\b"),
31+
re.compile(r"\b\w*(?:Speed|AvgSpeed|MaxSpeed|GroundSpeed)Mph\b"),
32+
re.compile(r"\b\w*(?:Pressure|TirePressure)Psi\b"),
33+
re.compile(r"\b\w*(?:Temp|Temperature|InsideTemp|OutsideTemp)F\b"),
34+
re.compile(r'json:"\w*_(?:mi|min|kwh|kw|mph|psi)"'),
35+
re.compile(r'json:"\w*_(?:mi|min|kwh|kw|mph|psi),omitempty"'),
36+
re.compile(
37+
r"\b\w+_(?:mi|min|kwh|kw|mph|psi)\b\s+(?:NUMERIC|FLOAT|REAL|DOUBLE|INT|BIGINT|SMALLINT)"
38+
),
39+
]
40+
41+
DEPRECATED_CALLERS = re.compile(
42+
r"\b(convertDistance|convertSpeed|convertTemp|convertEfficiency|"
43+
r"convertPressure|fmtDistance|fmtSpeed|fmtTemp|fmtPressure)\s*\("
44+
)
45+
46+
ALLOWLIST_PATHS = {
47+
"web/src/lib/unitConversion.ts",
48+
"web/src/lib/unitConversion.test.ts",
49+
"web/src/hooks/useSettings.ts",
50+
"web/src/hooks/useSettings.test.ts",
51+
}
52+
53+
54+
def iter_added_lines(diff_text: str):
55+
current_file = None
56+
for line in diff_text.splitlines():
57+
if line.startswith("+++ "):
58+
path = line[6:].strip()
59+
current_file = None if path == "dev/null" else path
60+
continue
61+
if line.startswith("---"):
62+
continue
63+
if not line.startswith("+"):
64+
continue
65+
if line.startswith("+++"):
66+
continue
67+
if current_file is None:
68+
continue
69+
yield current_file, line[1:]
70+
71+
72+
def check_go(diff_text: str) -> list[str]:
73+
violations: list[str] = []
74+
for current_file, added in iter_added_lines(diff_text):
75+
if any(current_file.startswith(pfx) for pfx in ALLOWED_PREFIXES):
76+
continue
77+
s = added.lstrip()
78+
if s.startswith("//") or s.startswith("#") or s.startswith("--"):
79+
continue
80+
for pat in BANNED:
81+
if pat.search(added):
82+
violations.append(f"{current_file}: {added.rstrip()}")
83+
break
84+
return violations
85+
86+
87+
def check_fe(diff_text: str) -> list[str]:
88+
violations: list[str] = []
89+
for current_file, added in iter_added_lines(diff_text):
90+
if current_file in ALLOWLIST_PATHS:
91+
continue
92+
if not (current_file.endswith(".ts") or current_file.endswith(".tsx")):
93+
continue
94+
s = added.lstrip()
95+
if s.startswith("//") or s.startswith("*"):
96+
continue
97+
if DEPRECATED_CALLERS.search(added):
98+
violations.append(f"{current_file}: {added.rstrip()}")
99+
return violations
100+
101+
102+
def main() -> int:
103+
mode = sys.argv[1] if len(sys.argv) > 1 else "all"
104+
diff_text = DIFF_PATH.read_text(encoding="utf-8", errors="replace") if DIFF_PATH.exists() else ""
105+
106+
if mode in ("go", "all"):
107+
violations = check_go(diff_text)
108+
if violations:
109+
print("SI canonical gate FAILED. The following added lines introduce")
110+
print("legacy unit-suffixed identifiers (mi/min/kwh/kw/mph/psi).")
111+
print("Rename them to SI (m/s/wh/w/mps/kpa) per Phase-48 mandate:")
112+
print()
113+
for v in violations:
114+
print(f" {v}")
115+
return 1
116+
print("SI canonical gate PASSED — no new legacy unit-suffixed identifiers added.")
117+
118+
if mode in ("fe", "all"):
119+
violations = check_fe(diff_text)
120+
if violations:
121+
print("SI canonical gate FAILED. Added lines call @deprecated unit")
122+
print("conversion helpers. Use useUnits() + SI helpers instead:")
123+
print()
124+
for v in violations:
125+
print(f" {v}")
126+
return 1
127+
print("SI canonical gate (FE) PASSED.")
128+
return 0
129+
130+
131+
if __name__ == "__main__":
132+
raise SystemExit(main())

.github/workflows/load-test.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ jobs:
7171
exit 1
7272
7373
- name: Run k6
74-
uses: grafana/k6-action@v0.3.1
75-
with:
76-
filename: tests/k6/api_smoke.js
74+
# grafana/k6-action runs k6 in a sibling container, so localhost
75+
# is not the compose-published API. Use host networking on
76+
# ubuntu-latest so BASE_URL=http://localhost:8080 reaches the stack.
77+
run: |
78+
# k6 image is non-root; make the bind-mount writable so
79+
# handleSummary / --summary-export can persist summary.json.
80+
chmod a+w tests/k6
81+
docker run --rm --network host \
82+
-e BASE_URL=http://localhost:8080 \
83+
-e SCENARIO="${SCENARIO}" \
84+
-v "${GITHUB_WORKSPACE}/tests/k6:/scripts" \
85+
-w /scripts \
86+
--user "$(id -u):$(id -g)" \
87+
grafana/k6:0.54.0 run /scripts/api_smoke.js
88+
test -f tests/k6/summary.json
7789
env:
78-
BASE_URL: http://localhost:8080
7990
SCENARIO: ${{ github.event.inputs.scenario || 'smoke' }}
8091

8192
- name: Upload k6 summary
@@ -88,7 +99,7 @@ jobs:
8899

89100
- name: Capture API logs on failure
90101
if: failure()
91-
run: docker compose logs api > api.log
102+
run: docker compose logs teslasync-api > api.log
92103
continue-on-error: true
93104

94105
- name: Upload API logs

.github/workflows/proto-gen-check.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ permissions:
2626
jobs:
2727
check:
2828
name: Verify generated Tesla protomodel matches proto
29-
runs-on: ${{ inputs.runner || 'arc-runner' }}
29+
runs-on: ubuntu-latest
3030
steps:
3131
- uses: actions/checkout@v4
3232
- uses: actions/setup-go@v5
3333
with:
3434
go-version: '1.25'
3535
- name: Verify generated files match proto
36-
run: make gen-tesla-check
36+
run: |
37+
set -euo pipefail
38+
go generate ./internal/tesla/protomodel/...
39+
if ! git diff --quiet -- internal/tesla/protomodel/; then
40+
echo "ERROR: generated files are out of sync with proto"
41+
git --no-pager diff -- internal/tesla/protomodel/
42+
exit 1
43+
fi

.github/workflows/security.yml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,33 @@ jobs:
136136
- name: Verify Gitleaks policy catches secrets
137137
shell: bash
138138
run: |
139-
fixture="$(mktemp -d)"
139+
# Keep fixtures under the workspace so Docker bind-mounts work on
140+
# self-hosted runners where host /tmp is not visible inside Docker.
141+
fixture="$(pwd)/.gitleaks-policy-fixture"
142+
rm -rf "$fixture"
143+
mkdir -p "$fixture"
140144
trap 'rm -rf "$fixture"' EXIT
141145
write_private_key() {
142146
printf '%s %s\n%s\n%s %s\n' \
143147
'-----BEGIN' 'PRIVATE KEY-----' \
144148
'MIIEpgIBAAKCAQEA7Q0qj5WmCqvTNSiP1w3M9yKf9c2V8zR4' \
145149
'-----END' 'PRIVATE KEY-----' > "$1"
146150
}
147-
for fixture_path in production.go internal/negative_test.go web/src/negative.test.ts; do
148-
mkdir -p "$(dirname "$fixture/$fixture_path")"
149-
write_private_key "$fixture/$fixture_path"
150-
if docker run --rm \
151+
run_detect() {
152+
local source_dir="$1"
153+
docker run --rm \
151154
-v "$(pwd)/.gitleaks.toml:/config.toml:ro" \
152155
-v "$fixture:/fixture:ro" \
153156
"${GITLEAKS_IMAGE}" \
154-
detect --source="/fixture/$fixture_path" --config=/config.toml --no-git --redact --no-banner; then
157+
detect --source="/fixture/${source_dir}" --config=/config.toml --no-git --redact --no-banner
158+
}
159+
n=0
160+
for fixture_path in production.go internal/negative_test.go web/src/negative.test.ts; do
161+
n=$((n + 1))
162+
case_dir="pk-${n}"
163+
mkdir -p "$fixture/$case_dir/$(dirname "$fixture_path")"
164+
write_private_key "$fixture/$case_dir/$fixture_path"
165+
if run_detect "$case_dir"; then
155166
echo "Gitleaks failed to detect generated $fixture_path" >&2
156167
exit 1
157168
fi
@@ -160,26 +171,24 @@ jobs:
160171
write_stopword_fixture() {
161172
printf 'const %s = "%s%s"\n' "$1" "$2" "$3" > "$4"
162173
}
174+
n=0
163175
for fixture_path in source-stopword.go web/src/stopword.test.ts; do
164-
mkdir -p "$(dirname "$fixture/$fixture_path")"
165-
write_stopword_fixture token 'sk_live_' 'abcdef1234' "$fixture/$fixture_path"
166-
if docker run --rm \
167-
-v "$(pwd)/.gitleaks.toml:/config.toml:ro" \
168-
-v "$fixture:/fixture:ro" \
169-
"${GITLEAKS_IMAGE}" \
170-
detect --source="/fixture/$fixture_path" --config=/config.toml --no-git --redact --no-banner; then
176+
n=$((n + 1))
177+
case_dir="stripe-${n}"
178+
mkdir -p "$fixture/$case_dir/$(dirname "$fixture_path")"
179+
write_stopword_fixture token 'sk_live_' 'abcdef1234' "$fixture/$case_dir/$fixture_path"
180+
if run_detect "$case_dir"; then
171181
echo "Gitleaks failed to detect generated Stripe-like $fixture_path" >&2
172182
exit 1
173183
fi
174184
done
185+
n=0
175186
for fixture_path in source-refresh.go web/src/refresh.test.ts; do
176-
mkdir -p "$(dirname "$fixture/$fixture_path")"
177-
write_stopword_fixture refresh_token 'rt_fake_refresh_token_for_seed_data_only_' 'abc123def456' "$fixture/$fixture_path"
178-
if docker run --rm \
179-
-v "$(pwd)/.gitleaks.toml:/config.toml:ro" \
180-
-v "$fixture:/fixture:ro" \
181-
"${GITLEAKS_IMAGE}" \
182-
detect --source="/fixture/$fixture_path" --config=/config.toml --no-git --redact --no-banner; then
187+
n=$((n + 1))
188+
case_dir="refresh-${n}"
189+
mkdir -p "$fixture/$case_dir/$(dirname "$fixture_path")"
190+
write_stopword_fixture refresh_token 'rt_fake_refresh_token_for_seed_data_only_' 'abc123def456' "$fixture/$case_dir/$fixture_path"
191+
if run_detect "$case_dir"; then
183192
echo "Gitleaks failed to detect generated refresh-token $fixture_path" >&2
184193
exit 1
185194
fi
@@ -193,6 +202,10 @@ jobs:
193202
"${GITLEAKS_IMAGE}" \
194203
detect --source=/fixture/allowlist-control --config=/config.toml --no-git --redact --no-banner
195204
205+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
206+
with:
207+
node-version: "20"
208+
196209
- name: Initialize CodeQL
197210
uses: github/codeql-action/init@b1bff81932f5cdfc8695c7752dcee935dcd061c8 # v4.33.0
198211
with:

0 commit comments

Comments
 (0)