Open History to see the last commit
1# Development and testing
2
3Use Node.js 24 (pinned in `.node-version` and `mise.toml`) and pnpm 10.32.1. Database-backed tests use actual Neon Postgres 18, Realtime, and Object Storage on disposable branches. Docker is not required.
4
5## Fast checks
6
7```sh
8mise exec node@24 -- pnpm install --frozen-lockfile
9mise exec node@24 -- pnpm check
10mise exec node@24 -- pnpm test:package
11```
12
13`pnpm test` runs the unit/property suite without a database or cloud credentials. `pnpm check` adds the build, typecheck, and consumer example typecheck. `pnpm test:package` installs a packed tarball in a temporary consumer and verifies public declarations, runtime exports, SQL assets, and licensing; it can fetch missing dependencies from the registry.
14
15## Neon tests from a development machine
16
17Copy [.env.example](../.env.example) to `.env.neon.local` and fill in a project-scoped `NEON_API_KEY`, `NEON_PROJECT_ID`, and non-expiring `NEON_PARENT_BRANCH_ID`. Provisioning creates a fresh branch and writes `.env.neon.test`; deployment also writes `.env.neon.function`. These files contain generated credentials and are ignored by Git. The commands below invoke Node entrypoints directly so `--env-file` applies to the process running the task.
18
19```sh
20mise exec node@24 -- pnpm build
21mise exec node@24 -- pnpm neon:test:create
22mise exec node@24 -- node --env-file=.env.neon.local --env-file=.env.neon.test scripts/neon-test-function.mjs
23mise exec node@24 -- node --env-file=.env.neon.test --env-file=.env.neon.function node_modules/vitest/vitest.mjs run --project function
24mise exec node@24 -- node --env-file=.env.neon.local --env-file=.env.neon.test node_modules/vitest/vitest.mjs run --project neon --testTimeout=300000
25mise exec node@24 -- node --env-file=.env.neon.test node_modules/vitest/vitest.mjs run --project integration
26mise exec node@24 -- node --env-file=.env.neon.local --env-file=.env.neon.test node_modules/vitest/vitest.mjs run --project recovery
27mise exec node@24 -- node --env-file=.env.neon.local --env-file=.env.neon.test scripts/neon-test-conformance.mjs
28mise exec node@24 -- pnpm neon:test:delete
29```
30
31Always run cleanup after a failure too. Provisioning records ownership before fetching credentials, refuses to overwrite an existing environment, and creates a branch with a 24-hour expiry. Cleanup deletes the recorded branch and its matching generated environment files. Do not use the parent branch as a test target.
32
33Tests create random `ds_test_*` schemas and remove them during teardown. They use explicit test connection strings, never an application's `DATABASE_URL`. Pooled connections serve requests; direct connections run migrations and tests of persistent session settings. The complete [four-file baseline](migrations.md) is installed before serving; earlier development histories require a fresh schema.
34
35| Command | Coverage |
36| --- | --- |
37| `test:integration` | Postgres transactions, concurrency, producer semantics, and child-process loss before/after commit |
38| `test:neon` | Real Realtime and Object Storage, replay, forks, subscriptions, collection, migration safety, operations, and eight packed multi-instance checks |
39| `test:function` | Deployed consumer ingress, authenticated streaming, sealed replay, public HTTPS webhooks, and cron recovery |
40| `test:recovery` | Point-in-time child-branch adoption and stopped-Function in-place restore |
41| `test:conformance:neon` | All 338 pinned upstream cases colocated on Neon, with subscriptions and collection enabled |
42
43`pnpm test:conformance` runs the same full suite from the coordinator on your machine against Neon services. Cross-region SQL latency can exceed deadlines inside upstream cases; the colocated command is the CI qualification gate. Use Vitest's file or test-name filters for focused debugging, then run the full suite for qualification. See [colocated conformance](neon-conformance-v1.md) for packaging and provenance.
44
45The loopback HTTP adapter and webhook receivers are active test fixtures. They run beside the test coordinator, including inside the conformance Neon Function, while Postgres, Realtime, and Object Storage remain actual Neon services. Separate deployed-ingress tests use a public HTTPS receiver. These fixtures are excluded from the library build.
46
47## CI and qualification
48
49[Required CI](../.github/workflows/ci.yml) has separate build/unit/package, Neon qualification, and append-hint jobs. Provisioning supplies generated credentials to later steps. Missing required credentials fail qualification. Fork PRs need review and a trusted maintainer run; the workflow does not execute fork code with secrets through `pull_request_target`.
50
51The Neon data and transaction CI profiles execute their unchanged Vitest fixtures in an authenticated temporary Neon Function. This removes coordinator SQL latency from test timing. The source manifest checks that every expected file ran with no failed or skipped tests. The Neon data profile runs every `test/neon` file except `rolling.test.ts`; CI executes that control-plane fixture separately through independently packed consumer Functions. No management credentials are sent to the data-test coordinator. The complete conformance profile still runs all 338 upstream cases without filters.
52
53For these colocated profiles, set `NEON_QUALIFICATION_PROFILE=neon` or `integration` when invoking `scripts/neon-test-conformance.mjs` with the recorded test environment. An unset profile runs full conformance. The local `test:neon` and `test:integration` commands remain useful for focused debugging.
54
55The ordinary Function profile disables append hints and tests scheduled recovery. The separate hints job uses a fresh branch with hints enabled and no cron: `test:hints` verifies Realtime pull wakes, full-chunk sealing, and smaller tails remaining in Postgres. It requires that profile's Function environment.
56
57The packed multi-instance fixture installs the current tarball into an independent consumer and deploys two Functions on a dedicated schema. It records four reserved Function slugs, including fresh deployments after recovery, before allocation. All eight checks and cleanup must pass. This tests coordination between instances; it does not establish cross-version compatibility. See the [compatibility contract](upgrade-compatibility-v1.md).
58
59Recovery tests allocate additional recorded branches. The child-branch drill temporarily removes its disposable parent's expiry because Neon forbids children of expiring branches, then restores it after cleanup. The in-place drill stops its Function/cron, drains SSE, restores a recorded WAL point, reconciles HOT/SEALED data, and deploys a fresh instance before checking replay, Realtime payloads, and token fencing. CI retries interrupted cleanup, and the [scheduled janitor](../.github/workflows/test-janitor.yml) removes recognized stale test branches after runner loss. See the [in-place runbook](inplace-restore-v1.md) for diagnostic preservation and cleanup.
60
61Remote coordinator tests allow explicit 120-second transaction/90-second lock budgets; deployed Function tests retain production defaults. The local Neon command gives database-heavy cases a 300-second outer budget for distant coordinators; CI retains its configured default. This changes neither their samples/assertions nor explicit Realtime delivery deadlines. Realtime delivery cases keep their shorter deadlines below the SQL fallback interval. The opt-in `test/fixtures/sql-latency.mjs` can delay SQL sends to reproduce distant-coordinator contention against real Neon; it is not shipped or enabled by default.
62
63[Load qualification](../.github/workflows/load-qualification.yml) is a separate manual workflow. Run it for capacity and sustained delivery evidence. Current test counts, exact source revisions, historical measurements, and unresolved qualification limits belong in the [qualification index](qualification/README.md).