Skip to content

Commit 4197594

Browse files
author
Mateusz
committed
refactor: split oversized test and compression modules
Decompose several oversized test suites and compression strategy logic into smaller modules while preserving import compatibility and behavior, improving maintainability without call-site changes. Harden duplicate test filename meta-check to evaluate tracked tests so concurrent untracked work does not produce false local failures. Made-with: Cursor
1 parent 5b936c4 commit 4197594

51 files changed

Lines changed: 13961 additions & 13411 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev/scripts/analyze_time_violations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import sys
77
from collections import defaultdict
88
from pathlib import Path
9+
from typing import Any
910

1011
# Add project root to path
1112
repo_root = Path(__file__).resolve().parents[2]
1213
sys.path.insert(0, str(repo_root))
1314

14-
from tests.unit.test_time_usage_linter import _scan_repo_for_time_usage
15+
from tests.unit.support.time_usage_linter_scanner import scan_repo_for_time_usage
1516
from tests.utils.time_policy import load_allowlist
1617

1718

@@ -24,10 +25,10 @@ def main() -> None:
2425
cache_path.unlink()
2526

2627
allowlist = load_allowlist()
27-
findings = _scan_repo_for_time_usage(repo_root, allowlist)
28+
findings = scan_repo_for_time_usage(repo_root, allowlist)
2829

2930
# Categorize by file and type
30-
by_file: dict[str, list[dict[str, any]]] = defaultdict(list)
31+
by_file: dict[str, list[dict[str, Any]]] = defaultdict(list)
3132
by_type: dict[str, int] = defaultdict(int)
3233

3334
for finding in findings:

dev/scripts/create_time_usage_inventory.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
import sys
1111
from collections import defaultdict
1212
from pathlib import Path
13+
from typing import Any
1314

1415
# Add repo root to path
1516
repo_root = Path(__file__).parent.parent.parent
1617
sys.path.insert(0, str(repo_root))
1718

18-
from tests.unit.test_time_usage_linter import (
19+
from tests.unit.support.time_usage_linter_scanner import (
1920
LintFinding,
20-
_scan_repo_for_time_usage,
21+
scan_repo_for_time_usage,
2122
)
2223
from tests.utils.time_policy import load_allowlist
2324

@@ -99,7 +100,7 @@ def create_inventory(repo_root: Path, output_path: Path) -> None:
99100
"""
100101
print("Scanning repository for time usage violations...")
101102
allowlist = load_allowlist()
102-
findings = _scan_repo_for_time_usage(repo_root, allowlist)
103+
findings = scan_repo_for_time_usage(repo_root, allowlist)
103104

104105
print(f"Found {len(findings)} violations")
105106

@@ -143,7 +144,7 @@ def create_inventory(repo_root: Path, output_path: Path) -> None:
143144
classified[classification].append(entry)
144145

145146
# Create summary statistics
146-
summary = {
147+
summary: dict[str, Any] = {
147148
"total_violations": len(findings),
148149
"by_rule": {
149150
rule: len(findings_list) for rule, findings_list in by_rule.items()

dev/scripts/pre-commit-hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def run_stall_linter_on_staged_tests() -> bool:
357357
"pytest",
358358
"-n",
359359
"0",
360-
"tests/unit/test_stall_linter.py",
360+
"tests/unit/stall_linter/",
361361
]
362362
for file_path in target_test_files:
363363
pytest_args.extend(["--stall-lint-file", file_path])
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Shared regexes, logging, and helpers for compression strategies."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
import re
7+
8+
_CSI_RE = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")
9+
_OSC_RE = re.compile(r"\x1B\][^\x07\x1B]*(?:\x07|\x1B\\)")
10+
_DCS_PM_APC_RE = re.compile(r"\x1B(?:P|_|\^)[\s\S]*?(?:\x1B\\)")
11+
_ESC_SINGLE_RE = re.compile(r"\x1B[@-Z\\-_]")
12+
_CONTROL_CHAR_RE = re.compile(r"[\x00-\x08\x0B\x0C\x0E-\x1A\x1C-\x1F\x7F-\x9F]")
13+
_FAILURE_INDICATOR_RE = re.compile(
14+
r"(?i)\b("
15+
r"error|errors|failed|failure|fatal|panic|exception|traceback|"
16+
r"assertion(?:error)?|segmentation fault|stack trace|"
17+
r"timed out|timeout|denied"
18+
r")\b|^\s*E\s+|^\s*FAILED\b|^\s*FAIL\b"
19+
)
20+
_ZERO_FAILURE_RE = re.compile(r"(?i)\b(?:0\s+failed|0\s+failures|0\s+errors?)\b")
21+
_POSITIVE_FAILURE_COUNT_RE = re.compile(
22+
r"(?i)\b[1-9]\d*\s+(?:failed|failures|errors?)\b"
23+
)
24+
logger = logging.getLogger("src.core.services.compression_strategies")
25+
26+
_REGEX_EVAL_SUBPROCESS_SNIPPET = (
27+
"import json\n"
28+
"import re\n"
29+
"import sys\n"
30+
"payload = json.loads(sys.stdin.read())\n"
31+
"try:\n"
32+
" compiled = re.compile(payload['pattern'], payload['flags'])\n"
33+
" matched = compiled.search(payload['text']) is not None\n"
34+
"except Exception:\n"
35+
" matched = False\n"
36+
"sys.stdout.write('1' if matched else '0')\n"
37+
)
38+
39+
40+
def _line_indicates_failure(line: str) -> bool:
41+
if not _FAILURE_INDICATOR_RE.search(line):
42+
return False
43+
return not (
44+
_ZERO_FAILURE_RE.search(line) and not _POSITIVE_FAILURE_COUNT_RE.search(line)
45+
)
46+
47+
48+
def _preserve_trailing_newline(*, original: str, transformed: str) -> str:
49+
"""Keep only trailing-newline presence aligned to the source string."""
50+
if original.endswith("\n"):
51+
return transformed if transformed.endswith("\n") else f"{transformed}\n"
52+
return transformed.rstrip("\n")
53+
54+
55+
_GIT_CMD_ERROR_RE = re.compile(r"^(fatal|error):\s", re.MULTILINE | re.IGNORECASE)
56+
_GIT_CONFLICT_RE = re.compile(r"\bCONFLICT\b", re.IGNORECASE)
57+
_COMMIT_HASH_IN_BRACKETS_RE = re.compile(
58+
r"\[([^\]\s]+)\s+([0-9a-f]{7,40})\]", re.IGNORECASE
59+
)
60+
_FILES_CHANGED_RE = re.compile(r"(\d+)\s+files?\s+changed", re.IGNORECASE)
61+
_INSERTIONS_RE = re.compile(r"(\d+)\s+insertions?", re.IGNORECASE)
62+
_DELETIONS_RE = re.compile(r"(\d+)\s+deletions?", re.IGNORECASE)
63+
_REF_ARROW_RE = re.compile(
64+
r"^\s*([^\s]+\.{2,3}[^\s]+|[0-9a-f]{7,40}\.{2,3}[0-9a-f]{7,40})\s+(\S+)\s+->\s+(\S+)",
65+
re.MULTILINE,
66+
)
67+
_NPM_ERR_RE = re.compile(r"\bERR!\b", re.IGNORECASE)
68+
_PIP_INSTALL_OK_RE = re.compile(
69+
r"Successfully installed\s+(.+)$", re.IGNORECASE | re.MULTILINE
70+
)
71+
72+
73+
def _mutating_ack_failure_heuristic(text: str) -> bool:
74+
if _GIT_CMD_ERROR_RE.search(text) or _GIT_CONFLICT_RE.search(text):
75+
return True
76+
if _NPM_ERR_RE.search(text):
77+
return True
78+
return any(_line_indicates_failure(line) for line in text.splitlines())

0 commit comments

Comments
 (0)