Files
StarPilot/openpilot/starpilot/flm/tests/test_exact_text_validation.py
T
firestar5683 6103e0395b Preserve FLM learning windows across unchanged steering repeats
The d5 Ioniq 6 logs repeatedly reset source tracking when Card repeats a command that already arrived on time. Discard only a recent unchanged repeat after the existing native CAN verifier succeeds; add no sample, application time or permission.

Use independently admitted pending CarState brackets to complete original poses without waiting for that command to reach Card. Classify stale control source clocks as transient stale evidence, preserving the original bounded study deadline. Replace Python character loops with equivalent strict text predicates.

Validation: focused regression suite and paced d5 replay with original Card command references; actual controller/CAN trial application and worsening-trial rollback. No timing/acceptance threshold changes or claimed road improvement.
2026-10-26 21:55:26 -05:00

42 lines
1.7 KiB
Python

"""Equivalent bounded text predicates, including malformed wire text."""
from dataclasses import replace
from types import SimpleNamespace
from openpilot.starpilot.flm.live_trial_contract import _digest, _text
from openpilot.starpilot.flm.runtime_adapter_registry import SourceState
from openpilot.starpilot.flm.steerlearnerd import _source_config_known
class TextSubclass(str):
pass
def old_text(value, maximum):
return type(value) is str and 0 < len(value) <= maximum and value.isascii() and all(32 <= ord(c) < 127 for c in value)
def old_digest(value):
return type(value) is str and len(value) == 64 and all(c in '0123456789abcdef' for c in value)
def test_text_and_digest_match_exact_prior_predicates():
values = [None, False, 0, b'a', [], {}, SimpleNamespace(), TextSubclass('a'), '', 'a' * 193]
alphabet = [chr(i) for i in range(256)] + ['\u200b', '\u2028', '\ud800', '\uffff', '\U0001f642']
for char in alphabet:
values.extend((char, char * 64, 'a' * 31 + char + '0' * 32, 'a' * 63 + char, char + 'a' * 63))
for value in values:
assert _digest(value) is old_digest(value)
for bound in (0, 1, 32, 64, 96, 192):
assert _text(value, bound) is old_text(value, bound)
def test_source_binding_hex_remains_strict():
source = SourceState(True, False, '0', 'a' * 64, 100, 500_000_100, 'b' * 64,
calibration_generation='c' * 32, persistent_source_epoch='d' * 64)
assert _source_config_known(source, 200)
for field in ('cp_sha256', 'reset', 'calibration_generation', 'persistent_source_epoch'):
original = getattr(source, field)
for bad in ('g', 'A', ' ', '\n', '\x00', '\u00e9'):
assert not _source_config_known(replace(source, **{field: original[:-1] + bad}), 200)
assert not _source_config_known(source, 500_000_101)