Files
WeKnora/scripts/git-hooks/pre-push
T
NianJiu 832b5fede8 ci: close 6 production test gate blind spots and add Lite E2E smoke test
Why:
PR CI previously left six production-critical paths unverified:
1. .github/workflows/app.yml ran without PostgreSQL/ParadeDB or Redis service
   containers and left WEKNORA_*_POSTGRES_DSN / WEKNORA_TEST_REDIS_ADDR unset,
   causing all PostgreSQL migration, row-locking, pgvector, catalog, and
   multi-replica Redis tests to 100% t.Skip (masking a step-down regression in
   TestPostgresMigrationsServeAgentHistory once migrations >000106 were added).
2. app.yml invoked go vet/test without -tags sqlite_fts5, causing SQLite FTS5
   retriever tests under internal/application/repository/retriever/sqlite to
   100% t.Skip.
3. Desktop build-tag checks only ran ./internal/container, missing
   ./internal/application/service, ./cmd/desktop, and darwin/windows
   cross-compilation of ./internal/localsandbox/{seatbelt,winhost}, while
   release-lite.yml remained pinned to GO_VERSION=1.24 (go.mod requires 1.26.0).
4. The standalone client/ Go SDK module was excluded by app.yml (!client/**)
   and ignored by cli.yml / cli-e2e.yml / pre-push hooks despite cli/
   depending on ../client (masking unformatted files and a Unix-only 0o640
   permission assertion on Windows in client/).
5. High-concurrency packages (internal/stream, internal/sandbox,
   internal/agent, internal/im) ran without -race, and PR CI had no
   zero-external-dependency Lite mode end-to-end smoke test.

What:
- Provision paradedb/paradedb:v0.25.11-pg17 and redis:7.0-alpine services in
  app.yml, create isolated disposable test databases, and inject all
  PostgreSQL/Redis test DSNs with WEKNORA_REQUIRE_INTEGRATION=1; fix
  TestPostgresMigrationsServeAgentHistory to migrate down before 000106 and
  back up instead of stepping -1 from HEAD.
- Pass -tags sqlite_fts5 across app.yml and git hooks while keeping an explicit
  non-FTS5 run for TestSaveWorksWhenTheFTS5ModuleIsNotCompiledIn.
- Vet, test, and build ./internal/container, ./internal/application/service,
  and ./cmd/desktop with -tags desktop,sqlite_fts5; isolate cgo-only pg_query
  and gojieba bindings behind !cgo stubs so darwin/arm64 and windows/amd64
  cross-compilation of ./internal/localsandbox/... runs on Linux CI; align
  release-lite.yml GO_VERSION to 1.26.
- Watch client/** in cli.yml, cli-e2e.yml, and git pre-push hooks, running
  client gofmt, build, vet, and -race tests across Linux, macOS, and Windows,
  and fix the pre-existing gofmt drift and Windows permission assertion in
  client/ uncovered by the new gate.
- Enable -race on internal/{stream,sandbox,agent,im}/... and add
  tests/lite_smoke/lite_e2e_test.go exercising a real WeKnora-lite subprocess
  end-to-end (auth, models, KB, Markdown upload/indexing, vector+FTS5 search,
  SSE RAG chat, message persistence, and SIGTERM shutdown).
2026-11-18 15:10:24 +08:00

87 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Pre-push checks aligned with CI (.github/workflows/app.yml, frontend.yml, cli.yml).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
# shellcheck source=scripts/git-hooks/common.sh
source "$ROOT/scripts/git-hooks/common.sh"
if hook_skip; then
exit 0
fi
cd "$ROOT"
remote="${1:-origin}"
while read -r _local_ref local_sha remote_ref remote_sha; do
if [[ "$local_sha" =~ ^0+$ ]]; then
continue
fi
log_step "pre-push ($remote ${remote_ref#refs/heads/})"
ensure_origin_main
pr_ref="$(pr_diff_base_ref)"
pr_tip="$local_sha"
pr_diff="${pr_ref}...${pr_tip}"
lint_from_rev="$pr_ref"
if [[ "$remote_sha" =~ ^0+$ ]]; then
push_start="$(git -C "$ROOT" merge-base "$pr_ref" "$local_sha")"
push_range="${push_start}..${local_sha}"
log_step "new branch; PR diff ${pr_ref}...${local_sha:0:12}"
else
if [[ "$remote_sha" == "$local_sha" ]]; then
log_ok "pre-push: nothing new to push"
continue
fi
push_range="${remote_sha}..${local_sha}"
log_step "pushing ${remote_sha:0:12}..${local_sha:0:12}; PR diff ${pr_ref}...${local_sha:0:12}"
fi
check_whitespace "$push_range"
pr_changed=()
while IFS= read -r line; do
[[ -n "$line" ]] && pr_changed+=("$line")
done < <(git diff --name-only --diff-filter=ACMR "$pr_diff" || true)
if [[ ${#pr_changed[@]} -eq 0 ]]; then
log_ok "pre-push: no PR diff changes"
continue
fi
pr_changed_go=()
while IFS= read -r line; do
[[ -n "$line" ]] && pr_changed_go+=("$line")
done < <(git diff --name-only --diff-filter=ACMR "$pr_diff" -- '*.go' ':!cli/**' ':!client/**' || true)
if [[ ${#pr_changed_go[@]} -gt 0 ]]; then
go_files=()
for f in "${pr_changed_go[@]}"; do
go_files+=("$ROOT/$f")
done
check_gofmt_files check "${go_files[@]}"
run_golangci_if_available "$lint_from_rev"
run_app_vet_test
log_step "go build ./cmd/server"
go build ./cmd/server
log_ok "go build ./cmd/server"
fi
if paths_match_prefix "cli/" "${pr_changed[@]}" || paths_match_prefix "client/" "${pr_changed[@]}"; then
run_cli_checks
fi
if paths_match_prefix "frontend/" "${pr_changed[@]}"; then
run_frontend_checks
fi
log_ok "pre-push passed"
done
exit 0