Skip to content

About

Interactive sandbox, cross-repo E2E soak oracle, and pre-release compatibility gauntlet for Auditstream.

Topics

Resources

Code of conduct

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

auditstream-lab

Live sandbox and consumer verification lab for Auditstream against real PostgreSQL, PgBouncer (transaction mode), the compiled auditstream CLI binary, and real npm / packed .tgz installs of @auditstream/* with zero workspace symlinks.

What is inside

  • Infrastructure (docker-compose.yml + docker/init/):
    • PostgreSQL (PG_VERSION=19 by default; compatible with 15 through 19, with version-scoped PGDATA=/var/lib/postgresql/pg${PG_VERSION} inside pg_data).
    • PgBouncer 1.26 (POOL_MODE=transaction, DEFAULT_POOL_SIZE=6, MAX_PREPARED_STATEMENTS=200, AUTH_TYPE=scram-sha-256).
    • Least-privilege runtime role app_user (LOGIN), provisioned on boot. The migration of auditstream init --app-role app_user creates the owner role of each database and grants app_user only SELECT on auditstream.changes and EXECUTE on auditstream.log_event.
    • Two isolated databases: lab_drizzle and lab_prisma.
  • Two live HTTP consumer apps (apps/):
    • apps/hono-drizzle: Hono + Drizzle ORM + @auditstream/node/hono + @auditstream/drizzle/pg (wrapPgPool), covering CRUD, excluded-column no-op updates (password_hash), delegated ai_agent + onBehalfOf, nested SAVEPOINT + rollback + full transaction rollback, direct raw pool.query, audit.log(), and an allowlisted GET /activity BFF feed.
    • apps/prisma-api: Hono + Prisma 7 (@prisma/adapter-pg) + @auditstream/node/hono + @auditstream/prisma SQL comments plugin + auditTransaction() (set_config fallback), audit.log(), and GET /activity.
  • Isolated staging (scripts/bootstrap.sh):
    • Stages clean consumer copies into .tmp/run/ so tracked files in apps/ stay clean and node_modules/@auditstream/* never links to sibling monorepo directories.
    • Writes a per-app pnpm-workspace.yaml (packages: ["."]) and .npmrc (registry=${NPM_REGISTRY}) before running pnpm install --no-frozen-lockfile.
    • Runs real auditstream init --app-role app_user (--migrations drizzle and --migrations prisma), applies the generated migrations, grants app_user access to the application tables, and verifies both databases with auditstream verify.

Prerequisites

  • Docker & Docker Compose v2
  • Bash (3.2+ including stock macOS /bin/bash)
  • Node.js 22.12+ and pnpm 12 (the apps declare packageManager: pnpm@12.15.0)
  • psql, curl, jq, tar, xz, realpath, and sha256sum (or shasum)

Quickstart (published artifacts)

  1. Start PostgreSQL and PgBouncer:

    docker compose up -d
  2. Bootstrap both apps using the latest published GitHub Release binary (SHA-256 verified) and published npm @auditstream/* packages:

    ./scripts/bootstrap.sh
  3. Run the automated end-to-end smoke suite (starts both HTTP servers via PgBouncer as app_user, exercises all flows, checks tamper resistance and pooled PgBouncer pg_prepared_statements, and verifies auditstream status, verify, history including --diff and --format json, and export):

    ./scripts/smoke-interactive.sh
  4. Run the unit tests (Node built-in test runner, zero extra dependencies; on Node 22.12–22.17, pass --experimental-strip-types):

    node --test tests/shared.test.ts tests/soak.test.ts

Continuous integration

ci.yml runs the unit tests on Node 22.12 and 26, and the bootstrap, the smoke suite and a 30-second soak on PostgreSQL 15, 17 and 19 with the latest published CLI and packages. It runs on every pull request and once a week; a manual run can pin the CLI version.

gauntlet.yml runs the pre-release gauntlet when started by hand.

Pre-release gauntlet

Run it before tagging an auditstream or @auditstream/* release, and again with the published version after the release. One command runs, for each PostgreSQL major in turn, on a clean stack:

  1. docker compose up -d --wait with that PG_VERSION.
  2. scripts/bootstrap.sh and scripts/smoke-interactive.sh (the fresh-user flow).
  3. soak/run.sh and its invariant oracle.
  4. scripts/upgrade-check.sh, the upgrade from v0.1.0 to the candidate CLI.
  5. docker compose down -v.

It stops at the first failed step and exits non-zero, after writing the report for what ran:

./gauntlet.sh --pg-versions 15,17,19 --soak-seconds 120 --report release-verification-report.md

Test a release candidate with a local binary and packed tarballs (see Testing local release candidates), or published versions:

AUDITSTREAM_BIN=/path/to/auditstream/target/release/auditstream \
AUDITSTREAM_JS_TGZ_DIR=/path/to/packed-tarballs \
./gauntlet.sh --pg-versions 19 --soak-seconds 30 --report /tmp/release-verification-report.md

AUDITSTREAM_VERSION=0.2.5 ./gauntlet.sh --js-version 0.7.1
  • --pg-versions <list>: PostgreSQL majors, comma-separated (default 15,17,19).
  • --soak-seconds <seconds>: soak duration for each version (default 120, with the soak's default 40 workers).
  • --report <path>: report path (default release-verification-report.md).
  • --js-version <version>: packs @auditstream/{node,drizzle,prisma} at that version from NPM_REGISTRY and installs them like local tarballs. Without it (and without AUDITSTREAM_JS_TGZ_DIR), the apps install what their package.json ranges resolve to.
  • The CLI comes from AUDITSTREAM_BIN, else the release AUDITSTREAM_VERSION, else the latest release, which the gauntlet downloads again on every run so a cached older binary is never tested. Every step uses that one binary.
  • The gauntlet uses its own Compose project, auditstream-lab-gauntlet (or COMPOSE_PROJECT_NAME), so it never removes the volumes of a lab you started with docker compose up. It needs the same ports, so stop that lab first, or set PG_PORT, PGBOUNCER_PORT, HONO_PORT and PRISMA_PORT. After an interrupted run that could not clean up, docker compose -p auditstream-lab-gauntlet down -v removes its stack; the next run also removes it.
  • Logs of every step, the soak reports and the upgrade summaries are in .tmp/gauntlet/.

The report gives the CLI version, where it came from and its SHA-256, the @auditstream/* versions installed, the lab commit, the result and duration of each step for each PostgreSQL version, the soak totals and latencies with its invariants, the upgrade check, the end of the log of a failed step, and the managed cloud status. Managed cloud poolers (Neon, Supabase) are not covered yet: the report says skipped (deferred, auditstream/auditstream#222).

Upgrade from v0.1.0

fixtures/v0.1.0/ pins the SQL that the published v0.1.0 CLI generated for the lab's tables. scripts/upgrade-check.sh installs it in a fresh lab_upgrade database, writes 7 history rows as app_user (INSERT, UPDATE and DELETE with actors in SQL comments, set_config and log_event), and runs the candidate's verify, which reports the drift. It then refreshes the installation in place as verify directs: auditstream init --app-role app_user in the project that v0.1.0 wrote, and the migration it writes, which moves the history from the v0.1 role auditstream_owner to the database's own owner role. It fails unless verify is then clean, init is then up to date, and, after 6 more rows (and one change to an excluded column only, which records nothing), every row written before and after the upgrade is in the table, in history and in export. It needs only a running stack and the CLI, so it also runs alone:

./scripts/upgrade-check.sh --summary /tmp/upgrade.json

The engine documents a reinstall, not this upgrade, for users of 0.1.0 (its init reference). The check covers what the specification requires of a migration over the role v0.1 shared ("Upgrade from another owner role", which keeps every row) and what the engine tests in upgrades_a_v0_1_0_installation_in_place, with the published binaries.

Running it on GitHub

Start gauntlet.yml from the Actions tab or with gh workflow run gauntlet.yml -R auditstream/auditstream-lab -f cli_version=0.2.5. Its inputs:

  • cli_version: the CLI release (empty for the latest).
  • cli_ref: a branch, tag or commit of auditstream/auditstream to build the CLI from instead (takes precedence over cli_version).
  • js_version: the @auditstream/* version from npm (empty for what the apps resolve).
  • pg_versions (default 15,17,19) and soak_seconds (default 120).

The job writes the report to its summary and uploads it as the release-verification-report artifact. It fails when the gauntlet fails.

Testing local release candidates

Point bootstrap.sh at a locally built auditstream binary and a directory containing packed .tgz tarballs (auditstream-node-*.tgz, auditstream-drizzle-*.tgz, auditstream-prisma-*.tgz):

AUDITSTREAM_BIN=/path/to/auditstream/target/release/auditstream \
AUDITSTREAM_JS_TGZ_DIR=/path/to/packed-tarballs \
./scripts/bootstrap.sh

AUDITSTREAM_BIN=/path/to/auditstream/target/release/auditstream \
./scripts/smoke-interactive.sh

bootstrap.sh copies the tarballs into .tmp/run/tarballs, writes a per-app pnpm-workspace.yaml with overrides pointing to those tarballs, installs with pnpm install --no-frozen-lockfile, and fails immediately if any node_modules/@auditstream/* package is missing, dangling, or resolves outside its isolated app directory.

Optional environment variables

Override defaults via the shell or a local .env file (see .env.example; .env is gitignored):

  • PG_VERSION, PG_PORT, PGBOUNCER_PORT, PG_ADMIN_PASSWORD, APP_USER_PASSWORD, HONO_PORT, PRISMA_PORT
  • AUDITSTREAM_BIN: path to a local executable auditstream binary (honored by bootstrap.sh, smoke-interactive.sh, and soak/run.sh).
  • AUDITSTREAM_JS_TGZ_DIR: directory containing packed @auditstream/{node,drizzle,prisma} .tgz tarballs (honored by bootstrap.sh).
  • AUDITSTREAM_VERSION: pin a specific GitHub Release version, 0.2.2 or newer, such as 0.2.4 instead of latest (cached separately per version under .tmp/bin/; honored by bootstrap.sh, smoke-interactive.sh, and soak/run.sh).
  • AUDITSTREAM_FORCE_DOWNLOAD=1: re-download the GitHub Release binary even if already cached (honored by bootstrap.sh, smoke-interactive.sh, and soak/run.sh).
  • NPM_REGISTRY: override the npm registry URL written into staged .npmrc files (default https://registry.npmjs.org/).

Switching PostgreSQL versions

Override PG_VERSION (for example 15, 17, or 19). Always tear down the stack when switching versions cleanly:

docker compose down -v
PG_VERSION=15 docker compose up -d
./scripts/bootstrap.sh
./scripts/smoke-interactive.sh

Interactive exploration

Start both HTTP servers (connected to PgBouncer on 127.0.0.1:6432 as app_user):

./scripts/start-apps.sh

In a second terminal, send sample requests to hono-drizzle (:3101) and prisma-api (:3102):

# 1. Create an invoice as human user alice (passwordHash is excluded from auditstream.changes)
HONO_INV_ID="$(curl -sS -X POST http://127.0.0.1:3101/invoices \
  -H 'content-type: application/json' \
  -H 'x-demo-user: alice' \
  -H 'x-demo-tenant: acme' \
  -d '{"status":"draft","total":"50.00","passwordHash":"secret-1"}' | jq -r '.id')"

# 2. Finalize as a delegated AI agent acting on behalf of alice (with a rolled-back savepoint)
curl -sS -X POST "http://127.0.0.1:3101/invoices/${HONO_INV_ID}/finalize" \
  -H 'content-type: application/json' \
  -H 'x-demo-agent: bot_billing' \
  -H 'x-demo-on-behalf-of: alice' \
  -H 'x-demo-tenant: acme' \
  -d '{"amount":"125.50","description":"Q4 subscription","simulateSavepointRollback":true}'

# 3. Record an application event via audit.log() and inspect the allowlisted BFF activity feed
curl -sS -X POST "http://127.0.0.1:3101/invoices/${HONO_INV_ID}/events" \
  -H 'content-type: application/json' \
  -H 'x-demo-user: alice' \
  -H 'x-demo-tenant: acme' \
  -d '{"action":"invoice.exported","format":"pdf"}'

curl -sS 'http://127.0.0.1:3101/activity?limit=10' | jq

# 4. Exercise Prisma 7 + auditTransaction() (actor_source = set_config) on :3102
PRISMA_INV_ID="$(curl -sS -X POST http://127.0.0.1:3102/invoices \
  -H 'content-type: application/json' \
  -H 'x-demo-user: alice' \
  -H 'x-demo-tenant: acme' \
  -d '{"status":"draft","total":"80.00","passwordHash":"secret-2"}' | jq -r '.id')"

curl -sS -X POST "http://127.0.0.1:3102/invoices/${PRISMA_INV_ID}/approve" \
  -H 'content-type: application/json' \
  -H 'x-demo-agent: bot_approver' \
  -H 'x-demo-on-behalf-of: alice' \
  -H 'x-demo-tenant: acme' \
  -d '{"status":"approved"}'

Inspect the recorded audit trail with the live auditstream CLI:

CLI="$(cat .tmp/run/cli-bin.path)"
DRIZZLE_URL="postgresql://postgres:postgres_dev_password@127.0.0.1:5432/lab_drizzle"
PRISMA_URL="postgresql://postgres:postgres_dev_password@127.0.0.1:5432/lab_prisma"

(cd .tmp/run/hono-drizzle && "$CLI" --database-url "$DRIZZLE_URL" status)
(cd .tmp/run/hono-drizzle && "$CLI" --database-url "$DRIZZLE_URL" verify)
(cd .tmp/run/hono-drizzle && "$CLI" --database-url "$DRIZZLE_URL" history --table public.invoice --diff)
(cd .tmp/run/hono-drizzle && "$CLI" --database-url "$DRIZZLE_URL" history --table public.invoice --format json)
(cd .tmp/run/hono-drizzle && "$CLI" --database-url "$DRIZZLE_URL" export --format jsonl)

(cd .tmp/run/prisma-api && "$CLI" --database-url "$PRISMA_URL" history --table public.invoice --format json)

Note: Demo HTTP headers (x-demo-user, x-demo-agent, x-demo-on-behalf-of, x-demo-tenant) exist solely for local sandbox exploration. Production applications must derive actors and tenants from a verified session or JWT and fail closed on unauthenticated requests.

Soak testing & invariant oracle

Run the concurrent HTTP + SQL soak generator and invariant oracle against both bootstrapped apps (hono-drizzle and prisma-api) via PgBouncer (DEFAULT_POOL_SIZE=6) while executing incremental auditstream export --format jsonl --cursor-file in parallel:

./soak/run.sh --duration 30 --concurrency 20 --out /tmp/soak-report.md

Full 2-minute contention run (defaults: --duration 120 --concurrency 40 --export-interval 2):

./soak/run.sh --duration 120 --concurrency 40

Options:

  • --duration <seconds> — soak duration in seconds (default 120).
  • --concurrency <workers> — total parallel HTTP workers split evenly across hono-drizzle and prisma-api (default 40, min 2).
  • --export-interval <seconds> — background auditstream export --cursor-file interval in seconds (default 2).
  • --out <path> — Markdown summary report path (default .tmp/soak/soak-report.md).
  • --json-out <path> — structured JSON report path (default derived from --out).
  • -h, --help — show CLI usage and exit 0.

What the soak workload exercises and verifies:

  • 35 distinct human actors (user_1..35) and 10 delegated AI agents (ai_agent + onBehalfOf) across INSERT/UPDATE/DELETE, Drizzle nested SAVEPOINT + full ROLLBACK, raw pool.query, Prisma SQL comments + auditTransaction(), excluded-only password_hash updates, mid-flight AbortController cancellations, audit.log(), and cursor-paginated GET /activity.
  • Periodic app_user tamper attempts (DELETE/UPDATE/INSERT on auditstream.changes, asserting 100% rejection with SQLSTATE 42501) and direct unattributed SQL writes over the same PgBouncer pool (asserting zero actor or context bleed).
  • Post-run invariant oracle verifying 0 lost or extra committed 2xx events across both apps, 0 duplicate event_ids, 0 rolled-back/excluded-only/secret leaks, 0 actor mismatches or unaccounted events, 0 auditstream= entries across all 6 distinct pooled pg_backend_pid() sessions, 0 HTTP 5xx or unexpected status responses, and auditstream verify exiting 0.

Clean teardown

Stop and remove all containers, networks, and volumes:

docker compose down -v

To also remove local staged installs and cached binaries:

rm -rf .tmp

About

Interactive sandbox, cross-repo E2E soak oracle, and pre-release compatibility gauntlet for Auditstream.

Topics

Resources

Code of conduct

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages