Files
StarPilot/scripts/lint/tests/test_large_file_policy.py
T
firestar5683 80fbb4f6db Feature registration
Register vehicle controls, planner modes, UI actions and Galaxy services after their providers exist. Wire the shared runtime entrypoints and cover their combined behavior.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Kacper Rączy <gfw.kra@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: haraschax <6804392+haraschax@users.noreply.github.com>
Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

44 lines
2.1 KiB
Python

import importlib.util
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
PATH = Path(__file__).parents[1] / 'check_added_large_files.py'
spec = importlib.util.spec_from_file_location('large_file_policy', PATH)
assert spec is not None and spec.loader is not None
policy = importlib.util.module_from_spec(spec)
spec.loader.exec_module(policy)
class LargeFilePolicyTest(unittest.TestCase):
def check(self, name, size, binary=False, pointer=False):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
path = root / name
path.parent.mkdir(parents=True, exist_ok=True)
with path.open('wb') as output:
output.write(b'version https://git-lfs.github.com/spec/v1\n' if pointer else b'ordinary data')
output.truncate(size)
info = path.stat()
with (patch.object(policy, 'binary_files', return_value={name} if binary else set()),
patch.object(policy.os, 'stat', return_value=info), patch('builtins.open', side_effect=lambda *_: path.open('rb'))):
return policy.check_added_large_files([name], 120)
def test_generated_text_and_exact_retained_fixture(self):
self.assertEqual(self.check('openpilot/cereal/gen/cpp/custom.capnp.h', 700000), 0)
self.assertEqual(self.check('openpilot/starpilot/lateral/tests/fixtures/oct2_turns.json', 200000), 0)
self.assertEqual(self.check('openpilot/cereal/gen/cpp/arbitrary.h', 200000), 1)
self.assertEqual(self.check('openpilot/starpilot/lateral/tests/fixtures/arbitrary.json', 200000), 1)
def test_binary_classification_does_not_bypass_hard_guards(self):
self.assertEqual(self.check('native.so', 500000, binary=True), 0)
self.assertEqual(self.check('native.so', 100 * 1024 * 1024 + 1, binary=True), 1)
self.assertEqual(self.check('native.so', 500000, binary=True, pointer=True), 1)
self.assertEqual(self.check('openpilot/cereal/gen/cpp/custom.capnp.h', 100 * 1024 * 1024 + 1), 1)
self.assertEqual(self.check('openpilot/cereal/gen/cpp/custom.capnp.h', 500000, pointer=True), 1)
if __name__ == '__main__':
unittest.main()