mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 19:47:12 +01:00
billsplit was a standalone Flutter app in ~/Downloads with one commit and no git remote — that directory was the only copy of its history. Three things the move needed beyond copying the tree: - The root .gitignore silently swallowed 32 of its files (*.png, *.ico, *.manifest). Ignored files do not error on `git add`, they just vanish, so this would have committed an app that cannot build. Added a trailing block of ! overrides plus .binary-allowlist (which did not exist yet) — the documented in-repo exception for binaries a build genuinely needs. The ../testsAndMisc_binaries/ symlink scheme does not apply: those directories are gone, and a symlinked PNG breaks a fresh clone. - billsplit/.github/workflows/ci.yaml was inert once nested; GitHub only reads workflows at the repository root. Relocated with a working-directory and a billsplit/** path filter. - The app's coverage gate moved to python_pkg/billsplit_coverage/ so every Python file stays under python_pkg/, and gained a test suite at 100% branch coverage as that location requires. billsplit/ now holds only Dart. Also replaces the stock Flutter icon with a family icon from the shared generator. The glyph is a filled silhouette because the family's 72px stroke cannot carry a fine torn edge, and the split is an evenodd-cut perforation so the holes stay transparent on the foreground and monochrome layers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
95 lines
3.2 KiB
Python
Executable File
95 lines
3.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Run pytest for all python_pkg subpackages whenever any Python file changes.
|
|
|
|
Used as a pre-commit hook entry point. Receives staged file paths as arguments.
|
|
If any Python file changed, discovers every subpackage under ``python_pkg/``
|
|
that has a ``tests/`` directory and runs them all in a single parallelised
|
|
invocation with whole-repo coverage measured against ``python_pkg``.
|
|
|
|
Running all packages together (rather than just the touched ones) ensures that
|
|
100% branch coverage is maintained across the entire codebase on every commit,
|
|
not just the files that happened to change.
|
|
|
|
Standalone script suites outside ``python_pkg/`` (currently
|
|
``linux_configuration/tests``) are also run so their behaviour is gated, but
|
|
they are not coverage-measured (coverage stays scoped to ``python_pkg``).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
# Memory ceiling for the whole suite. Measured peak RSS for all python_pkg
|
|
# tests plus linux_configuration/tests (1117 tests, branch coverage on) is
|
|
# ~0.23 GiB, so 2G leaves roughly 8x headroom. It was 4G, which is not free:
|
|
# a 4G request cannot be satisfied inside a smaller outer scope, so wrapping
|
|
# a commit in a tighter budget got the suite OOM-killed from the inside rather
|
|
# than merely slowed. Keep this at or below any outer cap a caller may impose.
|
|
_TOTAL_MEM = "2G"
|
|
|
|
# Standalone script test suites outside python_pkg/ that should be gated but
|
|
# not coverage-measured. Skipped silently if the directory does not exist.
|
|
_EXTRA_TEST_DIRS = ("linux_configuration/tests",)
|
|
|
|
|
|
def main() -> int:
|
|
"""Entry point."""
|
|
if not sys.argv[1:]:
|
|
return 0
|
|
|
|
packages = sorted(
|
|
entry.name
|
|
for entry in Path("python_pkg").iterdir()
|
|
if (entry / "tests").is_dir()
|
|
)
|
|
if not packages:
|
|
return 0
|
|
|
|
test_dirs = [f"python_pkg/{pkg}/tests" for pkg in packages]
|
|
test_dirs += [d for d in _EXTRA_TEST_DIRS if Path(d).is_dir()]
|
|
|
|
cmd = [
|
|
sys.executable,
|
|
"-m",
|
|
"pytest",
|
|
"--cov",
|
|
"python_pkg",
|
|
"--cov-branch",
|
|
"--cov-report=term-missing",
|
|
"--cov-fail-under=100",
|
|
"-q",
|
|
# No -n/xdist: pytest-cov's worker coverage combine has shown a
|
|
# reproducible (not flaky -- failed identically twice in a row) gap
|
|
# under -n 4 on the GitHub Actions runner that never occurs running
|
|
# serially, including run repeatedly with the same -n 4 locally.
|
|
# Serial is slightly slower but has never produced a false coverage
|
|
# failure, which matters more for a 100%-coverage gate.
|
|
# Override addopts from pyproject.toml to avoid double --cov flags.
|
|
"-o",
|
|
"addopts=--strict-markers --strict-config -ra",
|
|
*test_dirs,
|
|
]
|
|
|
|
if shutil.which("systemd-run") is not None:
|
|
cmd = [
|
|
"systemd-run",
|
|
"--user",
|
|
"--scope",
|
|
"--quiet",
|
|
"--collect",
|
|
"-p",
|
|
f"MemoryMax={_TOTAL_MEM}",
|
|
"-p",
|
|
"MemorySwapMax=0",
|
|
*cmd,
|
|
]
|
|
return subprocess.run(cmd, check=False, env=os.environ).returncode
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|