litellm/tests/test_litellm/test_prisma_generate_if_needed.py
Mateo Wang cf6fdac304
perf(lint): skip and cache base gate passes, parallelize make lint, skip redundant prisma generate (#32000)
* perf(lint): skip and cache base gate passes, parallelize make lint, skip redundant prisma generate

make pre-commit paid for a full second basedpyright pass over a merge-base
worktree on every run even when no rule was over its ceiling, re-generated an
unchanged Prisma client, and ran seven independent checks sequentially. The
basedpyright and ruff strict gates now skip the base pass when head is within
every limit (the same early-out type_discipline_gate already had), the
basedpyright base counts are cached under the git common dir keyed by
merge-base commit, pyrightconfig.json, and uv.lock, prisma generate only runs
when the schema or prisma version changed, and make lint fans its checks out
through a parallel sub-make after a single setup phase

* fix(lint): keep the base-cache scratch file out of the prune glob

The tmp+rename scratch in store_counts was named basedpyright-base-<hash>.json.tmp,
which the stale-entry prune glob (basedpyright-base-*) also matches, so a concurrent
lint run from another worktree sharing the same git common dir could unlink it between
write_text and replace and crash the gate with FileNotFoundError. The scratch is now
dot-prefixed so the glob can never see it, pid-suffixed so concurrent writers of the
same entry never share a scratch, and the prune glob is restricted to committed
*.json entries
2026-07-02 19:24:00 -07:00

35 lines
1.3 KiB
Python

import importlib.util
from pathlib import Path
_MODULE_PATH = (
Path(__file__).resolve().parents[2] / "scripts" / "prisma_generate_if_needed.py"
)
_spec = importlib.util.spec_from_file_location("prisma_generate_if_needed", _MODULE_PATH)
mod = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(mod)
def test_stamp_changes_with_schema_and_with_prisma_version():
stamp = mod.stamp_value(b"model A {}", "0.11.0")
assert mod.stamp_value(b"model A {}", "0.11.0") == stamp
assert mod.stamp_value(b"model B {}", "0.11.0") != stamp
assert mod.stamp_value(b"model A {}", "0.12.0") != stamp
def test_skip_requires_a_matching_stamp(tmp_path):
stamp = tmp_path / "stamp"
expected = mod.stamp_value(b"schema", "0.11.0")
assert mod.should_skip(stamp, expected, client_generated=True) is False
stamp.write_text(expected)
assert mod.should_skip(stamp, expected, client_generated=True) is True
assert (
mod.should_skip(stamp, mod.stamp_value(b"other", "0.11.0"), client_generated=True)
is False
)
def test_skip_requires_a_generated_client_even_with_a_matching_stamp(tmp_path):
stamp = tmp_path / "stamp"
expected = mod.stamp_value(b"schema", "0.11.0")
stamp.write_text(expected)
assert mod.should_skip(stamp, expected, client_generated=False) is False