Repository navigation
fix: isolate PGlite schema generation for initialized projects - #100
Open
1932819331hy-debug wants to merge 9 commits into
Open
1932819331hy-debug wants to merge 9 commits into
1932819331hy-debug wants to merge 9 commits into
Conversation
Track and destroy owned gateway sockets, await server and database cleanup on success and failure, and reject failed listener startup. Preserve original and cleanup errors together. Add real PGlite lifecycle and error-composition regressions.
1932819331hy-debug
marked this pull request as ready for review
October 19, 2026 06:42
Ask PGlite to return protocol ErrorResponse frames instead of throwing SQL errors into the generic gateway fallback. Add real simple and extended query regressions covering SQLSTATE, original messages and post-error recovery.
Generate an ES module default export for type:module projects so the built Node CLI can load the initialized configuration. Preserve CommonJS defaults and existing configuration files. Add real Node import regressions for all three project modes.
Encode the project config path with pathToFileURL before dynamic import so literal #, ? and percent characters reach the correct file. Retain CommonJS and ES module loading. Add real Node loader regressions, excluding question-mark paths on Windows where those directory names are invalid. Related to seveibar#8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New projects initialized with
pgstrap inituse PGlite fordb:generate, so schema generation does not need an external PostgreSQL server. The publicgenerate()default stays unchanged. Connection aliases are scoped to the schema-export child process, preserving the caller environment and isolation between concurrent PGlite and external-database calls.Security and lifecycle corrections
The lifecycle defect was reproduced with the real built Node library: generate() returned while the database remained open and an idle gateway connection remained alive. Migration exceptions also left the database open.
PostgreSQL protocol errors
The temporary gateway now asks PGlite to return PostgreSQL ErrorResponse frames. Previously, ordinary SQL failures threw into the adapter's generic fallback and clients received SQLSTATE
123/ "Message code not yet implemented" instead of the original error.Missing-table, syntax and division-by-zero queries still reject. Their standard SQLSTATE and original messages are preserved, and the connection can recover for subsequent simple and parameterized queries.
Initialization in ES module projects
When the target package declares
type: "module",pgstrap initnow writes an ES module default export inpgstrap.config.js. Default and explicit CommonJS packages keep CommonJS exports. Existing configuration files are preserved. This fixes a real built-CLI failure where initialization succeeded but the next generate command raisedmodule is not defined.Configuration paths
The project configuration loader now converts its absolute filesystem path with
pathToFileURL(...).hrefbefore dynamic import. The real Node CLI previously raisedERR_MODULE_NOT_FOUNDfor existing configurations under directories containing literal#,?or%25because the path was interpreted as URL syntax.This is the path-import root cause already recorded in issue #8. The regression was reproduced independently on this PR's previous head; no first-discovery or new Windows execution claim is made.
Current validation — 2026-10-19
Published head:
dcf621142c5aa028efba4e8ae84e3d2a259d06c1(parentf4f9818e9a77be1cf3e5a2fde5079596a0eed187).npm run buildgit diff --checkThe initial eight CLI boundary scenarios also checked space/Unicode paths and custom output directories, repeated initialization preserving existing files/dependencies, missing and malformed configuration, and a real schema-dump child failure followed by successful recovery. Those five unaffected scenarios passed on the predecessor; the three failing path cases were then re-run on the final built CLI. The earlier 18-case full suite below was not re-run for this two-file follow-up.
Local validation used Node 24.19.0 and Bun 1.4.3 with existing locked dependencies. The final CLI bundle has SHA-256
7288c25e540ba9a886352a949cd7f95bf767cc83c4f8b49ea41785d501d0d48e. The new test excludes the?directory case on Windows because that filename is invalid there; Windows execution remains unverified locally.Upstream checks for this exact new head require maintainer approval: Build, Bun Test, and Format Check all report
action_required. They have not executed and are not passing-test evidence.Earlier initialization validation —
f4f9818Tested previous head:
f4f9818e9a77be1cf3e5a2fde5079596a0eed187.50bc792for an ES module project, while default and explicit CommonJS cases pass.bun test: 10 outer cases plus 1 gateway, 4 cleanup and 3 concurrency fixture cases all passed — 18 cases and 62 assertions.generate --pglitein three fresh projects: default package type, explicit CommonJS and ES module. Every run applied a real SQL migration and produced fresh Zapatos types and table SQL while POSTGRES_URI, PG_URI, DATABASE_URL and DATABASE_URI pointed to an unreachable external endpoint.npm run build, including declarations: passed.npm run format:check: all 21 files passed;git diff --checkpassed.Local tests used Bun 1.4.3 with the frozen lockfile. On that recorded head, Build, Bun Test and Format Check require maintainer approval (
action_required); they have not executed and are not claimed as passing.Earlier protocol evidence —
50bc792The real gateway regression failed on predecessor
3b80946when an absent table lost its42P01response. The fix passed missing-table and parameterized division-by-zero regressions, including recovery and generated output. Independent built-Node validation also checked syntax42601, division by zero22012and successful subsequent queries. The earlier full suite retains the gateway, cleanup and connection-environment isolation regressions.Earlier integration evidence —
3b80946The built CLI completed init -> generated db:generate script -> npm run db:generate while POSTGRES_URI, PG_URI, DATABASE_URL and DATABASE_URI pointed to an unreachable external endpoint, producing fresh types and SQL. The lifecycle probe reported databaseClosed=true, gatewayListening=false and remainingConnections=0. The earlier suite continues to cover lifecycle cleanup and combined generation/cleanup failures; this earlier CLI run is identified by its own head.
Fork-only validation PR #1 remains an evidence reference. Implemented and independently reviewed with AI assistance.
@algora-pbc /claim #2