[PR #6917] [MERGED] ci: run the PostgreSQL suites that never ran, and lint the shell, the workflows and the docs spec #6520

Closed
opened 2026-11-02 04:09:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6917
Author: @muditagrawal2007
Created: 10/24/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: ci/close-coverage-gaps


📝 Commits (6)

  • 26574f6 style(x-ui): compare the argument count numerically
  • 2f24d2c ci: run the PostgreSQL suites that never ran
  • 8b80ef3 ci: lint the shell, pin the linter and check the docs spec
  • c23a376 ci: keep the workflow lint focused on real findings
  • bd2a88c ci: count only top-level passes in the durable-first step
  • 36edc37 Merge remote-tracking branch 'origin/main' into pr/6917

📊 Changes

6 files changed (+123 additions, -15 deletions)

View changed files

📝 .github/workflows/ci.yml (+86 -8)
📝 .github/workflows/docs-ci.yml (+17 -0)
📝 CLAUDE.md (+4 -3)
📝 Makefile (+13 -2)
📝 frontend/package.json (+1 -0)
📝 x-ui.sh (+2 -2)

📄 Description

Summary

Four gaps in the gates the repository could not enforce, closed. No product code changes — this PR is about CI, the local gate, and one shell bug the new lint found.

gap before after
PostgreSQL-only tests skipped in every CI job (they gate on XUI_TEST_PG_DSN, which no workflow set) a scratch database of their own, and the pass count is asserted
shell + workflow lint none actionlint on every workflow, shellcheck on the scripts
golangci-lint version: latest — the same commit could pass today and fail tomorrow pinned to v2.15.0
docs OpenAPI spec never compared with the panel's compared in CI and in make verify, along with the generated API reference

Why

1 · Four PostgreSQL tests had never run in CI

internal/database/migrate_data_test.go (3 tests) and internal/database/client_hwid_schema_test.go gate on XUI_TEST_PG_DSN:

dsn := os.Getenv("XUI_TEST_PG_DSN")
if dsn == "" {
    t.Skip("set XUI_TEST_PG_DSN to a reachable Postgres to run this test")
}

No workflow set that variable, so every CI run skipped them — including the PostgreSQL job. They are the tests that cover the SQLite→Postgres data migration (a composite-key table larger than the batch size, false-defaulted columns, and a failed copy leaving the destination untouched).

They write and drop their own tables, so they cannot share the durable database the panel tests use; the new postgres-migration job gives them a scratch database of their own:

  postgres-migration:
    services:
      postgres:
        env:
          POSTGRES_DB: xui_scratch
    env:
      XUI_TEST_PG_DSN: "host=127.0.0.1 port=5432 user=postgres password=postgres dbname=xui_scratch sslmode=disable"

The durable-first job also named only two of the six PostgreSQL-gated tests. The rest are named explicitly now, and the step counts the passes — a renamed test prints "no tests to run" and exits 0, which would otherwise leave the step green for nothing.

2 · The shell scripts and the workflows were never linted

~275 KB of shell (install.sh, update.sh, x-ui.sh, the two Docker entrypoints) and nine workflows, with no linter. The new shell-lint job runs actionlint on the workflows and shellcheck on the scripts: the ones that are clean today at every severity, the three legacy ones at error severity until their warning backlog (unquoted expansions, masked return codes) is worked off.

It immediately found two real bugs in x-ui.sh — the argument count was compared as a string:

x-ui.sh:102:14: error: > is for string comparisons. Use -gt instead. [SC2071]
x-ui.sh:3642:10: error: > is for string comparisons. Use -gt instead. [SC2071]

[[ $# > 1 ]] is false for ten or more arguments, because "10" > "1" compares lexicographically. Fixed in its own commit.

3 · golangci-lint floated on latest

        uses: golangci/golangci-lint-action@v9
        with:
          version: latest

The lint result could change between two runs of the same commit. It is pinned to v2.15.0 — the version this branch was verified against.

4 · The docs OpenAPI spec was never compared with the panel's

The API reference the docs site publishes is generated from a copy of the panel's spec. The copy step was manual and unchecked, and the generated MDX was never regenerated. Now:

  • cmp frontend/public/openapi.json docs/public/openapi.json runs in the codegen job and in make verify;
  • docs-ci.yml regenerates the API reference and fails if the committed MDX differs, and it now triggers on frontend/public/openapi.json and frontend/src/pages/api-docs/endpoints.ts as well as on docs/**.

The npm audit the frontend job already ran is now a script, so make verify runs the same command locally.

Evidence — the skipped tests, and the bug the lint found

before/after: the PostgreSQL tests skipped in CI, and the shellcheck finding

--- SKIP: TestClientHwidSchemaPostgres (0.00s)
--- SKIP: TestMigrateData_CompositeKeyTableLargerThanBatch (0.00s)
--- SKIP: TestMigrateData_PreservesFalseDefaultedColumns (0.00s)
--- SKIP: TestMigrateData_FailedCopyLeavesDestinationUntouched (0.00s)

--- PASS: TestClientHwidSchemaPostgres (0.02s)
--- PASS: TestMigrateData_CompositeKeyTableLargerThanBatch (0.11s)
--- PASS: TestMigrateData_PreservesFalseDefaultedColumns (0.11s)
--- PASS: TestMigrateData_FailedCopyLeavesDestinationUntouched (0.26s)

(The passing run was made against a real PostgreSQL 17, locally.)


Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Everything the new gates run was run locally:

actionlint -color                                                   → clean
shellcheck --severity=style DockerInit.sh DockerEntrypoint.sh deploy/test/smoke-noninteractive.sh → clean
shellcheck --severity=error install.sh update.sh x-ui.sh            → clean
make docs-openapi-check                                            → ok
cd frontend && npm run audit                                       → found 0 vulnerabilities
cd docs && pnpm gen:api && git diff --exit-code -- docs/content/docs/en/reference/api → clean
make verify                                                         → verify: OK

The PostgreSQL job was exercised against a local PostgreSQL 17 with a scratch database, and all four previously-skipped tests pass there.

Notes for the reviewer

  • The shell-lint job needs shellcheck; the runner does not have it, so the job installs it. actionlint runs through go run (the Go toolchain is already set up by the other jobs).
  • The legacy scripts are gated on errors only. They carry ~400 warnings (unquoted expansions, local masking return codes). Fixing those in the installer is a change of its own — this PR does not touch them beyond the two real comparisons.
  • make verify now needs the network for the dependency audit. CI already did the audit; the local gate now does the same, so the two cannot drift.
  • The docs spec check compares committed files — it does not perform the manual copy step, so a contributor who adds an endpoint still has to copy the spec and regenerate the MDX; the CI job now tells them if they forget.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6917 **Author:** [@muditagrawal2007](https://github.com/muditagrawal2007) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `ci/close-coverage-gaps` --- ### 📝 Commits (6) - [`26574f6`](https://github.com/MHSanaei/3x-ui/commit/26574f68ed1abdcec54b08e34217ce434234063b) style(x-ui): compare the argument count numerically - [`2f24d2c`](https://github.com/MHSanaei/3x-ui/commit/2f24d2cea6f9d43de2e546783c851ed96dfee965) ci: run the PostgreSQL suites that never ran - [`8b80ef3`](https://github.com/MHSanaei/3x-ui/commit/8b80ef38a7cce7c72d7a0470ff104f6ece93e01a) ci: lint the shell, pin the linter and check the docs spec - [`c23a376`](https://github.com/MHSanaei/3x-ui/commit/c23a376d188ee9738714f4ba9890e61b20f5163b) ci: keep the workflow lint focused on real findings - [`bd2a88c`](https://github.com/MHSanaei/3x-ui/commit/bd2a88c7286757cbb627b937020fc44de4ac30d0) ci: count only top-level passes in the durable-first step - [`36edc37`](https://github.com/MHSanaei/3x-ui/commit/36edc37c8eb6ec5917a6db6c8deeb5f73317932c) Merge remote-tracking branch 'origin/main' into pr/6917 ### 📊 Changes **6 files changed** (+123 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+86 -8) 📝 `.github/workflows/docs-ci.yml` (+17 -0) 📝 `CLAUDE.md` (+4 -3) 📝 `Makefile` (+13 -2) 📝 `frontend/package.json` (+1 -0) 📝 `x-ui.sh` (+2 -2) </details> ### 📄 Description ## Summary Four gaps in the gates the repository could not enforce, closed. No product code changes — this PR is about CI, the local gate, and one shell bug the new lint found. | gap | before | after | |---|---|---| | PostgreSQL-only tests | **skipped in every CI job** (they gate on `XUI_TEST_PG_DSN`, which no workflow set) | a scratch database of their own, and the pass count is asserted | | shell + workflow lint | none | `actionlint` on every workflow, `shellcheck` on the scripts | | golangci-lint | `version: latest` — the same commit could pass today and fail tomorrow | pinned to `v2.15.0` | | docs OpenAPI spec | never compared with the panel's | compared in CI and in `make verify`, along with the generated API reference | --- ## Why ### 1 · Four PostgreSQL tests had never run in CI `internal/database/migrate_data_test.go` (3 tests) and `internal/database/client_hwid_schema_test.go` gate on `XUI_TEST_PG_DSN`: ```go dsn := os.Getenv("XUI_TEST_PG_DSN") if dsn == "" { t.Skip("set XUI_TEST_PG_DSN to a reachable Postgres to run this test") } ``` No workflow set that variable, so **every** CI run skipped them — including the PostgreSQL job. They are the tests that cover the SQLite→Postgres data migration (a composite-key table larger than the batch size, false-defaulted columns, and a failed copy leaving the destination untouched). They write and drop their own tables, so they cannot share the durable database the panel tests use; the new `postgres-migration` job gives them a **scratch database** of their own: ```yaml postgres-migration: services: postgres: env: POSTGRES_DB: xui_scratch env: XUI_TEST_PG_DSN: "host=127.0.0.1 port=5432 user=postgres password=postgres dbname=xui_scratch sslmode=disable" ``` The durable-first job also named only two of the six PostgreSQL-gated tests. The rest are named explicitly now, and the step counts the passes — a renamed test prints "no tests to run" and exits 0, which would otherwise leave the step green for nothing. ### 2 · The shell scripts and the workflows were never linted ~275 KB of shell (`install.sh`, `update.sh`, `x-ui.sh`, the two Docker entrypoints) and nine workflows, with no linter. The new `shell-lint` job runs `actionlint` on the workflows and `shellcheck` on the scripts: the ones that are clean today at every severity, the three legacy ones at error severity until their warning backlog (unquoted expansions, masked return codes) is worked off. **It immediately found two real bugs in `x-ui.sh`** — the argument count was compared as a *string*: ``` x-ui.sh:102:14: error: > is for string comparisons. Use -gt instead. [SC2071] x-ui.sh:3642:10: error: > is for string comparisons. Use -gt instead. [SC2071] ``` `[[ $# > 1 ]]` is false for ten or more arguments, because `"10" > "1"` compares lexicographically. Fixed in its own commit. ### 3 · golangci-lint floated on `latest` ```yaml uses: golangci/golangci-lint-action@v9 with: version: latest ``` The lint result could change between two runs of the same commit. It is pinned to `v2.15.0` — the version this branch was verified against. ### 4 · The docs OpenAPI spec was never compared with the panel's The API reference the docs site publishes is generated from a **copy** of the panel's spec. The copy step was manual and unchecked, and the generated MDX was never regenerated. Now: - `cmp frontend/public/openapi.json docs/public/openapi.json` runs in the `codegen` job **and** in `make verify`; - `docs-ci.yml` regenerates the API reference and fails if the committed MDX differs, and it now triggers on `frontend/public/openapi.json` and `frontend/src/pages/api-docs/endpoints.ts` as well as on `docs/**`. The npm audit the frontend job already ran is now a script, so `make verify` runs the same command locally. ### Evidence — the skipped tests, and the bug the lint found ![before/after: the PostgreSQL tests skipped in CI, and the shellcheck finding](https://raw.githubusercontent.com/muditagrawal2007/3x-ui/pr-evidence/ci-gates/.github/pr-evidence/ci-gates.png) ``` --- SKIP: TestClientHwidSchemaPostgres (0.00s) --- SKIP: TestMigrateData_CompositeKeyTableLargerThanBatch (0.00s) --- SKIP: TestMigrateData_PreservesFalseDefaultedColumns (0.00s) --- SKIP: TestMigrateData_FailedCopyLeavesDestinationUntouched (0.00s) --- PASS: TestClientHwidSchemaPostgres (0.02s) --- PASS: TestMigrateData_CompositeKeyTableLargerThanBatch (0.11s) --- PASS: TestMigrateData_PreservesFalseDefaultedColumns (0.11s) --- PASS: TestMigrateData_FailedCopyLeavesDestinationUntouched (0.26s) ``` (The passing run was made against a real PostgreSQL 17, locally.) --- ## Type of change - [ ] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [x] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Everything the new gates run was run locally: ``` actionlint -color → clean shellcheck --severity=style DockerInit.sh DockerEntrypoint.sh deploy/test/smoke-noninteractive.sh → clean shellcheck --severity=error install.sh update.sh x-ui.sh → clean make docs-openapi-check → ok cd frontend && npm run audit → found 0 vulnerabilities cd docs && pnpm gen:api && git diff --exit-code -- docs/content/docs/en/reference/api → clean make verify → verify: OK ``` The PostgreSQL job was exercised against a local PostgreSQL 17 with a scratch database, and all four previously-skipped tests pass there. ## Notes for the reviewer - **The `shell-lint` job needs `shellcheck`**; the runner does not have it, so the job installs it. `actionlint` runs through `go run` (the Go toolchain is already set up by the other jobs). - **The legacy scripts are gated on errors only.** They carry ~400 warnings (unquoted expansions, `local` masking return codes). Fixing those in the installer is a change of its own — this PR does not touch them beyond the two real comparisons. - **`make verify` now needs the network** for the dependency audit. CI already did the audit; the local gate now does the same, so the two cannot drift. - **The docs spec check compares committed files** — it does not perform the manual copy step, so a contributor who adds an endpoint still has to copy the spec and regenerate the MDX; the CI job now tells them if they forget. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:21 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6520
No description provided.