diff --git a/starpilot/system/the_galaxy/assets/components/recordings/dashcam_routes_helpers.js b/starpilot/system/the_galaxy/assets/components/recordings/dashcam_routes_helpers.js index fc8600882..2cd9ecf48 100644 --- a/starpilot/system/the_galaxy/assets/components/recordings/dashcam_routes_helpers.js +++ b/starpilot/system/the_galaxy/assets/components/recordings/dashcam_routes_helpers.js @@ -151,18 +151,20 @@ export function routeMatchesSearch(route, searchQuery) { compactQuery.length >= 8 || (compactQuery.length >= 4 && /\d/.test(compactQuery) && /[a-f]/.test(compactQuery)) )) const valuesFor = key => Array.isArray(searchIndex[key]) ? searchIndex[key] : [] - const searchValues = [ - ...valuesFor("titles"), - ...(isDateQuery ? valuesFor("dates") : []), - ...(isTimeQuery ? valuesFor("times") : []), - ...(isIdQuery ? valuesFor("ids") : []), - ] - - return searchValues.some(value => { + const matchesValue = (value, dateValue = false) => { if (value.includes(normalizedQuery)) return true const searchTokens = value.split(" ").filter(Boolean) - return queryTokens.every(queryToken => searchTokens.some(searchToken => searchToken.startsWith(queryToken))) - }) + return queryTokens.every(queryToken => searchTokens.some(searchToken => { + // In a date query, "20" is a day prefix, not a match for the year "2026". + if (dateValue && /^\d{1,2}$/.test(queryToken) && /^\d{4}$/.test(searchToken)) return false + return searchToken.startsWith(queryToken) + })) + } + + return valuesFor("titles").some(value => matchesValue(value)) + || (isDateQuery && valuesFor("dates").some(value => matchesValue(value, true))) + || (isTimeQuery && valuesFor("times").some(value => matchesValue(value))) + || (isIdQuery && valuesFor("ids").some(value => matchesValue(value))) } export function buildRouteView(routes, options = {}) { diff --git a/starpilot/system/the_galaxy/tests/test_dashcam_routes_helpers.py b/starpilot/system/the_galaxy/tests/test_dashcam_routes_helpers.py index 75a3dae8a..b9ea6f616 100644 --- a/starpilot/system/the_galaxy/tests/test_dashcam_routes_helpers.py +++ b/starpilot/system/the_galaxy/tests/test_dashcam_routes_helpers.py @@ -173,6 +173,24 @@ def test_search_matches_partial_title_tokens_and_friendly_dates_as_the_user_type ] +def test_partial_day_does_not_match_the_four_digit_year(): + result = evaluate(''' + const routes = Array.from({ length: 9 }, (_, offset) => { + const day = 19 + offset + return route(`aug-${day}`, `2026-08-${day}T12:00:00Z`) + }) + return { + partial: buildRouteView(routes, { searchQuery: "aug 2" }).matching.map(item => item.name), + complete: buildRouteView(routes, { searchQuery: "aug 20" }).matching.map(item => item.name), + } + ''') + + assert result == { + "partial": ["aug-27", "aug-26", "aug-25", "aug-24", "aug-23", "aug-22", "aug-21", "aug-20"], + "complete": ["aug-20"], + } + + def test_route_search_input_updates_on_every_keystroke(): source = COMPONENT_PATH.read_text(encoding="utf-8")