dangkhoa2016 commited on
Commit
11f6f66
·
1 Parent(s): dcb1716

chore: add manual test coverage verification tool

Browse files

- Add a script that runs coverage per commit and writes a markdown report
- Support optional mise integration for the Node toolchain

.gitignore CHANGED
@@ -8,3 +8,5 @@ storage/*
8
  !storage/.gitkeep
9
 
10
  .env.dev
 
 
 
8
  !storage/.gitkeep
9
 
10
  .env.dev
11
+ manual-test-coverage/results
12
+ manual-test-coverage/coverage-report.md
README.md CHANGED
@@ -329,6 +329,9 @@ json-api-server/
329
  │ ├── posts.sh # Posts endpoints
330
  │ ├── todos.sh # Todos endpoints
331
  │ └── users.sh # Users endpoints
 
 
 
332
  ├── storage/ # SQLite database files (auto-created)
333
  ├── temp/ # Temporary files (gitignored)
334
  ├── .env # Base configuration (tried first in development — highest priority)
 
329
  │ ├── posts.sh # Posts endpoints
330
  │ ├── todos.sh # Todos endpoints
331
  │ └── users.sh # Users endpoints
332
+ ├── manual-test-coverage/
333
+ │ ├── README.md # Coverage verification documentation
334
+ │ └── verify-commit-coverage.sh # Coverage verification script
335
  ├── storage/ # SQLite database files (auto-created)
336
  ├── temp/ # Temporary files (gitignored)
337
  ├── .env # Base configuration (tried first in development — highest priority)
manual-test-coverage/README.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Coverage Verification Tool
2
+
3
+ > 🌐 Language / Ngôn ngữ: **English** | [Tiếng Việt](README.vi.md)
4
+
5
+ This directory contains a script to verify code coverage across commit history.
6
+
7
+ ## Files
8
+
9
+ - `verify-commit-coverage.sh` — iterates each commit in a range, checks coverage, produces report
10
+ - `coverage-report.md` — generated markdown report (gitignored)
11
+ - `results/` — per-commit raw logs (gitignored)
12
+
13
+ ## Usage
14
+
15
+ From the project root:
16
+
17
+ ```bash
18
+ bash manual-test-coverage/verify-commit-coverage.sh
19
+ ```
20
+
21
+ Optionally specify a commit range:
22
+
23
+ ```bash
24
+ bash manual-test-coverage/verify-commit-coverage.sh <base-sha> <head-sha>
25
+ ```
26
+
27
+ Each commit is checked out, `yarn test:coverage` is run, coverage percentages are captured, and a markdown report is written to `coverage-report.md`.
28
+
29
+ ## Requirements
30
+
31
+ - `yarn` and `vitest` with `--coverage` configured
32
+ - (Optional) `mise` — if available, the script will use it to restore the Node.js runtime environment for each commit
manual-test-coverage/README.vi.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Công cụ kiểm tra mức độ bao phủ
2
+
3
+ > 🌐 Language / Ngôn ngữ: [English](README.md) | **Tiếng Việt**
4
+
5
+ Thư mục này chứa script để kiểm tra mức độ bao phủ mã nguồn (code coverage) qua lịch sử commit.
6
+
7
+ ## Các file
8
+
9
+ - `verify-commit-coverage.sh` — duyệt từng commit trong một khoảng, kiểm tra coverage, tạo báo cáo
10
+ - `coverage-report.md` — báo cáo markdown được sinh ra (đã gitignore)
11
+ - `results/` — nhật ký thô từng commit (đã gitignore)
12
+
13
+ ## Cách dùng
14
+
15
+ Chạy từ thư mục gốc của dự án:
16
+
17
+ ```bash
18
+ bash manual-test-coverage/verify-commit-coverage.sh
19
+ ```
20
+
21
+ Có thể chỉ định khoảng commit:
22
+
23
+ ```bash
24
+ bash manual-test-coverage/verify-commit-coverage.sh <base-sha> <head-sha>
25
+ ```
26
+
27
+ Mỗi commit được checkout, chạy `yarn test:coverage`, thu thập tỷ lệ coverage, và ghi báo cáo markdown vào `coverage-report.md`.
28
+
29
+ ## Yêu cầu
30
+
31
+ - `yarn` và `vitest` đã cấu hình `--coverage`
32
+ - (Không bắt buộc) `mise` — nếu có, script sẽ dùng nó để khôi phục môi trường Node.js cho mỗi commit
manual-test-coverage/verify-commit-coverage.sh ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ BASE="${1:-$(git rev-list --max-parents=0 HEAD)}"
5
+ HEAD="${2:-HEAD}"
6
+ RESULTS_DIR="$(dirname "$0")/results"
7
+ REPORT="$(dirname "$0")/coverage-report.md"
8
+
9
+ mkdir -p "$RESULTS_DIR"
10
+
11
+ echo "# Coverage Report" > "$REPORT"
12
+ echo "" >> "$REPORT"
13
+ echo "| # | Commit | Stmts | Branch | Funcs | Lines | Message |" >> "$REPORT"
14
+ echo "|--:|--------|------:|-------:|------:|------:|---------|" >> "$REPORT"
15
+
16
+ COMMITS=()
17
+ while IFS= read -r line; do
18
+ COMMITS+=("$line")
19
+ done < <(git log --oneline --reverse "${BASE}..${HEAD}")
20
+
21
+ TOTAL=${#COMMITS[@]}
22
+ IDX=1
23
+ ORIG_BRANCH=$(git rev-parse --abbrev-ref HEAD)
24
+
25
+ cleanup() {
26
+ git checkout "$ORIG_BRANCH" 2>/dev/null || true
27
+ # mise is optional: only load if the user has it installed
28
+ command -v mise &>/dev/null && eval "$(mise activate bash)" || true
29
+ }
30
+ trap cleanup EXIT
31
+
32
+ for entry in "${COMMITS[@]}"; do
33
+ HASH=$(echo "$entry" | awk '{print $1}')
34
+ MSG=$(echo "$entry" | cut -d' ' -f2-)
35
+ SAFE_MSG=$(echo "$MSG" | sed 's/[^a-zA-Z0-9._-]/_/g' | head -c 80)
36
+ LOGFILE="$RESULTS_DIR/${IDX}-${HASH}-${SAFE_MSG}.log"
37
+
38
+ echo ""
39
+ echo "========================================"
40
+ echo "[${IDX}/${TOTAL}] Checking ${HASH}: ${MSG}"
41
+ echo "========================================"
42
+
43
+ git checkout "$HASH" > /dev/null 2>&1
44
+ # mise is optional: only load if the user has it installed
45
+ command -v mise &>/dev/null && eval "$(mise activate bash)" || true
46
+
47
+ yarn test:coverage 2>&1 | tee "$LOGFILE" || true
48
+
49
+ COV_LINE=$(grep -E "^All files" "$LOGFILE" || true)
50
+ if [ -n "$COV_LINE" ]; then
51
+ STMTS=$(echo "$COV_LINE" | awk '{print $4}')
52
+ BRANCH=$(echo "$COV_LINE" | awk '{print $6}')
53
+ FUNCS=$(echo "$COV_LINE" | awk '{print $8}')
54
+ LINES=$(echo "$COV_LINE" | awk '{print $10}')
55
+ else
56
+ STMTS="-"
57
+ BRANCH="-"
58
+ FUNCS="-"
59
+ LINES="-"
60
+ fi
61
+
62
+ echo "| $IDX | \`${HASH}\` | $STMTS | $BRANCH | $FUNCS | $LINES | $MSG |" >> "$REPORT"
63
+
64
+ IDX=$((IDX + 1))
65
+ done
66
+
67
+ cleanup
68
+ echo ""
69
+ echo "Report written to $REPORT"