feat(db,ci): fix missing ai_credits tables, wire integration tests to CI
Re-enables and corrects 20260703210000_ai_credits_wallet, which had been
disabled (.up.sql.skip) in commit 0163349 because 'relation already
exists' aborted the original CREATE TABLE script on its very first
table (ai_plans) - silently leaving ai_credit_ledger and
ai_reservation_holds never created, despite the wallet system being
actively wired into apps/users/handlers/ai_credits.rs, apps/payments,
apps/cron with real subscription rows already in prod.
Rewrote the migration to be idempotent: ADD COLUMN IF NOT EXISTS to
bring ai_plans/user_ai_subscriptions/ai_feature_costs/ai_usage_logs up
to the full column set crates/db/src/models/ai_credits.rs expects
(safe zero/default backfills, no data loss - verified against the 3
existing subscription rows), and CREATE TABLE IF NOT EXISTS for the 2
genuinely-missing tables. down.sql updated to only reverse what this
corrected version actually adds, not drop tables that predate it.
Applied directly to the live database (verified schema + existing rows
intact afterward).
Also wires crates/db/tests/ai_credits.rs + ai_credits_reaper.rs to
Forgejo Actions CI (docs/LIVE_SERVER_RUNBOOK.md step 6):
- New TEST_DATABASE_URL repo secret, pointing at a dedicated
nxtgauge_test database (created fresh, schema mirrored from live prod
via pg_dump --schema-only - never runs against the real nxtgauge DB).
- .forgejo/workflows/test.yaml: runs on push to main/high-performance,
skips when crates/db/ isn't touched, cargo test -p db --test
ai_credits --test ai_credits_reaper -- --test-threads=1.
Also commits docs/openapi.wallet-holds.json (hand-written minimal
OpenAPI spec used for schemathesis fuzzing in step 4) and gitignores
the local .schemathesis/ cache directory from that run.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 17:31:22 +05:30
|
|
|
name: backend-integration-tests
|
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
|
|
|
|
- high-performance
|
|
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
|
group: backend-tests-${{ github.ref }}
|
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
ai-credits:
|
|
|
|
|
runs-on: docker-ready
|
2026-08-13 17:55:30 +05:30
|
|
|
env:
|
|
|
|
|
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
|
feat(db,ci): fix missing ai_credits tables, wire integration tests to CI
Re-enables and corrects 20260703210000_ai_credits_wallet, which had been
disabled (.up.sql.skip) in commit 0163349 because 'relation already
exists' aborted the original CREATE TABLE script on its very first
table (ai_plans) - silently leaving ai_credit_ledger and
ai_reservation_holds never created, despite the wallet system being
actively wired into apps/users/handlers/ai_credits.rs, apps/payments,
apps/cron with real subscription rows already in prod.
Rewrote the migration to be idempotent: ADD COLUMN IF NOT EXISTS to
bring ai_plans/user_ai_subscriptions/ai_feature_costs/ai_usage_logs up
to the full column set crates/db/src/models/ai_credits.rs expects
(safe zero/default backfills, no data loss - verified against the 3
existing subscription rows), and CREATE TABLE IF NOT EXISTS for the 2
genuinely-missing tables. down.sql updated to only reverse what this
corrected version actually adds, not drop tables that predate it.
Applied directly to the live database (verified schema + existing rows
intact afterward).
Also wires crates/db/tests/ai_credits.rs + ai_credits_reaper.rs to
Forgejo Actions CI (docs/LIVE_SERVER_RUNBOOK.md step 6):
- New TEST_DATABASE_URL repo secret, pointing at a dedicated
nxtgauge_test database (created fresh, schema mirrored from live prod
via pg_dump --schema-only - never runs against the real nxtgauge DB).
- .forgejo/workflows/test.yaml: runs on push to main/high-performance,
skips when crates/db/ isn't touched, cargo test -p db --test
ai_credits --test ai_credits_reaper -- --test-threads=1.
Also commits docs/openapi.wallet-holds.json (hand-written minimal
OpenAPI spec used for schemathesis fuzzing in step 4) and gitignores
the local .schemathesis/ cache directory from that run.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 17:31:22 +05:30
|
|
|
steps:
|
|
|
|
|
- name: Checkout
|
|
|
|
|
uses: actions/checkout@v4
|
2026-08-13 17:48:43 +05:30
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
feat(db,ci): fix missing ai_credits tables, wire integration tests to CI
Re-enables and corrects 20260703210000_ai_credits_wallet, which had been
disabled (.up.sql.skip) in commit 0163349 because 'relation already
exists' aborted the original CREATE TABLE script on its very first
table (ai_plans) - silently leaving ai_credit_ledger and
ai_reservation_holds never created, despite the wallet system being
actively wired into apps/users/handlers/ai_credits.rs, apps/payments,
apps/cron with real subscription rows already in prod.
Rewrote the migration to be idempotent: ADD COLUMN IF NOT EXISTS to
bring ai_plans/user_ai_subscriptions/ai_feature_costs/ai_usage_logs up
to the full column set crates/db/src/models/ai_credits.rs expects
(safe zero/default backfills, no data loss - verified against the 3
existing subscription rows), and CREATE TABLE IF NOT EXISTS for the 2
genuinely-missing tables. down.sql updated to only reverse what this
corrected version actually adds, not drop tables that predate it.
Applied directly to the live database (verified schema + existing rows
intact afterward).
Also wires crates/db/tests/ai_credits.rs + ai_credits_reaper.rs to
Forgejo Actions CI (docs/LIVE_SERVER_RUNBOOK.md step 6):
- New TEST_DATABASE_URL repo secret, pointing at a dedicated
nxtgauge_test database (created fresh, schema mirrored from live prod
via pg_dump --schema-only - never runs against the real nxtgauge DB).
- .forgejo/workflows/test.yaml: runs on push to main/high-performance,
skips when crates/db/ isn't touched, cargo test -p db --test
ai_credits --test ai_credits_reaper -- --test-threads=1.
Also commits docs/openapi.wallet-holds.json (hand-written minimal
OpenAPI spec used for schemathesis fuzzing in step 4) and gitignores
the local .schemathesis/ cache directory from that run.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 17:31:22 +05:30
|
|
|
|
2026-08-13 17:59:04 +05:30
|
|
|
- name: Check for relevant changes
|
|
|
|
|
id: check
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
|
|
|
|
|
BASE="${{ github.event.before }}"
|
|
|
|
|
if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ] \
|
|
|
|
|
|| ! git rev-parse --verify "${BASE}^{commit}" >/dev/null 2>&1; then
|
|
|
|
|
BASE="HEAD^"
|
|
|
|
|
fi
|
|
|
|
|
CHANGED_FILES="$(git diff --name-only "$BASE" HEAD)"
|
|
|
|
|
else
|
|
|
|
|
CHANGED_FILES="$(git ls-files)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
run=false
|
2026-08-13 18:08:31 +05:30
|
|
|
if echo "$CHANGED_FILES" | grep -Eq '^(crates/db/|Cargo\.toml|Cargo\.lock|Dockerfile\.test|\.forgejo/workflows/test\.yaml)'; then
|
2026-08-13 17:59:04 +05:30
|
|
|
run=true
|
|
|
|
|
fi
|
|
|
|
|
echo "run=$run" >> "$GITHUB_OUTPUT"
|
|
|
|
|
if [ "$run" = "false" ]; then
|
|
|
|
|
echo "No changes relevant to crates/db - skipping integration tests."
|
|
|
|
|
fi
|
|
|
|
|
|
2026-08-13 18:08:31 +05:30
|
|
|
- name: Verify TEST_DATABASE_URL is configured
|
|
|
|
|
if: steps.check.outputs.run == 'true'
|
|
|
|
|
run: |
|
|
|
|
|
test -n "${TEST_DATABASE_URL:-}" || { echo "TEST_DATABASE_URL secret is not set - see docs/LIVE_SERVER_RUNBOOK.md step 6"; exit 1; }
|
|
|
|
|
|
|
|
|
|
- name: Point DOCKER_HOST at this container's own gateway
|
|
|
|
|
if: steps.check.outputs.run == 'true'
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
# Same trick build.yaml uses: this job container is nested one level
|
|
|
|
|
# inside the runner pod's dind sidecar, so its own loopback isn't the
|
|
|
|
|
# sidecar's - read the container's actual default-route gateway
|
|
|
|
|
# directly from /proc/net/route instead of relying on `ip`/`route`.
|
|
|
|
|
GATEWAY="$(awk '$2 == "00000000" {print $3}' /proc/net/route | head -1 | \
|
|
|
|
|
sed -E 's/(..)(..)(..)(..)/0x\4 0x\3 0x\2 0x\1/' | \
|
|
|
|
|
{ read -r a b c d; printf '%d.%d.%d.%d' "$a" "$b" "$c" "$d"; })"
|
|
|
|
|
echo "Detected docker host gateway: $GATEWAY"
|
|
|
|
|
echo "DOCKER_HOST=tcp://$GATEWAY:2375" >> "$GITHUB_ENV"
|
2026-08-13 18:01:39 +05:30
|
|
|
|
2026-08-13 18:08:31 +05:30
|
|
|
- name: Set up Docker Buildx
|
2026-08-13 18:01:39 +05:30
|
|
|
if: steps.check.outputs.run == 'true'
|
2026-08-13 18:08:31 +05:30
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
docker version
|
|
|
|
|
docker buildx create --use --name nxtgauge-builder || docker buildx use nxtgauge-builder
|
|
|
|
|
docker buildx inspect --bootstrap
|
2026-08-13 18:04:31 +05:30
|
|
|
|
2026-08-13 18:08:31 +05:30
|
|
|
- name: Run ai_credits integration tests
|
2026-08-13 18:04:31 +05:30
|
|
|
if: steps.check.outputs.run == 'true'
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-08-13 18:08:31 +05:30
|
|
|
# Build context transfer (not a bind mount) is what makes this work
|
|
|
|
|
# despite the nested dind setup - same reason build.yaml uses
|
|
|
|
|
# buildx rather than plain `docker run -v`. The Dockerfile's RUN
|
|
|
|
|
# step is the actual test; a non-zero exit fails this build (and
|
|
|
|
|
# this workflow step) the same way a failed `cargo test` would.
|
|
|
|
|
docker buildx build \
|
|
|
|
|
--secret id=test_db_url,env=TEST_DATABASE_URL \
|
|
|
|
|
-f Dockerfile.test \
|
|
|
|
|
.
|