mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-11-23 15:11:15 +08:00
fix(ci,smoke): prevent lite_smoke cleanup deadlock/race and close sibling CI gates
Why: 1. In tests/lite_smoke/lite_e2e_test.go, exited was a 1-buffered channel sent once without closing: if waitForHealth consumed <-exited on an early server crash, t.Cleanup blocked forever on <-exited; serverLogs also used an unsynchronized bytes.Buffer read concurrently on startup/shutdown timeouts under -race, and subprocess/client HTTP calls could inherit developer ENV_FILE, REDIS_ADDR, or proxy settings. 2. frontend/src/utils/catalogToolDisplay.test.ts asserts UI locale coverage against docs/swagger.json, but frontend.yml did not trigger on swagger.json changes. 3. pre-push and cli.yml enforced gofmt on client/ and root Go files, but skipped gofmt checks on changed cli/**/*.go files, and cli-e2e.yml omitted client/go.sum from its Go cache key. What: - Replace single-read exited channel and raw bytes.Buffer in lite_e2e_test.go with a closed done channel + mutex-guarded syncBuffer, and isolate subprocess ENV_FILE/REDIS_ADDR/NO_PROXY and loopback HTTP transport from local proxies. - Add docs/swagger.json to frontend.yml push and pull_request path triggers. - Check gofmt on all changed Go files in pre-push and changed cli Go files in cli.yml, and add client/go.sum to cli-e2e.yml cache-dependency-path.
This commit is contained in:
1 parent
6729e7bf38
commit
33138d3532
5 files changed
+95
-30
No files matched your search
@@ -44,7 +44,9 @@ jobs:
|
||||
- uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version: '1.26'
|
||||
cache-dependency-path: cli/go.sum
|
||||
cache-dependency-path: |
|
||||
cli/go.sum
|
||||
client/go.sum
|
||||
|
||||
- name: secrets present
|
||||
id: secrets
|
||||
|
||||
@@ -40,22 +40,48 @@ jobs:
|
||||
go: ['1.26']
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
cache-dependency-path: |
|
||||
cli/go.sum
|
||||
client/go.sum
|
||||
- name: Check client formatting
|
||||
- name: Check client and changed cli Go formatting
|
||||
if: runner.os == 'Linux'
|
||||
working-directory: client
|
||||
working-directory: .
|
||||
env:
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
|
||||
run: |
|
||||
unformatted=$(gofmt -l .)
|
||||
if [ -n "$unformatted" ]; then
|
||||
unformatted_client=$(cd client && gofmt -l .)
|
||||
if [ -n "$unformatted_client" ]; then
|
||||
echo "The following client Go files are not gofmt-formatted:"
|
||||
echo "$unformatted"
|
||||
echo "$unformatted_client"
|
||||
exit 1
|
||||
fi
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
diff_range="${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}"
|
||||
elif [ "${{ github.event_name }}" = "push" ]; then
|
||||
base="$BASE_SHA"
|
||||
if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then
|
||||
base=$(git rev-parse HEAD^)
|
||||
fi
|
||||
diff_range="$base..$GITHUB_SHA"
|
||||
else
|
||||
diff_range=""
|
||||
fi
|
||||
if [ -n "$diff_range" ]; then
|
||||
unformatted_cli=$(
|
||||
git diff --name-only --diff-filter=ACMR -z "$diff_range" -- ':(glob)cli/**/*.go' |
|
||||
xargs -0 -r gofmt -l
|
||||
)
|
||||
if [ -n "$unformatted_cli" ]; then
|
||||
echo "The following cli Go files are not gofmt-formatted:"
|
||||
echo "$unformatted_cli"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
- name: client go build, vet, and test
|
||||
working-directory: client
|
||||
run: |
|
||||
|
||||
@@ -5,12 +5,14 @@ on:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "frontend/**"
|
||||
- "docs/swagger.json"
|
||||
- "scripts/build_frontend_dist.sh"
|
||||
- "scripts/test_embed_nginx.py"
|
||||
- ".github/workflows/frontend.yml"
|
||||
pull_request:
|
||||
paths:
|
||||
- "frontend/**"
|
||||
- "docs/swagger.json"
|
||||
- "scripts/build_frontend_dist.sh"
|
||||
- "scripts/test_embed_nginx.py"
|
||||
- ".github/workflows/frontend.yml"
|
||||
|
||||
@@ -52,18 +52,20 @@ while read -r _local_ref local_sha remote_ref remote_sha; do
|
||||
continue
|
||||
fi
|
||||
|
||||
all_changed_go=()
|
||||
while IFS= read -r line; do
|
||||
[[ -n "$line" ]] && all_changed_go+=("$ROOT/$line")
|
||||
done < <(git diff --name-only --diff-filter=ACMR "$pr_diff" -- '*.go' || true)
|
||||
if [[ ${#all_changed_go[@]} -gt 0 ]]; then
|
||||
check_gofmt_files check "${all_changed_go[@]}"
|
||||
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
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -26,6 +27,23 @@ import (
|
||||
|
||||
const embeddingDims = 8
|
||||
|
||||
type syncBuffer struct {
|
||||
mu sync.Mutex
|
||||
buf bytes.Buffer
|
||||
}
|
||||
|
||||
func (b *syncBuffer) Write(p []byte) (int, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return b.buf.Write(p)
|
||||
}
|
||||
|
||||
func (b *syncBuffer) String() string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return b.buf.String()
|
||||
}
|
||||
|
||||
// TestLiteEditionEndToEndSmoke boots a real compiled WeKnora-lite server
|
||||
// subprocess (SQLite + sqlite-vec + FTS5 + local storage + in-memory stream
|
||||
// manager, zero external services) and exercises the full user journey:
|
||||
@@ -66,12 +84,16 @@ func TestLiteEditionEndToEndSmoke(t *testing.T) {
|
||||
port := allocateFreePort(t)
|
||||
baseURL := fmt.Sprintf("http://127.0.0.1:%d", port)
|
||||
|
||||
var serverLogs bytes.Buffer
|
||||
var serverLogs syncBuffer
|
||||
srvCmd := exec.Command(binPath)
|
||||
srvCmd.Dir = workDir
|
||||
srvCmd.Stdout = &serverLogs
|
||||
srvCmd.Stderr = &serverLogs
|
||||
srvCmd.Env = append(os.Environ(),
|
||||
"ENV_FILE=",
|
||||
"REDIS_ADDR=",
|
||||
"NO_PROXY=127.0.0.1,localhost",
|
||||
"no_proxy=127.0.0.1,localhost",
|
||||
"GIN_MODE=debug",
|
||||
"LOG_LEVEL=info",
|
||||
"SERVER_HOST=127.0.0.1",
|
||||
@@ -93,28 +115,38 @@ func TestLiteEditionEndToEndSmoke(t *testing.T) {
|
||||
)
|
||||
require.NoError(t, srvCmd.Start())
|
||||
|
||||
exited := make(chan error, 1)
|
||||
var waitErr error
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
exited <- srvCmd.Wait()
|
||||
waitErr = srvCmd.Wait()
|
||||
close(done)
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
if srvCmd.Process == nil {
|
||||
return
|
||||
}
|
||||
_ = srvCmd.Process.Signal(syscall.SIGTERM)
|
||||
select {
|
||||
case <-exited:
|
||||
case <-time.After(10 * time.Second):
|
||||
_ = srvCmd.Process.Kill()
|
||||
<-exited
|
||||
case <-done:
|
||||
default:
|
||||
if srvCmd.Process != nil {
|
||||
_ = srvCmd.Process.Signal(syscall.SIGTERM)
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(10 * time.Second):
|
||||
if srvCmd.Process != nil {
|
||||
_ = srvCmd.Process.Kill()
|
||||
}
|
||||
<-done
|
||||
}
|
||||
}
|
||||
if t.Failed() {
|
||||
t.Logf("WeKnora-lite server logs:\n%s", serverLogs.String())
|
||||
}
|
||||
})
|
||||
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
waitForHealth(t, client, baseURL, exited, &serverLogs)
|
||||
client := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
Transport: &http.Transport{Proxy: nil},
|
||||
}
|
||||
waitForHealth(t, client, baseURL, done, func() error { return waitErr }, &serverLogs)
|
||||
|
||||
// 1. Register + login user and verify Lite edition metadata.
|
||||
const (
|
||||
@@ -272,9 +304,8 @@ func TestLiteEditionEndToEndSmoke(t *testing.T) {
|
||||
// 8. Graceful shutdown on SIGTERM must exit cleanly (code 0).
|
||||
require.NoError(t, srvCmd.Process.Signal(syscall.SIGTERM))
|
||||
select {
|
||||
case waitErr := <-exited:
|
||||
case <-done:
|
||||
require.NoErrorf(t, waitErr, "WeKnora-lite did not exit cleanly on SIGTERM:\n%s", serverLogs.String())
|
||||
srvCmd.Process = nil
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Fatalf("timed out waiting for WeKnora-lite graceful shutdown:\n%s", serverLogs.String())
|
||||
}
|
||||
@@ -441,13 +472,15 @@ func allocateFreePort(t *testing.T) int {
|
||||
return ln.Addr().(*net.TCPAddr).Port
|
||||
}
|
||||
|
||||
func waitForHealth(t *testing.T, client *http.Client, baseURL string, exited <-chan error, logs *bytes.Buffer) {
|
||||
func waitForHealth(
|
||||
t *testing.T, client *http.Client, baseURL string, done <-chan struct{}, waitErr func() error, logs *syncBuffer,
|
||||
) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(30 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
select {
|
||||
case err := <-exited:
|
||||
t.Fatalf("WeKnora-lite exited before becoming healthy (%v):\n%s", err, logs.String())
|
||||
case <-done:
|
||||
t.Fatalf("WeKnora-lite exited before becoming healthy (%v):\n%s", waitErr(), logs.String())
|
||||
default:
|
||||
}
|
||||
resp, err := client.Get(baseURL + "/health")
|
||||
|
||||
Reference in new issue
Block a user