|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +if [[ $# -lt 1 ]]; then |
| 5 | + echo "Usage: scripts/db-onboard.sh <db> [--skip-gate] [--skip-matrix]" |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +db="$1" |
| 10 | +shift || true |
| 11 | + |
| 12 | +skip_gate=0 |
| 13 | +skip_matrix=0 |
| 14 | + |
| 15 | +for arg in "$@"; do |
| 16 | + case "$arg" in |
| 17 | + --skip-gate) |
| 18 | + skip_gate=1 |
| 19 | + ;; |
| 20 | + --skip-matrix) |
| 21 | + skip_matrix=1 |
| 22 | + ;; |
| 23 | + *) |
| 24 | + echo "[error] unknown option: $arg" |
| 25 | + echo "Usage: scripts/db-onboard.sh <db> [--skip-gate] [--skip-matrix]" |
| 26 | + exit 1 |
| 27 | + ;; |
| 28 | + esac |
| 29 | +done |
| 30 | + |
| 31 | +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 32 | +cd "${root_dir}" |
| 33 | + |
| 34 | +context_file="src-tauri/tests/common/${db}_context.rs" |
| 35 | +integration_file="src-tauri/tests/${db}_integration.rs" |
| 36 | +command_file="src-tauri/tests/${db}_command_integration.rs" |
| 37 | +stateful_file="src-tauri/tests/${db}_stateful_command_integration.rs" |
| 38 | +tracker_file="docs/zh/Development/MYSQL_TEST_COVERAGE_GAP_TRACKER.md" |
| 39 | + |
| 40 | +echo "[step] scaffold check: ${db}" |
| 41 | +missing=0 |
| 42 | +for file in "${context_file}" "${integration_file}" "${command_file}" "${stateful_file}"; do |
| 43 | + if [[ ! -f "${file}" ]]; then |
| 44 | + echo "[missing] ${file}" |
| 45 | + missing=1 |
| 46 | + else |
| 47 | + echo "[ok] ${file}" |
| 48 | + fi |
| 49 | +done |
| 50 | + |
| 51 | +if [[ ${missing} -ne 0 ]]; then |
| 52 | + echo "[error] scaffold is incomplete for '${db}'." |
| 53 | + echo "[hint] finish scaffold first, then rerun scripts/db-onboard.sh ${db}" |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +if [[ ${skip_gate} -eq 0 ]]; then |
| 58 | + echo "[step] gate syntax check" |
| 59 | + bash -n scripts/test-integration.sh |
| 60 | + |
| 61 | + echo "[step] compile smoke: ${db}_integration" |
| 62 | + cargo test --manifest-path src-tauri/Cargo.toml --test "${db}_integration" --no-run |
| 63 | + |
| 64 | + echo "[step] compile smoke: ${db}_command_integration" |
| 65 | + cargo test --manifest-path src-tauri/Cargo.toml --test "${db}_command_integration" --no-run |
| 66 | + |
| 67 | + echo "[step] compile smoke: ${db}_stateful_command_integration" |
| 68 | + cargo test --manifest-path src-tauri/Cargo.toml --test "${db}_stateful_command_integration" --no-run |
| 69 | + |
| 70 | + echo "[step] integration gate run: IT_DB=${db}" |
| 71 | + IT_DB="${db}" bash scripts/test-integration.sh |
| 72 | +else |
| 73 | + echo "[skip] gate run skipped by --skip-gate" |
| 74 | +fi |
| 75 | + |
| 76 | +if [[ ${skip_matrix} -eq 0 ]]; then |
| 77 | + echo "[step] matrix sync check" |
| 78 | + test_count="$(rg -n "async fn test_${db}_" src-tauri/tests --glob "*.rs" || true)" |
| 79 | + test_count="$(printf "%s\n" "${test_count}" | sed '/^$/d' | wc -l | tr -d ' ')" |
| 80 | + echo "[info] detected test functions for ${db}: ${test_count}" |
| 81 | + if [[ -f "${tracker_file}" ]]; then |
| 82 | + tracker_hits="$(rg -n "test_${db}_" "${tracker_file}" || true)" |
| 83 | + tracker_hits="$(printf "%s\n" "${tracker_hits}" | sed '/^$/d' | wc -l | tr -d ' ')" |
| 84 | + if [[ "${tracker_hits}" -eq 0 ]]; then |
| 85 | + echo "[warn] tracker has no '${db}' test entries yet: ${tracker_file}" |
| 86 | + echo "[next] sync capability matrix and command coverage sections for '${db}'" |
| 87 | + else |
| 88 | + echo "[ok] tracker already contains ${tracker_hits} '${db}' test entries" |
| 89 | + fi |
| 90 | + else |
| 91 | + echo "[warn] tracker file not found: ${tracker_file}" |
| 92 | + fi |
| 93 | +else |
| 94 | + echo "[skip] matrix sync check skipped by --skip-matrix" |
| 95 | +fi |
| 96 | + |
| 97 | +echo "[done] db onboarding pipeline finished for '${db}'" |
0 commit comments