fix(test): prima parte vuol dire tracciato, non fuori da vendor
Il controllo sui riferimenti esterni scandiva anche i file che git non conosce. Una copia di comodo di una libreria lasciata in static/js/ -- fabric-debug.js -- sembrava codice nostro e faceva fallire la prova con gli URL nei propri commenti, ma non sta nel repository e in reparto non ci arriva mai. Su un checkout pulito la prova passava: falliva solo su chi aveva quel file, cioe' proprio su chi stava lavorando. Il filtro ora e' la tracciabilita', non il percorso. Non i pattern di .gitignore, che non dicono nulla su un file gia' tracciato. Se git non risponde si scandisce tutto come prima: una prova-guardia che ammutolisce quando perde l'appoggio e' peggio di una che grida al lupo. Verificato che morda ancora: un fetch verso un CDN in un file tracciato la fa fallire. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014BBnuACZSCJqXrMYC3LUMU
This commit is contained in:
@@ -9,6 +9,7 @@ cdn...">` because it is the quickest way to try something, it works at their des
|
|||||||
and nobody finds out until the machine is on the shop floor.
|
and nobody finds out until the machine is on the shop floor.
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -32,11 +33,42 @@ _DOC_HOSTS = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _tracked_files():
|
||||||
|
"""The files git knows about, or None when git cannot answer.
|
||||||
|
|
||||||
|
Being outside `vendor/` is not the same as being ours. A scratch copy of a
|
||||||
|
library dropped into `static/js/` to debug something looks first-party and is
|
||||||
|
not: it is not in the repository, it never reaches the shop floor, and its
|
||||||
|
comments are not our comments. Trackedness is the honest test for that.
|
||||||
|
|
||||||
|
Trackedness, and not `.gitignore`: an ignore pattern says nothing about a
|
||||||
|
file that is already tracked, so matching patterns would be the wrong
|
||||||
|
question.
|
||||||
|
|
||||||
|
When git cannot answer we scan everything, as before. A guard test that goes
|
||||||
|
quiet the moment it loses its footing is worse than one that cries wolf.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
listed = subprocess.run(
|
||||||
|
["git", "ls-files", "-z"],
|
||||||
|
cwd=APP_ROOT, capture_output=True, text=True, check=True,
|
||||||
|
).stdout
|
||||||
|
except (OSError, subprocess.SubprocessError):
|
||||||
|
return None
|
||||||
|
return {(APP_ROOT / name).resolve() for name in listed.split("\0") if name}
|
||||||
|
|
||||||
|
|
||||||
def _first_party_files(suffixes):
|
def _first_party_files(suffixes):
|
||||||
|
tracked = _tracked_files()
|
||||||
|
|
||||||
|
def is_ours(path):
|
||||||
|
return tracked is None or path.resolve() in tracked
|
||||||
|
|
||||||
for path in sorted(STATIC.rglob("*")):
|
for path in sorted(STATIC.rglob("*")):
|
||||||
if path.suffix in suffixes and "vendor" not in path.parts:
|
if path.suffix in suffixes and "vendor" not in path.parts and is_ours(path):
|
||||||
yield path
|
yield path
|
||||||
for path in sorted(TEMPLATES.rglob("*.html")):
|
for path in sorted(TEMPLATES.rglob("*.html")):
|
||||||
|
if is_ours(path):
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user