From 249e45673d49f8824e5af062659f7e7e0a8e0898 Mon Sep 17 00:00:00 2001 From: Ricardo Boni Date: Tue, 1 Sep 2026 14:31:12 -0400 Subject: [PATCH] fix(standalone): initialize new clusters on PostgreSQL 16 The bundled PostgreSQL 18 Windows build links against libwinpthread-1.dll but does not ship it, so initdb cannot launch postgres on a machine without a MinGW toolchain and misreports the failure as a missing program. Every fresh standalone install on a stock Windows box failed this way. Initialize new clusters on 16 instead. Existing clusters are unaffected -- the data directory's own major is still honored. Co-Authored-By: Claude Opus 5 (1M context) --- testgen/common/standalone_postgres.py | 5 ++++- tests/unit/common/test_standalone_postgres.py | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/testgen/common/standalone_postgres.py b/testgen/common/standalone_postgres.py index bc12efcf..c25cb8c5 100644 --- a/testgen/common/standalone_postgres.py +++ b/testgen/common/standalone_postgres.py @@ -22,7 +22,10 @@ STANDALONE_MODE_ENV_VAR = "TG_STANDALONE_MODE" HOME_DIR_ENV_VAR = "TG_TESTGEN_HOME" STANDALONE_URI_ENV_VAR = "_TG_STANDALONE_URI" -NEW_INSTALL_POSTGRES_VERSION = 18 +# pgserver also bundles PostgreSQL 18, but its Windows build links against libwinpthread-1.dll +# without shipping it, so initdb cannot start postgres on a machine that has no MinGW toolchain. +# Raise this once that build runs on a stock Windows box. +NEW_INSTALL_POSTGRES_VERSION = 16 # Stored as ``project_host`` in the demo-DB connection row so that the actual # host/port — which can change across sessions on Windows (pgserver picks a diff --git a/tests/unit/common/test_standalone_postgres.py b/tests/unit/common/test_standalone_postgres.py index 35c106fe..2e7599e1 100644 --- a/tests/unit/common/test_standalone_postgres.py +++ b/tests/unit/common/test_standalone_postgres.py @@ -39,10 +39,17 @@ def test_fresh_data_dir_uses_new_install_version(fake_pgserver, tmp_path): ) -def test_existing_data_dir_honors_on_disk_version(fake_pgserver, tmp_path): - # A cluster initialized by an older bundled major must keep running on it. - fake_pgserver.pgdata_version.return_value = 16 +def test_new_install_version_is_16(): + # The bundled PostgreSQL 18 Windows build needs a MinGW runtime it does not ship, + # so a fresh cluster must be initialized on 16. + assert standalone_postgres.NEW_INSTALL_POSTGRES_VERSION == 16 + + +@pytest.mark.parametrize("on_disk_version", [16, 18]) +def test_existing_data_dir_honors_on_disk_version(fake_pgserver, tmp_path, on_disk_version): + # A cluster keeps running on the major that initialized it, whichever that was. + fake_pgserver.pgdata_version.return_value = on_disk_version standalone_postgres.start_server(tmp_path / "pgdata") - assert fake_pgserver.get_server.call_args.kwargs["postgres_version"] == 16 + assert fake_pgserver.get_server.call_args.kwargs["postgres_version"] == on_disk_version