Skip to content

Commit 723d573

Browse files
committed
tests: add way to run all tests with postgres though slow
Also adding note that postgres is not in active use so might not work out the box
1 parent e1ec3b4 commit 723d573

5 files changed

Lines changed: 52 additions & 1 deletion

File tree

config.template.jsonc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@
161161
"database": {
162162
// `sqlite` for single-node/dev, `mysql` for MariaDB/MySQL,
163163
// or `postgres` for PostgreSQL.
164+
//
165+
// NOTE: `postgres` support is a community contribution and is not
166+
// exercised by Puter.com production. It boots, passes its own
167+
// integration tests against pgmock, and runs the common user/app/
168+
// fsentry/session/permission/OIDC flows — but less-traveled code
169+
// paths may surface MySQL/SQLite-isms that haven't been ported yet.
170+
// Expect rough edges and please file issues if you hit one. For
171+
// production self-hosting today, `mysql` (MariaDB) and `sqlite` are
172+
// the supported defaults.
164173
"engine": "sqlite",
165174
// sqlite — file path on disk
166175
"path": "volatile/runtime/puter-database.sqlite",

doc/self-hosting.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ All optional. Drop any of the blocks below into `puter/config/config.json` and `
234234

235235
### PostgreSQL database
236236

237+
> **Community contribution — expect rough edges.** PostgreSQL support was contributed by the community and is not run by Puter.com production. It boots, applies the bundled schema, and exercises the common user/app/fsentry/session/permission/OIDC flows in the integration tests, but less-traveled SQL call sites may still need porting. If you hit a query that doesn't work on Postgres, please open an issue. For production self-hosting today, MariaDB/MySQL and SQLite are the supported defaults.
238+
237239
The bundled Docker Compose stack still defaults to MariaDB. To use PostgreSQL instead, run a PostgreSQL service yourself, point Puter at it, and use the PostgreSQL migration path:
238240

239241
```json

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
"scripts": {
4747
"test:backend": "vitest run --config src/backend/vitest.config.ts ",
48+
"test:backend:postgres": "PUTER_TEST_DB_ENGINE=postgres vitest run --config src/backend/vitest.config.ts ",
4849
"start=gui": "nodemon --exec \"node dev-server.js\" ",
4950
"start": "node --enable-source-maps -r ./dist/src/backend/telemetry.js ./dist/src/backend/index.js",
5051
"prestart": "npm run build:ts",

src/backend/testUtil.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ export const createPgMockPostgresDatabaseClient = async (
6666
};
6767
};
6868

69+
/**
70+
* When `PUTER_TEST_DB_ENGINE=postgres` is set, `setupTestServer` swaps its
71+
* default sqlite test database for an in-memory Postgres backed by pgmock
72+
* (with the bundled Postgres migrations applied on boot). Tests that
73+
* explicitly override `database` still win — the env var only affects the
74+
* implicit default used by callers that don't pass any DB overrides.
75+
*
76+
* Recognized values: `postgres` → pgmock. Anything else (including unset) →
77+
* the original sqlite-in-memory default.
78+
*/
79+
const testDatabaseDefault = (): IConfig['database'] => {
80+
const engine = (process.env.PUTER_TEST_DB_ENGINE ?? '').toLowerCase();
81+
if (engine === 'postgres') {
82+
return {
83+
engine: 'postgres',
84+
inMemory: true,
85+
migrationPaths: [POSTGRES_TEST_MIGRATIONS_PATH],
86+
};
87+
}
88+
return { engine: 'sqlite', inMemory: true };
89+
};
90+
6991
export const setupTestServer = async (
7092
configOverrides?: IConfig,
7193
): Promise<PuterServer> => {
@@ -80,7 +102,7 @@ export const setupTestServer = async (
80102
deepMerge(defaultConfig, {
81103
extensions: [],
82104
port: 0,
83-
database: { engine: 'sqlite', inMemory: true },
105+
database: testDatabaseDefault(),
84106
dynamo: { inMemory: true, bootstrapTables: true },
85107
redis: { useMock: true },
86108
s3: { localConfig: { inMemory: true } },

src/backend/vitest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ const isCi = process.env.CI === 'true';
2727
const backendDir = __dirname;
2828
const repoRoot = path.resolve(backendDir, '../..');
2929

30+
// pgmock boots a WASM-emulated Postgres on every `setupTestServer()` call —
31+
// migrations alone take ~60s, and the WASM VM serializes badly across
32+
// concurrent emulator instances. So in pgmock mode we (a) bump hook/test
33+
// timeouts well beyond the 10s default and (b) disable file parallelism so
34+
// only one pgmock VM runs at a time. Tests still race their own logic
35+
// internally; we only serialize the *files*.
36+
const isPgmockMode =
37+
(process.env.PUTER_TEST_DB_ENGINE ?? '').toLowerCase() === 'postgres';
38+
const pgmockTimeoutMs = 600_000;
39+
3040
// Vite 8's oxc transform leaves TC39 stage-3 decorators in place
3141
// (used by `@Controller`/`@Post`), so they reach Node verbatim and
3242
// crash with "SyntaxError: Invalid or unexpected token". Pre-transform
@@ -72,6 +82,13 @@ export default defineConfig(({ mode }) => ({
7282
},
7383
test: {
7484
globals: true,
85+
...(isPgmockMode
86+
? {
87+
testTimeout: pgmockTimeoutMs,
88+
hookTimeout: pgmockTimeoutMs,
89+
fileParallelism: false,
90+
}
91+
: {}),
7592
coverage: {
7693
provider: 'v8',
7794
reporter: isCi

0 commit comments

Comments
 (0)