Skip to content

Commit 3935a3a

Browse files
committed
refactor(tasks): restructure test tasks for CI compatibility
Fixes CI failure with "unbound variable" error by restructuring test task hierarchy with clear separation of concerns. Changes: - Add top-level `test` task in mise.toml (replaces test:all) - Create tasks/check-postgres.sh for shared postgres validation - Create tasks/test-all.sh as main test orchestrator - Remove duplicate tasks/test.sh - Simplify test:legacy (remove build/postgres setup) - Simplify test:sqlx (remove postgres setup) Task structure: - test → test-all.sh (accepts --postgres flag) - Checks postgres running - Builds EQL - Runs test:legacy --postgres ${VERSION} - Runs test:sqlx Design principles: - TOML tasks in top-level mise.toml for visibility - Shell scripts in /tasks for complex logic - Shared utilities extracted (check-postgres.sh) - Postgres setup handled by CI, not test tasks - Simple, maintainable structure CI compatibility: ✓ Accepts --postgres flag via MISE USAGE syntax ✓ No unbound variables ✓ Postgres check without setup ✓ Works with: mise run test --postgres ${POSTGRES_VERSION}
1 parent d0ae53a commit 3935a3a

File tree

7 files changed

+71
-153
lines changed

7 files changed

+71
-153
lines changed

mise.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ run = """
2323
rm -f release/cipherstash-encrypt-uninstall.sql
2424
rm -f release/cipherstash-encrypt.sql
2525
"""
26+
27+
[tasks."test"]
28+
description = "Run all tests (legacy SQL + SQLx Rust)"
29+
sources = ["src/**/*_test.sql", "tests/**/*.sql", "tests/sqlx/**/*.rs"]
30+
run = "{{config_root}}/tasks/test-all.sh"

tasks/check-postgres.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Check if PostgreSQL container is running"
3+
4+
set -euo pipefail
5+
6+
POSTGRES_VERSION=${1:-${POSTGRES_VERSION:-17}}
7+
container_name=postgres-${POSTGRES_VERSION}
8+
9+
containers=$(docker ps --filter "name=^${container_name}$" --quiet)
10+
if [ -z "${containers}" ]; then
11+
echo "error: Docker container for PostgreSQL is not running"
12+
echo "error: Try running 'mise run postgres:up postgres-${POSTGRES_VERSION}' to start the container"
13+
exit 65
14+
fi
15+
16+
echo "✓ PostgreSQL ${POSTGRES_VERSION} container is running"

tasks/rust.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ description = "Run SQLx tests with hybrid migration approach"
33
dir = "{{config_root}}"
44
env = { DATABASE_URL = "postgresql://{{get_env(name='POSTGRES_USER', default='cipherstash')}}:{{get_env(name='POSTGRES_PASSWORD', default='password')}}@{{get_env(name='POSTGRES_HOST', default='localhost')}}:{{get_env(name='POSTGRES_PORT', default='7432')}}/{{get_env(name='POSTGRES_DB', default='cipherstash')}}" }
55
run = """
6-
# Build EQL SQL from source
7-
echo "Building EQL SQL..."
8-
mise run build --force
9-
106
# Copy built SQL to SQLx migrations (EQL install is generated, not static)
117
echo "Updating SQLx migrations with built EQL..."
128
cp release/cipherstash-encrypt.sql tests/sqlx/migrations/001_install_eql.sql
139
14-
# Ensure PostgreSQL is running
15-
echo "Starting PostgreSQL..."
16-
mise run postgres:up --extra-args "--detach --wait"
17-
1810
# Run SQLx migrations and tests
1911
echo "Running SQLx migrations..."
2012
cd tests/sqlx

tasks/test-all.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Run all tests (legacy SQL + SQLx Rust)"
3+
#USAGE flag "--postgres <version>" help="PostgreSQL version to test against" default="17" {
4+
#USAGE choices "14" "15" "16" "17"
5+
#USAGE }
6+
7+
set -euo pipefail
8+
9+
POSTGRES_VERSION=${usage_postgres}
10+
11+
echo "=========================================="
12+
echo "Running Complete EQL Test Suite"
13+
echo "PostgreSQL Version: $POSTGRES_VERSION"
14+
echo "=========================================="
15+
echo ""
16+
17+
# Check PostgreSQL is running
18+
"$(dirname "$0")/check-postgres.sh" ${POSTGRES_VERSION}
19+
20+
# Build first
21+
echo "Building EQL..."
22+
mise run build --force
23+
24+
# Run legacy SQL tests
25+
echo ""
26+
echo "=========================================="
27+
echo "1/2: Running Legacy SQL Tests"
28+
echo "=========================================="
29+
mise run test:legacy --postgres ${POSTGRES_VERSION}
30+
31+
# Run SQLx Rust tests
32+
echo ""
33+
echo "=========================================="
34+
echo "2/2: Running SQLx Rust Tests"
35+
echo "=========================================="
36+
mise run test:sqlx
37+
38+
echo ""
39+
echo "=========================================="
40+
echo "✅ ALL TESTS PASSED"
41+
echo "=========================================="
42+
echo ""
43+
echo "Summary:"
44+
echo " ✓ Legacy SQL tests"
45+
echo " ✓ SQLx Rust tests"
46+
echo ""

tasks/test-legacy.sh

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#!/usr/bin/env bash
22
#MISE description="Run legacy SQL tests (inline test files)"
3-
#MISE alias="test"
43
#USAGE flag "--test <test>" help="Specific test file pattern to run" default="false"
54
#USAGE flag "--postgres <version>" help="PostgreSQL version to test against" default="17" {
65
#USAGE choices "14" "15" "16" "17"
76
#USAGE }
8-
#USAGE flag "--skip-build" help="Skip build step (use existing release)" default="false"
9-
10-
#!/bin/bash
117

128
set -euo pipefail
139

@@ -16,14 +12,8 @@ POSTGRES_VERSION=${usage_postgres}
1612
connection_url=postgresql://${POSTGRES_USER:-$USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
1713
container_name=postgres-${POSTGRES_VERSION}
1814

19-
fail_if_postgres_not_running () {
20-
containers=$(docker ps --filter "name=^${container_name}$" --quiet)
21-
if [ -z "${containers}" ]; then
22-
echo "error: Docker container for PostgreSQL is not running"
23-
echo "error: Try running 'mise run postgres:up ${container_name}' to start the container"
24-
exit 65
25-
fi
26-
}
15+
# Check postgres is running (script will exit if not)
16+
source "$(dirname "$0")/check-postgres.sh" ${POSTGRES_VERSION}
2717

2818
run_test () {
2919
echo
@@ -35,14 +25,7 @@ run_test () {
3525
cat $1 | docker exec -i ${container_name} psql --variable ON_ERROR_STOP=1 $connection_url -f-
3626
}
3727

38-
# Setup
39-
fail_if_postgres_not_running
40-
41-
# Build (optional)
42-
if [ "$usage_skip_build" = "false" ]; then
43-
mise run build --force
44-
fi
45-
28+
# Reset database
4629
mise run reset --force --postgres ${POSTGRES_VERSION}
4730

4831
echo

tasks/test.sh

Lines changed: 0 additions & 71 deletions
This file was deleted.

tasks/test.toml

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,7 @@
11
# Test tasks for EQL
2-
# Combines legacy SQL tests and modern SQLx Rust tests
3-
4-
["test:all"]
5-
description = "Run ALL tests: legacy SQL + SQLx (full test suite)"
6-
depends = ["build"]
7-
run = """
8-
#!/bin/bash
9-
set -euo pipefail
10-
11-
POSTGRES_VERSION="${POSTGRES_VERSION:-17}"
12-
13-
echo "=========================================="
14-
echo "Running Complete EQL Test Suite"
15-
echo "PostgreSQL Version: $POSTGRES_VERSION"
16-
echo "=========================================="
17-
echo ""
18-
19-
# Ensure PostgreSQL is running
20-
echo "→ Starting PostgreSQL $POSTGRES_VERSION..."
21-
mise run postgres:up postgres-${POSTGRES_VERSION} --extra-args "--detach --wait"
22-
23-
# Run legacy SQL tests
24-
echo ""
25-
echo "=========================================="
26-
echo "1/2: Running Legacy SQL Tests"
27-
echo "=========================================="
28-
mise run test:legacy --skip-build --postgres ${POSTGRES_VERSION}
29-
30-
# Run SQLx Rust tests
31-
echo ""
32-
echo "=========================================="
33-
echo "2/2: Running SQLx Rust Tests"
34-
echo "=========================================="
35-
mise run test:sqlx
36-
37-
echo ""
38-
echo "=========================================="
39-
echo "✅ ALL TESTS PASSED"
40-
echo "=========================================="
41-
echo ""
42-
echo "Summary:"
43-
echo " ✓ Legacy SQL tests"
44-
echo " ✓ SQLx Rust tests"
45-
echo ""
46-
"""
2+
# Legacy SQL tests (inline test files)
473

484
["test:legacy"]
495
description = "Run legacy SQL tests (inline test files)"
50-
alias = "test"
516
sources = ["src/**/*_test.sql", "tests/*.sql"]
527
run = "{{config_root}}/tasks/test-legacy.sh"
53-
54-
["test:quick"]
55-
description = "Quick test (skip build, use existing)"
56-
depends = []
57-
run = """
58-
echo "Running quick tests (using existing build)..."
59-
mise run test:legacy --skip-build
60-
"""

0 commit comments

Comments
 (0)