tenseleyflow/documentlanguagemodel / b41f337

Browse files

Add local coverage gate sweep

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
b41f337dbce1d99cd620f3a1f8043eda3aa1ec61
Parents
e884678
Tree
a80476a

2 changed files

StatusFile+-
A scripts/coverage-gates.sh 106 0
M scripts/pregate.sh 25 5
scripts/coverage-gates.shadded
@@ -0,0 +1,106 @@
1
+#!/usr/bin/env bash
2
+# Mirror the Ubuntu per-package coverage gates from `.github/workflows/ci.yml`.
3
+#
4
+# Usage:
5
+#   ./scripts/coverage-gates.sh
6
+#   ./scripts/coverage-gates.sh --list
7
+#   ./scripts/coverage-gates.sh --only lock --only export
8
+#
9
+# Best match with CI:
10
+#   uv sync --all-extras --dev
11
+
12
+set -euo pipefail
13
+
14
+cd "$(git rev-parse --show-toplevel)"
15
+export UV_CACHE_DIR="${UV_CACHE_DIR:-.uv-cache}"
16
+
17
+show_list=0
18
+selected=()
19
+
20
+while [[ $# -gt 0 ]]; do
21
+    case "$1" in
22
+        --list)
23
+            show_list=1
24
+            ;;
25
+        --only)
26
+            shift
27
+            if [[ $# -eq 0 ]]; then
28
+                echo "error: --only requires a gate name" >&2
29
+                exit 2
30
+            fi
31
+            selected+=("$1")
32
+            ;;
33
+        *)
34
+            echo "usage: ./scripts/coverage-gates.sh [--list] [--only <gate>]..." >&2
35
+            exit 2
36
+            ;;
37
+    esac
38
+    shift
39
+done
40
+
41
+gates=(
42
+    "doc|tests/unit/doc|src/dlm/doc"
43
+    "store|tests/unit/store|src/dlm/store"
44
+    "hardware|tests/unit/hardware|src/dlm/hardware"
45
+    "base_models|tests/unit/base_models|src/dlm/base_models"
46
+    "data|tests/unit/data|src/dlm/data"
47
+    "replay|tests/unit/replay|src/dlm/replay"
48
+    "train|tests/unit/train|src/dlm/train"
49
+    "train_preference|tests/unit/train/preference|src/dlm/train/preference"
50
+    "eval|tests/unit/eval|src/dlm/eval"
51
+    "inference|tests/unit/inference|src/dlm/inference"
52
+    "export|tests/unit/export|src/dlm/export"
53
+    "export_ollama|tests/unit/export/ollama|src/dlm/export/ollama"
54
+    "cli_reporter|tests/unit/cli|dlm.cli.reporter"
55
+    "io_ulid|tests/unit/test_io_ulid.py|dlm.io.ulid"
56
+    "pack|tests/unit/pack tests/integration/pack|src/dlm/pack"
57
+    "lock|tests/unit/lock|src/dlm/lock"
58
+)
59
+
60
+gate_selected() {
61
+    local name="$1"
62
+    if [[ ${#selected[@]} -eq 0 ]]; then
63
+        return 0
64
+    fi
65
+    local needle
66
+    for needle in "${selected[@]}"; do
67
+        if [[ "$needle" == "$name" ]]; then
68
+            return 0
69
+        fi
70
+    done
71
+    return 1
72
+}
73
+
74
+if [[ $show_list -eq 1 ]]; then
75
+    for gate in "${gates[@]}"; do
76
+        IFS="|" read -r name _tests _cov <<< "$gate"
77
+        printf '%s\n' "$name"
78
+    done
79
+    exit 0
80
+fi
81
+
82
+ran_any=0
83
+for gate in "${gates[@]}"; do
84
+    IFS="|" read -r name tests cov <<< "$gate"
85
+    if ! gate_selected "$name"; then
86
+        continue
87
+    fi
88
+    ran_any=1
89
+    echo "==> Coverage gate: $name ($cov)"
90
+    # shellcheck disable=SC2206
91
+    tests_arr=($tests)
92
+    uv run pytest \
93
+        "${tests_arr[@]}" \
94
+        --cov="$cov" \
95
+        --cov-report=term-missing \
96
+        --cov-fail-under=95 \
97
+        -q
98
+    echo
99
+done
100
+
101
+if [[ $ran_any -eq 0 ]]; then
102
+    echo "error: no matching coverage gate names selected" >&2
103
+    exit 2
104
+fi
105
+
106
+echo "==> coverage gates clean"
scripts/pregate.shmodified
@@ -12,8 +12,9 @@
1212
 #   - tests pinning `dlm_version == N` for a stale N (schema bumps break these)
1313
 #
1414
 # Usage:
15
-#   ./scripts/pregate.sh          # runs the full gate
16
-#   ./scripts/pregate.sh --fast   # skip mypy + pytest, only ruff + pattern checks
15
+#   ./scripts/pregate.sh              # runs the full gate
16
+#   ./scripts/pregate.sh --fast       # skip mypy + pytest, only ruff + pattern checks
17
+#   ./scripts/pregate.sh --coverage   # also mirror the Ubuntu package coverage gates
1718
 #
1819
 # Wire as a git hook with:
1920
 #   ln -s ../../scripts/pregate.sh .git/hooks/pre-push
@@ -21,11 +22,25 @@
2122
 set -euo pipefail
2223
 
2324
 cd "$(git rev-parse --show-toplevel)"
25
+export UV_CACHE_DIR="${UV_CACHE_DIR:-.uv-cache}"
2426
 
2527
 fast=0
26
-if [[ "${1:-}" == "--fast" ]]; then
27
-    fast=1
28
-fi
28
+coverage=0
29
+while [[ $# -gt 0 ]]; do
30
+    case "$1" in
31
+        --fast)
32
+            fast=1
33
+            ;;
34
+        --coverage)
35
+            coverage=1
36
+            ;;
37
+        *)
38
+            echo "usage: ./scripts/pregate.sh [--fast] [--coverage]" >&2
39
+            exit 2
40
+            ;;
41
+    esac
42
+    shift
43
+done
2944
 
3045
 echo "==> ruff check"
3146
 uv run ruff check .
@@ -44,6 +59,11 @@ if [[ $fast -eq 0 ]]; then
4459
     uv run pytest tests/unit -q --no-header
4560
 fi
4661
 
62
+if [[ $coverage -eq 1 ]]; then
63
+    echo "==> coverage gates (Ubuntu mirror)"
64
+    ./scripts/coverage-gates.sh
65
+fi
66
+
4767
 # --- Pattern checks that mirror known CI foot-guns --------------------
4868
 
4969
 echo "==> advisory: assert plan is not None in slow tests"