Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Maintainer ownership; existing repository review rules are unchanged.
* @scottconverse
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: pip
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 5
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 5
58 changes: 58 additions & 0 deletions .github/scripts/prepare-windows-test-db.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
param([switch]$WithVector, [switch]$WithPostgis)
$ErrorActionPreference = 'Stop'
$pgroot = $env:PGROOT
if (-not $pgroot) { $pgroot = 'C:\Program Files\PostgreSQL\17' }
$pgbin = Join-Path $pgroot 'bin'
if (-not (Test-Path (Join-Path $pgbin 'initdb.exe'))) { throw 'Hosted Windows PostgreSQL 17 tools are missing.' }
if ($WithVector) {
$vector = Join-Path $env:RUNNER_TEMP 'townlight-test-pgvector'
git clone --depth 1 --branch v0.8.2 https://github.com/pgvector/pgvector.git $vector
if ($LASTEXITCODE -ne 0) { throw 'pgvector source checkout failed.' }
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
$vs = & $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
$devcmd = Join-Path $vs 'Common7\Tools\VsDevCmd.bat'
if (-not (Test-Path $devcmd)) { throw 'Hosted MSVC build tools are missing.' }
Push-Location $vector
try {
$command = 'call "' + $devcmd + '" -arch=x64 -host_arch=x64 >nul && set "PGROOT=' + $pgroot + '" && nmake /F Makefile.win && nmake /F Makefile.win install'
& cmd.exe /d /s /c $command
if ($LASTEXITCODE -ne 0) { throw 'Windows pgvector build/install failed.' }
} finally { Pop-Location }
}
if ($WithPostgis) {
$archive = Join-Path $env:RUNNER_TEMP 'postgis.zip'
Invoke-WebRequest -Uri 'https://download.osgeo.org/postgis/windows/pg17/archive/postgis-bundle-pg17-3.6.2x64.zip' -OutFile $archive
if ((Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant() -ne '7ba180ee2a352987b9a2f194673652c59483b55852295ccf401dceccd8765425') { throw 'PostGIS hash mismatch.' }
$unpack = Join-Path $env:RUNNER_TEMP 'postgis'
Expand-Archive -LiteralPath $archive -DestinationPath $unpack
$bundle = Join-Path $unpack 'postgis-bundle-pg17-3.6.2x64'
foreach ($name in @('bin','lib','share')) {
Get-ChildItem -LiteralPath (Join-Path $bundle $name) -Force | Copy-Item -Destination (Join-Path $pgroot $name) -Recurse -Force
}
}
"PGBIN=$pgbin" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
$cluster = Join-Path $env:RUNNER_TEMP 'townlight-test-pg'
$password = [Guid]::NewGuid().ToString('N')
Write-Output "::add-mask::$password"
$pwfile = Join-Path $env:RUNNER_TEMP 'townlight-test-pg-password'
[IO.File]::WriteAllText($pwfile, $password)
try {
& "$pgbin\initdb.exe" -D $cluster -U postgres --auth=scram-sha-256 --pwfile=$pwfile --encoding=UTF8
if ($LASTEXITCODE -ne 0) { throw 'Private test cluster initialization failed.' }
} finally { Remove-Item -LiteralPath $pwfile -Force }
& "$pgbin\pg_ctl.exe" -D $cluster -l (Join-Path $env:RUNNER_TEMP 'townlight-test-pg.log') -o '-h 127.0.0.1 -p 55439' -w start
if ($LASTEXITCODE -ne 0) { throw 'Private loopback test cluster failed to start.' }
$env:PGPASSWORD = $password
& "$pgbin\createdb.exe" -h 127.0.0.1 -p 55439 -U postgres planning_p1p2_test
if ($LASTEXITCODE -ne 0) { throw 'Private test database creation failed.' }
"DATABASE_URL=postgresql+asyncpg://postgres:$password@127.0.0.1:55439/postgres" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"PLANNING_TEST_DATABASE_URL=postgresql+psycopg2://postgres:$password@127.0.0.1:55439/planning_p1p2_test" | Out-File $env:GITHUB_ENV -Append -Encoding utf8

foreach ($name in @('townlight_meetings_windows_test','townlight_zoning_test')) {
& "$pgbin/createdb.exe" -h 127.0.0.1 -p 55439 -U postgres $name
if ($LASTEXITCODE -ne 0) { throw "Could not create $name" }
}
"TOWNLIGHT_MEETINGS_TEST_DATABASE_URL=postgresql+psycopg2://postgres:$password@127.0.0.1:55439/townlight_meetings_windows_test" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"TOWNLIGHT_ZONING_TEST_DATABASE_URL=postgresql+psycopg2://postgres:$password@127.0.0.1:55439/townlight_zoning_test" | Out-File $env:GITHUB_ENV -Append -Encoding utf8

"TOWNLIGHT_CORE_TEST_DATABASE_URL=postgresql+psycopg2://postgres:$password@127.0.0.1:55439/postgres" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
30 changes: 30 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CodeQL
'on':
pull_request:
paths:
- '**/*.py'
- '**/*.js'
- '**/*.ts'
- '**/*.tsx'
- '**/*.jsx'
- '**/pyproject.toml'
- '**/package*.json'
- .github/workflows/codeql.yml
workflow_dispatch: null
permissions:
contents: read
security-events: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
analyze:
runs-on: windows-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v5
- uses: github/codeql-action/init@v4
with:
languages: python
build-mode: none
- uses: github/codeql-action/analyze@v4
28 changes: 21 additions & 7 deletions .github/workflows/windows-contracts.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Windows component contracts
on:
pull_request:
paths: ["**/*.py", "**/pyproject.toml", ".github/workflows/windows-contracts.yml"]
push:
paths: ["**/*.py", "**/pyproject.toml", ".github/workflows/windows-contracts.yml"]
branches: [main]
paths: ["**/*.py", "**/*.toml", "**/*.sql", "**/*.json", "**/*.ini", "**/*.cfg", "**/*.ps1", "**/*.sh", "**/*.yaml", "**/*.yml", "**/requirements*.txt", "**/*.lock"]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
windows-contracts:
runs-on: windows-latest
timeout-minutes: 20
timeout-minutes: 45
defaults:
run:
working-directory: .
Expand All @@ -20,14 +20,28 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: '3.13'
cache: pip
cache-dependency-path: '**/pyproject.toml'
- name: Install component and test tools
run: python -m pip install -e ".[dev]" pytest
- name: Run existing Windows contracts
run: python -X utf8 -m pytest tests/test_auth_suite_session.py tests/test_security_config_validation.py tests/test_connector_manifest.py tests/test_export_bundle.py -q --junitxml=windows-contracts.xml
- name: Prepare isolated native PostgreSQL fixture
shell: pwsh
run: ./.github/scripts/prepare-windows-test-db.ps1 -WithVector
- name: Run full Python suite on Windows
run: python -X utf8 -m pytest tests -q -ra --junitxml=windows-contracts.xml
- name: Preserve results
if: always()
uses: actions/upload-artifact@v4
with:
name: windows-contract-results
path: ./windows-contracts.xml
retention-days: 7
- name: Stop owned test database
if: always()
shell: pwsh
run: |
$cluster = Join-Path $env:RUNNER_TEMP 'townlight-test-pg'
if (Test-Path (Join-Path $cluster 'postmaster.pid')) {
& "$env:PGBIN/pg_ctl.exe" -D $cluster -m fast -w stop
if ($LASTEXITCODE -ne 0) { throw 'Owned test database did not stop.' }
}
7 changes: 7 additions & 0 deletions docs/WINDOWS-CI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Windows component testing

The Windows component workflow collects and runs the full Python tests directory.
SQL, configuration, dependency and script changes trigger the job alongside Python changes.
JUnit results retain exact passes, failures and explicit platform/dependency skips.
The existing hosted database/browser checks remain; component tests do not establish signed MSI installed acceptance.
The obsolete manual release-preflight workflow is preserved under docs/history/retired-workflows-2026-11, not used to describe current release readiness.
32 changes: 32 additions & 0 deletions tests/_postgres_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Disposable real PostgreSQL databases for hosted Windows and Docker tests."""
from contextlib import contextmanager
import os
import uuid
from sqlalchemy import create_engine, text
from sqlalchemy.engine import make_url


@contextmanager
def postgres_fixture(image):
native = os.environ.get("TOWNLIGHT_CORE_TEST_DATABASE_URL")
if not native:
from testcontainers.postgres import PostgresContainer
with PostgresContainer(image) as database:
yield database
return
url = make_url(native)
assert url.host in {"127.0.0.1", "localhost"}
assert url.port == 55439 and url.database == "postgres"
name = "townlight_core_ci_" + uuid.uuid4().hex
admin = create_engine(url, isolation_level="AUTOCOMMIT")
class NativeDatabase:
def get_connection_url(self):
return url.set(database=name).render_as_string(hide_password=False)
try:
with admin.connect() as connection:
connection.execute(text(f'CREATE DATABASE "{name}"'))
yield NativeDatabase()
finally:
with admin.connect() as connection:
connection.execute(text(f'DROP DATABASE IF EXISTS "{name}" WITH (FORCE)'))
admin.dispose()
6 changes: 4 additions & 2 deletions tests/test_baseline_idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"testcontainers.postgres",
reason="testcontainers[postgres] not installed; install dev extras to run idempotency tests",
)
PostgresContainer = testcontainers.PostgresContainer
from tests._postgres_fixture import postgres_fixture # noqa: E402

from townlight_core.migrations.runner import current_revision, upgrade_to_head # noqa: E402
from townlight_core.migrations.versions.townlight_core_0001_baseline_v1 import ( # noqa: E402
Expand All @@ -33,6 +33,8 @@ def _docker_available() -> bool:
when the daemon is unreachable. We probe once at fixture setup so that
dev machines without Docker get a clear skip rather than a stack trace.
"""
if os.environ.get("TOWNLIGHT_CORE_TEST_DATABASE_URL"):
return True
try:
import docker # type: ignore[import-untyped]

Expand All @@ -58,7 +60,7 @@ def pg_container():
"Docker daemon not reachable — idempotency tests require testcontainers "
"with a running Docker host. Install Docker Desktop or run in CI."
)
with PostgresContainer("pgvector/pgvector:pg17") as pg:
with postgres_fixture("pgvector/pgvector:pg17") as pg:
yield pg


Expand Down
6 changes: 4 additions & 2 deletions tests/test_llm_migration_0002.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"testcontainers.postgres",
reason="testcontainers[postgres] not installed; install dev extras to run migration tests",
)
PostgresContainer = testcontainers.PostgresContainer
from tests._postgres_fixture import postgres_fixture # noqa: E402

import townlight_core # noqa: E402
from townlight_core.migrations.runner import current_revision, upgrade_to_head # noqa: E402
Expand All @@ -36,6 +36,8 @@

def _docker_available() -> bool:
"""Return True if a Docker daemon is reachable; False otherwise."""
if os.environ.get("TOWNLIGHT_CORE_TEST_DATABASE_URL"):
return True
try:
import docker # type: ignore[import-untyped]

Expand All @@ -53,7 +55,7 @@ def pg_container():
"Docker daemon not reachable — migration tests require testcontainers "
"with a running Docker host. Install Docker Desktop or run in CI."
)
with PostgresContainer("pgvector/pgvector:pg17") as pg:
with postgres_fixture("pgvector/pgvector:pg17") as pg:
yield pg


Expand Down
6 changes: 4 additions & 2 deletions tests/test_llm_registry_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"testcontainers.postgres",
reason="testcontainers[postgres] not installed; install dev extras to run service tests",
)
PostgresContainer = testcontainers.PostgresContainer
from tests._postgres_fixture import postgres_fixture # noqa: E402

from townlight_core.llm.context import DEFAULT_CONTEXT_WINDOW # noqa: E402
from townlight_core.llm.registry import ( # noqa: E402
Expand All @@ -53,6 +53,8 @@

def _docker_available() -> bool:
"""Return True if a Docker daemon is reachable; False otherwise."""
if os.environ.get("TOWNLIGHT_CORE_TEST_DATABASE_URL"):
return True
try:
import docker # type: ignore[import-untyped]

Expand Down Expand Up @@ -113,7 +115,7 @@ def pg_container():
"Docker daemon not reachable — service tests require testcontainers "
"with a running Docker host. Install Docker Desktop or run in CI."
)
with PostgresContainer("pgvector/pgvector:pg17") as pg:
with postgres_fixture("pgvector/pgvector:pg17") as pg:
yield pg


Expand Down
6 changes: 4 additions & 2 deletions tests/test_llm_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"testcontainers.postgres",
reason="testcontainers[postgres] not installed; install dev extras to run resolver tests",
)
PostgresContainer = testcontainers.PostgresContainer
from tests._postgres_fixture import postgres_fixture # noqa: E402

from townlight_core.llm.templates.engine import RenderedPrompt, render_template # noqa: E402
from townlight_core.llm.templates.exceptions import ( # noqa: E402
Expand All @@ -58,6 +58,8 @@

def _docker_available() -> bool:
"""Return True if a Docker daemon is reachable; False otherwise."""
if os.environ.get("TOWNLIGHT_CORE_TEST_DATABASE_URL"):
return True
try:
import docker # type: ignore[import-untyped]

Expand Down Expand Up @@ -120,7 +122,7 @@ def pg_container():
"Docker daemon not reachable — resolver tests require testcontainers "
"with a running Docker host. Install Docker Desktop or run in CI."
)
with PostgresContainer("pgvector/pgvector:pg17") as pg:
with postgres_fixture("pgvector/pgvector:pg17") as pg:
yield pg


Expand Down
6 changes: 4 additions & 2 deletions tests/test_platform_task_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"testcontainers.postgres",
reason="testcontainers[postgres] not installed; install dev extras to run queue tests",
)
PostgresContainer = testcontainers.PostgresContainer
from tests._postgres_fixture import postgres_fixture # noqa: E402

from townlight_core.migrations.runner import upgrade_to_head # noqa: E402
from townlight_core.platform import ( # noqa: E402
Expand All @@ -37,6 +37,8 @@


def _docker_available() -> bool:
if os.environ.get("TOWNLIGHT_CORE_TEST_DATABASE_URL"):
return True
try:
import docker # type: ignore[import-untyped]

Expand Down Expand Up @@ -71,7 +73,7 @@ def _async_url(sync_url: str) -> str:
def pg_container():
if not _docker_available():
pytest.skip("Docker daemon not reachable; queue tests require a PostgreSQL container.")
with PostgresContainer("pgvector/pgvector:pg17") as pg:
with postgres_fixture("pgvector/pgvector:pg17") as pg:
yield pg


Expand Down
Loading